diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/WeShareWishHairApplication.java b/src/main/java/com/inq/wishhair/wesharewishhair/WeShareWishHairApplication.java index a4353b4..0a62189 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/WeShareWishHairApplication.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/WeShareWishHairApplication.java @@ -1,7 +1,22 @@ package com.inq.wishhair.wesharewishhair; +import java.util.ArrayList; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Profile; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Component; + +import com.inq.wishhair.wesharewishhair.hairstyle.domain.HairStyle; +import com.inq.wishhair.wesharewishhair.hairstyle.domain.HairStyleRepository; +import com.inq.wishhair.wesharewishhair.user.domain.UserRepository; +import com.inq.wishhair.wesharewishhair.user.domain.entity.Password; +import com.inq.wishhair.wesharewishhair.user.domain.entity.Sex; +import com.inq.wishhair.wesharewishhair.user.domain.entity.User; + +import jakarta.annotation.PostConstruct; +import lombok.RequiredArgsConstructor; @SpringBootApplication public class WeShareWishHairApplication { @@ -10,4 +25,27 @@ public static void main(String[] args) { SpringApplication.run(WeShareWishHairApplication.class, args); } + @Component + @Profile("prod") + @RequiredArgsConstructor + static class TestData { + + private final UserRepository userRepository; + private final HairStyleRepository hairStyleRepository; + private final PasswordEncoder passwordEncoder; + + @PostConstruct + public void setUp() { + userRepository.save(User.createUser( + "namhm23@naver.com", + Password.encrypt("hello123@", passwordEncoder), + "userA", + "hello", + Sex.MAN + )); + + hairStyleRepository.save(HairStyle.createHairStyle("hairStyleA", Sex.MAN, new ArrayList<>(), new ArrayList<>())); + } + } + } diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java b/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java index 17427dd..681eee5 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/global/config/WebConfig.java @@ -29,7 +29,7 @@ public class WebConfig implements WebMvcConfigurer { @Override public void addCorsMappings(final CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("http://localhost:8080", "http://13.59.136.85:8080") + .allowedOrigins("http://localhost:8080", "http://3.21.14.25:8080", "http://localhost:80") .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") .allowedHeaders("*"); } diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java b/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java index acb759e..9f59b60 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewService.java @@ -10,7 +10,6 @@ import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReview; import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReviewRepository; -import jakarta.persistence.EntityExistsException; import lombok.RequiredArgsConstructor; @Service @@ -29,11 +28,7 @@ private Long updateLikeCountFromRedis(Long reviewId) { @Transactional public boolean executeLike(Long reviewId, Long userId) { - try { - likeReviewRepository.save(LikeReview.addLike(userId, reviewId)); - } catch (EntityExistsException e) { - return false; - } + likeReviewRepository.save(LikeReview.addLike(userId, reviewId)); //락을 걸지않고 값이없으면 좋아요 개수를 로드해서 반영 기능 추가 redisUtils.getData(reviewId) diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/review/domain/likereview/LikeReview.java b/src/main/java/com/inq/wishhair/wesharewishhair/review/domain/likereview/LikeReview.java index d65f701..9dd69b1 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/review/domain/likereview/LikeReview.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/review/domain/likereview/LikeReview.java @@ -5,7 +5,6 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; -import jakarta.persistence.UniqueConstraint; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -13,7 +12,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"userId", "reviewId"})) +@Table(name = "like_review") public class LikeReview { @Id diff --git a/src/main/java/com/inq/wishhair/wesharewishhair/user/application/UserService.java b/src/main/java/com/inq/wishhair/wesharewishhair/user/application/UserService.java index 2d008ed..afaef6d 100644 --- a/src/main/java/com/inq/wishhair/wesharewishhair/user/application/UserService.java +++ b/src/main/java/com/inq/wishhair/wesharewishhair/user/application/UserService.java @@ -10,20 +10,20 @@ import com.inq.wishhair.wesharewishhair.global.exception.ErrorCode; import com.inq.wishhair.wesharewishhair.global.exception.WishHairException; import com.inq.wishhair.wesharewishhair.hairstyle.domain.hashtag.Tag; +import com.inq.wishhair.wesharewishhair.point.domain.PointLogRepository; import com.inq.wishhair.wesharewishhair.review.application.ReviewService; -import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordRefreshRequest; -import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordUpdateRequest; -import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.SignUpRequest; -import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.UserUpdateRequest; +import com.inq.wishhair.wesharewishhair.user.application.utils.UserValidator; +import com.inq.wishhair.wesharewishhair.user.domain.AiConnector; +import com.inq.wishhair.wesharewishhair.user.domain.UserRepository; import com.inq.wishhair.wesharewishhair.user.domain.entity.Email; import com.inq.wishhair.wesharewishhair.user.domain.entity.FaceShape; import com.inq.wishhair.wesharewishhair.user.domain.entity.Nickname; import com.inq.wishhair.wesharewishhair.user.domain.entity.Password; import com.inq.wishhair.wesharewishhair.user.domain.entity.User; -import com.inq.wishhair.wesharewishhair.user.domain.UserRepository; -import com.inq.wishhair.wesharewishhair.point.domain.PointLogRepository; -import com.inq.wishhair.wesharewishhair.user.application.utils.UserValidator; -import com.inq.wishhair.wesharewishhair.user.domain.AiConnector; +import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordRefreshRequest; +import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.PasswordUpdateRequest; +import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.SignUpRequest; +import com.inq.wishhair.wesharewishhair.user.presentation.dto.request.UserUpdateRequest; import lombok.RequiredArgsConstructor; diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index aea798b..a44ee49 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -71,7 +71,7 @@ decorator: #JWT key jwt: secret-key: abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc - access-token-validity: 1800000 + access-token-validity: 180000000 refresh-token-validity: 259200000 # 네이버 클라우드 오브젝트 스토리지 diff --git a/src/test/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewServiceTest.java b/src/test/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewServiceTest.java index ecb7ee4..5b9f663 100644 --- a/src/test/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewServiceTest.java +++ b/src/test/java/com/inq/wishhair/wesharewishhair/review/application/LikeReviewServiceTest.java @@ -15,11 +15,8 @@ import com.inq.wishhair.wesharewishhair.common.support.MockTestSupport; import com.inq.wishhair.wesharewishhair.global.utils.RedisUtils; import com.inq.wishhair.wesharewishhair.review.application.dto.response.LikeReviewResponse; -import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReview; import com.inq.wishhair.wesharewishhair.review.domain.likereview.LikeReviewRepository; -import jakarta.persistence.EntityExistsException; - @DisplayName("[LikeReviewService 테스트]") class LikeReviewServiceTest extends MockTestSupport { @@ -71,19 +68,6 @@ void success2() { verify(redisUtils, timeout(1)).setData(1L, 10L); } } - - @Test - @DisplayName("[이미 좋아요한 상태여서 false 를 반환한다]") - void returnFalse() { - given(likeReviewRepository.save(any(LikeReview.class))) - .willThrow(new EntityExistsException()); - - //when - boolean actual = likeReviewService.executeLike(1L, 1L); - - //then - assertThat(actual).isFalse(); - } } @Nested