-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathservice.py
More file actions
71 lines (57 loc) · 1.93 KB
/
service.py
File metadata and controls
71 lines (57 loc) · 1.93 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
68
69
70
71
from fastapi import APIRouter, Depends
from backend.models.user_model import User
from ..services import ServiceService, UserService
from ..models.service_model import Service
from typing import List
api = APIRouter(prefix="/api/service")
openapi_tags = {
"name": "Service",
"description": "Service search and related operations.",
}
# TODO: Add security using HTTP Bearer Tokens
# TODO: Enable authorization by passing user uuid to API
# TODO: Create custom exceptions
@api.post("", response_model=Service, tags=["Service"])
def create(
uuid: str,
service: Service,
user_svc: UserService = Depends(),
service_svc: ServiceService = Depends(),
):
subject = user_svc.get_user_by_uuid(uuid)
return service_svc.create(subject, service)
@api.get("", response_model=List[Service], tags=["Service"])
def get_all(
uuid: str,
user_svc: UserService = Depends(),
service_svc: ServiceService = Depends(),
):
subject = user_svc.get_user_by_uuid(uuid)
return service_svc.get_service_by_user(subject)
@api.get("/{name}", response_model=Service, tags=["Service"])
def get_by_name(
name: str,
uuid: str,
user_svc: UserService = Depends(),
service_svc: ServiceService = Depends(),
):
subject = user_svc.get_user_by_uuid(uuid)
return service_svc.get_service_by_name(name, subject)
@api.put("", response_model=Service, tags=["Service"])
def update(
uuid: str,
service: Service,
user_svc: UserService = Depends(),
service_svc: ServiceService = Depends(),
):
subject = user_svc.get_user_by_uuid(uuid)
return service_svc.update(subject, service)
@api.delete("", response_model=dict, tags=["Service"])
def delete(
uuid: str,
id: int,
user_svc: UserService = Depends(),
service_svc: ServiceService = Depends(),
):
subject = user_svc.get_user_by_uuid(uuid)
return service_svc.delete(subject, id)