Skip to content

Commit

Permalink
feat(route): add basic route
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu <[email protected]>
  • Loading branch information
mathieu-brl committed Nov 27, 2024
1 parent 6f352fc commit 7bfb9fa
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions server/server.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
#!/usr/bin/env python

from flask import Flask, jsonify, request
from flask import Flask, jsonify, request, Response
from sqlalchemy import create_engine, text, Table, select, MetaData, inspect, Column
import time

app = Flask(__name__)
engine = create_engine('mysql://root:[email protected]:3305/area', echo=False)
"""engine = create_engine('mysql://root:[email protected]:3305/area', echo=False)
connection = engine.connect()
metadata = MetaData()
insp = inspect(engine)
print(insp.get_table_names())
users = Table('users', metadata)
query = select([users])
#print(query)
#print(query)"""

@app.route("/user")
def users():
return
class User:
def __init__(self, name):
self.name = name

users = []

@app.route("/user", methods=['GET'])
def get_users():
return jsonify([user.__dict__ for user in users])

@app.route("/user/<name>", methods=['GET'])
def get_user(name):
for user in users:
if user.name == name:
return jsonify(user.__dict__)
return Response(status=404)

@app.route("/user", methods=['POST'])
def create_user():
name = request.json['name']
users.append(User(name))
return Response(status=200)

@app.route("/user/<name>", methods=['DELETE'])
def delete_user(name):
for user in users:
if user.name == name:
users.remove(user)
return Response(status=200)
return Response(status=404)

@app.route("/about.json")
def about():
Expand All @@ -31,4 +58,5 @@ def about():
}
return jsonify(data)


if __name__ == '__main__':
app.run(port=8000, debug=True)

0 comments on commit 7bfb9fa

Please sign in to comment.