-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Be/#251 : 쪽지 목록 조회 API 구현
- Loading branch information
Showing
7 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/graphy/backend/domain/message/dto/response/GetMessageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.graphy.backend.domain.message.dto.response; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
public class GetMessageResponse { | ||
private Long senderId; | ||
private String memberNickname; | ||
private String content; | ||
private LocalDateTime sentAt; | ||
|
||
@QueryProjection | ||
public GetMessageResponse(Long senderId, String memberNickname, String content, LocalDateTime sentAt) { | ||
this.senderId = senderId; | ||
this.memberNickname = memberNickname; | ||
this.content = content; | ||
this.sentAt = sentAt; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...d/src/main/java/com/graphy/backend/domain/message/repository/MessageCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.graphy.backend.domain.message.repository; | ||
|
||
import com.graphy.backend.domain.message.dto.response.GetMessageResponse; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface MessageCustomRepository { | ||
List<GetMessageResponse> findMessages(Pageable pageable, Long memberId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...java/com/graphy/backend/domain/message/repository/custom/MessageCustomRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.graphy.backend.domain.message.repository.custom; | ||
|
||
import com.graphy.backend.domain.message.dto.response.GetMessageResponse; | ||
import com.graphy.backend.domain.message.dto.response.QGetMessageResponse; | ||
import com.graphy.backend.domain.message.repository.MessageCustomRepository; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
import static com.graphy.backend.domain.member.domain.QMember.member; | ||
import static com.graphy.backend.domain.message.domain.QMessage.message; | ||
|
||
@RequiredArgsConstructor | ||
public class MessageCustomRepositoryImpl implements MessageCustomRepository { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public List<GetMessageResponse> findMessages(Pageable pageable, Long memberId) { | ||
return jpaQueryFactory | ||
.select(new QGetMessageResponse( | ||
member.id, | ||
member.nickname, | ||
message.content, | ||
message.createdAt | ||
)) | ||
.from(message) | ||
.join(message.sender, member) | ||
.where(message.receiver.id.eq(memberId)) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters