Skip to content

Commit

Permalink
[OING-174] feat: 사용자 그룹 가입 일자 필드 추가 (#127)
Browse files Browse the repository at this point in the history
* feat: add familyJoinAt column

* test: fix member related test issues

* feat: add migration sql script
  • Loading branch information
CChuYong authored Jan 28, 2024
1 parent 8c350e3 commit f881b1a
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `member` ADD COLUMN `family_join_at` TIMESTAMP COMMENT '가족가입일시';
UPDATE member SET family_join_at = created_at WHERE family_id IS NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class CalendarControllerTest {
LocalDate.of(1999, 10, 18),
"testMember1",
"profile.com/1",
"1"
"1",
LocalDateTime.now()
);

private final Member testMember2 = new Member(
Expand All @@ -57,7 +58,8 @@ class CalendarControllerTest {
LocalDate.of(1999, 10, 18),
"testMember2",
"profile.com/2",
"2"
"2",
LocalDateTime.now()
);

private final List<String> familyIds = List.of(testMember1.getId(), testMember2.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class MemberPostRepositoryCustomTest {
LocalDate.of(1999, 10, 18),
"testMember1",
"profile.com/1",
"1"
"1",
LocalDateTime.now()
);

private final Member testMember2 = new Member(
Expand All @@ -54,7 +55,8 @@ class MemberPostRepositoryCustomTest {
LocalDate.of(1999, 10, 18),
"testMember2",
"profile.com/2",
"2"
"2",
LocalDateTime.now()
);

private final Member testMember3 = new Member(
Expand All @@ -63,7 +65,8 @@ class MemberPostRepositoryCustomTest {
LocalDate.of(1999, 10, 18),
"testMember3",
"profile.com/3",
"2"
"2",
LocalDateTime.now()
);

private final List<String> familyIds = List.of(testMember1.getId(), testMember2.getId());
Expand Down
4 changes: 3 additions & 1 deletion gateway/src/test/java/com/oing/restapi/MemberApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.test.web.servlet.ResultActions;

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

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
Expand Down Expand Up @@ -51,7 +52,8 @@ void setUp() {
TEST_MEMBER_ID,
"testUser1",
LocalDate.now(),
"", "", ""
"", "", "",
LocalDateTime.now()
)
);
TEST_MEMBER_TOKEN = tokenGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
Expand Down Expand Up @@ -56,7 +57,8 @@ void setUp() {
TEST_MEMBER_ID,
"testUser1",
LocalDate.now(),
"", "", ""
"", "", "",
LocalDateTime.now()
)
);
TEST_MEMBER_TOKEN = tokenGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -58,7 +59,8 @@ void setUp() {
TEST_MEMBER_ID,
"testUser1",
LocalDate.now(),
"", "", ""
"", "", "",
LocalDateTime.now()
)
);
TEST_MEMBER_TOKEN = tokenGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -58,7 +59,8 @@ void setUp() {
TEST_MEMBER_ID,
"testUser1",
LocalDate.now(),
"", "", ""
"", "", "",
LocalDateTime.now()
)
);
TEST_MEMBER_TOKEN = tokenGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -55,7 +56,8 @@ public class MemberPostRealEmojiApiTest {
@BeforeEach
void setUp() {
memberRepository.save(new Member(TEST_MEMBER_ID, "testUser1", LocalDate.now(), "",
"", ""));
"", "",
LocalDateTime.now()));
TEST_MEMBER_TOKEN = tokenGenerator.generateTokenPair(TEST_MEMBER_ID).accessToken();

memberPostRepository.save(new MemberPost(TEST_POST_ID, TEST_MEMBER_ID, "img", "img",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -56,7 +57,8 @@ void setUp() {
TEST_MEMBER_ID,
"testUser1",
LocalDate.now(),
"", "", ""
"", "", "",
LocalDateTime.now()
)
);
TEST_MEMBER_TOKEN = tokenGenerator
Expand Down
11 changes: 11 additions & 0 deletions member/src/main/java/com/oing/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* no5ing-server
Expand Down Expand Up @@ -39,10 +40,15 @@ public class Member extends DeletableBaseAuditEntity {
@Column(name = "profile_img_key")
private String profileImgKey;

@Column(name = "family_join_at")
private LocalDateTime familyJoinAt;


public void setProfileImgKey(String profileImgKey) {
this.profileImgKey = profileImgKey;
}


public void updateProfileImg(String profileImgUrl, String profileImgKey) {
this.profileImgUrl = profileImgUrl;
this.profileImgKey = profileImgKey;
Expand All @@ -60,6 +66,11 @@ public void deleteMemberInfo() {

public void setFamilyId(String familyId) {
this.familyId = familyId;
if(familyId == null) {
this.familyJoinAt = null;
} else {
this.familyJoinAt = LocalDateTime.now();
}
}

public boolean hasFamily() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ public record FamilyMemberProfileResponse(
@Schema(description = "구성원 프로필 이미지 주소", example = "https://asset.no5ing.kr/post/01HGW2N7EHJVJ4CJ999RRS2E97")
String imageUrl,

@Schema(description = "가족 가입 날짜", example = "2023-12-23")
LocalDate familyJoinAt,

@Schema(description = "구성원의 생일", example = "2021-12-05")
LocalDate dayOfBirth
) {
public static FamilyMemberProfileResponse of(String memberId, String name, String imageUrl, LocalDate dayOfBirth) {
return new FamilyMemberProfileResponse(memberId, name, imageUrl, dayOfBirth);
public static FamilyMemberProfileResponse of
(String memberId, String name, String imageUrl, LocalDate familyJoinAt, LocalDate dayOfBirth) {
return new FamilyMemberProfileResponse(memberId, name, imageUrl, familyJoinAt, dayOfBirth);
}

public static FamilyMemberProfileResponse of(Member member) {
return of(member.getId(), member.getName(), member.getProfileImgUrl(), member.getDayOfBirth());
return of(member.getId(), member.getName(), member.getProfileImgUrl(),
member.getFamilyJoinAt() == null ? null : member.getFamilyJoinAt().toLocalDate(), member.getDayOfBirth());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public record MemberResponse(
@Schema(description = "구성원 가족 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E")
String familyId,

@Schema(description = "가족 가입 날짜", example = "2023-12-23")
LocalDate familyJoinAt,

@Schema(description = "구성원 생일", example = "2023-12-23")
LocalDate dayOfBirth
) {
Expand All @@ -33,6 +36,7 @@ public static MemberResponse of(Member member) {
member.getName(),
member.getProfileImgUrl(),
member.getFamilyId(),
member.getFamilyJoinAt() == null ? null : member.getFamilyJoinAt().toLocalDate(),
member.getDayOfBirth()
);
}
Expand Down
32 changes: 21 additions & 11 deletions member/src/test/java/com/oing/controller/MemberControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.security.InvalidParameterException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -48,7 +49,8 @@ public class MemberControllerTest {
void 멤버_프로필_조회_테스트() {
// given
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(memberService.findMemberById(any())).thenReturn(member);

// when
Expand All @@ -66,15 +68,17 @@ public class MemberControllerTest {
void 가족_멤버_프로필_조회_테스트() {
// given
Member member1 = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
Member member2 = new Member("2", "1", LocalDate.of(2003, 7, 26),
"testMember2", null, null);
"testMember2", null, null,
LocalDateTime.now());
String familyId = "1";
when(authenticationHolder.getUserId()).thenReturn("1");
when(memberService.findFamilyIdByMemberId(anyString())).thenReturn(familyId);
Page<FamilyMemberProfileResponse> profilePage = new PageImpl<>(Arrays.asList(
new FamilyMemberProfileResponse(member1.getId(), member1.getName(), member1.getProfileImgUrl(), member1.getDayOfBirth()),
new FamilyMemberProfileResponse(member2.getId(), member2.getName(), member2.getProfileImgUrl(), member2.getDayOfBirth())
new FamilyMemberProfileResponse(member1.getId(), member1.getName(), member1.getProfileImgUrl(), member1.getFamilyJoinAt().toLocalDate(), member1.getDayOfBirth()),
new FamilyMemberProfileResponse(member2.getId(), member2.getName(), member2.getProfileImgUrl(),member2.getFamilyJoinAt().toLocalDate(), member2.getDayOfBirth())
));
when(memberService.findFamilyMembersProfilesByFamilyId(familyId, 1, 5))
.thenReturn(profilePage);
Expand All @@ -93,7 +97,8 @@ public class MemberControllerTest {
// given
String newName = "newName";
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(memberService.findMemberById(any())).thenReturn(member);
when(authenticationHolder.getUserId()).thenReturn("1");

Expand All @@ -110,7 +115,8 @@ public class MemberControllerTest {
// given
String newName = "wrong-length-nam";
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(memberService.findMemberById(any())).thenReturn(member);
when(authenticationHolder.getUserId()).thenReturn("1");

Expand All @@ -126,7 +132,8 @@ public class MemberControllerTest {
// given
String newName = "";
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(memberService.findMemberById(any())).thenReturn(member);
when(authenticationHolder.getUserId()).thenReturn("1");

Expand Down Expand Up @@ -157,7 +164,8 @@ public class MemberControllerTest {
// given
String newProfileImageUrl = "http://test.com/profile.jpg";
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(memberService.findMemberById(any())).thenReturn(member);
when(authenticationHolder.getUserId()).thenReturn("1");
when(preSignedUrlGenerator.extractImageKey(any())).thenReturn("/profile.jpg");
Expand All @@ -174,7 +182,8 @@ public class MemberControllerTest {
void 멤버_탈퇴_테스트() {
// given
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(memberService.findMemberById(any())).thenReturn(member);
when(authenticationHolder.getUserId()).thenReturn("1");

Expand All @@ -190,7 +199,8 @@ public class MemberControllerTest {
void 잘못된_요청의_멤버_탈퇴_예외_테스트() {
// given
Member member = new Member("1", "1", LocalDate.of(2000, 7, 8),
"testMember1", "http://test.com/test-profile.jpg", null);
"testMember1", "http://test.com/test-profile.jpg", null,
LocalDateTime.now());
when(authenticationHolder.getUserId()).thenReturn("2");

// then
Expand Down
10 changes: 7 additions & 3 deletions member/src/test/java/com/oing/domain/model/MemberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -27,7 +28,8 @@ void testMemberConstructorAndGetters() {
String name = "sampleName";

// When
Member member = new Member(memberId, familyId, dayofBirth, name, null, null);
Member member = new Member(memberId, familyId, dayofBirth, name, null, null,
LocalDateTime.now());

// Then
assertNotNull(member);
Expand All @@ -44,8 +46,10 @@ void testMemberEqualsAndHashCode() {
String name = "sampleName";

// When
Member member1 = new Member(memberId, familyId, dayofBirth, name, null, null);
Member member2 = new Member(memberId, familyId, dayofBirth, name, null, null);
Member member1 = new Member(memberId, familyId, dayofBirth, name, null, null,
LocalDateTime.now());
Member member2 = new Member(memberId, familyId, dayofBirth, name, null, null,
LocalDateTime.now());

// Then
assertEquals(member1, member2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -28,7 +29,8 @@ void testSocialMemberConstructorAndGetters() {

// When
Member member = new Member("sampleId", "sampleFamilyId",
LocalDate.of(2023, 7, 8), "sampleName", null, null);
LocalDate.of(2023, 7, 8), "sampleName", null, null,
LocalDateTime.now());

// When
SocialMember socialMember = new SocialMember(provider, identifier, member);
Expand All @@ -47,7 +49,8 @@ void testSocialMemberEqualsAndHashCode() {
SocialLoginProvider provider = SocialLoginProvider.APPLE;
String identifier = "user123";
Member member = new Member("sampleId", "sampleFamilyId",
LocalDate.of(2023, 7, 8), "sampleName", null, null);
LocalDate.of(2023, 7, 8), "sampleName", null, null,
LocalDateTime.now());

// When
SocialMember socialMember1 = new SocialMember(provider, identifier, member);
Expand Down
Loading

0 comments on commit f881b1a

Please sign in to comment.