Skip to content

PodiumDreaming/Dreaming_Podium_Backend

Repository files navigation

Dreaming_Podium

Wright_logo
Mobile App 'Wright' Backend Server using FastAPI


Team Member

경희대학교 컴퓨터공학과

2017104024 정민혁 jeongmh09@naver.com / jeongmh09@gmail.com
2018103062 정지현 jihyoun0602@gmail.com


Abstract

빠르고 간편하게 작성하는 훈련일지.
체계적이고 효과적으로 훈련 내용, 부상, 컨디셔닝을 관리할 수 있도록 도와주는 모바일 어플리케이션입니다.
이 버전은 현재 '구글 플레이스토어'와 '앱스토어' 모두 릴리즈 되었으며, 이 레포지토리에는 클라이언트에서 필요한 데이터를 주고 받는 백엔드 구축 내용이 담겨있습니다.
백엔드는 정민혁이 담당하였고 관리하고 있습니다.

프런트엔드에 관한 내용은 여기서 확인할 수 있습니다: Click Here

Quick and easy way to write trainging repoert.
Wright is a mobile application that helps manage training, injury, conditioning records in a systematic and effeective manner.
This version is currently released both on 'Google Play Store' and 'App Store', and this repository contains all information about backend that handles data client needs.
Backend part is made and managed by Minhyeok Jeong.

You can check frontend here: Click Here


Features

diagram

language: Python

Web Framework: FastAPI

Server running on: AWS EC2

Database: MariaDB

Databse running on: AWS RDS

Image Server: AWS S3 bucket.

더 자세한 정보는 레포지토리 내의 보고서를 확인해주세요.
For more detail, refer report in the repo.


About FastAPI

FastAPI FastAPI는 파이썬 언어의 3.6버전이상의 API를 빌드하기 위한 파이썬 기반의 웹 프레임워크입니다.
빠른 속도와 쉽게 배울수 있다는 장점으로 사용률이 증가하고 있는 추세입니다.
본 프로젝트에서는 RESTful API를 통한 CRUD작업을 처리하기 위한 환경 구축을 위해 사용되었습니다.
더 자세한 정보는 공식홈페이지에서 확인할 수 있습니다: FastAPI

FastAPI is a Python based web framwork that helps build Python API above version 3.6.
It's usage is at an increasing rate for its fast speed and ease to use.
In this project, FastAPI was used to build RESTful API for CRUD operation.
For more information, check official website: FastAPI


Composition

프로젝트의 주요 구성 요소는 다음과 같습니다:
Major composition of this project are as followed:

  • app
    • config
      • config.py
    • databse
      • Models.py
      • Tables.py
      • conn.py
      • crud.py
    • router
      • Apple.py
      • Images.py
      • KaKao.py
      • Objective.py
      • Profile.py
      • Record.py
    • util.py
  • main.py
  • requirement.txt
  • LICENSE

Description

config.py

데이터베이스 주소나 알고리즘 secret key등의 환경변수를 불러오는 파일입니다.
Configuration for environmental variables like DB connection information, algorithm and secret keys.

Models.py

Object Relational Mapping(ORM)을 통해 데이터베이스 테이블로 전환이 가능한 Pydantic model을 선언한 파일입니다.
Pydantic 라이브러리를 통해 입력 데이터의 검증을 편리하게 할 수 있습니다.
Includes Pydantic models that are convertible to databse tables through Object Relational Mapping (ORM).
Data validation is easily achieved by Pydantic library.

Tables.py

SQL Alchempy ORM 라이브러리를 사용하여 생성할 테이블의 스키마를 정의한 파일입니다.
Defines schemas for tables that will be generated by SQL Alchemy ORM.

conn.py

AWS RDS와 S3로 연결하는 인스턴스를 생성하는 함수를 정의한 파일입니다.
Defines functions that yields instances of session on AWS RDS and S3 connection.

crud.py

데이터베이스로의 Create, Read, Update, Delete 오퍼레이션을 구현해 놓은 파일입니다.
Defines Create, Read, Update, Delete operations to database.

Apple.py

애플 계정을 통한 로그인을 처리합니다. Handles login by Apple.

Images.py

AWS S3버킷으로의 사진 업로드를 처리합니다.
Handles image upload to AWS S3 bucket.

KaKao.py

