Skip to content

Commit

Permalink
✨ feat: 사용자별 메시지 송/수신기록 조회 API (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
loveysuby committed Nov 5, 2024
1 parent f5c16ac commit a6b60d9
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package slvtwn.khu.toyouserver.application;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import slvtwn.khu.toyouserver.dto.RollingPaperExchangeCountResponse;

@Component
@RequiredArgsConstructor
public class RollingPaperCommandFacade {

private final RollingPaperService rollingPaperService;
private final UserService userService;

public RollingPaperExchangeCountResponse getExchangeCount(Long userId) {
return RollingPaperExchangeCountResponse.of(
userService.getProfile(userId).name(),
rollingPaperService.countSentRollingPapers(userId),
rollingPaperService.countReceivedRollingPapers(userId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ public RollingPaperPagedResponse findReceivedRollingPapers(Long userId, Long gro
return RollingPaperPagedResponse.from(cursorPageInfo, responses);
}

public Long countSentRollingPapers(Long userId) {
return rollingPaperRepository.countAllBySenderSnapshot_SenderId(userId);
}

public Long countReceivedRollingPapers(Long userId) {
List<Member> members = memberRepository.findByUserId(userId);
return rollingPaperRepository.findAllByMemberIn(members).stream()
.filter(rollingPaper -> !rollingPaper.getSenderSnapshot().getSenderId().equals(userId))
.count();
}

private List<Sticker> parseStickers(RollingPaperRequest request, RollingPaper rollingPaper) {
return request.stickers().stream()
.map(each -> new Sticker(rollingPaper, each.imageUrl(), each.x(), each.y(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package slvtwn.khu.toyouserver.dto;

public record RollingPaperExchangeCountResponse(String userName, Long sentCount, Long receivedCount) {
public static RollingPaperExchangeCountResponse of(String userName, Long sentCount, Long receivedCount) {
return new RollingPaperExchangeCountResponse(userName, sentCount, receivedCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

List<Member> findByUser(User user);

List<Member> findByUserId(Long userId);

@Query("select m from Member m join m.user u where m.group = :group and u.name like %:pattern%")
List<Member> findByGroupAndUserNameLike(Group group, String pattern);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ Slice<RollingPaper> findByMembersWithCursor(@Param("memberIds") List<Long> membe

List<RollingPaper> findAllByMemberIn(List<Member> members);

Long countAllBySenderSnapshot_SenderId(Long senderId);

List<RollingPaper> findAllBySenderSnapshot_SenderId(Long senderId);

void deleteAllByMemberIn(List<Member> members);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package slvtwn.khu.toyouserver.presentation;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import slvtwn.khu.toyouserver.application.RollingPaperCommandFacade;
import slvtwn.khu.toyouserver.common.authentication.UserAuthentication;
import slvtwn.khu.toyouserver.common.response.ToyouResponse;
import slvtwn.khu.toyouserver.dto.RollingPaperExchangeCountResponse;

@RequestMapping("/rollingpapers/folders")
@RequiredArgsConstructor
@RestController
public class RollingPaperFolderController {

private final RollingPaperCommandFacade rollingPaperCommandFacade;

@GetMapping("/info")
public ToyouResponse<RollingPaperExchangeCountResponse> findRollingPaperExchangeCount(
@UserAuthentication Long userId) {
return ToyouResponse.from(rollingPaperCommandFacade.getExchangeCount(userId));
}
}

0 comments on commit a6b60d9

Please sign in to comment.