From ac34a8ba3afaa505a64f0155adb390278768e730 Mon Sep 17 00:00:00 2001 From: EunChanNam Date: Mon, 27 Nov 2023 19:25:11 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=84=B1?= =?UTF-8?q?=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=EC=84=9C=EB=B2=84=20=EC=9E=AC=EB=B0=B0=ED=8F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WeShareWishHairApplication.java | 38 +++++++++++++++++++ .../review/application/LikeReviewService.java | 7 +--- .../review/domain/likereview/LikeReview.java | 3 +- .../user/application/UserService.java | 16 ++++---- src/main/resources/application-prod.yml | 2 +- 5 files changed, 49 insertions(+), 17 deletions(-) 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/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 # 네이버 클라우드 오브젝트 스토리지