Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5025df1
[feat] 기록장 조회 필요한 dto 정의 (#52)
buzz0331 Jul 7, 2025
c6ee6b7
[feat] api 핸들러 정의 (#52)
buzz0331 Jul 7, 2025
407951f
[feat] 기록장 조회 필요한 Response dto 정의 (#52)
buzz0331 Jul 7, 2025
c939462
[feat] 기록장 조회 UseCase 정의 및 구현 (#52)
buzz0331 Jul 7, 2025
713c70c
[feat] RecordQueryRepository 도입 (#52)
buzz0331 Jul 7, 2025
cc22862
[feat] Querydsl을 이용해 동적 join을 통해 record, vote 모두 조회후 정렬, 필터링 (#52)
buzz0331 Jul 7, 2025
45d2b6f
[test] Querydsl 쿼리 확인을 위한 테스트 코드 (#52)
buzz0331 Jul 7, 2025
9624ef7
[test] Querydsl 쿼리 확인을 위한 테스트 코드 (#52)
buzz0331 Jul 7, 2025
6e3fbc2
[feat] Room으로 Vote를 조회하는 쿼리 정의 (#52)
buzz0331 Jul 9, 2025
1706950
[feat] JpaRepository가 Querydsl 사용 repository 상속하도록 (#52)
buzz0331 Jul 9, 2025
9774c28
[feat] 필요한 port 정의 (#52)
buzz0331 Jul 9, 2025
a35794d
[feat] DTO에 of 팩토리 메서드 추가 (#52)
buzz0331 Jul 9, 2025
71c37a9
[feat] Room으로 Record를 조회하는 쿼리 저으이 (#52)
buzz0331 Jul 9, 2025
8157217
[feat] 쿼리 조회용 dto (#52)
buzz0331 Jul 9, 2025
773213a
[feat] PostLike용 repository, port 정의 (#52)
buzz0331 Jul 9, 2025
39e2d2e
[feat] PostLike용 persistence adapter (#52)
buzz0331 Jul 9, 2025
6b2575c
[feat] Comment용 repository, persistence adapter (#52)
buzz0331 Jul 9, 2025
cbe762a
[feat] Record 조회용 dto 정의 (#52)
buzz0331 Jul 9, 2025
9067ded
[feat] UserVote 도메인 Vote 도메인으로 옮기기 (#52)
buzz0331 Jul 9, 2025
2cda225
[feat] UserVoteJpaRepository에 확인여부용 쿼리 추가 (#52)
buzz0331 Jul 9, 2025
332db3e
[feat] vote persistence adapter 확인여부용 쿼리 추가 (#52)
buzz0331 Jul 9, 2025
512c521
[feat] voteitem percentage 구하는 도메인 규칙 추가 (#52)
buzz0331 Jul 9, 2025
9771981
[feat] RecordSearch 용 usecase 정의 및 service 구현 (#52)
buzz0331 Jul 9, 2025
cfdc977
[feat] RecordQueryController 선언 (#52)
buzz0331 Jul 9, 2025
9dd6389
[feat] RecordQueryPersistenceAdapter 정의 (#52)
buzz0331 Jul 9, 2025
3ca033b
[feat] Date 관련 util 메서드를 모아두는 DateUtil (#52)
buzz0331 Jul 9, 2025
4db47e5
[feat] dto에서 postDate 형식 변경 (#52)
buzz0331 Jul 9, 2025
0c97b1b
[feat] postDate 파싱에서 주입 + 파라미터 유효성 검증 (#52)
buzz0331 Jul 9, 2025
9da1c6a
[test] controller 통합 테스트 (#52)
buzz0331 Jul 9, 2025
0dd327b
[test] service 단위 테스트 (유효성 검증 + 정렬 + 페이징 처리) (#52)
buzz0331 Jul 9, 2025
7917128
[test] repository 테스트 (필터링) (#52)
buzz0331 Jul 9, 2025
968b9e3
[fix] errocode 충돌 해결 (#52)
buzz0331 Jul 9, 2025
cba1cee
[fix] errocode 충돌 해결 머지 (#52)
buzz0331 Jul 9, 2025
7ef7cca
Merge branch 'develop' of https://github.com/THIP-TextHip/THIP-Server…
buzz0331 Jul 9, 2025
16c8996
[fix] 비밀번호 검증시 password NotNull 조건 제거 (#52)
buzz0331 Jul 9, 2025
e5cfb46
[fix] Command, Query 컨벤션 맞게 이동 + 메서드 시그니처 명확히 수정 (#52)
buzz0331 Jul 9, 2025
7612165
[fix] 파라미터 이름 수정 (#52)
buzz0331 Jul 9, 2025
69c6881
[fix] commentCount 구하는 쿼리 오류 수정 (#52)
buzz0331 Jul 9, 2025
2f4745e
[fix] 필터링 시에 start end 모두 null이 되도록 조건 수정 (#52)
buzz0331 Jul 9, 2025
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package konkuk.thip.comment.adapter.out.persistence;

import konkuk.thip.comment.adapter.out.mapper.CommentMapper;
import konkuk.thip.comment.application.port.out.CommentCommandPort;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand All @@ -9,7 +8,5 @@
@RequiredArgsConstructor
public class CommentCommandPersistenceAdapter implements CommentCommandPort {

private final CommentJpaRepository jpaRepository;
private final CommentMapper userMapper;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface CommentJpaRepository extends JpaRepository<CommentJpaEntity, Long> {
int countByPostJpaEntity_PostId(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public class CommentQueryPersistenceAdapter implements CommentQueryPort {
private final CommentJpaRepository jpaRepository;
private final CommentMapper userMapper;

@Override
public int countByPostId(Long postId) {
return jpaRepository.countByPostJpaEntity_PostId(postId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface CommentQueryPort {

int countByPostId(Long postId);

}
21 changes: 13 additions & 8 deletions src/main/java/konkuk/thip/common/exception/code/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,27 @@ public enum ErrorCode implements ResponseCode {
INVALID_VOTE_PAGE_RANGE(HttpStatus.BAD_REQUEST, 110002, "VOTE의 page 값이 유효하지 않습니다."),

/**
* 120000 : record error
* 120000 : voteItem error
*/
RECORD_NOT_FOUND(HttpStatus.NOT_FOUND, 120000, "존재하지 않는 RECORD 입니다."),
RECORD_CANNOT_BE_OVERVIEW(HttpStatus.BAD_REQUEST, 120001, "총평이 될 수 없는 RECORD 입니다."),
INVALID_RECORD_PAGE_RANGE(HttpStatus.BAD_REQUEST, 120002, "RECORD의 page 값이 유효하지 않습니다."),
VOTE_ITEM_NOT_FOUND(HttpStatus.NOT_FOUND, 120000, "투표는 존재하지만 투표항목이 비어있습니다."),

/**
* 130000 : record error
*/
RECORD_NOT_FOUND(HttpStatus.NOT_FOUND, 130000, "존재하지 않는 RECORD 입니다."),
RECORD_CANNOT_BE_OVERVIEW(HttpStatus.BAD_REQUEST, 130001, "총평이 될 수 없는 RECORD 입니다."),
INVALID_RECORD_PAGE_RANGE(HttpStatus.BAD_REQUEST, 130002, "RECORD의 page 값이 유효하지 않습니다."),
RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 120003, "만료된 방에는 기록을 남길 수 없습니다."),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

에러 코드 번호 불일치 수정 필요

에러 코드가 120003으로 되어 있으나, 130000 범위에 속해야 합니다.

-RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 120003, "만료된 방에는 기록을 남길 수 없습니다."),
+RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 130003, "만료된 방에는 기록을 남길 수 없습니다."),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 120003, "만료된 방에는 기록을 남길 수 없습니다."),
RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 130003, "만료된 방에는 기록을 남길 수 없습니다."),
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/common/exception/code/ErrorCode.java at line 91,
the error code number for RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM is incorrectly set
to 120003 but should be within the 130000 range. Update the error code number to
a valid value in the 130000 range to maintain consistency with the error code
classification.

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

에러 코드 번호 불일치를 수정하세요.

RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM의 에러 코드가 120003으로 되어 있지만, record 도메인은 130000 범위를 사용해야 합니다.

- RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 120003, "만료된 방에는 기록을 남길 수 없습니다."),
+ RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 130003, "만료된 방에는 기록을 남길 수 없습니다."),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 120003, "만료된 방에는 기록을 남길 수 없습니다."),
RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 130003, "만료된 방에는 기록을 남길 수 없습니다."),
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/common/exception/code/ErrorCode.java at line 91,
the error code for RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM is incorrectly set to
120003, which does not match the record domain's 130000 range. Change the error
code number from 120003 to a valid 130000-range code to align with the record
domain's error code conventions.


/**
* 130000 : userRoom error
* 140000 : userRoom error
*/
USER_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, 130000, "존재하지 않는 USER_ROOM (방과 사용자 관계) 입니다."),
USER_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, 140000, "존재하지 않는 USER_ROOM (방과 사용자 관계) 입니다."),

/**
* 140000 : Category error
* 150000 : Category error
*/
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, 140000, "존재하지 않는 CATEGORY 입니다.")
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, 150000, "존재하지 않는 CATEGORY 입니다.")
Comment on lines +90 to +103
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

기존 에러 코드 변경의 호환성을 확인하세요.

RECORD, USER_ROOM, CATEGORY 관련 에러 코드들이 다른 범위로 이동되었습니다. 이미 사용 중인 클라이언트가 있다면 호환성 문제가 발생할 수 있습니다.

다음 스크립트를 실행하여 기존 에러 코드 사용 현황을 확인하세요:


🏁 Script executed:

#!/bin/bash
# 기존 에러 코드 사용 현황 검색
echo "=== RECORD 관련 에러 코드 사용 현황 ==="
rg -n "120000|120001|120002" --type java

echo "=== USER_ROOM 관련 에러 코드 사용 현황 ==="
rg -n "130000" --type java

echo "=== CATEGORY 관련 에러 코드 사용 현황 ==="
rg -n "140000" --type java

Length of output: 1050


RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM 에러 코드 범위 수정 필요
RECORD 관련 에러 코드들은 모두 130xxx 범위를 사용하고 있으나, 해당 항목만 잘못된 120003으로 지정되어 있습니다. 아래와 같이 변경해주세요:

  • 파일: src/main/java/konkuk/thip/common/exception/code/ErrorCode.java
  • 위치: RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM 선언부
-    RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 120003, "만료된 방에는 기록을 남길 수 없습니다."),
+    RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM(HttpStatus.BAD_REQUEST, 130003, "만료된 방에는 기록을 남길 수 없습니다."),

수정 후 다음 사항을 점검하세요:

  • 에러 코드 고유성 및 연속성
  • API 문서나 클라이언트 로직에서 사용하는 코드 반영 여부
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/common/exception/code/ErrorCode.java at line 91,
the error code for RECORD_CANNOT_WRITE_IN_EXPIRED_ROOM is incorrectly set to
120003, which is outside the 130xxx range used for RECORD errors. Change this
error code to a unique and continuous number within the 130xxx range, such as
130003. After updating, verify that the new code is unique and consistent with
other RECORD error codes and update any API documentation or client logic that
references this error code accordingly.


;

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/konkuk/thip/common/util/DateUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package konkuk.thip.common.util;

import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.LocalDateTime;

@Component
public class DateUtil {

//마지막 활동 시간 포맷팅 -> ex. 1분 전, 1시간 전, 1일 전
public String formatLastActivityTime(LocalDateTime createdAt) {
long minutes = Duration.between(createdAt, LocalDateTime.now()).toMinutes();
if (minutes < 1) return "방금 전";
if (minutes < 60) return minutes + "분 전";
long hours = minutes / 60;
if (hours < 24) return hours + "시간 전";
return (hours / 24) + "일 전";
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package konkuk.thip.post.adapter.out.persistence;

import konkuk.thip.post.application.port.out.PostLikeCommandPort;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class PostLikeCommandPersistenceAdapter implements PostLikeCommandPort {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package konkuk.thip.post.adapter.out.persistence;

import konkuk.thip.post.adapter.out.jpa.PostLikeJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PostLikeJpaRepository extends JpaRepository<PostLikeJpaEntity, Long> {
int countByPostJpaEntity_PostId(Long postId);

boolean existsByPostJpaEntity_PostIdAndUserJpaEntity_UserId(Long postId, Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package konkuk.thip.post.adapter.out.persistence;

import konkuk.thip.post.application.port.out.PostLikeQueryPort;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class PostLikeQueryPersistenceAdapter implements PostLikeQueryPort {

private final PostLikeJpaRepository postLikeJpaRepository;

@Override
public int countByPostId(Long postId) {
return postLikeJpaRepository.countByPostJpaEntity_PostId(postId);
}

@Override
public boolean existsByPostIdAndUserId(Long postId, Long userId) {
return postLikeJpaRepository.existsByPostJpaEntity_PostIdAndUserJpaEntity_UserId(postId, userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package konkuk.thip.post.application.port.out;

public interface PostLikeCommandPort {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package konkuk.thip.post.application.port.out;

public interface PostLikeQueryPort {

int countByPostId(Long postId);
boolean existsByPostIdAndUserId(Long postId, Long userId);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
package konkuk.thip.record.adapter.in.web;

import konkuk.thip.common.dto.BaseResponse;
import konkuk.thip.common.security.annotation.UserId;
import konkuk.thip.record.adapter.in.web.response.RecordSearchResponse;
import konkuk.thip.record.application.port.in.dto.RecordSearchQuery;
import konkuk.thip.record.application.port.in.dto.RecordSearchUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class RecordQueryController {

private final RecordSearchUseCase recordSearchUseCase;

@GetMapping("/rooms/{roomId}/posts")
public BaseResponse<RecordSearchResponse> viewRecordList(
@PathVariable final Long roomId,
@RequestParam final String type,
@RequestParam final String sort,
@RequestParam(required = false) final Integer pageStart,
@RequestParam(required = false) final Integer pageEnd,
@RequestParam final Integer pageNum,
@UserId final Long userId
) {
return BaseResponse.ok(recordSearchUseCase.search(
RecordSearchQuery.builder()
.roomId(roomId)
.type(type)
.sort(sort)
.pageStart(pageStart)
.pageEnd(pageEnd)
.pageNum(pageNum)
.userId(userId)
.build()
));
}
Comment on lines +20 to +41
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

입력 검증 및 문서화 추가 필요

컨트롤러 메서드에 입력 검증과 문서화가 필요합니다:

+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Positive;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+
+    /**
+     * 방의 기록 및 투표 목록을 조회합니다.
+     * 
+     * @param roomId 방 ID
+     * @param type 검색 타입 (all, record, vote, mine)
+     * @param sort 정렬 기준 (latest, oldest, popular)
+     * @param pageStart 페이지 시작 번호 (선택사항)
+     * @param pageEnd 페이지 끝 번호 (선택사항)
+     * @param pageNum 페이지 번호
+     * @param userId 현재 사용자 ID
+     * @return 검색 결과
+     */
+    @Operation(summary = "방의 기록 및 투표 목록 조회")
     @GetMapping("/rooms/{roomId}/posts")
     public BaseResponse<RecordSearchResponse> viewRecordList(
+            @Parameter(description = "방 ID", required = true)
+            @NotNull
             @PathVariable final Long roomId,
+            @Parameter(description = "검색 타입", required = true)
+            @NotBlank
             @RequestParam final String type,
+            @Parameter(description = "정렬 기준", required = true)
+            @NotBlank
             @RequestParam final String sort,
+            @Parameter(description = "페이지 시작 번호")
+            @Positive
             @RequestParam(required = false) final Integer pageStart,
+            @Parameter(description = "페이지 끝 번호")
+            @Positive
             @RequestParam(required = false) final Integer pageEnd,
+            @Parameter(description = "페이지 번호", required = true)
+            @Positive
             @RequestParam final Integer pageNum,
+            @Parameter(description = "사용자 ID", hidden = true)
             @UserId final Long userId
     ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@GetMapping("/rooms/{roomId}/posts")
public BaseResponse<RecordSearchResponse> viewRecordList(
@PathVariable final Long roomId,
@RequestParam final String type,
@RequestParam final String sort,
@RequestParam(required = false) final Integer pageStart,
@RequestParam(required = false) final Integer pageEnd,
@RequestParam final Integer pageNum,
@UserId final Long userId
) {
return BaseResponse.ok(recordSearchUseCase.search(
RecordSearchQuery.builder()
.roomId(roomId)
.type(type)
.sort(sort)
.pageStart(pageStart)
.pageEnd(pageEnd)
.pageNum(pageNum)
.userId(userId)
.build()
));
}
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
/**
* 방의 기록 투표 목록을 조회합니다.
*
* @param roomId ID
* @param type 검색 타입 (all, record, vote, mine)
* @param sort 정렬 기준 (latest, oldest, popular)
* @param pageStart 페이지 시작 번호 (선택사항)
* @param pageEnd 페이지 번호 (선택사항)
* @param pageNum 페이지 번호
* @param userId 현재 사용자 ID
* @return 검색 결과
*/
@Operation(summary = "방의 기록 및 투표 목록 조회")
@GetMapping("/rooms/{roomId}/posts")
public BaseResponse<RecordSearchResponse> viewRecordList(
@Parameter(description = "방 ID", required = true)
@NotNull
@PathVariable final Long roomId,
@Parameter(description = "검색 타입", required = true)
@NotBlank
@RequestParam final String type,
@Parameter(description = "정렬 기준", required = true)
@NotBlank
@RequestParam final String sort,
@Parameter(description = "페이지 시작 번호")
@Positive
@RequestParam(required = false) final Integer pageStart,
@Parameter(description = "페이지 끝 번호")
@Positive
@RequestParam(required = false) final Integer pageEnd,
@Parameter(description = "페이지 번호", required = true)
@Positive
@RequestParam final Integer pageNum,
@Parameter(description = "사용자 ID", hidden = true)
@UserId final Long userId
) {
return BaseResponse.ok(recordSearchUseCase.search(
RecordSearchQuery.builder()
.roomId(roomId)
.type(type)
.sort(sort)
.pageStart(pageStart)
.pageEnd(pageEnd)
.pageNum(pageNum)
.userId(userId)
.build()
));
}
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/record/adapter/in/web/RecordQueryController.java
around lines 20 to 41, the controller method lacks input validation and API
documentation. Add validation annotations like @NotNull, @Min, or @Max to the
method parameters to enforce input constraints. Also, include Swagger or similar
API documentation annotations to describe the endpoint, parameters, and expected
responses for better clarity and maintainability.


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package konkuk.thip.record.adapter.in.web.response;

import konkuk.thip.record.domain.Record;
import konkuk.thip.user.domain.User;
import lombok.Builder;

@Builder
public record RecordDto(
String postDate,
int page,
Long userId,
String nickName,
String profileImageUrl,
String content,
int likeCount,
int commentCount,
boolean isLiked,
boolean isWriter,
Long recordId
) implements RecordSearchResponse.PostDto {
@Override
public String type() {
return "RECORD";
}

public static RecordDto of(Record record, String postDate, User user, int likeCount, int commentCount, boolean isLiked, boolean isWriter) {
return RecordDto.builder()
.postDate(postDate)
.page(record.getPage())
.userId(record.getCreatorId())
.nickName(user.getNickname())
.profileImageUrl(user.getImageUrl())
.content(record.getContent())
.likeCount(likeCount)
.commentCount(commentCount)
.isLiked(isLiked)
.isWriter(isWriter)
.recordId(record.getId())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package konkuk.thip.record.adapter.in.web.response;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import java.util.List;

public record RecordSearchResponse(
List<PostDto> recordList,
Integer page,
Integer size,
Boolean first,
Boolean last
){

public static RecordSearchResponse of(List<PostDto> recordList,
Integer page,
Integer size,
Boolean first,
Boolean last) {
return new RecordSearchResponse(recordList, page, size, first, last);
}

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = RecordDto.class, name = "RECORD"),
@JsonSubTypes.Type(value = VoteDto.class, name = "VOTE")
})
public sealed interface PostDto permits RecordDto, VoteDto {
String type();
String postDate();
int page();
Long userId();
String nickName();
String profileImageUrl();
String content();
int likeCount();
int commentCount();
boolean isLiked();
boolean isWriter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package konkuk.thip.record.adapter.in.web.response;

import konkuk.thip.user.domain.User;
import konkuk.thip.vote.domain.Vote;
import konkuk.thip.vote.domain.VoteItem;
import lombok.Builder;

import java.util.List;

@Builder
public record VoteDto(
String postDate,
int page,
Long userId,
String nickName,
String profileImageUrl,
String content,
int likeCount,
int commentCount,
boolean isLiked,
boolean isWriter,
Long voteId,
List<VoteItemDto> voteItems
) implements RecordSearchResponse.PostDto {
@Override
public String type() {
return "VOTE";
}

public static VoteDto of(
Vote vote, String postDate, User user, int likeCount, int commentCount, boolean isLiked, boolean isWriter,
List<VoteItemDto> voteItems
) {
return VoteDto.builder()
.postDate(postDate)
.page(vote.getPage())
.userId(vote.getCreatorId())
.nickName(user.getNickname())
.profileImageUrl(user.getImageUrl())
.content(vote.getContent())
.likeCount(likeCount)
.commentCount(commentCount)
.isLiked(isLiked)
.isWriter(isWriter)
.voteId(vote.getId())
.voteItems(voteItems)
.build();
}

public record VoteItemDto(
Long voteItemId,
String itemName,
int percentage,
boolean isVoted
) {
public static VoteItemDto of(VoteItem voteItem, int percentage, boolean isVoted) {
return new VoteItemDto(
voteItem.getId(),
voteItem.getItemName(),
percentage,
isVoted
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import konkuk.thip.record.adapter.out.jpa.RecordJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface RecordJpaRepository extends JpaRepository<RecordJpaEntity, Long> {
public interface RecordJpaRepository extends JpaRepository<RecordJpaEntity, Long>, RecordQueryRepository {

}
Loading