def get(self, request): film_id = request.GET.get('film_id') logger.debug("film_id:{}".format(film_id)) if film_id is None: return ResponseHelper.build_fail("film_id is empty") film_service = FilmService() film = film_service.get_film_by_id(film_id) return ResponseHelper.build_success(model_to_dict(film))
def post(self, request): data = json.loads(request.body) name = data.get('name') img = data.get('img') video = data.get('video') main_page = data.get('main_page') if name is None: return ResponseHelper.build_fail("name is empty") film_service = FilmService() film_id = film_service.create_film(name, img, video, main_page) return ResponseHelper.build_success({"film_id": film_id})
def support_film(request): """ Give a like to film :return: """ film_id = request.POST.get('film_id') if film_id is None: return ResponseHelper.build_fail(constants.FILM_ID_IS_EMPTY) film_service = FilmService() film_service.support_film(film_id) return ResponseHelper.build_success(None)
def get(self, request): """ Get email code :param email: :param is_test: :return: """ email = request.GET.get("email") is_test = request.GET.get("is_test") email_code_service = EmailCodeService() email_code = email_code_service.send_email(email, is_test) if is_test: return ResponseHelper.build_success({"email_code": email_code}) return ResponseHelper.build_success()
def put(self, request): data = json.loads(request.body) film_id = data.get('film_id') img = data.get('img') video = data.get('video') main_page = data.get('main_page') if film_id is None: return ResponseHelper.build_fail(constants.FILM_ID_IS_EMPTY) if img is None and video is None and main_page is None: return ResponseHelper.build_fail( constants.UPDATED_FIELDS_ARE_EMPTY) film_service = FilmService() film_service.update_film_by_id(film_id, img, video, main_page) return ResponseHelper.build_success()
def delete(self, request): # Check whether the user login token = request.META.get("TOKEN") if token is None: return ResponseHelper.build_fail('Please login first') user_dict = LocalCacheUtil.get_data("token-" + token.__str__()) if user_dict is not None: return ResponseHelper.build_fail('Please login first') film_id = request.GET.get("film_id") if film_id is None: return ResponseHelper.build_fail( 'Please choose the film to delete') logger.debug('begin to delete film , film id is :{}'.format(film_id)) film_service = FilmService() film_service.delete_movie(film_id) return ResponseHelper.build_success()
def post(self, request): """ login :param request: :return: """ data = json.loads(request.body) email = data['email'] password = data['password'] # check parameter if email is None or len(email) == 0: return ResponseHelper.build_fail(constants.EMAIL_IS_INVALID) if password is None or len(password) == 0: return ResponseHelper.build_fail(constants.PASSWORD_IS_INVALID) session_service = SessionService() token = session_service.create_session(email, password) return ResponseHelper.build_success({"token": token.__str__()})
def post(self, request): """ Register user :param request: :return: """ data = json.loads(request.body) email = data.get("email") email_code = data.get("email_code") password = data.get("password") user_service = UserService() try: count = user_service.register_user(email, email_code, password) except RegisterException as e: return ResponseHelper.build_fail(e.reason) if count < 1: return ResponseHelper.build_fail(constants.REGISTER_FAIL) return ResponseHelper.build_fail(constants.REGISTER_SUCCESS)
def get(self, request): """ Get user including detail information :param request: :return: """ token = request.META.get("TOKEN") # TODO get user_id by token user_id = 1 user_service = UserService() user_detail = user_service.get_user_detail_by_id(user_id) return ResponseHelper.build_success(model_to_dict(user_detail))
def delete(self, request): """ Delete user :param request: :return: """ token = request.META.get("TOKEN") # TODO get user_id by token user_id = 1 user_service = UserService() user_service.delete_user(user_id) # TODO logout user return ResponseHelper.build_success()
def delete(self, request): token = request.META.get("TOKEN") if token is None: return ResponseHelper.build_fail('token is null') username = SessionService.delete_session(token) return ResponseHelper.build_success({"username": username})