-
-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathresources.py
More file actions
121 lines (106 loc) · 2.57 KB
/
resources.py
File metadata and controls
121 lines (106 loc) · 2.57 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from databases import Database
from fastapi import APIRouter, Depends
from backend.db import get_db
from backend.models.dtos.mapping_badge_dto import (
MappingBadgeDTO,
MappingBadgeCreateDTO,
MappingBadgeUpdateDTO,
MappingBadgeListDTO,
MappingBadgePublicListDTO,
)
from backend.models.dtos.user_dto import AuthUserDTO
from backend.services.mapping_badges import MappingBadgeService
from backend.services.users.authentication_service import pm_only
router = APIRouter(
prefix="/badges",
tags=["mapping_badges"],
responses={404: {"description": "Not found"}},
)
@router.get("/")
async def get_mapping_badges(
db: Database = Depends(get_db),
) -> MappingBadgeListDTO:
"""
List mapping badges
---
tags:
- badges
produces:
- application/json
"""
return await MappingBadgeService.get_all(db)
@router.post("/")
async def create_mapping_badge(
data: MappingBadgeCreateDTO,
db: Database = Depends(get_db),
user: AuthUserDTO = Depends(pm_only),
) -> MappingBadgeDTO:
"""
Creates a new MappingBadge
---
tags:
- badges
produces:
- application/json
"""
return await MappingBadgeService.create(data, db)
@router.get("/{badge_id}/")
async def get_mapping_badge(
badge_id: int,
db: Database = Depends(get_db),
) -> MappingBadgeDTO:
"""
Gets information for a single badge
---
tags:
- badges
produces:
- application/json
"""
return await MappingBadgeService.get_by_id(badge_id, db)
@router.patch("/{badge_id}/")
async def update_mapping_badge(
data: MappingBadgeUpdateDTO,
badge_id: int,
db: Database = Depends(get_db),
user: AuthUserDTO = Depends(pm_only),
) -> MappingBadgeDTO:
"""
Updates a mapping badge
---
tags:
- badges
produces:
- application/json
"""
data.id = badge_id
return await MappingBadgeService.update(data, db)
@router.delete("/{badge_id}/")
async def delete_mapping_badge(
badge_id: int,
db: Database = Depends(get_db),
user: AuthUserDTO = Depends(pm_only),
):
"""
Deletes a mapping badge
---
tags:
- badges
produces:
- application/json
"""
await MappingBadgeService.delete(badge_id, db)
@router.get("/user/{user_id}/")
async def get_for_user(
user_id: int,
db: Database = Depends(get_db),
) -> MappingBadgePublicListDTO:
"""
Get all mapping badges that a user has earned
---
tags:
- badges
produces:
- application/json
"""
return await MappingBadgeService.get_for_user(user_id, db)