Skip to content

Commit

Permalink
[feat]add server
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrkw1497 committed Dec 15, 2019
1 parent ae57d01 commit 886e52b
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fakeCloud
.vscode
main/__pycache__
main/test.db
1 change: 1 addition & 0 deletions server/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn run:app --log-file -
25 changes: 25 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# サーバー
## 仮想環境を作ろう!!
python3が入った状態で
`$ py -m venv [newenvname]`
仮想環境アクティベート!!
`$ .\[newenvname]\Scripts\activate`
## やれ!! ↓
```$ pip install -r requirements.txt```
ライブラリを追加した際は報告すること
また、ライブラリを追加した際は```$ pip freeze > requirements.txt```を実行すること
## 起動方法について
仮想環境に入り必要なライブラリをインストールした状態で`$ python run.py`を実行する
また、初回起動時は`$ python -c "import main.models; main.models.init()"`を実行する
## apiの仕様について
基本的には`https://p2server.herokuapp.com`にサーバーを構築する(基本的にサーバーは閉じているので使いたいときは連絡する slackなどで連絡)

`/user`に対し`{"mail":"任意の文字列","address":"任意の文字列"}`のようなJSONをPOSTするとデータベースにユーザーが登録される

`/user/<user_mail>`に対しGETするとuser_mailに対応したユーザーのIDを取得できる

`/answer`に対し`{"id":整数値,"result":[要素数17の1から5の値の格納された配列]}`のようなJSONをPOSTすると質問結果を計算し解答をデータベースに格納する

`/answer/<user_mail>`に対しGETするとuser_mailに対応した質問結果を取得できる

`/all_users`に対しGETすると登録されているユーザーの一覧を取得できる
11 changes: 11 additions & 0 deletions server/main/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS

app=Flask(__name__)
app.config.from_object('main.config')
CORS(app)

db=SQLAlchemy(app)

import main.views
5 changes: 5 additions & 0 deletions server/main/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

SQLALCHEMY_DATABASE_URI=os.environ.get("DATABASE_URL") or "sqlite:///test.db"
SQLALCHEMY_TRACK_MODIFICATIONS=True
SECRET_KEY="aaa"
34 changes: 34 additions & 0 deletions server/main/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from main import db
from flask_sqlalchemy import SQLAlchemy


class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
mail = db.Column(db.Text,nullable=False,unique=True)
address = db.Column(db.Text)
results=db.relationship("Result",backref="user",lazy=True)

def __repr__(self):
return "<User id={} mail={!r} address={!r}>".format(self.id,self.mail,self.address)

class Result(db.Model):
id=db.Column(db.Integer,primary_key=True)
user_mail=db.Column(db.Text,db.ForeignKey("user.mail"),nullable=False)
answer=db.Column(db.String(50))

def __repr__(self):
return "<Result id={} user_mail={!r} answer={!r}>".format(self.id,self.user_mail,self.answer)

class Shop(db.Model):
id=db.Column(db.Integer,primary_key=True)
tag=db.Column(db.Text)
url=db.Column(db.Text)

def __repr__(self):
return "<Shop id={} tag={!r} url={!r}>".format(self.id,self.tag,self.url)

def init():
db.create_all()

def registerShops():
pass
57 changes: 57 additions & 0 deletions server/main/templates/shop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Shop sample</title>
<style>
body{
margin: 0;
padding: 0;
background: gray;
}
.container{
width:80%;
background: white;
margin-top: 0;
margin-left: auto;
margin-right: auto;
height:100vh;
padding: 20px;
}
h3{
border-left: 8px solid green;
padding-left:5px;
}
</style>
</head>
<body>
<div class="container">
<h1>あなたが渡すべきプレゼントは{{ans}}です.</h1>
<h3>説明</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<h3>ショッピングサイト一覧</h3>
<ul>
{% for url in urls %}
<li><a href={{url}}>{{url}}</a></li>
{% endfor %}
</ul>
</div>
</body>
</html>
Loading

0 comments on commit 886e52b

Please sign in to comment.