Skip to content

Commit

Permalink
fix: โœ๏ธ Modify the format of chat search api (#182)
Browse files Browse the repository at this point in the history
* rename: content -> contents ์ˆ˜์ •

* fix: size ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ธฐ๋ณธ๊ฐ’ ํ• ๋‹น

* docs: swagger ๋ฌธ์„œ์—์„œ query param์œผ๋กœ ํ‘œํ˜„๋˜๋„๋ก ์ˆ˜์ •

* rename: jsend protocol ๋ช…์„ธ์— ์˜ํ•ด slice์˜ domain ์œ„์น˜์— ๋‹จ์ˆ˜ ๋ช…์‚ฌ๊ฐ€ ์˜ค๋„๋ก ์ˆ˜์ •
  • Loading branch information
psychology50 authored Oct 24, 2024
1 parent eb8b8d0 commit 149756f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kr.co.pennyway.api.apis.chat.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -26,7 +28,13 @@ public interface ChatRoomApi {
@ApiResponse(responseCode = "200", description = "๊ฐ€์ž…ํ•œ ์ฑ„ํŒ…๋ฐฉ ๋ชฉ๋ก ์กฐํšŒ ์„ฑ๊ณต", content = @Content(schemaProperties = @SchemaProperty(name = "chatRooms", array = @ArraySchema(schema = @Schema(implementation = ChatRoomRes.Detail.class)))))
ResponseEntity<?> getMyChatRooms(@AuthenticationPrincipal SecurityUserDetails user);

@Operation(summary = "์ฑ„ํŒ…๋ฐฉ ๊ฒ€์ƒ‰", method = "GET", description = "์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ž…ํ•œ ์ฑ„ํŒ…๋ฐฉ ์ค‘ ๊ฒ€์ƒ‰์–ด์— ์ผ์น˜ํ•˜๋Š” ์ฑ„ํŒ…๋ฐฉ ๋ชฉ๋ก์„ ์กฐํšŒํ•œ๋‹ค. ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋Š” ๋ฌดํ•œ ์Šคํฌ๋กค ์‘๋‹ต์œผ๋กœ ๋ฐ˜ํ™˜๋˜๋ฉฐ, ์ •๋ ฌ ์ˆœ์„œ๋Š” ์ •ํ™•๋„๊ฐ€ ๋†’์€ ์ˆœ์œผ๋กœ ๋ฐ˜ํ™˜๋œ๋‹ค. content ํ•„๋“œ๋Š” List<ChatRoomRes.Detail> ํƒ€์ž…์œผ๋กœ, '๊ฐ€์ž…ํ•œ ์ฑ„ํŒ…๋ฐฉ ๋ชฉ๋ก ์กฐํšŒ' API ์‘๋‹ต๊ณผ ๋™์ผํ•˜๋‹ค.")
@Operation(summary = "์ฑ„ํŒ…๋ฐฉ ๊ฒ€์ƒ‰", method = "GET", description = "์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ž…ํ•œ ์ฑ„ํŒ…๋ฐฉ ์ค‘ ๊ฒ€์ƒ‰์–ด์— ์ผ์น˜ํ•˜๋Š” ์ฑ„ํŒ…๋ฐฉ ๋ชฉ๋ก์„ ์กฐํšŒํ•œ๋‹ค. ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋Š” ๋ฌดํ•œ ์Šคํฌ๋กค ์‘๋‹ต์œผ๋กœ ๋ฐ˜ํ™˜๋˜๋ฉฐ, ์ •๋ ฌ ์ˆœ์„œ๋Š” ์ •ํ™•๋„๊ฐ€ ๋†’์€ ์ˆœ์œผ๋กœ ๋ฐ˜ํ™˜๋œ๋‹ค. contents ํ•„๋“œ๋Š” List<ChatRoomRes.Detail> ํƒ€์ž…์œผ๋กœ, '๊ฐ€์ž…ํ•œ ์ฑ„ํŒ…๋ฐฉ ๋ชฉ๋ก ์กฐํšŒ' API ์‘๋‹ต๊ณผ ๋™์ผํ•˜๋‹ค.")
@Parameters({
@Parameter(name = "target", description = "๊ฒ€์ƒ‰ ๋Œ€์ƒ. ์ฑ„ํŒ…๋ฐฉ ์ œ๋ชฉ ํ˜น์€ ์„ค๋ช…์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค. ์ตœ์†Œํ•œ 2์ž ์ด์ƒ์˜ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•œ๋‹ค.", example = "ํŽ˜๋‹ˆ์›จ์ด", required = true),
@Parameter(name = "page", description = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ. 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค.", example = "0", required = true),
@Parameter(name = "size", description = "ํŽ˜์ด์ง€ ํฌ๊ธฐ. ํ•œ ํŽ˜์ด์ง€ ๋‹น ๋ฐ˜ํ™˜๋˜๋Š” ์ฑ„ํŒ…๋ฐฉ ๊ฐœ์ˆ˜์ด๋‹ค. ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ 10๊ฐœ์”ฉ ๋ฐ˜ํ™˜ํ•œ๋‹ค."),
@Parameter(name = "query", hidden = true)
})
@ApiResponse(responseCode = "200", description = "์ฑ„ํŒ…๋ฐฉ ๊ฒ€์ƒ‰ ์„ฑ๊ณต", content = @Content(schemaProperties = @SchemaProperty(name = "chatRooms", schema = @Schema(implementation = SliceResponseTemplate.class))))
ResponseEntity<?> searchChatRooms(@Validated ChatRoomReq.SearchQuery query, @AuthenticationPrincipal SecurityUserDetails user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public ResponseEntity<?> getMyChatRooms(@AuthenticationPrincipal SecurityUserDet
public ResponseEntity<?> searchChatRooms(@Validated ChatRoomReq.SearchQuery query, @AuthenticationPrincipal SecurityUserDetails user) {
Pageable pageable = Pageable.ofSize(query.size()).withPage(query.page());

return ResponseEntity.ok(SuccessResponse.from(CHAT_ROOMS, chatRoomUseCase.searchChatRooms(user.getUserId(), query.target(), pageable)));
return ResponseEntity.ok(SuccessResponse.from(CHAT_ROOM, chatRoomUseCase.searchChatRooms(user.getUserId(), query.target(), pageable)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ public ChatRoom toEntity(long chatRoomId, String originImageUrl) {
}

public record SearchQuery(
@Schema(description = "๊ฒ€์ƒ‰ ๋Œ€์ƒ. ์ฑ„ํŒ…๋ฐฉ ์ œ๋ชฉ ํ˜น์€ ์„ค๋ช…์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค. ์ตœ์†Œํ•œ 2์ž ์ด์ƒ์˜ ๋ฌธ์ž์—ด์ด์–ด์•ผ ํ•œ๋‹ค.", example = "ํŽ˜๋‹ˆ์›จ์ด")
@NotNull(message = "๊ฒ€์ƒ‰ ๋Œ€์ƒ์€ NULL์ด ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
@Size(min = 2)
String target,
@Schema(description = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ. 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค.", example = "0")
int page,
@Schema(description = "ํŽ˜์ด์ง€ ํฌ๊ธฐ. ํ•œ ํŽ˜์ด์ง€ ๋‹น ๋ฐ˜ํ™˜๋˜๋Š” ์ฑ„ํŒ…๋ฐฉ ๊ฐœ์ˆ˜์ด๋‹ค.", example = "10")
int size
Integer size
) {
public SearchQuery {
if (size == null) {
size = 10;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Schema(description = "ํŽ˜์ด์ง•๋œ ๋ฌดํ•œ ์Šคํฌ๋กค ์‘๋‹ต")
public record SliceResponseTemplate<E>(
@Schema(description = "์‘๋‹ต ์ปจํ…์ธ  ๋‚ด์šฉ")
List<E> content,
List<E> contents,
@Schema(description = "ํ˜„์žฌ ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ")
int currentPageNumber,
@Schema(description = "ํŽ˜์ด์ง€ ํฌ๊ธฐ")
Expand All @@ -19,7 +19,7 @@ public record SliceResponseTemplate<E>(
@Schema(description = "๋‹ค์Œ ํŽ˜์ด์ง€ ์กด์žฌ ์—ฌ๋ถ€")
boolean hasNext
) {
public static <E> SliceResponseTemplate<E> of(@NonNull List<E> content, @NonNull Pageable pageable, int numberOfElements, boolean hasNext) {
return new SliceResponseTemplate<>(content, pageable.getPageNumber(), pageable.getPageSize(), numberOfElements, hasNext);
public static <E> SliceResponseTemplate<E> of(@NonNull List<E> contents, @NonNull Pageable pageable, int numberOfElements, boolean hasNext) {
return new SliceResponseTemplate<>(contents, pageable.getPageNumber(), pageable.getPageSize(), numberOfElements, hasNext);
}
}

0 comments on commit 149756f

Please sign in to comment.