Skip to content

Commit 816191f

Browse files
author
Shafaf
committed
Temp: api updated
1 parent 1e69fc7 commit 816191f

6 files changed

Lines changed: 41 additions & 13 deletions

File tree

api/__init.py__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
from .v1 import v1

api/v1/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from flask import Blueprint
2+
3+
# v1 blueprint
4+
v1 = Blueprint("v1", __name__, url_prefix="/api/v1")
5+
6+
from .views import *
7+
from .plan import *

api/v1/plan.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import jsonify
2+
from flask.views import MethodView
3+
4+
from . import v1
5+
6+
# test v1 api endpoint.
7+
class Plan(MethodView):
8+
def get(self):
9+
return jsonify({"test": "This is plan api"}), 200
10+
11+
v1.add_url_rule("/plan", view_func=Plan.as_view("plan"))

api/v1/views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import jsonify
2+
from flask.views import MethodView
3+
4+
from . import v1
5+
6+
# test v1 api endpoint.
7+
class Live(MethodView):
8+
def get(self):
9+
return jsonify({"Live": True, "version": "v0.0.1"}), 200
10+
11+
v1.add_url_rule("", view_func=Live.as_view("live"))

app.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
from flask import Flask
22
from sqlalchemy import create_engine
33

4-
from connection import conn
5-
from model.subscription import hello
4+
from api.v1 import v1
5+
6+
# from connection import conn
7+
# from model.subscription import hello
68

79
def create_app():
810
app = Flask(__name__)
911

10-
# open a cursor to perform database operations
11-
cur = conn.cursor()
12-
# print("Cursor opened successfully", cur)
13-
# engine = create_engine('postgresql:///tutorial.db', echo=True)
14-
hello()
15-
# Execute a database query
16-
cur.execute("SELECT * FROM student;")
17-
18-
# Fetch the result
19-
result = cur.fetchall()
2012
print("Result fetched successfully")
2113

14+
app.register_blueprint(v1)
15+
2216
@app.route("/")
2317
def index():
24-
return result
18+
return "hello how are you!"
2519

2620
return app
2721

utils/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from sqlalchemy import create_engine
2+
3+
engine = create_engine("sqlite+pysqlite:///:memory:", echo=True)

0 commit comments

Comments
 (0)