Exemplo n.º 1
0
 def get(self):
     """ユーザ情報の取得(自分)."""
     user = check_authorize()
     user = vars(user)
     del user['_sa_instance_state']
     del user['password']
     return jsonify(user)
Exemplo n.º 2
0
 def get(self):
     """自分のストレス値一覧の取得."""
     user = check_authorize()
     stress_data = [{
         'value': s.stress,
         'date': s.date.isoformat()
     } for s in ss.query(Stress).filter_by(owner_id=user.id)]
     return jsonify(stress_data)
Exemplo n.º 3
0
 def post(self):
     """サインアウト."""
     user = check_authorize()
     token = Token(user.token)
     token.update()
     user.token = token.tokenize()
     ss.commit()
     return jsonify(message='See you again!')
Exemplo n.º 4
0
 def get(self):
     """自分の勤務時間一覧の取得."""
     user = check_authorize()
     records = [{
         'id': r.id,
         'begin': r.begin,
         'end': r.end
     } for r in (ss.query(AttendanceRecord).filter_by(owner_id=user.id))]
     return jsonify(records)
Exemplo n.º 5
0
 def post(self):
     """退勤."""
     user = check_authorize()
     latest_record = (ss.query(AttendanceRecord).filter_by(
         owner_id=user.id).order_by(AttendanceRecord.id.desc()).first())
     if latest_record is None or latest_record.end is not None:
         abort(409, "既に退勤しています")
     latest_record.end = datetime.datetime.now()
     ss.commit()
     print('check out at %s' % latest_record.end)
     latest_record = vars(latest_record)
     del latest_record['_sa_instance_state']
     del latest_record['owner_id']
     return jsonify(latest_record)
Exemplo n.º 6
0
 def get(self):
     """ユーザ一覧の取得."""
     user = check_authorize()
     users = []
     for u in ss.query(User).filter_by(group_id=user.group_id):
         u = vars(u)
         del u['_sa_instance_state']
         del u['password']
         del u['token']
         del u['fitbit_id']
         del u['fitbit_access_token']
         del u['fitbit_refresh_token']
         users.append(u)
     return jsonify(users)
Exemplo n.º 7
0
 def get(self, user_id):
     """ユーザ情報の取得."""
     own = check_authorize()
     user = ss.query(User).filter_by(id=user_id,
                                     group_id=own.group_id).first()
     if user is None: abort(404)
     user = vars(user)
     del user['_sa_instance_state']
     del user['password']
     del user['token']
     del user['fitbit_id']
     del user['fitbit_access_token']
     del user['fitbit_refresh_token']
     return jsonify(user)
Exemplo n.º 8
0
 def post(self):
     """出勤."""
     user = check_authorize()
     latest_record = (ss.query(AttendanceRecord).filter_by(
         owner_id=user.id).order_by(AttendanceRecord.id.desc()).first())
     if latest_record is not None and latest_record.end is None:
         abort(409, "既に出勤しています")
     record = AttendanceRecord(begin=datetime.datetime.now(),
                               owner_id=user.id)
     ss.add(record)
     ss.commit()
     print('go to walk at %s' % record.begin)
     record = vars(record)
     del record['_sa_instance_state']
     del record['owner_id']
     return jsonify(record)
Exemplo n.º 9
0
 def put(self):
     """ユーザ情報の更新(自分)."""
     user = check_authorize()
     if 'email' in rq.form:
         query = ss.query(User).filter_by(email=rq.form['email'])
         if query.count() > 0: abort(409, 'そのメールアドレスは既に使われています')
         else: user.email = rq.form['email']
     if 'first_name' in rq.form: user.first_name = rq.form['first_name']
     if 'last_name' in rq.form: user.last_name = rq.form['last_name']
     if 'gender' in rq.form: user.gender = rq.form['gender']
     if 'password' in rq.form: user.password = rq.form['password']
     if 'fitbit_id' in rq.form: user.fitbit_id = rq.form['fitbit_id']
     if 'fitbit_access_token' in rq.form:
         user.fitbit_access_token = rq.form['fitbit_access_token']
     if 'fitbit_refresh_token' in rq.form:
         user.fitbit_refresh_token = rq.form['fitbit_refresh_token']
     if ss.dirty: ss.commit()
     # commit()後一度オブジェクトを参照しないとvars()で表示できない??
     print('add', user.first_name)
     user = vars(user)
     del user['_sa_instance_state']
     del user['password']
     return jsonify(user)
Exemplo n.º 10
0
 def delete(self):
     """ユーザの削除(自分)."""
     user = check_authorize()
     ss.delete(user)
     ss.commit()
     return jsonify(message='Good Bye!')