Skip to content

Commit

Permalink
Merge pull request #230 from TeamDilly/develop
Browse files Browse the repository at this point in the history
* fix: CorsConfig 추가

* fix: CORS origin 변경 (#224)

* fix: 박스 만들기, 박스 열기 API 응답값에 로띠 추가 (#226)

* fix: 웹용 선물박스 열기 API 7일 제한 제거 (#227)

* fix: 웹용 선물박스 열기 API id와 uuid 둘 다 사용 가능하도록 변경 (#228)

* refactor: UUID인지 검증하는 코드 validator로 분리

* fix: 웹용 선물박스 열기 API id와 uuid 둘 다 사용 가능하도록 변경

* chore: docker-compose version 제거

* style: 유틸 클래스에 private 생성자 추가

* fix: CORS origin 추가 (#229)

* fix: CORS origin 추가

* style: 누락된 세미콜론 추가

* fix: allowedOrigins 코드 수정 (#231)
  • Loading branch information
leeeeeyeon authored Jun 17, 2024
2 parents b002894 + 0bedc23 commit a622d1b
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 29 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
mysql-docker:
image: mysql:latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public record BoxImgResponse(
@Schema(example = "www.example.com")
String boxSet,
@Schema(example = "www.example.com")
String boxTop
String boxTop,
@Schema(example = "www.example.com")
String boxLottie
) {

public static BoxImgResponse from(Box box) {
Expand All @@ -28,6 +30,7 @@ public static BoxImgResponse from(Box box) {
.boxSmall(box.getSmallImgUrl())
.boxSet(box.getSetImgUrl())
.boxTop(box.getTopImgUrl())
.boxLottie(box.getLottieMakeUrl())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ public DataResponseDto<GiftBoxResponse> openGiftBox(
@ApiErrorCodeExamples({
ErrorCode.GIFTBOX_NOT_FOUND,
ErrorCode.GIFTBOX_ALREADY_DELETED,
ErrorCode.GIFTBOX_URL_EXPIRED
ErrorCode.GIFTBOX_URL_EXPIRED,
ErrorCode.INVALID_INPUT_VALUE
})
@GetMapping("/web/{giftBoxUuid}")
@GetMapping("/web/{giftBoxId}")
public DataResponseDto<GiftBoxResponse> openGiftBoxForWeb(
@PathVariable("giftBoxUuid") String giftBoxUuid
@PathVariable("giftBoxId") String giftBoxId
) {
return DataResponseDto.from(giftBoxService.openGiftBoxForWeb(giftBoxUuid));
return DataResponseDto.from(giftBoxService.openGiftBoxForWeb(giftBoxId));
}

@Operation(summary = "주고받은 선물박스 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.dilly.gift.dto.response.StickerResponse;
import com.dilly.gift.dto.response.WaitingGiftBoxResponse;
import com.dilly.global.util.SecurityUtil;
import com.dilly.global.util.validator.UuidValidator;
import com.dilly.member.adaptor.MemberReader;
import com.dilly.member.domain.Member;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -176,15 +177,25 @@ public GiftBoxResponse openGiftBox(Long giftBoxId) {
return toGiftBoxResponse(giftBox);
}

public GiftBoxResponse openGiftBoxForWeb(String giftBoxUuid) {
GiftBox giftBox = giftBoxReader.findByUuid(giftBoxUuid);

LocalDateTime sentDate = giftBox.getUpdatedAt();
LocalDateTime now = LocalDateTime.now();
public GiftBoxResponse openGiftBoxForWeb(String giftBoxId) {
GiftBox giftBox;

if (now.minusDays(7).isAfter(sentDate)) {
throw new UnsupportedException(ErrorCode.GIFTBOX_URL_EXPIRED);
if (UuidValidator.isValidUUID(giftBoxId)) {
giftBox = giftBoxReader.findByUuid(giftBoxId);
} else {
try {
giftBox = giftBoxReader.findById(Long.parseLong(giftBoxId));
} catch (NumberFormatException e) {
throw new UnsupportedException(ErrorCode.INVALID_INPUT_VALUE);
}
}

// LocalDateTime sentDate = giftBox.getUpdatedAt();
// LocalDateTime now = LocalDateTime.now();

// if (now.minusDays(7).isAfter(sentDate)) {
// throw new UnsupportedException(ErrorCode.GIFTBOX_URL_EXPIRED);
// }

return toGiftBoxResponse(giftBox);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ public record BoxResponse(
Long id,
@Schema(example = "www.example.com")
String boxNormal,

@Schema(example = "www.example.com")
String boxTop
String boxTop,
@Schema(example = "www.example.com")
String boxLottie
) {

public static BoxResponse from(Box box) {
return BoxResponse.builder()
.id(box.getId())
.boxNormal(box.getNormalImgUrl())
.boxTop(box.getTopImgUrl())
.boxLottie(box.getLottieArrivedUrl())
.build();
}
}
16 changes: 16 additions & 0 deletions packy-api/src/main/java/com/dilly/global/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dilly.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("GET")
.allowedOrigins("https://packyforyou.com", "https://dev.packyforyou.com");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.dilly.exception.AuthorizationFailedException;
import com.dilly.exception.ErrorCode;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SecurityUtil {

public static Long getMemberId() {
Expand Down
6 changes: 3 additions & 3 deletions packy-api/src/main/java/com/dilly/global/util/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TextUtil {

private TextUtil() {
}

private static final Pattern graphemePattern = Pattern.compile("\\X");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dilly.global.util.validator;

import java.util.regex.Pattern;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UuidValidator {

public static boolean isValidUUID(String value) {
final Pattern uuidPattern =
Pattern.compile(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
return value != null && uuidPattern.matcher(value).matches();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import com.dilly.global.IntegrationTestSupport;
import com.dilly.global.WithCustomMockUser;
import com.dilly.global.util.SecurityUtil;
import com.dilly.global.util.validator.UuidValidator;
import com.dilly.member.domain.Member;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -97,7 +97,7 @@ Collection<DynamicTest> createGiftBox() {
assertThat(giftBox.getGiftBoxType()).isEqualTo(GiftBoxType.PRIVATE);

assertThat(giftBoxIdResponse.id()).isEqualTo(giftBox.getId());
assertTrue(isValidUUID(giftBoxIdResponse.uuid()));
assertTrue(UuidValidator.isValidUUID(giftBoxIdResponse.uuid()));
assertThat(giftBoxIdResponse.kakaoMessageImgUrl()).isEqualTo(
giftBox.getBox().getKakaoMessageImgUrl());
}),
Expand Down Expand Up @@ -132,7 +132,7 @@ Collection<DynamicTest> createGiftBox() {
assertThat(giftBox.getGiftBoxType()).isEqualTo(GiftBoxType.PRIVATE);

assertThat(giftBoxIdResponse.id()).isEqualTo(giftBox.getId());
assertTrue(isValidUUID(giftBoxIdResponse.uuid()));
assertTrue(UuidValidator.isValidUUID(giftBoxIdResponse.uuid()));
assertThat(giftBoxIdResponse.kakaoMessageImgUrl()).isEqualTo(
giftBox.getBox().getKakaoMessageImgUrl());
})
Expand Down Expand Up @@ -331,11 +331,4 @@ void getWaitingGiftBoxes() {
assertThat(result.get(5).id()).isEqualTo(lastGiftBoxId - 5);
}
}

private boolean isValidUUID(String value) {
final Pattern uuidPattern =
Pattern.compile(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
return value != null && uuidPattern.matcher(value).matches();
}
}
4 changes: 4 additions & 0 deletions packy-domain/src/main/java/com/dilly/gift/domain/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ public class Box {
private String topImgUrl;

private String kakaoMessageImgUrl;

private String lottieMakeUrl;

private String lottieArrivedUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- 컬럼 추가
ALTER TABLE box ADD COLUMN lottie_make_url VARCHAR(255) NOT NULL;
ALTER TABLE box ADD COLUMN lottie_arrived_url VARCHAR(255) NOT NULL;

-- 데이터 삽입
UPDATE box SET lottie_make_url = CONCAT('https://packy-bucket.s3.ap-northeast-2.amazonaws.com/admin/design/Box_motion/make/Box_motion_make_', id, '.json');
UPDATE box SET lottie_arrived_url = CONCAT('https://packy-bucket.s3.ap-northeast-2.amazonaws.com/admin/design/Box_motion/arr/Box_motion_arr_', id, '.json');
2 changes: 1 addition & 1 deletion packy-submodule

0 comments on commit a622d1b

Please sign in to comment.