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: cursor 데이터 일치 #163

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,22 @@
package org.example.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;

public record CursorApiResponse(

@Schema(description = "조회한 데이터의 Cursor Id")
UUID id,

@Schema(description = "조회한 데이터의 Cursor Value")
Object value
) {
public static CursorApiResponse toCursorResponse(UUID id, Object value) {
return new CursorApiResponse(id, value);
}

public static CursorApiResponse toCursorId(UUID id) {
return new CursorApiResponse(id, "");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example.util;

public final class ValidatorCursorSize {

private static final Integer DEFAULT_SIZE = 30;

public static int getDefaultSize(Integer size) {
if (size == null) {
return DEFAULT_SIZE;
}

return size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class ArtistController {
@Operation(summary = "구독하지 않은 아티스트 목록 조회")
public ResponseEntity<PaginationApiResponse<ArtistUnsubscriptionPaginationApiParam>> getUnsubscribedArtists(
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ArtistUnsubscriptionPaginationApiRequest request
@Valid @ParameterObject ArtistUnsubscriptionPaginationApiRequest request
) {
var response =
(user == null)
Expand All @@ -67,7 +68,7 @@ public ResponseEntity<PaginationApiResponse<ArtistUnsubscriptionPaginationApiPar
@Operation(summary = "구독한 아티스트 목록 조회")
public ResponseEntity<PaginationApiResponse<ArtistSubscriptionPaginationApiParam>> getSubscribedArtists(
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ArtistSubscriptionPaginationApiRequest request
@Valid @ParameterObject ArtistSubscriptionPaginationApiRequest request
) {
var response = artistService.findArtistSubscriptions(
request.toServiceRequest(user.userId()));
Expand All @@ -83,6 +84,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 @@ -113,7 +126,7 @@ public ResponseEntity<ArtistUnsubscriptionApiResponse> unsubscribe(
@Operation(summary = "검색하기")
public ResponseEntity<PaginationApiResponse<ArtistSearchPaginationApiParam>> search(
@AuthenticationPrincipal AuthenticatedUser user,
@ParameterObject ArtistSearchPaginationApiRequest request
@Valid @ParameterObject ArtistSearchPaginationApiRequest request
) {
var response = artistService.searchArtist(request.toServiceRequest(user));
var data = response.data().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.example.artist.service.dto.param.ArtistSearchPaginationServiceParam;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import org.example.dto.response.CursorApiResponse;

public record ArtistSearchPaginationApiParam(
@Schema(description = "아티스트 ID")
UUID id,
@Schema(description = "아티스트 Cursor")
CursorApiResponse cursor,

@Schema(description = "아티스트 이미지 URL")
String imageURL,
Expand All @@ -23,7 +23,7 @@ public record ArtistSearchPaginationApiParam(

public static ArtistSearchPaginationApiParam from(ArtistSearchPaginationServiceParam param) {
return new ArtistSearchPaginationApiParam(
param.artistId(),
CursorApiResponse.toCursorId(param.artistId()),
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.example.artist.service.dto.param.ArtistSubscriptionPaginationServiceParam;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import org.example.dto.response.CursorApiResponse;

public record ArtistSubscriptionPaginationApiParam(
@Schema(description = "아티스트 ID")
UUID id,
@Schema(description = "아티스트 Cursor")
CursorApiResponse cursor,
@Schema(description = "아티스트 이미지 URL")
String imageURL,
@Schema(description = "아티스트 한글 이름")
Expand All @@ -17,7 +17,7 @@ public record ArtistSubscriptionPaginationApiParam(

public static ArtistSubscriptionPaginationApiParam from(ArtistSubscriptionPaginationServiceParam param) {
return new ArtistSubscriptionPaginationApiParam(
param.artistId(),
CursorApiResponse.toCursorId(param.artistId()),
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

public record ArtistUnsubscriptionPaginationApiParam(
@Schema(description = "아티스트 ID")
UUID id,
@Schema(description = "아티스트 Cursor")
CursorApiResponse cursor,
@Schema(description = "아티스트 이미지 URL")
String imageURL,
@Schema(description = "아티스트 한글 이름")
Expand All @@ -19,7 +19,7 @@ public static ArtistUnsubscriptionPaginationApiParam from(
ArtistUnsubscriptionPaginationServiceParam param
) {
return new ArtistUnsubscriptionPaginationApiParam(
param.artistId(),
CursorApiResponse.toCursorId(param.artistId()),
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.example.artist.vo.ArtistSortApiType;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import java.util.UUID;
import org.example.security.dto.AuthenticatedUser;
import org.example.util.ValidatorCursorSize;

public record ArtistSearchPaginationApiRequest(

Expand All @@ -15,11 +17,12 @@ public record ArtistSearchPaginationApiRequest(
)
ArtistSortApiType sortStandard,

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

@Parameter(description = "조회하는 데이터 개수", required = true)
int size,
@Max(value = 30, message = "조회하는 데이터 개수는 최대 30개 이어야 합니다.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 포인트: 5
default 30, min은 없고, maz 30이에요!
입력이 들어오지 않았을 때 30으로 기본 할당 되어야 해요!
image

Integer size,

@Parameter(description = "검색어", required = true)
String search
Expand All @@ -40,8 +43,8 @@ public ArtistSearchPaginationServiceRequest toServiceRequest(AuthenticatedUser u
return ArtistSearchPaginationServiceRequest.builder()
.userId(userId)
.sortStandard(sortStandard)
.cursor(cursor)
.size(size)
.cursor(cursorId)
.size(ValidatorCursorSize.getDefaultSize(size))
.search(search)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.example.vo.SubscriptionStatusApiType;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import java.util.UUID;
import org.example.util.ValidatorCursorSize;

@Schema
public record ArtistSubscriptionPaginationApiRequest(
Expand All @@ -16,29 +18,30 @@ public record ArtistSubscriptionPaginationApiRequest(
)
ArtistSortApiType sort,

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

@Parameter(description = "조회하는 데이터 개수", required = true)
int size
@Max(value = 30, message = "조회하는 데이터 개수는 최대 30개 이어야 합니다.")
Integer size
) {

public ArtistSubscriptionPaginationApiRequest(
ArtistSortApiType sort,
UUID cursor,
int size
UUID cursorId,
Integer size
) {
this.sort = sort == null ? ArtistSortApiType.ENGLISH_NAME_ASC : sort;
this.cursor = cursor;
this.size = size;
this.cursorId = cursorId;
this.size = ValidatorCursorSize.getDefaultSize(size);
}

public ArtistSubscriptionPaginationServiceRequest toServiceRequest(UUID userId) {
return ArtistSubscriptionPaginationServiceRequest.builder()
.subscriptionStatusApiType(SubscriptionStatusApiType.SUBSCRIBED)
.size(size)
.sortStandard(sort)
.cursor(cursor)
.cursor(cursorId)
.userId(userId)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import com.example.vo.SubscriptionStatusApiType;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import java.util.List;
import java.util.UUID;
import org.example.util.ValidateStatus;
import org.example.util.ValidatorCursorSize;

@Schema
public record ArtistUnsubscriptionPaginationApiRequest(
@Parameter(
description = "정렬 기준, default: ENGLISH_NAME_ASC",
Expand All @@ -28,28 +29,29 @@ public record ArtistUnsubscriptionPaginationApiRequest(
@Parameter(description = "장르 ID 목록")
List<UUID> genreIds,

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

@Parameter(description = "조회하는 데이터 개수", required = true)
int size
@Max(value = 30, message = "조회하는 데이터 개수는 최대 30개 이어야 합니다.")
Integer size
) {

public ArtistUnsubscriptionPaginationApiRequest(
ArtistSortApiType sortStandard,
List<ArtistGenderApiType> artistGenderApiTypes,
List<ArtistApiType> artistApiTypes,
List<UUID> genreIds,
UUID cursor,
int size
UUID cursorId,
Integer size
) {
this.sortStandard =
sortStandard == null ? ArtistSortApiType.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;
this.cursorId = cursorId;
this.size = ValidatorCursorSize.getDefaultSize(size);
}


Expand All @@ -61,7 +63,7 @@ public ArtistUnsubscriptionPaginationServiceRequest toServiceRequest(UUID userId
.artistApiTypes(artistApiTypes)
.genreIds(genreIds)
.userId(userId)
.cursor(cursor)
.cursor(cursorId)
.size(size)
.build();
}
Expand All @@ -74,7 +76,7 @@ public ArtistUnsubscriptionPaginationServiceRequest toNonUserServiceRequest() {
.artistApiTypes(artistApiTypes)
.genreIds(genreIds)
.userId(null)
.cursor(cursor)
.cursor(cursorId)
.size(size)
.build();
}
Expand Down
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());
}
}
Loading