Working on API
parent
8e91115915
commit
a7554f5e43
|
|
@ -2,3 +2,4 @@
|
||||||
/venv
|
/venv
|
||||||
.gitignore
|
.gitignore
|
||||||
/resource
|
/resource
|
||||||
|
./api_server/swagger_docstring_template.txt
|
||||||
|
|
@ -0,0 +1,215 @@
|
||||||
|
import os
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
|
from flasgger import Swagger
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
from models import db, User, TimeStamp
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
api = Swagger(app)
|
||||||
|
|
||||||
|
app.config['SECRET_KEY'] = 'dksldkkwkdkllk' # todo: os.environ['TIMESTAMP_SECRET_KEY']
|
||||||
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db"
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def index_handler():
|
||||||
|
return "hallo"
|
||||||
|
|
||||||
|
|
||||||
|
# USER SECTION
|
||||||
|
|
||||||
|
@app.route("/user/", methods=['POST'])
|
||||||
|
def create_user():
|
||||||
|
"""Endpoint returning success of operation
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- name: user id to delete
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
- name: user
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
definitions:
|
||||||
|
Palette:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
palette_name:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Color'
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A list of colors (may be filtered by palette)
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Palette'
|
||||||
|
examples:
|
||||||
|
rgb: ['red', 'green', 'blue']
|
||||||
|
"""
|
||||||
|
user = User(
|
||||||
|
name=request.form["username"],
|
||||||
|
email=request.form["email"],
|
||||||
|
)
|
||||||
|
db.session.add(user)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/user/<int:user_id>", methods=['GET'])
|
||||||
|
def get_user_by_id(user_id):
|
||||||
|
"""Endpoint returning user by id
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- name: user_id
|
||||||
|
type: integer
|
||||||
|
in: form
|
||||||
|
required: true
|
||||||
|
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A list of properties of a user by given id
|
||||||
|
"""
|
||||||
|
user = db.get_or_404(User, user_id)
|
||||||
|
return jsonify(str(user))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/user/<int:user_id>", methods=['DELETE'])
|
||||||
|
def delete_user_by_id(user_id):
|
||||||
|
"""Endpoint returning success of operation
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- name: user id to delete
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
enum: ['all', 'rgb', 'cmyk']
|
||||||
|
required: true
|
||||||
|
default: all
|
||||||
|
definitions:
|
||||||
|
Palette:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
palette_name:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Color'
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A list of colors (may be filtered by palette)
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Palette'
|
||||||
|
examples:
|
||||||
|
rgb: ['red', 'green', 'blue']
|
||||||
|
"""
|
||||||
|
return "Delete"
|
||||||
|
|
||||||
|
|
||||||
|
#END USER SECTION
|
||||||
|
#TIMESTAMP SECTION
|
||||||
|
@app.route("/timestamp/<int:user_id>", methods=['POST'])
|
||||||
|
def create_timestamp(user_id):
|
||||||
|
"""Endpoint returning success of operation
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- name: user id to delete
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
enum: ['all', 'rgb', 'cmyk']
|
||||||
|
required: true
|
||||||
|
default: all
|
||||||
|
definitions:
|
||||||
|
Palette:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
palette_name:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Color'
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A list of colors (may be filtered by palette)
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Palette'
|
||||||
|
examples:
|
||||||
|
rgb: ['red', 'green', 'blue']
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/timestamp/<int:user_id>", methods=['GET'])
|
||||||
|
def get_timestamps_by_id(user_id):
|
||||||
|
"""Endpoint returning user by id
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- name: user id
|
||||||
|
in: path
|
||||||
|
type: integer
|
||||||
|
required: true
|
||||||
|
definitions:
|
||||||
|
Palette:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
palette_name:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Color'
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A list of properties of a user by given id
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Palette'
|
||||||
|
examples:
|
||||||
|
rgb: ['red', 'green', 'blue']
|
||||||
|
"""
|
||||||
|
return str(user_id)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/timestamp/<int:user_id>", methods=['DELETE'])
|
||||||
|
def delete_timestamps_by_id(user_id):
|
||||||
|
"""Endpoint returning success of operation
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- name: user id to delete
|
||||||
|
in: path
|
||||||
|
type: string
|
||||||
|
enum: ['all', 'rgb', 'cmyk']
|
||||||
|
required: true
|
||||||
|
default: all
|
||||||
|
definitions:
|
||||||
|
Palette:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
palette_name:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Color'
|
||||||
|
Color:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A list of colors (may be filtered by palette)
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/Palette'
|
||||||
|
examples:
|
||||||
|
rgb: ['red', 'green', 'blue']
|
||||||
|
"""
|
||||||
|
return "Delete"
|
||||||
|
|
||||||
|
#END TIMESTAMP SECTION
|
||||||
|
|
||||||
|
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
|
||||||
|
class User(db.Model):
|
||||||
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
|
name = sa.Column(sa.String)
|
||||||
|
email = sa.Column(sa.String)
|
||||||
|
|
||||||
|
|
||||||
|
class TimeStamp(db.Model):
|
||||||
|
id = sa.Column(sa.Integer, primary_key=True)
|
||||||
|
user_id = sa.ForeignKey(User.id)
|
||||||
|
create = sa.Column(sa.TIMESTAMP) # create time
|
||||||
|
timestamp = sa.Column(sa.TIMESTAMP) # insertet by user
|
||||||
|
|
@ -2,16 +2,22 @@ aniso8601==9.0.1
|
||||||
attrs==23.1.0
|
attrs==23.1.0
|
||||||
blinker==1.6.2
|
blinker==1.6.2
|
||||||
click==8.1.6
|
click==8.1.6
|
||||||
|
flasgger==0.9.7.1
|
||||||
Flask==2.3.2
|
Flask==2.3.2
|
||||||
Flask-RESTful==0.3.10
|
Flask-SQLAlchemy==3.0.5
|
||||||
flask-restx==1.1.0
|
greenlet==2.0.2
|
||||||
itsdangerous==2.1.2
|
itsdangerous==2.1.2
|
||||||
Jinja2==3.1.2
|
Jinja2==3.1.2
|
||||||
jsonschema==4.18.4
|
jsonschema==4.18.4
|
||||||
jsonschema-specifications==2023.7.1
|
jsonschema-specifications==2023.7.1
|
||||||
MarkupSafe==2.1.3
|
MarkupSafe==2.1.3
|
||||||
|
mistune==3.0.1
|
||||||
|
packaging==23.1
|
||||||
pytz==2023.3
|
pytz==2023.3
|
||||||
|
PyYAML==6.0.1
|
||||||
referencing==0.30.0
|
referencing==0.30.0
|
||||||
rpds-py==0.9.2
|
rpds-py==0.9.2
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
|
SQLAlchemy==2.0.19
|
||||||
|
typing_extensions==4.7.1
|
||||||
Werkzeug==2.3.6
|
Werkzeug==2.3.6
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue