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)
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
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
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)
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()