Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 유저 프로필 조회 파사드 생성 #79

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,27 @@
package slvtwn.khu.toyouserver.application;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import slvtwn.khu.toyouserver.dto.GroupResponse;
import slvtwn.khu.toyouserver.dto.UserProfileResponse;
import slvtwn.khu.toyouserver.dto.UserResponse;

@Component
@RequiredArgsConstructor
public class UserProfileFacade {

private final UserService userService;
private final GroupService groupService;

@Transactional(readOnly = true)
public UserProfileResponse getProfile(Long userId) {
UserResponse userResponse = userService.getProfile(userId);
List<GroupResponse> groupResponses = groupService.findRegisteredGroupsByUser(userId);

return new UserProfileResponse(userResponse.id(), userResponse.birthday(), userResponse.name(),
userResponse.introduction(), userResponse.imageUrl(), groupResponses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package slvtwn.khu.toyouserver.dto;

import java.time.LocalDate;
import java.util.List;

public record UserProfileResponse(Long id, LocalDate birthday, String name, String introduction,
String imageUrl, List<GroupResponse> groups) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import slvtwn.khu.toyouserver.application.UserProfileFacade;
import slvtwn.khu.toyouserver.application.UserService;
import slvtwn.khu.toyouserver.common.authentication.UserAuthentication;
import slvtwn.khu.toyouserver.common.response.ToyouResponse;
import slvtwn.khu.toyouserver.dto.UserProfileResponse;
import slvtwn.khu.toyouserver.dto.UserResponse;
import slvtwn.khu.toyouserver.dto.UserUpdateRequest;

Expand All @@ -18,11 +20,12 @@
public class
UserController {

private final UserProfileFacade userProfileFacade;
private final UserService userService;

@GetMapping("/me")
public ToyouResponse<UserResponse> getProfile(@UserAuthentication Long userId) {
return ToyouResponse.from(userService.getProfile(userId));
public ToyouResponse<UserProfileResponse> getProfile(@UserAuthentication Long userId) {
return ToyouResponse.from(userProfileFacade.getProfile(userId));
}

@PutMapping("/users")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class EventServiceTest {
void 연월로_이벤트를_조회할_수_있다() {
// given
LocalDate baseDate = LocalDate.of(2024, 9, 15);
User user1 = new User("name", baseDate, "introduction", "picture_url");
User user2 = new User("name", baseDate.minus(1, ChronoUnit.DAYS), "introduction", "picture_url");
User user1 = new User("name", baseDate, "introduction", "picture_url", null);
User user2 = new User("name", baseDate.minus(1, ChronoUnit.DAYS), "introduction", "picture_url", null);
Event event1 = new Event("name", baseDate, EventType.BIRTHDAY, "description", user1);
Event event2 = new Event("name", baseDate.minus(1, ChronoUnit.DAYS), EventType.BIRTHDAY, "description", user2);

Expand All @@ -65,8 +65,8 @@ class EventServiceTest {
// given
LocalDate baseDate = LocalDate.of(2024, 9, 15);
LocalDate beforeDate = LocalDate.of(2023, 9, 15);
User user1 = new User("name", baseDate, "introduction", "picture_url");
User user2 = new User("name", beforeDate, "introduction", "picture_url");
User user1 = new User("name", baseDate, "introduction", "picture_url", null);
User user2 = new User("name", beforeDate, "introduction", "picture_url", null);
Event event1 = new Event("name", baseDate, EventType.BIRTHDAY, "description", user1);
Event event2 = new Event("name", beforeDate, EventType.BIRTHDAY, "description", user2);

Expand All @@ -91,8 +91,8 @@ class EventServiceTest {
// given
LocalDate baseDate = LocalDate.of(2024, 9, 15);
LocalDate beforeDate = LocalDate.of(2024, 8, 15);
User user1 = new User("name", baseDate, "introduction", "picture_url");
User user2 = new User("name", beforeDate, "introduction", "picture_url");
User user1 = new User("name", baseDate, "introduction", "picture_url", null);
User user2 = new User("name", beforeDate, "introduction", "picture_url", null);
Event event1 = new Event("name", baseDate, EventType.BIRTHDAY, "description", user1);
Event event2 = new Event("name", beforeDate, EventType.BIRTHDAY, "description", user2);

Expand All @@ -117,8 +117,8 @@ class EventServiceTest {
// given
LocalDate baseDate = LocalDate.of(2024, 9, 15);
LocalDate beforeDate = LocalDate.of(2024, 8, 15);
User user1 = new User("name", baseDate, "introduction", "picture_url");
User user2 = new User("name", beforeDate, "introduction", "picture_url");
User user1 = new User("name", baseDate, "introduction", "picture_url", null);
User user2 = new User("name", beforeDate, "introduction", "picture_url", null);
Event event1 = new Event("name", baseDate, EventType.BIRTHDAY, "description", user1);
Event event2 = new Event("name", beforeDate, EventType.BIRTHDAY, "description", user2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.transaction.annotation.Transactional;
import slvtwn.khu.toyouserver.domain.Group;
import slvtwn.khu.toyouserver.domain.Member;
import slvtwn.khu.toyouserver.domain.SocialAuthProvider;
import slvtwn.khu.toyouserver.domain.User;
import slvtwn.khu.toyouserver.dto.GroupCreateRequest;
import slvtwn.khu.toyouserver.dto.GroupMemberResponse;
Expand Down Expand Up @@ -49,7 +50,7 @@ class GroupServiceTest {
@Test
void 유저는_그룹에_가입할_수_있다() {
// given
User user = new User("name", LocalDate.now(), "introduction", "profile_pic");
User user = new User("name", LocalDate.now(), "introduction", "profile_pic", null);
Group group = new Group("group_name");

entityManager.persist(user);
Expand All @@ -63,7 +64,7 @@ class GroupServiceTest {
@Test
void 그룹이_존재하지_않는다면_가입이_불가능하다() {
// given
User user = new User("name", LocalDate.now(), "introduction", "profile_pic");
User user = new User("name", LocalDate.now(), "introduction", "profile_pic", null);
long groupIdNonExists = 1L;

entityManager.persist(user);
Expand All @@ -76,8 +77,8 @@ class GroupServiceTest {
@Test
void 그룹에_속한_멤버들을_찾을_수_있다() {
// given
User user1 = new User("name1", LocalDate.now(), "introduction", "profile_pic");
User user2 = new User("name2", LocalDate.now(), "introduction", "profile_pic");
User user1 = new User("name1", LocalDate.now(), "introduction", "profile_pic", null);
User user2 = new User("name2", LocalDate.now(), "introduction", "profile_pic", null);

Group group = new Group("group_name");

Expand All @@ -101,7 +102,7 @@ class GroupServiceTest {
@Test
void 유저는_가입한_그룹을_조회할_수_있다() {
// given
User user = new User("name", LocalDate.now(), "introduction", "profile_pic");
User user = new User("name", LocalDate.now(), "introduction", "profile_pic", null);
Group group1 = new Group("group_name1");
Group group2 = new Group("group_name2");
Member member1 = new Member(user, group1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import slvtwn.khu.toyouserver.domain.Group;
import slvtwn.khu.toyouserver.domain.Member;
import slvtwn.khu.toyouserver.domain.RollingPaper;
import slvtwn.khu.toyouserver.domain.SocialAuthProvider;
import slvtwn.khu.toyouserver.domain.User;
import slvtwn.khu.toyouserver.dto.CoverRequest;
import slvtwn.khu.toyouserver.dto.RollingPaperRequest;
Expand All @@ -44,7 +45,7 @@ class RollingPaperServiceTest {
void 커버_이미지를_생성하면_롤링페이퍼_커버가_업데이트된다() {
// given
Group group = new Group("name");
User user = new User("name", LocalDate.now(), "introduction", "profile_picture");
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);

Expand All @@ -70,8 +71,8 @@ class RollingPaperServiceTest {
void 롤링페이퍼를_전송할_수_있다() {
// given
Group group = new Group("name");
User user1 = new User("name", LocalDate.now(), "introduction", "profile_picture");
User user2 = new User("name", LocalDate.now(), "introduction", "profile_picture");
User user1 = new User("name", LocalDate.now(), "introduction", "profile_picture", null);
User user2 = new User("name", LocalDate.now(), "introduction", "profile_picture", null);
Member member1 = new Member(user1, group);
Member member2 = new Member(user2, group);

Expand All @@ -94,7 +95,7 @@ class RollingPaperServiceTest {
void 롤링페이퍼를_조회할_수_있다() {
// given
Group group = new Group("name");
User user = new User("name", LocalDate.now(), "introduction", "profile_picture");
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class UserServiceTest {
@Test
void 같은_그룹의_유저들을_키워드로_검색할_수_있다() {
// given
User user1 = new User("name1", LocalDate.now(), "introduction", "profile_picture");
User user2 = new User("name2", LocalDate.now(), "introduction", "profile_picture");
User user1 = new User("name1", LocalDate.now(), "introduction", "profile_picture", null);
User user2 = new User("name2", LocalDate.now(), "introduction", "profile_picture", null);
Group group = new Group("name");
Member member1 = new Member(user1, group);
Member member2 = new Member(user2, group);
Expand All @@ -57,8 +57,8 @@ class UserServiceTest {
@Test
void 다른_그룹의_유저들을_키워드로_검색할_수_있다() {
// given
User user1 = new User("name1", LocalDate.now(), "introduction", "profile_picture");
User user2 = new User("name2", LocalDate.now(), "introduction", "profile_picture");
User user1 = new User("name1", LocalDate.now(), "introduction", "profile_picture", null);
User user2 = new User("name2", LocalDate.now(), "introduction", "profile_picture", null);
Group group1 = new Group("name");
Group group2 = new Group("name");
Member member1 = new Member(user1, group1);
Expand All @@ -82,7 +82,7 @@ class UserServiceTest {
@Test
void 유저_정보를_업데이트_할_수_있다() {
// given
User user = new User("name", LocalDate.now(), "introduction", "profile_picture");
User user = new User("name", LocalDate.now(), "introduction", "profile_picture", null);
Group group1 = new Group("name");
Group group2 = new Group("name");
Member member = new Member(user, group1);
Expand All @@ -101,7 +101,7 @@ class UserServiceTest {
userService.updateUser(user.getId(), request);

// then
User expectedUser = new User(request.name(), request.birthday(), request.introduction(), request.imageUrl());
User expectedUser = new User(request.name(), request.birthday(), request.introduction(), request.imageUrl(), null);

assertThat(user).usingRecursiveComparison()
.ignoringFields("id", "createdDate", "lastModifiedDate")
Expand Down