Skip to content

Commit

Permalink
♻️ refactor: 편지 발신자 기록은 사용자 정보로 바인딩하도록 변경 (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
loveysuby committed Nov 5, 2024
1 parent 648dc38 commit f5c16ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ private RollingPaper generateRollingPaper(Long requestUserId, Long recipientUser
() -> new ToyouException(ResponseType.BAD_REQUEST));
User requestUser = userRepository.findById(requestUserId)
.orElseThrow(() -> new ToyouException(ResponseType.BAD_REQUEST));

return new RollingPaper(request.coverImageUrl(), request.title(), request.content(), request.themeId(),
member, new SenderSnapshot(requestUser.getName(), requestUser.getProfilePicture()));
member, SenderSnapshot.of(requestUser));
}

public RollingPaperResponse findById(Long userId, Long rollingPaperId) {
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/slvtwn/khu/toyouserver/domain/SenderSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Embeddable
@Getter
public class SenderSnapshot {

private String name;
private String profileImageUrl;
private Long senderId;
private String name;
private String profileImageUrl;

public SenderSnapshot(String name, String profileImageUrl) {
this.name = name;
this.profileImageUrl = profileImageUrl;
}
public static SenderSnapshot of(User user) {
return new SenderSnapshot(user.getId(), user.getName(), user.getProfilePicture());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RollingPaperServiceTest {
User user = new User("name", LocalDate.now(), "introduction", "profile_picture", null);
Member member = new Member(user, group);
RollingPaper rollingPaper = new RollingPaper(null, "title", "content", 1L,
member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group);
Expand All @@ -118,7 +118,7 @@ class RollingPaperServiceTest {
User user = new User("name", LocalDate.now(), "introduction", "profile_picture", null);
Member member = new Member(user, group);
RollingPaper rollingPaper = new RollingPaper(null, "title", "content", 1L,
member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group);
Expand All @@ -144,9 +144,9 @@ class RollingPaperServiceTest {
Member member1 = new Member(user, group1);
Member member2 = new Member(user, group2);
RollingPaper rollingPaper = new RollingPaper(null, "title", "rollingPaper", 1L,
member1, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
member1, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper anotherRollingPaper = new RollingPaper(null, "title", "anotherRollingPaper", 1L,
member2, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
member2, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group1);
Expand Down Expand Up @@ -180,9 +180,9 @@ class RollingPaperServiceTest {
Member member1 = new Member(user, group1);
Member member2 = new Member(user, group2);
RollingPaper rollingPaper = new RollingPaper(null, "title", "rollingPaper", 1L,
member1, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
member1, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper anotherRollingPaper = new RollingPaper(null, "title", "anotherRollingPaper", 1L,
member2, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
member2, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group1);
Expand Down Expand Up @@ -214,11 +214,11 @@ class RollingPaperServiceTest {
Member member2 = new Member(user, group2);

RollingPaper rollingPaper1 = new RollingPaper(null, "title1", "rollingPaper1",
1L, member1, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member1, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper2 = new RollingPaper(null, "title2", "rollingPaper2",
1L, member1, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member1, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper3 = new RollingPaper(null, "title3", "rollingPaper3",
1L, member2, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member2, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group1);
Expand Down Expand Up @@ -254,11 +254,11 @@ class RollingPaperServiceTest {
Member member = new Member(user, group);

RollingPaper rollingPaper1 = new RollingPaper(null, "title1", "rollingPaper1",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper2 = new RollingPaper(null, "title2", "rollingPaper2",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper3 = new RollingPaper(null, "title3", "rollingPaper3",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group);
Expand Down Expand Up @@ -293,11 +293,11 @@ class RollingPaperServiceTest {
Member member = new Member(user, group);

RollingPaper rollingPaper1 = new RollingPaper(null, "title1", "rollingPaper1",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper2 = new RollingPaper(null, "title2", "rollingPaper2",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper3 = new RollingPaper(null, "title3", "rollingPaper3",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group);
Expand Down Expand Up @@ -331,11 +331,11 @@ class RollingPaperServiceTest {
Member member = new Member(user, group);

RollingPaper rollingPaper1 = new RollingPaper(null, "title1", "rollingPaper1",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper2 = new RollingPaper(null, "title2", "rollingPaper2",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper3 = new RollingPaper(null, "title3", "rollingPaper3",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group);
Expand Down Expand Up @@ -363,11 +363,11 @@ class RollingPaperServiceTest {
Member member = new Member(user, group);

RollingPaper rollingPaper1 = new RollingPaper(null, "title1", "rollingPaper1",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper2 = new RollingPaper(null, "title2", "rollingPaper2",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));
RollingPaper rollingPaper3 = new RollingPaper(null, "title3", "rollingPaper3",
1L, member, new SenderSnapshot(sender.getName(), sender.getProfilePicture()));
1L, member, new SenderSnapshot(sender.getId(), sender.getName(), sender.getProfilePicture()));

entityManager.persist(user);
entityManager.persist(group);
Expand Down

0 comments on commit f5c16ac

Please sign in to comment.