-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (43 loc) · 1.54 KB
/
main.py
File metadata and controls
67 lines (43 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging
import pathlib
from fastapi import FastAPI
from pydantic import BaseModel
from sys import path
path.append(str(pathlib.Path(__file__).resolve()))
from app.core.config_manager import ConfigManager
from app.core.log_manager import LogManager
from app.core.db.db_manager import DBManager
logger = logging.getLogger(__name__)
confFilePath = pathlib.Path.cwd() / "app" / "conf" / "config.ini"
configManager = ConfigManager()
LogManager(configManager)
logger.info("Starting app")
logger.info(f"Config manager init successful with config file {confFilePath}")
logger.info("Logger manager init successful")
class Hello(BaseModel):
message: str
app = FastAPI()
# This is for when we will need to store information the database
dbManager = DBManager(configManager)
logger.info("DB manager init succesful")
@app.get("/")
async def show_welcome_page():
message = {
"Message": "Welcome to your own API ! It is kind of empty don't you think ? Why don't you try adding an /health !"
}
return message
# add your /health here, reload and make the /health return ok !
@app.get("/getAllStudents")
async def get_all_students():
logger.info("All students where accessed")
all_students = dbManager.getAllStudents()
return all_students
@app.get("/getTeacher")
async def get_all_teachers(n: int):
all_students = dbManager.getAllTeachers()
all_students[0:n]
return all_students
@app.post("/postTeacher")
async def create_teacher(name: str, subject: str):
dbManager.createTeacher(name, subject)
return "Ok !"