示例#1
0
async def get_all_moods(template_id: str = None,
                        db: Session = Depends(get_db)):
    if template_id:
        template = get_mood_template(db, template_id)
        if not template:
            raise NoResourceWithIdError("mood_template", template_id)
    return crud.get_all_moods(db, template_id)
示例#2
0
def create_mood(db: Session, mood: MoodCreate):
    template = get_mood_template(db, mood.template_id)
    mood_model = model.Mood(
        public_id=str(uuid.uuid4()),
        name=mood.name,
        colour=mood.colour.as_hex(),
        template=template,
    )
    db.add(mood_model)
    db.commit()
    db.refresh(mood_model)
    return mood_model
示例#3
0
async def get_mood_template(template_id: str, db: Session = Depends(get_db)):
    template = crud.get_mood_template(db, template_id)
    if not template:
        raise NoResourceWithIdError("mood_template", template_id)
    return template
示例#4
0
async def create_mood(mood: schema.MoodCreate, db: Session = Depends(get_db)):
    template = get_mood_template(db, mood.template_id)
    if not template:
        raise NoResourceWithIdError("mood_template", mood.template_id)
    return crud.create_mood(db, mood)
示例#5
0
def get_all_moods(db: Session, template_id: str = None):
    query = db.query(model.Mood)
    if template_id:
        template = get_mood_template(db, template_id)
        query = query.filter_by(template_id=template.id)
    return query.all()