์ƒˆ์†Œ์‹

๐Ÿ’ฟ ๊ธฐํƒ€

binaryTime (Flask + mongoDB) flask REST API

  • -

*๋ฐฐํฌ๋œ ์ฃผ์†Œ

youjunyong.shop/

 

Color of time

ํ•˜๋ฃจ์˜ timeline์„ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.

youjunyong.shop

 

*ํ”„๋กœ์ ํŠธ ์˜๋„

 

 ๋‚ด๊ฐ€ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์–ดํ”Œ์ค‘์— ๊ณต๋ถ€์‹œ๊ฐ„์„ ์ฒดํฌํ•˜๋Š” ์–ดํ”Œ์ด ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ๋”ด์ง“ํ•˜๋ฉฐ ๋‚ญ๋น„ํ•˜๋Š” ์‹œ๊ฐ„๊ณผ ๊ณต๋ถ€ํ•˜๋Š” ์‹œ๊ฐ„์„ ๋น„๊ตํ•ด๋ณด๊ณ  ์‹ถ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ–ˆ๊ณ ,  web์—์„œ ์ž‘๋™ํ•œ๋‹ค๋ฉด, ํ…Œ๋ธ”๋ฆฟ , pc , ์Šค๋งˆํŠธํฐ์—์„œ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ž‘๋™์ด ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“ค์–ด ๋งŒ๋“ค์–ด ๋ณด์•˜๋‹ค.

์•„๋งˆ ์ด๊ฒƒ์„ ๋‚˜์˜ ์ฒซ ํ”„๋กœ์ ํŠธ๋ผ๊ณ  ๋งํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๊ณ„ํš์—†์ด ์ถ”์ƒ์ ์ธ ์ƒ๊ฐ๋งŒ ๊ฐ€์ง€๊ณ  ์ฆ‰ํฅ์ ์œผ๋กœ ๋งŒ๋“ค๋‹ค๋ณด๋‹ˆ, ๋ณ€์ˆ˜๋ช…๋„ ์ผ๊ด€๋˜์ง€ ์•Š๊ณ  ๋ง๊ทธ๋Œ€๋กœ ์ŠคํŒŒ๊ฒŒํ‹ฐ ์ฝ”๋“œ๊ฐ€ ๋œ๊ฒƒ๊ฐ™๋‹ค. ํŠนํžˆ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์ž˜ ์„ค๊ณ„ํ•˜๋Š”๊ฒŒ ์ค‘์š”ํ•˜๋‹ค๋Š” ์ ์„ ๋Š๊ผˆ๋‹ค.

 

*์‚ฌ์šฉ

  • Chart.js
  • Flask
  • AWS EC2(๋ฐฐํฌ)
  • ๊ฐ€๋น„์•„(๋„๋ฉ”์ธ)
  • MongoDB
  • html, css, js

 

* Home ํ™”๋ฉด

https://startbootstrap.com/themes/

์ด๊ณณ์— ์žˆ๋Š” ํ…Œ๋งˆ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค. ํ…Œ๋งˆ ์ด๋ฆ„์€ Grayscale ์ด๋ฉฐ ๋ฌด๋ฃŒ์ด๋‹ค.

"์‹œ๊ฐ„๊ด€๋ฆฌ"๋ผ๋Š” ์ปจ์…‰์— ๋งž๊ฒŒ ์‹œ๊ณ„์‚ฌ์ง„๊ณผ ํ˜„์žฌ์‹œ๊ฐ์„ ํ˜„ ์œ„์น˜์— ๋งž๊ฒŒ ํ‘œ์‹œํ•˜๋„๋ก JavaScript๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค.

 

*ํšŒ์›๊ฐ€์ž… ๋ฐ ๋กœ๊ทธ์ธ

 

 

 

*ํƒ€์ž„๋ผ์ธ

ํŒŒ๋ž€๋ฒ„ํŠผ์ด๋‚˜ ๋นจ๊ฐ„๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด , ํ™”๋ฉด์˜ ๊ณต์ด ์ƒ‰๊น”์ด ๋ณ€ํ•˜๋ฉด์„œ ์œ„์•„๋ž˜๋กœ ํŠ•๊ธฐ๋“ฏ์ด ์›€์ง์ด๋ฉฐ ์นด์šดํŒ…์ด ์‹œ์ž‘๋œ๋‹ค.

๊ธ์ •์ ์ธ ์‹œ๊ฐ„์€ ํŒŒ๋ž€์ƒ‰์œผ๋กœ ํƒ€์ž„๋ผ์ธ์— ๊ธฐ๋ก๋˜๋ฉฐ, ๋ถ€์ •์ ์ธ ์‹œ๊ฐ„์€ ๋นจ๊ฐ„์ƒ‰์œผ๋กœ ๊ธฐ๋ก๋œ๋‹ค. 

์ œ๋ชฉ์„ ๋ˆŒ๋Ÿฌ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œ ๊ฐ€๋Šฅํ•˜๋„๋ก ๋งŒ๋“ค์—ˆ๋‹ค. 

์‚ฌ์šฉ๊ธฐ๊ธฐ๋ฅผ ๋ฐ”๊พธ์–ด ๋กœ๊ทธ์ธํ–ˆ์„๋•Œ , ์นด์šดํŠธ ๋˜๊ณ ์žˆ๋Š” ์‹œ๊ฐ„์ด ์œ ์ง€๊ฐ€ ์•ˆ๋˜๋Š” ๋ถ€๋ถ„์„ ๋’ค๋Šฆ๊ฒŒ ๋ฐœ๊ฒฌํ•ด์„œ ๋งŽ์ด ์‚ฝ์งˆ์„ ํ–ˆ์—ˆ๋‹ค.

 

 

