Ejemplo n.º 1
0
def create_review(
    request: CreateReviewJsonRequest,
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(
        Provide[Container.auth_application_service]),
    review_application_service: ReviewApplicationService = Depends(
        Provide[Container.review_application_service]),
    drink_application_service: DrinkApplicationService = Depends(
        Provide[Container.drink_application_service]),
) -> Union[CreateReviewJsonResponse, JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(
        get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(
            get_token_data_output_dto)

    input_dto = CreateReviewInputDto(
        drink_id=request.drink_id,
        user_id=get_token_data_output_dto.user_id,
        rating=request.rating,
        comment=request.comment,
    )
    output_dto = review_application_service.create_review(
        input_dto=input_dto,
        drink_application_service=drink_application_service)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
    return CreateReviewJsonResponse.build_by_output_dto(output_dto)
Ejemplo n.º 2
0
def test_get_token_data_fail(jwt_secret_key, jwt_algorithm):
    auth_application_service = AuthApplicationService(
        user_application_service=mock.Mock(spec=UserApplicationService),
        jwt_secret_key=jwt_secret_key,
        jwt_algorithm=jwt_algorithm,
    )
    input_dto = GetTokenDataInputDto(access_token="wrong jwt token")

    actual = auth_application_service.get_token_data(input_dto)
    expected = FailedOutputDto.build_unauthorized_error(message="올바른 access-token이 아닙니다.")
    assert actual == expected
Ejemplo n.º 3
0
def test_get_token_data_success(jwt_secret_key, jwt_algorithm):
    auth_application_service = AuthApplicationService(
        user_application_service=mock.Mock(spec=UserApplicationService),
        jwt_secret_key=jwt_secret_key,
        jwt_algorithm=jwt_algorithm,
    )

    input_dto = GetTokenDataInputDto(
        access_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiaGV1bXNpIn0.OuFWvZ07CwSzR1j7I-wxFHweVb6sB8_U2LezYL7nz3I"
    )
    actual = auth_application_service.get_token_data(input_dto)
    expected = GetTokenDataOutputDto(user_id="heumsi")
    assert actual == expected
Ejemplo n.º 4
0
def delete_wish(
    wish_id: str,
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(Provide[Container.auth_application_service]),
    wish_application_service: WishApplicationService = Depends(Provide[Container.wish_application_service]),
    drink_application_service: DrinkApplicationService = Depends(Provide[Container.drink_application_service]),
) -> Union[CreateWishJsonResponse, JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(get_token_data_output_dto)

    input_dto = DeleteWishInputDto(wish_id=wish_id)
    output_dto = wish_application_service.delete_wish(input_dto, drink_application_service)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
def delete_user(
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(
        Provide[Container.auth_application_service]),
    user_application_service: UserApplicationService = Depends(
        Provide[Container.user_application_service]),
) -> Optional[JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(
        get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(
            get_token_data_output_dto)

    input_dto = DeleteUserInputDto(user_id=get_token_data_output_dto.user_id)
    output_dto = user_application_service.delete_user(input_dto)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
Ejemplo n.º 6
0
def delete_review(
    request: DeleteReviewJsonRequest,
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(
        Provide[Container.auth_application_service]),
    review_application_service: ReviewApplicationService = Depends(
        Provide[Container.review_application_service]),
    drink_application_service: DrinkApplicationService = Depends(
        Provide[Container.drink_application_service]),
) -> Optional[JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(
        get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(
            get_token_data_output_dto)

    input_dto = DeleteReviewInputDto(review_id=request.review_id)
    output_dto = review_application_service.delete_review(
        input_dto, drink_application_service)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
def update_user(
    request: UpdateUserJsonRequest,
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(
        Provide[Container.auth_application_service]),
    user_application_service: UserApplicationService = Depends(
        Provide[Container.user_application_service]),
) -> Optional[JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(
        get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(
            get_token_data_output_dto)

    input_dto = UpdateUserInputDto(
        user_id=get_token_data_output_dto.user_id,
        user_name=request.user_name,
        description=request.description,
        password=request.password,
    )
    output_dto = user_application_service.update_user(input_dto)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)