Skip to content

Commit

Permalink
Merge pull request #79 from Princess-in-silvertown/feat/78
Browse files Browse the repository at this point in the history
Feat: μœ μ € ν”„λ‘œν•„ 쑰회 νŒŒμ‚¬λ“œ 생성
  • Loading branch information
woosung1223 authored Sep 29, 2024
2 parents 40253b4 + 8f90124 commit 7cec15c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 25 deletions.
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

0 comments on commit 7cec15c

Please sign in to comment.