*์ฐจํŠธ (ํ†ต๊ณ„)

์ด๋ ‡๊ฒŒ ํƒ€์ž„๋ผ์ธ์„ ์ฒดํฌํ•˜๋ฉด์„œ ๊ธฐ๋ก์ด ์Œ“์ด๊ฒŒ ๋˜๋ฉด ์ฐจํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋ฒ„ํŠผ์ด ์ƒ๊ธด๋‹ค. ๋ฒ„ํŠผ์•ˆ์—๋Š” ๊ทธ๋‚ ์˜ ๋‚ ์งœ๊ฐ€ ์‚ฝ์ž…๋œ๋‹ค.

๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ฒŒ ๋˜๋ฉด, ํŒŒ์ด๊ทธ๋ž˜ํ”„๋กœ ๊ณต๋ฐฑ์ธ ์‹œ๊ฐ„(๊ธฐ๋ก ์—†๋Š”์‹œ๊ฐ„) , Plus ์‹œ๊ฐ„, Minus์‹œ๊ฐ„์œผ๋กœ 3๊ฐ€์ง€๋กœ ํ‘œ์‹œ๋œ๋‹ค.  

์ฐจํŠธ๋Š” Chart.JS ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค.

 

 


* ๊ฐœ์„ ์‚ฌํ•ญ (๋Š๋‚€์ )

 ์›ํŽ˜์ด์ง€ + ๋น„๋™๊ธฐ ํ†ต์‹ ์„ ํ†ตํ•ด์„œ ์ตœ๋Œ€ํ•œ ์–ดํ”Œ๊ฐ™์€ ๋Š๋‚Œ์œผ๋กœ ๋งŒ๋“ค์–ด๋ณด๊ณ  ์‹ถ์—ˆ๋‹ค. ์•„๋ฌด๋„ ์“ฐ์ง€ ์•Š์„ ๋งŒํผ ๊ตฌ๋ฆฌ์ง€๋งŒ, ์ •๋ง ๋งŽ์€ ๊ณต๋ถ€๊ฐ€ ๋œ ๊ฒƒ ๊ฐ™์•˜๋‹ค.

 ๊ธฐ๋ก (๊ณ„ํš ๋ฐ ์„ค๊ณ„, ๊ทธ๋ฆฌ๊ณ  ๊ฐœ๋ฐœ๋…ธํŠธ?) ์„ ๋‚จ๊ฒผ๋”๋ผ๋ฉด ์ข‹์•˜๊ฒ ๋‹ค ๋ผ๋Š” ์ƒ๊ฐ์„ ํ–ˆ๋‹ค. ์ฒซ๋ฒˆ์งธ ํ”„๋กœ์ ํŠธ๋‹ค ๋ณด๋‹ˆ , ์–ด๋–ป๊ฒŒ ? ๋ญ๋ถ€ํ„ฐ ? ํ•ด์•ผํ• ์ง€ ๋ชฐ๋ผ ๋ฌด์ž‘์ • ์‹œ์ž‘ํ–ˆ๋Š”๋ฐ ๊ทธ๋ž˜๋„ ํ•œ๋ฒˆ ํ•˜๊ณ ๋‚˜๋‹ˆ๊นŒ ๋‹ค์Œ์—” ์–ด๋–ป๊ฒŒ ํ•ด์•ผ๊ฒ ๋‹ค ๋ผ๋Š”๊ฒŒ ๋ชธ์œผ๋กœ ์™€๋‹ฟ๋Š”๋‹ค.  

 

 

 

 

 

* app.py  (์ผ๋ถ€)

from api_v1 import api as api_v1

app = Flask(__name__)
app.register_blueprint(api_v1 , url_prefix='/api/v1')

flask blueprint๋ฅผ ์ด์šฉํ•˜์—ฌ api_v1๋กœ ๋ชจ๋“ˆ์„ ๋‚˜๋ˆ„์–ด ์ฃผ์—ˆ๋‹ค. 

 

*api_v1 (์ผ๋ถ€)

from . import api
from flask import jsonify, request, Blueprint, session, redirect ,flash
from models import db , MyUser , SaveTime , LoadTime
import requests


@api.route('/plustime' , methods=["GET", "POST"])
def plustime():
    if request.method == "POST":
        timeType = request.form['timeType']
        time = request.form['Time']
        
        userEmail = session.get('userEmail', None)
        save = SaveTime
        save.saveTime(userEmail , time, timeType)
        if 'Start' in timeType :
            return jsonify({'result':'success','msg':'Plustime ์‹œ์ž‘'})
        elif 'End' in timeType :
            return jsonify({'result':'success','msg':'Plustime ๋'})

ํšŒ์›๊ฐ€์ž…์„ ์ œ์™ธํ•œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ ํ†ต์‹ ์€ api_v1์—์„œ ํ•˜๋„๋ก ๊ตฌ์„ฑํ–ˆ๋‹ค. 

 

 

*ํŒŒ์ผ ๊ตฌ์„ฑ

https://github.com/Youjunyong/binaryTime

* ์†Œ์Šค์ฝ”๋“œ

 

Youjunyong/binaryTime

Contribute to Youjunyong/binaryTime development by creating an account on GitHub.

github.com

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.