def lambda_handler(event: dict, context): body = json.loads(event.get("body", "{}")) team_name = body.get("team_name") password = body.get("password") goal_minute = body.get("goal_minute") if None in [team_name, password, goal_minute]: return response(400) user_id = get_user_id_from_header(event.get("headers", {})) if user_id is None: return response(403) session = Session() team = TeamModel(team_name, password, goal_minute) session.add(team) session.commit() cards: List[CardModel] = session.query(CardModel).filter( CardModel.user_id == user_id).all() for c in cards: c.team_id = team.team_id session.add(c) session.add(UserTeamMappingModel(user_id, team.team_id)) session.commit() return response(201)
def lambda_handler(event: dict, context): team_name = event.get("pathParameters", {}).get("team_name") body = json.loads(event.get("body", "{}")) password = body.get("password") if None in [team_name, password]: return response(400) user_id = get_user_id_from_header(event.get("headers", {})) if user_id is None: return response(403) session = Session() team = session.query(TeamModel).filter( TeamModel.team_name == team_name).one_or_none() if team is None: response(404, {"message": "no team"}) cards: List[CardModel] = session.query(CardModel).filter( CardModel.user_id == user_id).all() for c in cards: c.team_id = team.team_id session.add(c) session.add(UserTeamMappingModel(user_id, team.team_id)) session.commit() return response(201)
def lambda_handler(event: dict, context): card_id = event.get("pathParameters", {}).get("card_id") if card_id is None: return response(400) user_id = get_user_id_from_header(event.get("headers", {})) if user_id is None: return response(403) session = Session() card: CardModel = session.query(CardModel).filter( CardModel.card_id == card_id ).filter( CardModel.user_id == user_id ).filter( CardModel.progress_status == "IN_PROGRESS" ).one_or_none() if card is None: return response(404, {"message": "wrong card id or user id"}) team = session.query(TeamModel).filter( TeamModel.team_id == card.team_id ).one_or_none() if team is None: response(404, {"message": "no team"}) card.start_time = datetime.utcnow() card.progress_status = "DONE" session.add(card) session.commit() return response(201)
def lambda_handler(event: dict, context): team_name = event.get("queryStringParameters", "{}").get("team_name") user_id = event.get("queryStringParameters", "{}").get("user_id") progress_status = event.get("queryStringParameters", "{}").get("progress_status") if team_name is None and user_id is None: return response(400) user_id_from_token = get_user_id_from_header(event.get("headers", {})) if user_id_from_token is None: return response(403) session = Session() query = session.query(CardModel) if team_name is not None: team = session.query(TeamModel).filter( TeamModel.team_name == team_name).one_or_none() if team is None: return response(404, {"message": "no team matched"}) query = query.filter(CardModel.team_id == team.team_id) if user_id is not None: query = query.filter(CardModel.user_id == user_id) if progress_status is not None: query = query.filter(CardModel.progress_status == progress_status) cards = query.all() users = [ session.query(UserModel).filter(UserModel.user_id == c.user_id).one() for c in cards ] result = [{ "card_id": card.card_id, "goal_focus_minute": card.goal_focus_minute, "color": card.color, "content": card.content, "start_time": card.start_time.isoformat() if card.start_time is not None else None, "progress_status": card.progress_status, "username": user.username, } for user, card in zip(users, cards)] return response(200, {"cards": result})
def lambda_handler(event: dict, context): team_name = event.get("queryStringParameters", "{}").get("team_name") user_id = get_user_id_from_header(event.get("headers", {})) if user_id is None: return response(403) session = Session() team = session.query(TeamModel).filter( TeamModel.team_name == team_name).one_or_none() if team is None: return response(404, {"message": "wrong team name"}) users = session.query(UserModel).join( UserTeamMappingModel, UserTeamMappingModel.team_id == team.team_id) for user in users: if user.user_id == user_id: break else: return response(403) my_cards = session.query(CardModel).filter( CardModel.user_id == user_id).all() my_count = { "count": len(my_cards), "done_count": len([c for c in my_cards if c.process_status == "DONE"]) } team_cards = session.query(CardModel).filter( CardModel.team_id == team.team_id).all() team_count = { "count": len(team_cards), "done_count": len([c for c in team_cards if c.process_status == "DONE"]) } return response( 200, { "team_name": team.team_name, "start_time": team.start_time.isoformat() if team.start_time is not None else None, "user_names": [user.username for user in users], "all_cards": team_count, "my_cards": my_count })
def lambda_handler(event: dict, context): card_id = event.get("pathParameters", "{}").get("card_id") if None in [card_id]: return response(400) user_id = get_user_id_from_header(event.get("headers", {})) if user_id is None: return response(403) session = Session() card = session.query(CardModel).filter( CardModel.user_id == user_id).filter( CardModel.card_id == card_id).one_or_none() if card is not None: session.delete(card) session.commit() return response(204)
def lambda_handler(event: dict, context): body = json.loads(event.get("body", "{}")) content = body.get("content") goal_focus_minute = body.get("goal_focus_minute") color = body.get("color") if None in [content, goal_focus_minute, color]: return response(400) user_id = get_user_id_from_header(event.get("headers", {})) if user_id is None: return response(403) session = Session() card = CardModel(user_id, goal_focus_minute, color, content) session.add(card) session.commit() return response(201, {"card_id": card.card_id})