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

[RELEASE/1.2.2] Release v1.2.2 #263

Merged
merged 8 commits into from
Jun 21, 2024
5 changes: 5 additions & 0 deletions common/src/main/java/com/oing/service/FamilyBridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.oing.service;

public interface FamilyBridge {
String findFamilyNameByFamilyId(String familyId);
}
8 changes: 8 additions & 0 deletions common/src/main/java/com/oing/service/MemberBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public interface MemberBridge {
boolean isDeletedMember(String memberId);

List<String> getFamilyMembersIdsByFamilyId(String familyId);

String getMemberNameByMemberId(String memberId);

List<String> getFamilyMemberNamesByFamilyId(String familyId);

List<String> getFamilyMemberProfileImgUrlsByFamilyId(String familyId);

int getFamilyMemberCountByFamilyId(String familyId);
}
2 changes: 2 additions & 0 deletions common/src/main/java/com/oing/service/PostBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
*/
public interface PostBridge {
boolean isUploadedToday(String familyId, String memberId);

int countSurvivalPostsByFamilyId(String familyId);
}
11 changes: 11 additions & 0 deletions family/src/main/java/com/oing/controller/FamilyController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.oing.controller;

import com.oing.domain.Family;
import com.oing.dto.request.UpdateFamilyNameRequest;
import com.oing.dto.response.FamilyResponse;
import com.oing.exception.AuthorizationFailedException;
import com.oing.restapi.FamilyApi;
Expand Down Expand Up @@ -28,4 +29,14 @@ public FamilyResponse getFamilyCreatedAt(String familyId, String loginFamilyId)
Family family = familyService.getFamilyById(familyId);
return FamilyResponse.of(family);
}

@Override
public FamilyResponse updateFamilyName(String familyId, String loginFamilyId, String loginMemberId, UpdateFamilyNameRequest request) {
if (!familyId.equals(loginFamilyId)) {
throw new AuthorizationFailedException();
}

Family family = familyService.updateFamilyName(familyId, loginMemberId, request.familyName());
return FamilyResponse.of(family);
}
}
29 changes: 28 additions & 1 deletion family/src/main/java/com/oing/domain/Family.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.security.InvalidParameterException;

