コード例 #1
0
    def get(self, request, format=None):
        self.initialize_dependencies()

        # TODO access_token is currently name. Should change later
        username = get_query_value_from(request, query_name=ACCESS_TOKEN)
        groupid = get_query_value_from(request, query_name=GROUPID)
        api_type_from_query = get_query_value_from(request, query_name=API_TYPE)
        sorting_option = get_query_value_from(request, query_name=SORTING_OPTION)
        max_number = get_query_value_from(request, query_name=MAX_NUMBER)

        # TODO create an option class
        option = self.suggestion_manager.get_option(sorting_option_string=sorting_option, max_number=max_number)
        # TODO currently we are using Yelp API
        suggested_restaurants_list = \
            self.suggestion_manager.get_restaurant_suggestions_of_group(
                groupid,
                api_type=APIType.get_type_of(api_type_from_query),
                option=option
            )
        serialized_restaurant_list = \
            self.dto_manager.serialize_list(
                data=suggested_restaurants_list,
                Response_DTO=ResponseRestaurantDTO
            )

        # TODO change here
        return Response(serialized_restaurant_list, status=status.HTTP_200_OK)
コード例 #2
0
 def get(self, request, format=None):
     access_token = get_query_value_from(request, query_name=ACCESS_TOKEN)
     # wrapper checks if access token is valid
     success_message = "Access token ({}) is verified".format(
         str(access_token))
     success_DTO = ResponseSuccessDTO(success_message)
     return Response(success_DTO.serialize(), status=status.HTTP_200_OK)
コード例 #3
0
 def get(self, request, format=None):
     self.initialize_dependencies()
     username = get_query_value_from(request, query_name=ACCESS_TOKEN)
     group_list = self.group_manager.get_group_list_of_user_by_username(
         username)
     return Response(self.dto_manager.serialize_list(
         data=group_list, Response_DTO=ResponseGroupDTO),
                     status=status.HTTP_200_OK)
コード例 #4
0
    def post(self, request, format=None):
        self.initialize_dependencies()
        # TODO currently username == access token change later.
        username = get_query_value_from(request, query_name=USERNAME)

        user_account = self.model_creator.create_user_with_default_settings_and_return_instance(
            username)

        serializer = UserAccountSerializer(user_account)
        return Response(serializer.data, status=status.HTTP_201_CREATED)
コード例 #5
0
    def get(self, request, format=None):
        self.initialize_dependencies()
        # TODO access_token is currently name. Should change later
        username = get_query_value_from(request, query_name=ACCESS_TOKEN)
        # TODO This should be consistent. Change it to our DTO.
        group_list = self.group_manager.get_group_list_of_user_by_username(
            username)
        serialize_group_list_data = self.dto_manager.serialize_list(
            data=group_list, Response_DTO=ResponseGroupDTO)

        return Response(serialize_group_list_data, status=status.HTTP_200_OK)
コード例 #6
0
 def get(self, request, format=None):
     self.initialize_dependencies()
     group_id = get_query_value_from(request, query_name=GROUPID)
     user_list = self.group_manager.get_users_in_the_group_by_group_id(
         group_id)
     if user_list:
         return Response(self.dto_manager.serialize_list(
             data=user_list, Response_DTO=ResponseUserDTO),
                         status=status.HTTP_200_OK)
     else:
         return Response(status=status.HTTP_404_NOT_FOUND)
コード例 #7
0
    def post(self, request, form=None):
        self.initialize_dependencies()
        # TODO access_token is currently name. Should change later
        joinGroupDTO = RequestJoinGroupDTO().deserialize(request)
        username = get_query_value_from(request, query_name=ACCESS_TOKEN)
        groupid = joinGroupDTO.id

        self.group_manager.add_group_of_groupid_to_user_of_username(
            username=username, groupid=groupid)
        success_message = "group {} is successfully added to {}".format(
            groupid, username)
        return Response(ResponseSuccessDTO(success_message).serialize(),
                        status=status.HTTP_200_OK)
コード例 #8
0
    def post(self, request, format=None):
        self.initialize_dependencies()
        # TODO access_token is currently name. Should change later
        username = get_query_value_from(request, query_name=ACCESS_TOKEN)
        create_group_dto = RequestCreateGroupDTO().deserialize(request)
        group_name = create_group_dto.name
        meeting_time = get_body_field_value_from(request,
                                                 body_field_name=MEETING_TIME)

        group = self.group_manager.create_group_and_add_to_user_of_username(
            username=username, groupname=group_name)
        # TODO change access token to username later
        response_dto = ResponseGroupDTO().sync_with_instance(group)
        return Response(response_dto.serialize(), status=status.HTTP_200_OK)
コード例 #9
0
    def delete(self, request, format=None):
        self.initialize_dependencies()
        # TODO access_token is currently name. Should change later
        username = get_query_value_from(request, query_name=ACCESS_TOKEN)
        groupid = get_body_field_value_from(request, body_field_name=ID)
        group = self.group_manager.get_group_by_groupid(groupid)

        self.group_manager.user_of_username_leave_group_of_groupid(
            groupid, username)
        # TODO change access token to username later
        success_message = "group {} is successfully removed from {}".format(
            groupid, username)
        return Response(ResponseSuccessDTO(success_message).serialize(),
                        status=status.HTTP_200_OK)
コード例 #10
0
 def get(self, request, format=None):
     """
     get preference settings of an given user
     @get response {
         "id": 46,
         "food_vegetarian": 0,
         "food_vegan": 0,
         "food_spicy": 0,
         "place_loud": 0
     }
     """
     self.initialize_dependencies()
     # TODO access_token is currently name. Should change later
     username = get_query_value_from(request, query_name=ACCESS_TOKEN)
     preference_settings = self.preference_manager.get_preference_settings_by_username(
         username)
     preference_settings_DTO = PreferenceSettingsDTO().sync_with_instance(
         preference_settings)
     return Response(preference_settings_DTO.serialize(),
                     status=status.HTTP_200_OK)
コード例 #11
0
    def get(self, request, format=None):
        self.initialize_dependencies()
        # TODO access_token is currently name. Should change later
        username = get_query_value_from(request, query_name=ACCESS_TOKEN)
        user = self.user_model_manager.get_user_by_name(username)

        preference_detail = self.preference_model_manager.get_preference_settings_by_id(
            user.preferences.id)
        preference_detail_dto = PreferenceSettingsDTO().serialize(
            instance_to_sync=preference_detail)
        group_detail = self.group_manager.get_group_list_of_user_by_username(
            username)
        group_detail_dto = self.dto_manager.serialize_list(
            data=group_detail, Response_DTO=ResponseGroupDTO)

        response_dto = ResponseUserDetailDTO(user.id, username,
                                             preference_detail_dto,
                                             group_detail_dto)

        return Response(response_dto.serialize(), status=status.HTTP_200_OK)
コード例 #12
0
    def post(self, request, format=None):
        """
        change user preference settings
        @post response {
            "id": 46,
            "food_vegetarian": 2,
            "food_vegan": 1,
            "food_spicy": 1,
            "place_loud": 3
        }
        """
        self.initialize_dependencies()
        # TODO access_token is currently name. Should change later
        username = get_query_value_from(request, ACCESS_TOKEN)
        preference_update_dict = request.data

        preference_settings = \
            self.preference_manager.update_preference_settings_of_username_and_return_instance(username, preference_update_dict)
        preference_settings_dto = PreferenceSettingsDTO().sync_with_instance(
            preference_settings)
        return Response(preference_settings_dto.serialize(),
                        status=status.HTTP_200_OK)