Skip to content

Commit

Permalink
feat: spotless 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviarla committed Dec 27, 2023
1 parent 87a2681 commit e1ee9ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

public record UserProfileDto(Long id, String username, String bio, Sex sex, String thumbnail) {
public static UserProfileDto of(UserProfileResult userProfileResult) {
return new UserProfileDto(userProfileResult.id(), userProfileResult.username(), userProfileResult.bio(), userProfileResult.sex(),
return new UserProfileDto(
userProfileResult.id(),
userProfileResult.username(),
userProfileResult.bio(),
userProfileResult.sex(),
userProfileResult.thumbnail());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
public record UserProfileResult(Long id, String username, String bio, Sex sex, String thumbnail) {
public static UserProfileResult from(User user, String thumbnail) {
return new UserProfileResult(
user.getId(),
user.getUsername(),
user.getBio(),
user.getSex(),
thumbnail
);
user.getId(), user.getUsername(), user.getBio(), user.getSex(), thumbnail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,38 +258,34 @@ void failToUpdateProfile() throws Exception {
@DisplayName("유저의 프로필 정보를 조회할 수 있다.")
void getUser() throws Exception {
// given
UserProfileResult userProfileResult = new UserProfileResult(1L, "useruser", "반가워요-!", Sex.MALE, "file.com/1");
UserProfileResult userProfileResult =
new UserProfileResult(1L, "useruser", "반가워요-!", Sex.MALE, "file.com/1");
given(findUserUseCase.findUserProfileById(anyLong())).willReturn(userProfileResult);

// when & then
mockMvc.perform(RestDocumentationRequestBuilders.get( "/v1/user/{id}", 1))
mockMvc
.perform(RestDocumentationRequestBuilders.get("/v1/user/{id}", 1))
.andExpect(status().isOk())
.andDo(
document( "get-user",
pathParameters(
parameterWithName("id").description("유저 ID")
),
document(
"get-user",
pathParameters(parameterWithName("id").description("유저 ID")),
responseFields(
fieldWithPath("id").description("유저 ID(PK)"),
fieldWithPath("username").description("유저 이름"),
fieldWithPath("bio").description("유저 한줄 소개"),
fieldWithPath("sex").description("유저 성별"),
fieldWithPath("thumbnail").description("유저 썸네일 이미지")
)
)
);
fieldWithPath("thumbnail").description("유저 썸네일 이미지"))));
}

@Test
@DisplayName("유저가 존재하지 않으면 프로필 정보를 조회할 수 없다.")
void getUserNotFound() throws Exception {
given(findUserUseCase.findUserProfileById(anyLong())).willThrow(new UserNotFoundException(1L));

mockMvc.perform(RestDocumentationRequestBuilders.get( "/v1/user/{id}", 1))
mockMvc
.perform(RestDocumentationRequestBuilders.get("/v1/user/{id}", 1))
.andExpect(status().isNotFound())
.andDo(
document( "get-user-failed"
)
);
.andDo(document("get-user-failed"));
}
}
30 changes: 16 additions & 14 deletions perfume-core/src/main/java/dto/repository/CursorPagination.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public static <T, R> CursorPagination<R> of(
}

public static <T> CursorPagination<T> of(
final List<T> items,
final CursorPageable pageable,
final Function<T, String> tokenSelector) {
final List<T> items, final CursorPageable pageable, final Function<T, String> tokenSelector) {

final List<T> paginatedItems = paginateItems(items, pageable);
final String nextToken = encodeNextToken(paginatedItems, tokenSelector);
Expand All @@ -47,25 +45,28 @@ public static <T> CursorPagination<T> of(
final boolean hasRequestedWithCursor = pageable.hasCursor();
final boolean hasMoreItemsThanPage = isItemsSizeGreaterThanPageSize(items, pageable);

return new CursorPagination<> (
paginatedItems,
hasMoreItemsThanPage,
hasRequestedWithCursor,
hasMoreItemsThanPage ? nextToken : null,
hasRequestedWithCursor ? prevToken : null
);
return new CursorPagination<>(
paginatedItems,
hasMoreItemsThanPage,
hasRequestedWithCursor,
hasMoreItemsThanPage ? nextToken : null,
hasRequestedWithCursor ? prevToken : null);
}

private static <T> List<T> paginateItems(final List<T> items, final CursorPageable pageable) {
return isItemsSizeGreaterThanPageSize(items, pageable) ? items.subList(0, pageable.getSize()) : items;
return isItemsSizeGreaterThanPageSize(items, pageable)
? items.subList(0, pageable.getSize())
: items;
}

private static <T> boolean isItemsSizeGreaterThanPageSize(final List<T> items, final CursorPageable pageable) {
private static <T> boolean isItemsSizeGreaterThanPageSize(
final List<T> items, final CursorPageable pageable) {
final long pageSize = pageable.getSize();
return items.size() > pageSize;
}

private static <T> String encodeNextToken(final List<T> items, final Function<T, String> tokenSelector) {
private static <T> String encodeNextToken(
final List<T> items, final Function<T, String> tokenSelector) {
if (items.isEmpty()) {
return null;
}
Expand All @@ -74,7 +75,8 @@ private static <T> String encodeNextToken(final List<T> items, final Function<T,
return new String(Base64.getEncoder().encode(tokenSelector.apply(lastItem).getBytes()));
}

private static <T> String encodePreviousToken(final List<T> items, final Function<T, String> tokenSelector) {
private static <T> String encodePreviousToken(
final List<T> items, final Function<T, String> tokenSelector) {
if (items.isEmpty()) {
return null;
}
Expand Down

0 comments on commit e1ee9ba

Please sign in to comment.