@Entity(name = "family")
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@AllArgsConstructor
Expand All @@ -17,12 +19,20 @@ public class Family extends BaseEntity {
@Column(name = "family_id", columnDefinition = "CHAR(26)", nullable = false)
private String id;

@Column(name = "family_name", columnDefinition = "CHAR(10)")
private String familyName;

@Column(name = "family_name_editor_id", columnDefinition = "CHAR(26)")
private String familyNameEditorId;

@Column(name = "score", nullable = false)
private Integer score = 0;


public Family(String id) {
public Family(String id, String familyName, String familyNameEditorId) {
this.id = id;
this.familyName = familyName;
this.familyNameEditorId = familyNameEditorId;
}

public static final int NEW_POST_SCORE = 20;
Expand Down Expand Up @@ -82,4 +92,21 @@ public void subtractScore(int score) {
public void resetScore() {
this.score = 0;
}

public void updateFamilyName(String familyName, String loginFamilyId) {
if (familyName == null) {
this.familyName = null;
this.familyNameEditorId = null;
} else {
validateFamilyName(familyName);
this.familyName = familyName;
this.familyNameEditorId = loginFamilyId;
}
}

private void validateFamilyName(String familyName) {
if ((familyName.codePoints().count() > 10) || familyName.isBlank()) {
throw new InvalidParameterException();
}
}
}
8 changes: 7 additions & 1 deletion family/src/main/java/com/oing/domain/FamilyInviteLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ public class FamilyInviteLink extends BaseEntity implements SerializableDeepLink
@Column(name = "family_id", columnDefinition = "CHAR(26)", nullable = false)
private String familyId;

@Column(name = "member_id", columnDefinition = "CHAR(26)", nullable = false)
private String memberId;

@Override
public Map<String, String> serialize() {
return Map.of("familyId", familyId);
return Map.of(
"familyId", familyId,
"memberId", memberId
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.oing.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;

@Schema(description = "가족 이름 수정 요청")
public record UpdateFamilyNameRequest(

@Size(max = 10)
@Schema(description = "가족 이름", example = "오잉")
String familyName
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.oing.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

@Schema(description = "가족 초대 링크 응답")
public record FamilyInviteDeepLinkResponse(

@Schema(description = "가족 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97")
String familyId,

@Schema(description = "가족 명", example = "사랑하는 우리가족")
String familyName,

@Schema(description = "대표 가족구성원 닉네임", example = "미밍이")
List<String> familyMemberNames,

@Schema(description = "대표 가족구성원 프로필 이미지 URL", example = "https://asset.no5ing.kr/member/profile/ab3fde93ee")
List<String> familyMembersProfileImageUrls,

@Schema(description = "대표 가족구성원 외 구성원 수", example = "3")
Integer extraFamilyMembersCount,

@Schema(description = "전체 가족 구성원 수", example = "5")
Integer familyMembersCount,


@Schema(description = "초대자 이름", example = "김철수")
String inviterName,

@Schema(description = "완료한 생존신고의 수", example = "3")
Integer survivalCount,

@Schema(description = "요청자가 이미 가족에 가입되어 있는지 여부 (토큰 첨부 시에만 반환, 미첨부 시 null 반환)", example = "true")
Boolean isRequesterJoinedFamily
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ public record FamilyResponse(
@Schema(description = "가족 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97")
String familyId,

@Schema(description = "가족 이름", example = "미밍이네")
String familyName,

@Schema(description = "가족 이름 마지막 수정자 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97")
String familyNameEditorId,

@Schema(description = "가족 생성 시간", example = "2021-12-05T12:30:00.000+09:00")
ZonedDateTime createdAt
) {
public static FamilyResponse of(Family family) {
return new FamilyResponse(
family.getId(),
family.getFamilyName(),
family.getFamilyNameEditorId(),
family.getCreatedAt().atZone(ZoneId.systemDefault())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
* Time: 7:17 PM
*/
public interface FamilyInviteLinkRepository extends JpaRepository<FamilyInviteLink, String> {
public FamilyInviteLink findByFamilyId(String familyId);
public FamilyInviteLink findByFamilyIdAndMemberId(String familyId, String memberId);
}
21 changes: 21 additions & 0 deletions family/src/main/java/com/oing/restapi/FamilyApi.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.oing.restapi;

import com.oing.dto.request.UpdateFamilyNameRequest;
import com.oing.dto.response.FamilyResponse;
import com.oing.util.security.LoginFamilyId;
import com.oing.util.security.LoginMemberId;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -28,4 +30,23 @@ FamilyResponse getFamilyCreatedAt(
@LoginFamilyId
String loginFamilyId
);

@Operation(summary = "가족 이름 변경", description = "가족 이름을 변경합니다.")
@PutMapping("/{familyId}/name")
FamilyResponse updateFamilyName(
@Parameter(description = "가족 ID", example = "01HGW2N7EHJVJ4CJ999RRS2E97")
@PathVariable
String familyId,

@Parameter(hidden = true)
@LoginFamilyId
String loginFamilyId,

@Parameter(hidden = true)
@LoginMemberId
String loginMemberId,

@RequestBody
UpdateFamilyNameRequest request
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FamilyInviteLink storeDeepLinkDetails(FamilyInviteLink details) {

@Override
public FamilyInviteLink findPriorDeepLinkDetails(FamilyInviteLink details) {
return familyInviteLinkRepository.findByFamilyId(details.getFamilyId());
return familyInviteLinkRepository.findByFamilyIdAndMemberId(details.getFamilyId(), details.getMemberId());
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion family/src/main/java/com/oing/service/FamilyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FamilyService {

@Transactional
public Family createFamily() {
Family family = new Family(identityGenerator.generateIdentity());
Family family = new Family(identityGenerator.generateIdentity(), null, null);
return familyRepository.save(family);
}

Expand Down Expand Up @@ -57,4 +57,11 @@ private int calculateLiveFamilyTopPercentage(String familyId) {
// score 를 통한 순위를 통해 전체 가족들 중 상위 백분율 계산 (1%에 가까울수록 고순위)
return familyScoreBridge.calculateFamilyTopPercentage(rank, familiesCount);
}

@Transactional
public Family updateFamilyName(String familyId, String loginMemberId, String familyName) {
Family family = getFamilyById(familyId);
family.updateFamilyName(familyName, loginMemberId);
return family;
}
}
80 changes: 80 additions & 0 deletions family/src/test/java/com/oing/service/FamilyServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.oing.service;

import com.oing.domain.Family;
import com.oing.repository.FamilyRepository;
import com.oing.util.IdentityGenerator;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;

import java.security.InvalidParameterException;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;

@Transactional
@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
public class FamilyServiceTest {

@InjectMocks
private FamilyService familyService;
@Mock
private FamilyRepository familyRepository;
@Mock
private FamilyTopPercentageHistoryService familyTopPercentageHistoryService;
@Mock
private FamilyScoreBridge familyScoreBridge;
@Mock
private IdentityGenerator identityGenerator;

@Test
void 가족_이름_수정_테스트() {
// given
String newName = "new-name";
String memberId = "1";
String familyId = "1";

// when
when(familyRepository.findById(familyId)).thenReturn(Optional.of(new Family(familyId, null, null)));
Family family = familyService.updateFamilyName(familyId, memberId, newName);

// then
assertEquals(newName, family.getFamilyName());
assertEquals(memberId, family.getFamilyNameEditorId());
}

@Test
void 열_자_초과_가족_이름_수정_예외_검증() {
// given
String newName = "wrong-length-name";
String memberId = "1";
String familyId = "1";

// when
when(familyRepository.findById(familyId)).thenReturn(Optional.of(new Family(familyId, null, null)));

// then
assertThrows(InvalidParameterException.class, () -> familyService.updateFamilyName(familyId, memberId, newName));
}

@Test
void 공백만을_포함한_이름_수정_예외_검증() {
// given
String newName = " ";
String memberId = "1";
String familyId = "1";

// when
when(familyRepository.findById(familyId)).thenReturn(Optional.of(new Family(familyId, null, null)));

// then
assertThrows(InvalidParameterException.class, () -> familyService.updateFamilyName(familyId, memberId, newName));
}
}
11 changes: 11 additions & 0 deletions gateway/src/main/java/com/oing/config/SpringWebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand Down Expand Up @@ -53,4 +54,14 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
resolvers.add(familyIdArgumentResolver);
resolvers.add(loginMemberIdArgumentResolver);
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("https://bibbi.app", "https://no5ing.kr", "https://dev.no5ing.kr")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("Authorization", "Content-Type")
.allowCredentials(true)
.maxAge(3600);
}
}
Loading
Loading