카카오 계정을 통한 로그인을 처리합니다. Handles login by KaKao

Objectives.py

목표 설정에 관한 함수들이 정의된 파일입니다.
Defines functions related to Objective configuration.

Profile.py

사용자 프로필에 관한 함수들이 정의된 파일입니다.
Defines functions related to User Profile.

Record.py

트레이닝, 컨디셔닝 기록에 관한 함수들이 정의된 파일입니다.
Defomes functions related to Training and Conditioning.


To try run this server on localhost for API test

  1. Have Python3.8 or above installed.

  2. install requirements.

pip3 install -r requirements.txt
  1. Prepare local database.
    MySQL or MariaDB is recommanded as this guideline is based on those database.

  2. Prepare AWS S3 bucket(Optional,but needed if you want to test image upload).
    Refer following page for creating S3 bucket and getting Key pair.
    https://assaeunji.github.io/aws/2020-04-02-boto3/ (KOR)

  3. Set envrionmetal variables and connection.
    In ./app/config/config.py, you will find:

import os

# KAKAO API
kakao_client = os.getenv("kakao_client")
callback_url = "http://localhost:8000/kakao/callback"

# AWS RDS CONNECTION
Remote = os.getenv("MariaDB")
RDS_Account = os.getenv("RDS_Account")
Local_Account = os.getenv("Local_Account")

# AWS S3 CONNECTION
AWS_ACCESS_KEY = os.getenv("AWS_ACCESS_KEY")
AWS_SECRET_KEY = os.getenv("AWS_SECRET_KEY")
BUCKET_NAME = os.getenv("S3_BUCKET")

# JWT
SECRET_KEY = os.getenv("SECRET_KEY")
ALGORITHM = os.getenv("ALGORITHM")

5.1 kakao_client, callback_url

5.1.1 Refer following page for detailed guideline:
https://developers.kakao.com/docs/latest/ko/getting-started/app
5.1.2 Register your app and get 'REST API KEY' 5.1.3 Set corresponding environmental variable with the created key on your pc.
5.1.4 Register platform to enable calling KaKao API from your server.
5.1.5 Register callback url for KaKao Login API.

5.2 JWT

5.2.1 For basic explanation, refer FastAPI's official document:
https://fastapi.tiangolo.com/ko/tutorial/security/oauth2-jwt/
5.2.2 Choosing what SECRET_KEY and ALGORITHM to use is up to you.
5.2.3 You may have to alter codes depending on the algorithm.
5.2.4 Set corresponding environmental variables on your pc.

5.3 Database Connection

Set environmental variable "Local_Account" as your database user passowrd.

5.4 AWS S3 CONNECTION

Set corresponding environmental variables on yout pc with key pair generated during step 4.

5.5 Database Connection configuration In ./app/database/conn.py , you can find:

RDS_Account = config.RDS_Account
Local_Account = config.Local_Account
Remote = config.Remote
db_url = f"mysql+pymysql://admin:{RDS_Account}@{Remote}:3306/MariaDB?charset=utf8mb4"
# db_url = f"mysql+pymysql://root:{Local_Account}@localhost:3306/dptest?charset=utf8mb4"

5.5.1 Instead of 'db_url' using "RDS_Account", use the one with the one wiht "Local_Accout".
5.5.2 You may have to change "mysql+pymysql" part depending on the databse you use. For more information, refer following page.
https://docs.sqlalchemy.org/en/14/core/engines.html
5.5.3 You may have to change 'root' to the username of your databse.
5.5.4 You may have to open port depending on the database you use.
5.5.5 Change "dptest" to the name of your database.

e.g. db_url = "mysql+pymysql://{user}:{password}@localhost:{port}/{database}?charset=utf8mb4"

  1. Run server
uvicorn main:app --reload

or

python3 -m uvicorn main:app --host 0.0.0.0 --port 8000
  1. Open internet browser and go to http://localhost:8000/docs#

You may now test APIs.


Reference

https://fastapi.tiangolo.com/ko/tutorial/security/oauth2-jwt/ https://assaeunji.github.io/aws/2020-04-02-boto3/ https://developers.kakao.com/docs/latest/ko/getting-started/app https://docs.sqlalchemy.org/en/14/core/engines.html https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api

Releases

No releases published

Packages

No packages published

Languages