Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : 헤더 값 요청 수정 #161

Merged
merged 19 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/showpot-dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- develop
- temp-develop

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface TokenRepository {

boolean existAccessTokenInBlacklist(UUID userId, String accessToken);

void deleteRefreshToken(UUID userId);
boolean deleteRefreshToken(UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public void makeAccessTokenBlacklistAndDeleteRefreshToken(
UUID userId
) {
tokenRepository.saveBlacklistAccessToken(userId, accessToken);
tokenRepository.deleteRefreshToken(userId);

if (!tokenRepository.deleteRefreshToken(userId)) {
throw new BusinessException(TokenError.INVALID_TOKEN);
}
}

private String getExistRefreshToken(UserParam userParam) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.example.util;

public final class ParseToken {

public static String getAccessToken(String accessToken) {
return accessToken.replace("Bearer ", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import com.example.artist.controller.dto.response.ArtistFilterTotalCountApiResponse;
import com.example.artist.controller.dto.response.ArtistSubscriptionApiResponse;
import com.example.artist.controller.dto.response.ArtistUnsubscriptionApiResponse;
import com.example.artist.controller.dto.response.NumberOfSubscribedArtistApiResponse;
import com.example.artist.service.ArtistService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.response.PaginationApiResponse;
import org.example.security.dto.AuthenticatedUser;
import org.example.util.ValidatorUser;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -42,15 +45,8 @@ public ResponseEntity<PaginationApiResponse<ArtistUnsubscriptionPaginationApiPar
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ArtistUnsubscriptionPaginationApiRequest request
) {
var response =
(user == null)
? artistService.findArtistUnsubscriptionsForNonUser(
request.toNonUserServiceRequest()
)
: artistService.findArtistUnsubscriptions(
request.toServiceRequest(user.userId())
);

UUID userId = ValidatorUser.getUserId(user);
var response = artistService.findArtistUnsubscriptions(request.toServiceRequest(userId));
var data = response.data().stream()
.map(ArtistUnsubscriptionPaginationApiParam::from)
.toList();
Expand Down Expand Up @@ -83,6 +79,18 @@ public ResponseEntity<PaginationApiResponse<ArtistSubscriptionPaginationApiParam
);
}

@GetMapping("/subscriptions/count")
@Operation(summary = "구독한 아티스트 수")
public ResponseEntity<NumberOfSubscribedArtistApiResponse> getNumberOfSubscribedArtist(
@AuthenticationPrincipal AuthenticatedUser user
) {
return ResponseEntity.ok(
NumberOfSubscribedArtistApiResponse.from(
artistService.countSubscribedArtists(user.userId())
)
);
}

@PostMapping("/subscribe")
@Operation(summary = "구독하기")
public ResponseEntity<ArtistSubscriptionApiResponse> subscribe(
Expand Down Expand Up @@ -115,7 +123,8 @@ public ResponseEntity<PaginationApiResponse<ArtistSearchPaginationApiParam>> sea
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ArtistSearchPaginationApiRequest request
) {
var response = artistService.searchArtist(request.toServiceRequest(user));
UUID userId = ValidatorUser.getUserId(user);
var response = artistService.searchArtist(request.toServiceRequest(userId));
var data = response.data().stream()
.map(ArtistSearchPaginationApiParam::from)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import org.example.security.dto.AuthenticatedUser;

public record ArtistSearchPaginationApiRequest(

Expand All @@ -31,12 +30,7 @@ public record ArtistSearchPaginationApiRequest(
}
}

public ArtistSearchPaginationServiceRequest toServiceRequest(AuthenticatedUser user) {
UUID userId = null;
if (user != null) {
userId = user.userId();
}

public ArtistSearchPaginationServiceRequest toServiceRequest(UUID userId) {
return ArtistSearchPaginationServiceRequest.builder()
.userId(userId)
.sortStandard(sortStandard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,4 @@ public ArtistUnsubscriptionPaginationServiceRequest toServiceRequest(UUID userId
.size(size)
.build();
}

public ArtistUnsubscriptionPaginationServiceRequest toNonUserServiceRequest() {
return ArtistUnsubscriptionPaginationServiceRequest.builder()
.subscriptionStatusApiType(SubscriptionStatusApiType.UNSUBSCRIBED)
.sortStandard(sortStandard)
.artistGenderApiTypes(artistGenderApiTypes)
.artistApiTypes(artistApiTypes)
.genreIds(genreIds)
.userId(null)
.cursor(cursor)
.size(size)
.build();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.artist.controller.dto.response;


import com.example.artist.service.dto.response.NumberOfSubscribedArtistServiceResponse;

public record NumberOfSubscribedArtistApiResponse(
long count
) {

public static NumberOfSubscribedArtistApiResponse from(
NumberOfSubscribedArtistServiceResponse response
) {
return new NumberOfSubscribedArtistApiResponse(response.count());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.example.artist.service.dto.response.ArtistFilterTotalCountServiceResponse;
import com.example.artist.service.dto.response.ArtistSubscriptionServiceResponse;
import com.example.artist.service.dto.response.ArtistUnsubscriptionServiceResponse;
import com.example.artist.service.dto.response.NumberOfSubscribedArtistServiceResponse;
import com.example.publish.MessagePublisher;
import com.example.publish.message.ArtistServiceMessage;
import com.example.publish.message.ArtistSubscriptionServiceMessage;
Expand All @@ -22,10 +23,9 @@
import org.example.dto.response.PaginationServiceResponse;
import org.example.entity.ArtistSubscription;
import org.example.entity.artist.Artist;
import org.example.usecase.ArtistSubscriptionUseCase;
import org.example.usecase.UserShowUseCase;
import org.example.usecase.UserUseCase;
import org.example.usecase.artist.ArtistUseCase;
import org.example.usecase.subscription.ArtistSubscriptionUseCase;
import org.example.usecase.user.UserUseCase;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -35,7 +35,6 @@ public class ArtistService {

private final ArtistUseCase artistUseCase;
private final ArtistSubscriptionUseCase artistSubscriptionUseCase;
private final UserShowUseCase userShowUseCase;
private final UserUseCase userUseCase;
private final MessagePublisher messagePublisher;

Expand All @@ -46,7 +45,7 @@ public PaginationServiceResponse<ArtistSearchPaginationServiceParam> searchArtis

List<UUID> subscribedArtistIds = request.userId() == null
? List.of()
: userShowUseCase.findArtistSubscriptionByUserId(request.userId()).stream()
: artistSubscriptionUseCase.findArtistSubscriptionByUserId(request.userId()).stream()
.map(ArtistSubscription::getArtistId)
.toList();

Expand Down Expand Up @@ -123,7 +122,6 @@ public ArtistUnsubscriptionServiceResponse unsubscribe(
.map(ArtistServiceMessage::toUnsubscribe)
.toList();


var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());

messagePublisher.publishArtistSubscription(
Expand Down Expand Up @@ -168,7 +166,9 @@ public PaginationServiceResponse<ArtistSubscriptionPaginationServiceParam> findA
public PaginationServiceResponse<ArtistUnsubscriptionPaginationServiceParam> findArtistUnsubscriptions(
ArtistUnsubscriptionPaginationServiceRequest request
) {
List<UUID> subscriptionArtistIds = getSubscriptionArtistIds(request.userId());
List<UUID> subscriptionArtistIds = request.userId() == null
? List.of()
: getSubscriptionArtistIds(request.userId());

var response = artistUseCase.findAllArtistInCursorPagination(
request.toDomainRequest(subscriptionArtistIds));
Expand All @@ -179,21 +179,14 @@ public PaginationServiceResponse<ArtistUnsubscriptionPaginationServiceParam> fin
return PaginationServiceResponse.of(data, response.hasNext());
}

public PaginationServiceResponse<ArtistUnsubscriptionPaginationServiceParam> findArtistUnsubscriptionsForNonUser(
ArtistUnsubscriptionPaginationServiceRequest request
) {
var response = artistUseCase.findAllArtistInCursorPagination(
request.toNonUserDomainRequest());
List<ArtistUnsubscriptionPaginationServiceParam> data = response.data().stream()
.map(ArtistUnsubscriptionPaginationServiceParam::new)
.toList();

return PaginationServiceResponse.of(data, response.hasNext());
public NumberOfSubscribedArtistServiceResponse countSubscribedArtists(UUID userId) {
return NumberOfSubscribedArtistServiceResponse.from(
artistSubscriptionUseCase.countSubscribedArtists(userId)
);
}

private List<UUID> getSubscriptionArtistIds(UUID userId) {
List<ArtistSubscription> subscriptions = artistSubscriptionUseCase.findSubscriptionList(
userId);
List<ArtistSubscription> subscriptions = artistSubscriptionUseCase.findSubscriptionList(userId);

return subscriptions.stream()
.map(ArtistSubscription::getArtistId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public record ArtistUnsubscriptionPaginationServiceRequest(
) {

public ArtistPaginationDomainRequest toDomainRequest(List<UUID> artistIds) {
return buildDomainRequest(artistIds);
}

public ArtistPaginationDomainRequest toNonUserDomainRequest() {
return buildDomainRequest(List.of());
}

private ArtistPaginationDomainRequest buildDomainRequest(List<UUID> artistIds) {
var artistGenders = artistGenderApiTypes.stream()
.map(ArtistGenderApiType::toDomainType)
.toList();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example.service.dto.response;
package com.example.artist.service.dto.response;

public record NumberOfSubscribedArtistServiceResponse(
long count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface ViewCountComponent {

boolean validateViewCount(UUID showId, String viewIdentifier);
boolean validateViewCount(UUID showId, String deviceToken);
}
Loading