Skip to content

Commit

Permalink
feat : 구독하지 않은 정보 조회 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 5, 2024
1 parent 5fe52cd commit bb0f138
Show file tree
Hide file tree
Showing 107 changed files with 2,406 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ private RequestMatcher getMatcherForAnyone() {
antMatcher(HttpMethod.GET, "/api/v1/shows"),
antMatcher(HttpMethod.GET, "/api/v1/shows/{showId}"),
antMatcher(HttpMethod.GET, "/api/v1/artists/search/**"),
antMatcher(HttpMethod.GET, "/api/v1/shows/search/**")
antMatcher(HttpMethod.GET, "/api/v1/shows/search/**"),
antMatcher(HttpMethod.GET, "/api/v1/artists/filter"),
antMatcher(HttpMethod.GET, "/api/v1/artists/filter-total-count")
);
}

Expand All @@ -87,14 +89,12 @@ private RequestMatcher getMatcherForUserAndAdmin() {
antMatcher(HttpMethod.POST, "/api/v1/users/withdrawal"),
antMatcher(HttpMethod.POST, "/api/v1/shows/**/interest"),
antMatcher(HttpMethod.POST, "/api/v1/shows/**/alert"),
antMatcher(HttpMethod.POST, "/api/v1/artists/subscribe"),
antMatcher(HttpMethod.POST, "/api/v1/genres/subscribe"),
antMatcher(HttpMethod.POST, "/api/v1/genres/unsubscribe"),
antMatcher(HttpMethod.GET, "/api/v1/genres/subscriptions"),
antMatcher(HttpMethod.POST, "/api/v1/genres/**"),
antMatcher(HttpMethod.GET, "/api/v1/artists/subscribed"),
antMatcher(HttpMethod.POST, "/api/v1/artists/subscribe"),
antMatcher(HttpMethod.POST, "/api/v1/artists/unsubscribe")
antMatcher(HttpMethod.POST, "/api/v1/artists/unsubscribe"),
antMatcher(HttpMethod.GET, "/api/v1/artists/subscriptions")
);
}
}
4 changes: 4 additions & 0 deletions app/api/show-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ dependencies {
implementation project(":app:domain:show-domain")
implementation project(":app:domain:user-domain")
implementation project(':app:api:common-api')

//testFixtures
testImplementation(testFixtures(project(":app:domain:show-domain")))
testImplementation(testFixtures(project(":app:domain:user-domain")))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import com.example.artist.controller.dto.param.ArtistSearchPaginationApiParam;
import com.example.artist.controller.dto.param.ArtistSubscriptionPaginationApiParam;
import com.example.artist.controller.dto.param.ArtistUnsubscriptionPaginationApiParam;
import com.example.artist.controller.dto.request.ArtistFilterTotalCountApiRequest;
import com.example.artist.controller.dto.request.ArtistSearchPaginationApiRequest;
import com.example.artist.controller.dto.request.ArtistSubscriptionApiRequest;
import com.example.artist.controller.dto.request.ArtistSubscriptionPaginationApiRequest;
import com.example.artist.controller.dto.request.ArtistUnsubscriptionApiRequest;
import com.example.artist.controller.dto.response.ArtistPaginationApiResponse;
import com.example.artist.controller.dto.response.ArtistSimpleApiResponse;
import com.example.artist.controller.dto.request.ArtistUnsubscriptionPaginationApiRequest;
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.service.ArtistService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.response.PaginationApiResponse;
import org.example.security.dto.AuthenticatedUser;
Expand All @@ -26,7 +26,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -36,24 +35,24 @@
public class ArtistController {

private final ArtistService artistService;
private String image = "https://thumb.mtstarnews.com/06/2023/06/2023062914274537673_1.jpg";

@GetMapping
@Operation(summary = "아티스트 목록 조회")
public ResponseEntity<ArtistPaginationApiResponse> getArtists(
@RequestParam(required = false) ArtistSearchPaginationApiRequest param
@Operation(summary = "구독하지 않은 아티스트 목록 조회")
public ResponseEntity<PaginationApiResponse<ArtistUnsubscriptionPaginationApiParam>> getUnsubscribedArtists(
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ArtistUnsubscriptionPaginationApiRequest request
) {
var response = artistService.findArtistUnsubscriptions(
request.toServiceRequest(user.userId()));
var data = response.data().stream()
.map(ArtistUnsubscriptionPaginationApiParam::from)
.toList();

return ResponseEntity.ok(
new ArtistPaginationApiResponse(
List.of(
new ArtistSimpleApiResponse(
UUID.randomUUID(),
"윈터",
image
)
),
false
)
PaginationApiResponse.<ArtistUnsubscriptionPaginationApiParam>builder()
.hasNext(response.hasNext())
.data(data)
.build()
);
}

Expand Down Expand Up @@ -96,7 +95,6 @@ public ResponseEntity<ArtistUnsubscriptionApiResponse> unsubscribe(
@AuthenticationPrincipal AuthenticatedUser user,
@Valid @RequestBody ArtistUnsubscriptionApiRequest request
) {
;
return ResponseEntity.ok(
ArtistUnsubscriptionApiResponse.from(
artistService.unsubscribe(request.toServiceRequest(user.userId()))
Expand All @@ -122,4 +120,18 @@ public ResponseEntity<PaginationApiResponse<ArtistSearchPaginationApiParam>> sea
.build()
);
}

@GetMapping("/filter-total-count")
@Operation(summary = "필터링한 데이터의 총 개수 가져오기")
public ResponseEntity<ArtistFilterTotalCountApiResponse> filterTotalCount(
@AuthenticationPrincipal AuthenticatedUser user,
@Valid @RequestBody ArtistFilterTotalCountApiRequest request
) {
var response = artistService.filterArtistTotalCount(
request.toServiceRequest(user.userId()));

return ResponseEntity.ok(
ArtistFilterTotalCountApiResponse.from(response.totalCount())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.artist.controller.dto.param;

import com.example.artist.service.dto.param.ArtistUnsubscriptionPaginationServiceParam;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;

public record ArtistUnsubscriptionPaginationApiParam(
@Schema(description = "아티스트 ID")
UUID id,
@Schema(description = "아티스트 이미지 URL")
String imageUrl,
@Schema(description = "아티스트 한글 이름")
String koreanName,
@Schema(description = "아티스트 영문 이름")
String englishName
) {

public static ArtistUnsubscriptionPaginationApiParam from(
ArtistUnsubscriptionPaginationServiceParam param
) {
return new ArtistUnsubscriptionPaginationApiParam(
param.artistId(),
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.artist.controller.dto.request;

import com.example.artist.service.dto.request.ArtistFilterTotalCountServiceRequest;
import com.example.artist.vo.ArtistApiType;
import com.example.artist.vo.ArtistGenderApiType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.UUID;
import org.example.util.ValidateStatus;

public record ArtistFilterTotalCountApiRequest(
@Schema(description = "아티스트 성별")
List<ArtistGenderApiType> artistGenderApiTypes,

@Schema(description = "아티스트 타입")
List<ArtistApiType> artistApiTypes,

@Schema(description = "장르 ID 목록")
List<UUID> genreIds
) {

public ArtistFilterTotalCountApiRequest(
List<ArtistGenderApiType> artistGenderApiTypes,
List<ArtistApiType> artistApiTypes,
List<UUID> genreIds
) {
this.artistGenderApiTypes = ValidateStatus.checkNullOrEmpty(artistGenderApiTypes);
this.artistApiTypes = ValidateStatus.checkNullOrEmpty(artistApiTypes);
this.genreIds = ValidateStatus.checkNullOrEmpty(genreIds);
}

public ArtistFilterTotalCountServiceRequest toServiceRequest(UUID userId) {
return ArtistFilterTotalCountServiceRequest.builder()
.artistGenderApiTypes(artistGenderApiTypes)
.artistApiTypes(artistApiTypes)
.genreIds(genreIds)
.userId(userId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public record ArtistSearchPaginationApiRequest(
@Parameter(description = "이전 페이지네이션 마지막 데이터의 ID / 최초 조회라면 null")
UUID cursor,

@Parameter(description = "조회하는 데이터 개수")
@Parameter(description = "조회하는 데이터 개수", required = true)
int size,

@Parameter(description = "검색어")
@Parameter(description = "검색어", required = true)
String search
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.artist.service.dto.request.ArtistSubscriptionPaginationServiceRequest;
import com.example.artist.vo.ArtistSortStandardApiType;
import com.example.vo.SubscriptionStatusApiType;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
Expand All @@ -18,7 +19,7 @@ public record ArtistSubscriptionPaginationApiRequest(
@Parameter(description = "이전 페이지네이션 마지막 데이터의 ID / 최초 조회라면 null")
UUID cursor,

@Parameter(description = "조회하는 데이터 개수")
@Parameter(description = "조회하는 데이터 개수", required = true)
int size
) {

Expand All @@ -27,13 +28,15 @@ public ArtistSubscriptionPaginationApiRequest(
UUID cursor,
int size
) {
this.sortStandard = sortStandard == null ? ArtistSortStandardApiType.ENGLISH_NAME_ASC : sortStandard;
this.sortStandard =
sortStandard == null ? ArtistSortStandardApiType.ENGLISH_NAME_ASC : sortStandard;
this.cursor = cursor;
this.size = size;
}

public ArtistSubscriptionPaginationServiceRequest toServiceRequest(UUID userId) {
return ArtistSubscriptionPaginationServiceRequest.builder()
.subscriptionStatusApiType(SubscriptionStatusApiType.SUBSCRIBED)
.size(size)
.sortStandard(sortStandard)
.cursor(cursor)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.example.artist.controller.dto.request;

import com.example.artist.service.dto.request.ArtistUnsubscriptionPaginationServiceRequest;
import com.example.artist.vo.ArtistApiType;
import com.example.artist.vo.ArtistGenderApiType;
import com.example.artist.vo.ArtistSortStandardApiType;
import com.example.vo.SubscriptionStatusApiType;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.UUID;
import org.example.util.ValidateStatus;

@Schema
public record ArtistUnsubscriptionPaginationApiRequest(
@Parameter(
description = "정렬 기준, default: ENGLISH_NAME_ASC",
schema = @Schema(implementation = ArtistSortStandardApiType.class)
)
ArtistSortStandardApiType sortStandard,

@Parameter(description = "아티스트 성별 목록")
List<ArtistGenderApiType> artistGenderApiTypes,

@Parameter(description = "아티스트 타입 목록")
List<ArtistApiType> artistApiTypes,

@Parameter(description = "장르 ID 목록")
List<UUID> genreIds,

@Parameter(description = "이전 페이지네이션 마지막 데이터의 ID / 최초 조회라면 null")
UUID cursor,

@Parameter(description = "조회하는 데이터 개수", required = true)
int size
) {

public ArtistUnsubscriptionPaginationApiRequest(
ArtistSortStandardApiType sortStandard,
List<ArtistGenderApiType> artistGenderApiTypes,
List<ArtistApiType> artistApiTypes,
List<UUID> genreIds,
UUID cursor,
int size
) {
this.sortStandard =
sortStandard == null ? ArtistSortStandardApiType.ENGLISH_NAME_ASC : sortStandard;
this.artistGenderApiTypes = ValidateStatus.checkNullOrEmpty(artistGenderApiTypes);
this.artistApiTypes = ValidateStatus.checkNullOrEmpty(artistApiTypes);
this.genreIds = ValidateStatus.checkNullOrEmpty(genreIds);
this.cursor = cursor;
this.size = size;
}


public ArtistUnsubscriptionPaginationServiceRequest toServiceRequest(UUID userId) {
return ArtistUnsubscriptionPaginationServiceRequest.builder()
.subscriptionStatusApiType(SubscriptionStatusApiType.UNSUBSCRIBED)
.sortStandard(sortStandard)
.artistGenderApiTypes(artistGenderApiTypes)
.artistApiTypes(artistApiTypes)
.genreIds(genreIds)
.userId(userId)
.cursor(cursor)
.size(size)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.artist.controller.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

public record ArtistFilterTotalCountApiResponse(
@Schema(description = "필터링한 아티스트 총 개수")
int totalCount
) {

public static ArtistFilterTotalCountApiResponse from(int totalCount) {
return new ArtistFilterTotalCountApiResponse(totalCount);
}

}

This file was deleted.

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

import com.example.artist.service.dto.response.ArtistUnsubscriptionServiceResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.UUID;

public record ArtistUnsubscriptionApiResponse(
@Schema(description = "구독 취소한 아티스트 ID")
List<UUID> successUnsubscriptionArtistIds
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

import org.example.exception.BusinessError;

public enum ArtistSubscriptionError implements BusinessError {

ARTIST_NOT_EXIST {
public enum ArtistError implements BusinessError {
ENTITY_NOT_FOUND {
@Override
public int getHttpStatus() {
return 404;
}

@Override
public String getErrorCode() {
return "ASB-001";
return "ART-001";
}

@Override
public String getClientMessage() {
return "구독하려는 아티스트가 존재하지 않습니다.";
return "존재하지 않은 아티스트입니다.";
}

@Override
public String getLogMessage() {
return "요청으로 들어온 아티스트 ID에 해당하는 아티스트가 존재하지 않습니다.";
return "요청 값이 잘못 처리되었습니다.";
}
}
}
Loading

0 comments on commit bb0f138

Please sign in to comment.