Coverage for src/resources/profile_resource.py : 60%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from flask import request
2from flask_restx import Resource, reqparse
3from flask_jwt_extended import jwt_required, get_jwt_identity
5from src.service import ProfileService, ExternalService
6from src.dto import ProfileDto
8from src.utils import validation_error
11api = ProfileDto.api
12data_resp = ProfileDto.data_resp
13data_resp_list = ProfileDto.data_resp_list
14liked_genres_resp_list = ProfileDto.liked_genres_resp_list
15search_data_resp = ProfileDto.search_data_resp
16meta_application_resp = ProfileDto.meta_application_resp
17meta_book_resp = ProfileDto.meta_book_resp
18meta_game_resp = ProfileDto.meta_game_resp
19meta_movie_resp = ProfileDto.meta_movie_resp
20meta_serie_resp = ProfileDto.meta_serie_resp
21meta_track_resp = ProfileDto.meta_track_resp
22result_app_resp = ProfileDto.result_app_resp
23result_book_resp = ProfileDto.result_book_resp
24result_game_resp = ProfileDto.result_game_resp
25result_movie_resp = ProfileDto.result_movie_resp
26result_serie_resp = ProfileDto.result_serie_resp
27result_track_resp = ProfileDto.result_track_resp
30@api.route("", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
31class UserProfileResource(Resource):
32 @api.doc(
33 "Get a specific profile",
34 responses={
35 200: ("Profile data successfully sent", search_data_resp),
36 401: ("Authentication required"),
37 403: ("Permission missing"),
38 },
39 )
40 @jwt_required
41 def get(self):
42 """ Get list of user's profile """
43 user_uuid = get_jwt_identity()
45 try:
46 page = int(request.args.get('page'))
47 except (ValueError, TypeError):
48 page = 1
50 return ProfileService.get_profiles(user_uuid, page)
52 profile_data = ProfileDto.profile_data
54 @api.doc(
55 "Create a new profile",
56 responses={
57 200: ("Profile successfully created", data_resp),
58 401: ("Malformed data or validations failed."),
59 401: ("Authentication required"),
60 403: ("Permission missing"),
61 },
62 )
63 @jwt_required
64 @api.expect(profile_data, validate=True)
65 def post(self):
66 """ Get list of user's profile """
67 user_uuid = get_jwt_identity()
69 data = request.get_json()
71 return ProfileService.create_profile(data, user_uuid)
74@api.route("/<uuid:uuid>")
75class ProfileResource(Resource):
76 @api.doc(
77 "Get a specific profile",
78 responses={
79 200: ("Profile data successfully sent", data_resp),
80 401: ("Authentication required"),
81 404: "Profile not found!",
82 },
83 )
84 @jwt_required
85 def get(self, uuid):
86 """ Get a specific profile's data by their uuid """
87 profile_uuid = get_jwt_identity()
88 return ProfileService.get_profile_data(uuid, profile_uuid)
90 @api.doc(
91 "Delete a specific profile account",
92 responses={
93 200: ("Profile account successfully deleted", data_resp),
94 401: ("Authentication required"),
95 403: ("Unable to delete an account which is not your's"),
96 404: "Profile not found!",
97 },
98 )
99 @jwt_required
100 def delete(self, uuid):
101 """ Delete a specific profile's account by their uuid """
102 profile_uuid = get_jwt_identity()
103 return ProfileService.delete_account(uuid, profile_uuid)
105 profile_data = ProfileDto.profile_data
107 @api.doc(
108 "Update a specific profilename",
109 responses={
110 200: ("Profilename successfully updated", data_resp),
111 401: ("Authentication required"),
112 403: ("Unable to update an account which is not your's"),
113 404: "Profile not found!",
114 },
115 )
116 @jwt_required
117 @api.expect(profile_data, validate=True)
118 def patch(self, uuid):
119 profile_uuid = get_jwt_identity()
120 data = request.get_json()
122 return ProfileService.update_profile_data(uuid, profile_uuid, data)
125@api.route("/<uuid:profile_uuid>/genre")
126class ProfileGenresResource(Resource):
127 @api.doc(
128 "Get liked genres (connected profile)",
129 responses={
130 200: ("Successfully send", liked_genres_resp_list),
131 401: ("Authentication required"),
132 404: "Profile not found!",
133 }
134 )
135 @jwt_required
136 def get(self, profile_uuid):
137 """ Get liked genres (connected profile) """
138 uuid = get_jwt_identity()
140 return ProfileService.get_genres(uuid, profile_uuid)
143@api.route("/<uuid:profile_uuid>/genre/<int:genre_id>")
144class ProfileGenreResource(Resource):
145 @api.doc(
146 "Like a genre (connected profile)",
147 responses={
148 201: ("Successfully send"),
149 401: ("Authentication required"),
150 404: "Profile or Genre not found!",
151 }
152 )
153 @jwt_required
154 def put(self, genre_id, profile_uuid):
155 """ Like a genre (connected profile) """
156 user_uuid = get_jwt_identity()
158 return ProfileService.like_genre(genre_id, user_uuid, profile_uuid)
160 @api.doc(
161 "Unlike a genre (connected profile)",
162 responses={
163 201: ("Successfully send"),
164 401: ("Authentication required"),
165 404: "Profile or Genre not found!",
166 }
167 )
168 @jwt_required
169 def delete(self, genre_id, profile_uuid):
170 """ Unlike a genre (connected profile) """
171 user_uuid = get_jwt_identity()
173 return ProfileService.unlike_genre(genre_id, user_uuid, profile_uuid)
176@api.route("/<uuid:profile_uuid>/content/<int:content_id>/meta")
177class ProfileMetaContentResource(Resource):
178 content_meta = ProfileDto.content_meta
180 @api.doc(
181 "Update or set meta between porfile and content",
182 responses={
183 201: ("Successfully send"),
184 401: ("Authentication required"),
185 404: "User or Profile not found!",
186 }
187 )
188 @jwt_required
189 @api.expect(content_meta, validate=True)
190 def put(self, profile_uuid, content_id):
191 """ Update or set meta between porfile and content """
192 user_uuid = get_jwt_identity()
194 # Grab the json data
195 data = request.get_json()
197 return ProfileService.update_meta(profile_uuid, content_id, user_uuid, data)
200@api.route("/<uuid:profile_uuid>/application/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
201class ProfileMetaApplicationResource(Resource):
202 @api.doc(
203 "Get meta between profile and application",
204 responses={
205 200: ("Successfully send", meta_application_resp),
206 401: ("Authentication required"),
207 404: "User or Profile not found!",
208 }
209 )
210 @jwt_required
211 def get(self, profile_uuid):
212 """ Get meta between profile and application """
213 user_uuid = get_jwt_identity()
215 try:
216 page = int(request.args.get('page'))
217 except (ValueError, TypeError):
218 page = 1
220 return ProfileService.get_profile_meta_app(profile_uuid, user_uuid, page)
223@api.route("/<uuid:profile_uuid>/book/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
224class ProfileMetaBookResource(Resource):
225 @api.doc(
226 "Get meta between profile and book",
227 responses={
228 200: ("Successfully send", meta_book_resp),
229 401: ("Authentication required"),
230 404: "User or Profile not found!",
231 }
232 )
233 @jwt_required
234 def get(self, profile_uuid):
235 """ Get meta between profile and book """
236 user_uuid = get_jwt_identity()
238 try:
239 page = int(request.args.get('page'))
240 except (ValueError, TypeError):
241 page = 1
243 return ProfileService.get_profile_meta_book(profile_uuid, user_uuid, page)
246@api.route("/<uuid:profile_uuid>/game/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
247class ProfileMetaGameResource(Resource):
248 @api.doc(
249 "Get meta between profile and game",
250 responses={
251 200: ("Successfully send", meta_game_resp),
252 401: ("Authentication required"),
253 404: "User or Profile not found!",
254 }
255 )
256 @jwt_required
257 def get(self, profile_uuid):
258 """ Get meta between profile and game """
259 user_uuid = get_jwt_identity()
261 try:
262 page = int(request.args.get('page'))
263 except (ValueError, TypeError):
264 page = 1
266 return ProfileService.get_profile_meta_game(profile_uuid, user_uuid, page)
269@api.route("/<uuid:profile_uuid>/movie/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
270class ProfileMetaMovieResource(Resource):
271 @api.doc(
272 "Get meta between profile and movie",
273 responses={
274 200: ("Successfully send", meta_movie_resp),
275 401: ("Authentication required"),
276 404: "User or Profile not found!",
277 }
278 )
279 @jwt_required
280 def get(self, profile_uuid):
281 """ Get meta between profile and movie """
282 user_uuid = get_jwt_identity()
284 try:
285 page = int(request.args.get('page'))
286 except (ValueError, TypeError):
287 page = 1
289 return ProfileService.get_profile_meta_movie(profile_uuid, user_uuid, page)
292@api.route("/<uuid:profile_uuid>/serie/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
293class ProfileMetaSerieResource(Resource):
294 @api.doc(
295 "Get meta between profile and serie",
296 responses={
297 200: ("Successfully send", meta_serie_resp),
298 401: ("Authentication required"),
299 404: "User or Profile not found!",
300 }
301 )
302 @jwt_required
303 def get(self, profile_uuid):
304 """ Get meta between profile and serie """
305 user_uuid = get_jwt_identity()
307 try:
308 page = int(request.args.get('page'))
309 except (ValueError, TypeError):
310 page = 1
312 return ProfileService.get_profile_meta_serie(profile_uuid, user_uuid, page)
315@api.route("/<uuid:profile_uuid>/track/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
316class ProfileMetaTrackResource(Resource):
317 @api.doc(
318 "Get meta between profile and track",
319 responses={
320 200: ("Successfully send", meta_track_resp),
321 401: ("Authentication required"),
322 404: "User or Profile not found!",
323 }
324 )
325 @jwt_required
326 def get(self, profile_uuid):
327 """ Get meta between profile and track """
328 user_uuid = get_jwt_identity()
330 try:
331 page = int(request.args.get('page'))
332 except (ValueError, TypeError):
333 page = 1
335 return ProfileService.get_profile_meta_track(profile_uuid, user_uuid, page)
338@api.route("/<uuid:profile_uuid>/history", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
339class ProfileRecoHistoryResource(Resource):
340 @api.doc(
341 "Get recommendation history",
342 responses={
343 200: ("Successfully send", data_resp_list),
344 401: ("Authentication required"),
345 404: "User or Profile not found!",
346 }
347 )
348 @jwt_required
349 def get(self, profile_uuid):
350 """ Get recommendation history """
351 user_uuid = get_jwt_identity()
353 parser = reqparse.RequestParser()
354 parser.add_argument('page', type=int, default=1)
355 args = parser.parse_args()
357 return ProfileService.get_reco_history(profile_uuid, user_uuid, args["page"])
360@api.route("/<uuid:profile_uuid>/history/<int:id>/genres", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
361class ProfileRecoHistoryGenresResource(Resource):
362 @api.doc(
363 "Get liked genres from event",
364 responses={
365 200: ("Successfully send", liked_genres_resp_list),
366 401: ("Authentication required"),
367 404: "User or Profile not found!",
368 }
369 )
370 @jwt_required
371 def get(self, profile_uuid, id):
372 """ Get liked genres from event """
373 user_uuid = get_jwt_identity()
375 parser = reqparse.RequestParser()
376 parser.add_argument('page', type=int, default=1)
377 args = parser.parse_args()
379 return ProfileService.get_liked_genre_history(profile_uuid, id, user_uuid, args["page"])
382@api.route("/<uuid:profile_uuid>/history/<int:id>/application/result", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
383class ProfileRecoHistoryApplicationResultResource(Resource):
384 @api.doc(
385 "Get recommended application result history",
386 responses={
387 200: ("Successfully send", result_app_resp),
388 401: ("Authentication required"),
389 404: "User or Profile not found!",
390 }
391 )
392 @jwt_required
393 def get(self, profile_uuid, id):
394 """ Get recommended application result history """
395 user_uuid = get_jwt_identity()
397 parser = reqparse.RequestParser()
398 parser.add_argument('page', type=int, default=1)
399 args = parser.parse_args()
401 return ProfileService.get_app_reco_result_history(profile_uuid, id, user_uuid, args["page"])
404@api.route("/<uuid:profile_uuid>/history/<int:id>/application/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
405class ProfileRecoHistoryApplicationMetaResource(Resource):
406 @api.doc(
407 "Get recommended application meta history",
408 responses={
409 200: ("Successfully send", meta_application_resp),
410 401: ("Authentication required"),
411 404: "User or Profile not found!",
412 }
413 )
414 @jwt_required
415 def get(self, profile_uuid, id):
416 """ Get recommended application meta history """
417 user_uuid = get_jwt_identity()
419 parser = reqparse.RequestParser()
420 parser.add_argument('page', type=int, default=1)
421 args = parser.parse_args()
423 return ProfileService.get_app_reco_meta_history(profile_uuid, id, user_uuid, args["page"])
426@api.route("/<uuid:profile_uuid>/history/<int:id>/book/result", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
427class ProfileRecoHistoryBookResultResource(Resource):
428 @api.doc(
429 "Get recommended book result history",
430 responses={
431 200: ("Successfully send", result_book_resp),
432 401: ("Authentication required"),
433 404: "User or Profile not found!",
434 }
435 )
436 @jwt_required
437 def get(self, profile_uuid, id):
438 """ Get recommended book result history """
439 user_uuid = get_jwt_identity()
441 parser = reqparse.RequestParser()
442 parser.add_argument('page', type=int, default=1)
443 args = parser.parse_args()
445 return ProfileService.get_book_reco_result_history(profile_uuid, id, user_uuid, args["page"])
448@api.route("/<uuid:profile_uuid>/history/<int:id>/book/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
449class ProfileRecoHistoryBookMetaResource(Resource):
450 @api.doc(
451 "Get recommended book meta history",
452 responses={
453 200: ("Successfully send", meta_book_resp),
454 401: ("Authentication required"),
455 404: "User or Profile not found!",
456 }
457 )
458 @jwt_required
459 def get(self, profile_uuid, id):
460 """ Get recommended book meta history """
461 user_uuid = get_jwt_identity()
463 parser = reqparse.RequestParser()
464 parser.add_argument('page', type=int, default=1)
465 args = parser.parse_args()
467 return ProfileService.get_book_reco_meta_history(profile_uuid, id, user_uuid, args["page"])
470@api.route("/<uuid:profile_uuid>/history/<int:id>/game/result", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
471class ProfileRecoHistoryResultGameResource(Resource):
472 @api.doc(
473 "Get recommended game result istory",
474 responses={
475 200: ("Successfully send", result_game_resp),
476 401: ("Authentication required"),
477 404: "User or Profile not found!",
478 }
479 )
480 @jwt_required
481 def get(self, profile_uuid, id):
482 """ Get recommended game result history """
483 user_uuid = get_jwt_identity()
485 parser = reqparse.RequestParser()
486 parser.add_argument('page', type=int, default=1)
487 args = parser.parse_args()
489 return ProfileService.get_game_reco_result_history(profile_uuid, id, user_uuid, args["page"])
492@api.route("/<uuid:profile_uuid>/history/<int:id>/game/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
493class ProfileRecoHistoryGameMEtaResource(Resource):
494 @api.doc(
495 "Get recommended game meta history",
496 responses={
497 200: ("Successfully send", meta_game_resp),
498 401: ("Authentication required"),
499 404: "User or Profile not found!",
500 }
501 )
502 @jwt_required
503 def get(self, profile_uuid, id):
504 """ Get recommended game meta history """
505 user_uuid = get_jwt_identity()
507 parser = reqparse.RequestParser()
508 parser.add_argument('page', type=int, default=1)
509 args = parser.parse_args()
511 return ProfileService.get_game_reco_meta_history(profile_uuid, id, user_uuid, args["page"])
514@api.route("/<uuid:profile_uuid>/history/<int:id>/movie/result", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
515class ProfileRecoHistoryMovieResultResource(Resource):
516 @api.doc(
517 "Get recommended movie result history",
518 responses={
519 200: ("Successfully send", result_movie_resp),
520 401: ("Authentication required"),
521 404: "User or Profile not found!",
522 }
523 )
524 @jwt_required
525 def get(self, profile_uuid, id):
526 """ Get recommended movie result history """
527 user_uuid = get_jwt_identity()
529 parser = reqparse.RequestParser()
530 parser.add_argument('page', type=int, default=1)
531 args = parser.parse_args()
533 return ProfileService.get_movie_reco_result_history(profile_uuid, id, user_uuid, args["page"])
536@api.route("/<uuid:profile_uuid>/history/<int:id>/movie/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
537class ProfileRecoHistoryMovieMetaResource(Resource):
538 @api.doc(
539 "Get recommended movie meta history",
540 responses={
541 200: ("Successfully send", meta_movie_resp),
542 401: ("Authentication required"),
543 404: "User or Profile not found!",
544 }
545 )
546 @jwt_required
547 def get(self, profile_uuid, id):
548 """ Get recommended movie meta history """
549 user_uuid = get_jwt_identity()
551 parser = reqparse.RequestParser()
552 parser.add_argument('page', type=int, default=1)
553 args = parser.parse_args()
555 return ProfileService.get_movie_reco_meta_history(profile_uuid, id, user_uuid, args["page"])
558@api.route("/<uuid:profile_uuid>/history/<int:id>/serie/result", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
559class ProfileRecoHistoryResultSerieResource(Resource):
560 @api.doc(
561 "Get recommended serie result history",
562 responses={
563 200: ("Successfully send", result_serie_resp),
564 401: ("Authentication required"),
565 404: "User or Profile not found!",
566 }
567 )
568 @jwt_required
569 def get(self, profile_uuid, id):
570 """ Get recommended serie result history """
571 user_uuid = get_jwt_identity()
573 parser = reqparse.RequestParser()
574 parser.add_argument('page', type=int, default=1)
575 args = parser.parse_args()
577 return ProfileService.get_serie_reco_result_history(profile_uuid, id, user_uuid, args["page"])
580@api.route("/<uuid:profile_uuid>/history/<int:id>/serie/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
581class ProfileRecoHistoryMetaSerieResource(Resource):
582 @api.doc(
583 "Get recommended serie meta history",
584 responses={
585 200: ("Successfully send", meta_serie_resp),
586 401: ("Authentication required"),
587 404: "User or Profile not found!",
588 }
589 )
590 @jwt_required
591 def get(self, profile_uuid, id):
592 """ Get recommended serie meta history """
593 user_uuid = get_jwt_identity()
595 parser = reqparse.RequestParser()
596 parser.add_argument('page', type=int, default=1)
597 args = parser.parse_args()
599 return ProfileService.get_serie_reco_meta_history(profile_uuid, id, user_uuid, args["page"])
602@api.route("/<uuid:profile_uuid>/history/<int:id>/track/result", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
603class ProfileRecoHistoryResultTrackResource(Resource):
604 @api.doc(
605 "Get recommended track result history",
606 responses={
607 200: ("Successfully send", result_track_resp),
608 401: ("Authentication required"),
609 404: "User or Profile not found!",
610 }
611 )
612 @jwt_required
613 def get(self, profile_uuid, id):
614 """ Get recommended track result history """
615 user_uuid = get_jwt_identity()
617 parser = reqparse.RequestParser()
618 parser.add_argument('page', type=int, default=1)
619 args = parser.parse_args()
621 return ProfileService.get_track_reco_result_history(profile_uuid, id, user_uuid, args["page"])
624@api.route("/<uuid:profile_uuid>/history/<int:id>/track/meta", doc={"params": {"page": {"in": "query", "type": "int", "default": 1}}})
625class ProfileRecoHistoryMetaTrackResource(Resource):
626 @api.doc(
627 "Get recommended track meta history",
628 responses={
629 200: ("Successfully send", meta_track_resp),
630 401: ("Authentication required"),
631 404: "User or Profile not found!",
632 }
633 )
634 @jwt_required
635 def get(self, profile_uuid, id):
636 """ Get recommended track meta history """
637 user_uuid = get_jwt_identity()
639 parser = reqparse.RequestParser()
640 parser.add_argument('page', type=int, default=1)
641 args = parser.parse_args()
643 return ProfileService.get_track_reco_meta_history(profile_uuid, id, user_uuid, args["page"])