From ba1115ef66b732ec2c663a31e62498ef3222f832 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Fri, 10 Feb 2023 04:42:54 +0900 Subject: [PATCH 01/55] =?UTF-8?q?test:=20=EB=94=94=EC=A0=80=ED=8A=B8->?= =?UTF-8?q?=ED=94=BC=EB=93=9C->=ED=83=9C=EA=B7=B8,=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80,=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codepatissier/keki/common/BeanUtils.java | 19 +++++++++++++++++++ .../entityListener/DessertEntityListener.java | 16 ++++++++++++++++ .../entityListener/PostEntityListener.java | 16 ++++++++++++++++ .../dessert/controller/DessertController.java | 2 +- .../keki/dessert/entity/Dessert.java | 4 ++++ .../keki/dessert/service/DessertService.java | 7 ++----- .../keki/post/controller/PostController.java | 2 +- .../codepatissier/keki/post/entity/Post.java | 4 ++++ .../keki/post/entity/PostImg.java | 2 ++ .../keki/post/entity/PostLike.java | 2 ++ .../keki/post/entity/PostTag.java | 2 ++ .../post/repository/PostLikeRepository.java | 2 ++ .../keki/post/repository/PostRepository.java | 2 ++ .../keki/post/service/PostService.java | 7 ++++--- 14 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/common/BeanUtils.java create mode 100644 src/main/java/com/codepatissier/keki/common/entityListener/DessertEntityListener.java create mode 100644 src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java diff --git a/src/main/java/com/codepatissier/keki/common/BeanUtils.java b/src/main/java/com/codepatissier/keki/common/BeanUtils.java new file mode 100644 index 0000000..25662f4 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/BeanUtils.java @@ -0,0 +1,19 @@ +package com.codepatissier.keki.common; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class BeanUtils implements ApplicationContextAware { + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext act) throws BeansException { + applicationContext = act; + } + public static T getBean(Class tClass){ + return applicationContext.getBean(tClass); + } +} diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/DessertEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/DessertEntityListener.java new file mode 100644 index 0000000..e301e52 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/entityListener/DessertEntityListener.java @@ -0,0 +1,16 @@ +package com.codepatissier.keki.common.entityListener; + +import com.codepatissier.keki.common.BeanUtils; +import com.codepatissier.keki.dessert.entity.Dessert; +import com.codepatissier.keki.post.repository.PostRepository; + +import javax.persistence.PreRemove; + +public class DessertEntityListener { + + @PreRemove + public void onUpdate(Dessert dessert){ + PostRepository postRepository = BeanUtils.getBean(PostRepository.class); + postRepository.deleteByDessert(dessert); + } +} diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java new file mode 100644 index 0000000..8060201 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java @@ -0,0 +1,16 @@ +package com.codepatissier.keki.common.entityListener; + +import com.codepatissier.keki.common.BeanUtils; +import com.codepatissier.keki.post.entity.Post; +import com.codepatissier.keki.post.repository.PostLikeRepository; + +import javax.persistence.PreRemove; + +public class PostEntityListener { + + @PreRemove + public void onUpdate(Post post){ + PostLikeRepository postLikeRepository = BeanUtils.getBean(PostLikeRepository.class); + postLikeRepository.deleteByPost(post); + } +} diff --git a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java index e0cc190..c7722ea 100644 --- a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java +++ b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java @@ -82,7 +82,7 @@ public BaseResponse addDessert(@Valid @RequestBody PostDessertReq postDe * [PATCH] /desserts/:dessertIdx */ @ResponseBody - @PatchMapping("/{dessertIdx}") + @DeleteMapping("/{dessertIdx}") public BaseResponse deleteDessert(@PathVariable("dessertIdx") Long dessertIdx) { try { dessertService.deleteDessert(authService.getUserIdx(), dessertIdx); diff --git a/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java b/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java index f93d31c..143c61e 100644 --- a/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java +++ b/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java @@ -1,11 +1,13 @@ package com.codepatissier.keki.dessert.entity; import com.codepatissier.keki.common.BaseEntity; +import com.codepatissier.keki.common.entityListener.DessertEntityListener; import com.codepatissier.keki.store.entity.Store; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import javax.validation.constraints.NotBlank; @@ -14,6 +16,8 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE dessert SET status = 'inactive' WHERE dessert_idx = ?") +@EntityListeners(DessertEntityListener.class) public class Dessert extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java index 0a8071a..dda032e 100644 --- a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java +++ b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java @@ -134,11 +134,8 @@ public void addDessert(Long userIdx, PostDessertReq postDessertReq) throws BaseE public void deleteDessert(Long userIdx, Long dessertIdx) throws BaseException { try { checkStore(userIdx); - Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); - dessert.setStatus(INACTIVE_STATUS); - dessertRepository.save(dessert); - } catch (BaseException e) { - throw e; + dessertRepository.deleteById(dessertIdx); +// dessertRepository.save(dessert); } catch (Exception e) { throw new BaseException(DATABASE_ERROR); } diff --git a/src/main/java/com/codepatissier/keki/post/controller/PostController.java b/src/main/java/com/codepatissier/keki/post/controller/PostController.java index 00ff202..ebc0fc8 100644 --- a/src/main/java/com/codepatissier/keki/post/controller/PostController.java +++ b/src/main/java/com/codepatissier/keki/post/controller/PostController.java @@ -189,7 +189,7 @@ public BaseResponse modifyPost(@RequestBody PatchPostReq patchPostReq, @ * [PATCH] /posts/:postIdx */ @ResponseBody - @PatchMapping("/{postIdx}") + @DeleteMapping("/{postIdx}") public BaseResponse deletePost(@PathVariable Long postIdx){ try{ this.postService.deletePost(authService.getUserIdx(), postIdx); diff --git a/src/main/java/com/codepatissier/keki/post/entity/Post.java b/src/main/java/com/codepatissier/keki/post/entity/Post.java index e781e45..3d3d872 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/Post.java +++ b/src/main/java/com/codepatissier/keki/post/entity/Post.java @@ -1,12 +1,14 @@ package com.codepatissier.keki.post.entity; import com.codepatissier.keki.common.BaseEntity; +import com.codepatissier.keki.common.entityListener.PostEntityListener; import com.codepatissier.keki.dessert.entity.Dessert; import com.codepatissier.keki.store.entity.Store; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import java.util.ArrayList; @@ -16,6 +18,8 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE post SET status = 'inactive' WHERE post_idx = ?") +@EntityListeners(PostEntityListener.class) public class Post extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostImg.java b/src/main/java/com/codepatissier/keki/post/entity/PostImg.java index 9e8e690..ba0e786 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostImg.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostImg.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -12,6 +13,7 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE post_img SET status = 'inactive' WHERE post_img_idx = ?") public class PostImg extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostLike.java b/src/main/java/com/codepatissier/keki/post/entity/PostLike.java index b2dba92..620d41c 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostLike.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostLike.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -13,6 +14,7 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE post_like SET status = 'inactive' WHERE post_like_idx = ?") public class PostLike extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostTag.java b/src/main/java/com/codepatissier/keki/post/entity/PostTag.java index d37ced1..3b18918 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostTag.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostTag.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -13,6 +14,7 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE post_tag SET status = 'inactive' WHERE post_tag_idx = ?") public class PostTag extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java b/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java index 8a4dbc3..768b3e5 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java @@ -17,4 +17,6 @@ public interface PostLikeRepository extends JpaRepository { List findByUserAndStatusAndLastModifiedDateLessThanOrderByLastModifiedDateDesc(User user, String status, LocalDateTime lastModifiedDate, Pageable page); boolean existsByPostAndUserAndStatus(Post post, User user, String status); boolean existsByUserAndStatusAndLastModifiedDateLessThan(User user, String status, LocalDateTime lastDate); + + void deleteByPost(Post post); } diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java b/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java index f1a6d06..d137d9c 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java @@ -22,4 +22,6 @@ public interface PostRepository extends JpaRepository, PostCustom { boolean existsByStoreAndStatusAndPostIdxLessThan(Store store, String status, Long postIdx); boolean existsByDessertDessertNameContainingAndStatusAndPostIdxLessThan(String word, String status, Long postIdx); List findTop5ByDessertAndStatusOrderByPostIdxDesc(Dessert dessert, String activeStatus); + + void deleteByDessert(Dessert dessert); } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/post/service/PostService.java b/src/main/java/com/codepatissier/keki/post/service/PostService.java index ef1d2f6..238e3ea 100644 --- a/src/main/java/com/codepatissier/keki/post/service/PostService.java +++ b/src/main/java/com/codepatissier/keki/post/service/PostService.java @@ -151,9 +151,10 @@ public void deletePost(Long userIdx, Long postIdx) throws BaseException { if(!user.getUserIdx().equals(post.getStore().getUser().getUserIdx())) throw new BaseException(NO_MATCH_POST_STORE); - post.setStatus(INACTIVE_STATUS); - - this.postRepository.save(post); + this.postRepository.deleteById(postIdx); +// post.setStatus(INACTIVE_STATUS); +// +// this.postRepository.save(post); } catch (BaseException e) { throw e; } catch (Exception e){ From 1c054f3eee23bc4ffbb77dc99d45998095a729a5 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Sun, 12 Feb 2023 13:04:43 +0900 Subject: [PATCH 02/55] =?UTF-8?q?test:=20=EB=94=94=EC=A0=80=ED=8A=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=ED=94=BC=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C,=20=ED=83=9C=EA=B7=B8,=20=EC=9D=B4=EB=AF=B8=EC=A7=80,?= =?UTF-8?q?=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codepatissier/keki/dessert/entity/Dessert.java | 2 +- src/main/java/com/codepatissier/keki/post/entity/Post.java | 2 +- src/main/java/com/codepatissier/keki/post/entity/PostImg.java | 2 +- src/main/java/com/codepatissier/keki/post/entity/PostLike.java | 2 +- src/main/java/com/codepatissier/keki/post/entity/PostTag.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java b/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java index 143c61e..c56f02e 100644 --- a/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java +++ b/src/main/java/com/codepatissier/keki/dessert/entity/Dessert.java @@ -16,7 +16,7 @@ @Entity @NoArgsConstructor @DynamicInsert -@SQLDelete(sql = "UPDATE dessert SET status = 'inactive' WHERE dessert_idx = ?") +@SQLDelete(sql = "UPDATE dessert SET status = 'inactive', last_modified_date = current_timestamp WHERE dessert_idx = ?") @EntityListeners(DessertEntityListener.class) public class Dessert extends BaseEntity { @Id diff --git a/src/main/java/com/codepatissier/keki/post/entity/Post.java b/src/main/java/com/codepatissier/keki/post/entity/Post.java index 3d3d872..7ea8a41 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/Post.java +++ b/src/main/java/com/codepatissier/keki/post/entity/Post.java @@ -18,7 +18,7 @@ @Entity @NoArgsConstructor @DynamicInsert -@SQLDelete(sql = "UPDATE post SET status = 'inactive' WHERE post_idx = ?") +@SQLDelete(sql = "UPDATE post SET status = 'inactive', last_modified_date = current_timestamp WHERE post_idx = ?") @EntityListeners(PostEntityListener.class) public class Post extends BaseEntity { @Id diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostImg.java b/src/main/java/com/codepatissier/keki/post/entity/PostImg.java index ba0e786..c75f151 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostImg.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostImg.java @@ -13,7 +13,7 @@ @Entity @NoArgsConstructor @DynamicInsert -@SQLDelete(sql = "UPDATE post_img SET status = 'inactive' WHERE post_img_idx = ?") +@SQLDelete(sql = "UPDATE post_img SET status = 'inactive', last_modified_date = current_timestamp WHERE post_img_idx = ?") public class PostImg extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostLike.java b/src/main/java/com/codepatissier/keki/post/entity/PostLike.java index 620d41c..3f57251 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostLike.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostLike.java @@ -14,7 +14,7 @@ @Entity @NoArgsConstructor @DynamicInsert -@SQLDelete(sql = "UPDATE post_like SET status = 'inactive' WHERE post_like_idx = ?") +@SQLDelete(sql = "UPDATE post_like SET status = 'inactive', last_modified_date = current_timestamp WHERE post_like_idx = ?") public class PostLike extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostTag.java b/src/main/java/com/codepatissier/keki/post/entity/PostTag.java index 3b18918..75b65ae 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostTag.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostTag.java @@ -14,7 +14,7 @@ @Entity @NoArgsConstructor @DynamicInsert -@SQLDelete(sql = "UPDATE post_tag SET status = 'inactive' WHERE post_tag_idx = ?") +@SQLDelete(sql = "UPDATE post_tag SET status = 'inactive', last_modified_date = current_timestamp WHERE post_tag_idx = ?") public class PostTag extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 4b5cb01f53718691321b3d72be76d44118a96f8c Mon Sep 17 00:00:00 2001 From: joonghyun Date: Sun, 12 Feb 2023 16:45:07 +0900 Subject: [PATCH 03/55] =?UTF-8?q?#7=20refactor:=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/common/BaseResponseStatus.java | 25 ++++++++-------- .../dessert/controller/DessertController.java | 2 +- .../keki/dessert/service/DessertService.java | 30 ++++++++++--------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java index 0dd6a72..72ddf95 100644 --- a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java +++ b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java @@ -21,7 +21,13 @@ public enum BaseResponseStatus { ALREADY_WITHDRAW_USER(false, 2003, "이미 삭제된 회원입니다."), // stores(2100~2199) - + NULL_ADDRESS(false, 2100, "주소를 입력해주세요."), + NULL_ORDER_URL(false, 2101, "주문 링크를 입력해주세요."), + NULL_BUSINESS_NAME(false, 2102, "대표자명을 입력해주세요."), + NULL_BRAND_NAME(false, 2103, "상호명을 입력해주세요."), + NULL_BUSINESS_ADDRESS(false, 2104, "사업자 주소를 입력해주세요."), + NULL_BUSINESS_NUMBER(false, 2105, "사업자 번호를 입력해주세요."), + NULL_NICKNAME(false, 2106, "가게 이름을 입력해주세요."), // posts(2200~2299) INVALID_POSTS_SIZE(false, 2200, "리스트 사이즈는 1 이상이어야 합니다."), @@ -36,7 +42,11 @@ public enum BaseResponseStatus { INVALID_SORT_TYPE_CURSOR(false, 2208, "정렬 조건과 cursor 조건을 맞춰서 입력해주세요."), // desserts(2300~2399) - + NULL_DESSERT_IMG(false, 3301, "디저트 이미지를 추가해주세요."), + NULL_DESSERT_NAME(false, 3302, "디저트 이름을 입력해주세요."), + INVALID_DESERT_PRICE(false, 3303, "디저트 가격은 0원 이상이어야 합니다."), + NULL_DESSERT_DESCRIPTION(false, 3304, "디저트 설명을 입력해주세요."), + DELETED_DESSERT(false, 3305, "이미 삭제된 디저트입니다."), // calendars(2400~2499) NULL_TITLE(false, 2400, "캘린더 제목을 입력해주세요."), @@ -60,13 +70,6 @@ public enum BaseResponseStatus { // stores(3100~3199) INVALID_STORE_IDX(false, 3100, "존재하지 않는 스토어입니다."), - NULL_ADDRESS(false, 3101, "주소를 입력해주세요."), - NULL_ORDER_URL(false, 3102, "주문 링크를 입력해주세요."), - NULL_BUSINESS_NAME(false, 3103, "대표자명을 입력해주세요."), - NULL_BRAND_NAME(false, 3104, "상호명을 입력해주세요."), - NULL_BUSINESS_ADDRESS(false, 3105, "사업자 주소를 입력해주세요."), - NULL_BUSINESS_NUMBER(false, 3106, "사업자 번호를 입력해주세요."), - NULL_NICKNAME(false, 3107, "가게 이름을 입력해주세요."), // posts(3200~3299) INVALID_POST_IDX(false, 3200, "존재하지 않는 피드입니다."), @@ -74,10 +77,6 @@ public enum BaseResponseStatus { // desserts(3300~3399) INVALID_DESSERT_IDX(false, 3300, "존재하지 않는 디저트입니다."), - NULL_DESSERT_IMG(false, 3301, "디저트 이미지를 추가해주세요."), - NULL_DESSERT_NAME(false, 3302, "디저트 이름을 입력해주세요."), - INVALID_DESERT_PRICE(false, 3303, "디저트 가격은 0원 이상이어야 합니다."), - NULL_DESSERT_DESCRIPTION(false, 3304, "디저트 설명을 입력해주세요."), // calendars(3400~3499) INVALID_CALENDAR_TAG(false, 3400, "캘린더 TAG를 찾을 수 없습니다."), diff --git a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java index c7722ea..1250ff1 100644 --- a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java +++ b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java @@ -79,7 +79,7 @@ public BaseResponse addDessert(@Valid @RequestBody PostDessertReq postDe /** * [판매자] 상품 삭제 - * [PATCH] /desserts/:dessertIdx + * [DELETE] /desserts/:dessertIdx */ @ResponseBody @DeleteMapping("/{dessertIdx}") diff --git a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java index dda032e..0766862 100644 --- a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java +++ b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java @@ -1,7 +1,6 @@ package com.codepatissier.keki.dessert.service; import com.codepatissier.keki.common.BaseException; -import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.common.Role; import com.codepatissier.keki.dessert.dto.*; import com.codepatissier.keki.dessert.entity.Dessert; @@ -20,6 +19,7 @@ import java.util.stream.Collectors; import static com.codepatissier.keki.common.BaseResponseStatus.*; +import static com.codepatissier.keki.common.Constant.ACTIVE_STATUS; import static com.codepatissier.keki.common.Constant.INACTIVE_STATUS; @Service @@ -35,7 +35,7 @@ public class DessertService { */ public GetStoreDessertsRes getDessertList(Long storeIdx, Long cursorIdx, Integer size) throws BaseException { try { - Store store = storeRepository.findByStoreIdxAndStatus(storeIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_STORE_IDX)); + Store store = storeRepository.findByStoreIdxAndStatus(storeIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_STORE_IDX)); List dessertList = cursorIdx == null ? getDessertList(store, size) : @@ -52,15 +52,15 @@ public GetStoreDessertsRes getDessertList(Long storeIdx, Long cursorIdx, Integer } private List getDessertList(Store store, Integer size) { - return dessertRepository.findByStoreAndStatusOrderByDessertIdxDesc(store, Constant.ACTIVE_STATUS, PageRequest.of(0, size)).stream() + return dessertRepository.findByStoreAndStatusOrderByDessertIdxDesc(store, ACTIVE_STATUS, PageRequest.of(0, size)).stream() .map(dessert -> new GetStoreDessertsRes.Dessert(dessert.getDessertIdx(), dessert.getDessertImg(), dessert.getDessertName())).collect(Collectors.toList()); } private List getDessertListWithCursor(Store store, Long cursorIdx, Integer size) throws BaseException { - dessertRepository.findByDessertIdxAndStatus(cursorIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); + dessertRepository.findByDessertIdxAndStatus(cursorIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); - return dessertRepository.findByStoreAndStatusAndDessertIdxLessThanOrderByDessertIdxDesc(store, Constant.ACTIVE_STATUS, cursorIdx, PageRequest.of(0, size)).stream() + return dessertRepository.findByStoreAndStatusAndDessertIdxLessThanOrderByDessertIdxDesc(store, ACTIVE_STATUS, cursorIdx, PageRequest.of(0, size)).stream() .map(dessert -> new GetStoreDessertsRes.Dessert(dessert.getDessertIdx(), dessert.getDessertImg(), dessert.getDessertName())).collect(Collectors.toList()); } @@ -70,7 +70,7 @@ private static Long getLastIdxOfList(List dessertLi } private Boolean hasNext(Long lastIdx) { - return lastIdx != null && this.dessertRepository.existsByStatusAndDessertIdxLessThan(Constant.ACTIVE_STATUS, lastIdx); + return lastIdx != null && this.dessertRepository.existsByStatusAndDessertIdxLessThan(ACTIVE_STATUS, lastIdx); } /** @@ -78,7 +78,7 @@ private Boolean hasNext(Long lastIdx) { */ public GetDessertRes getDessert(Long dessertIdx) throws BaseException { try { - Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); + Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); List imgList = getPostImgList(dessert); @@ -93,7 +93,7 @@ public GetDessertRes getDessert(Long dessertIdx) throws BaseException { // 특정 dessert가 들어간 post 5개를 가져와 postIdx와 대표 postImg를 반환 private List getPostImgList(Dessert dessert) { - return postRepository.findTop5ByDessertAndStatusOrderByPostIdxDesc(dessert, Constant.ACTIVE_STATUS).stream() + return postRepository.findTop5ByDessertAndStatusOrderByPostIdxDesc(dessert, ACTIVE_STATUS).stream() .map(posts -> new GetDessertRes.Image(posts.getPostIdx(), representPostImgUrl(posts.getImages()))).collect(Collectors.toList()); } @@ -108,10 +108,10 @@ private String representPostImgUrl(List postImages){ */ public void addDessert(Long userIdx, PostDessertReq postDessertReq) throws BaseException { try { - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); if (!Role.getRoleByName(user.getRole()).equals(Role.STORE)) throw new BaseException(NO_STORE_ROLE); - Store store = storeRepository.findByUserAndStatus(user, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_STORE_IDX)); + Store store = storeRepository.findByUserAndStatus(user, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_STORE_IDX)); Dessert dessert = Dessert.builder() .store(store) @@ -134,8 +134,10 @@ public void addDessert(Long userIdx, PostDessertReq postDessertReq) throws BaseE public void deleteDessert(Long userIdx, Long dessertIdx) throws BaseException { try { checkStore(userIdx); + dessertRepository.findByDessertIdxAndStatus(dessertIdx, INACTIVE_STATUS).orElseThrow(() -> new BaseException(DELETED_DESSERT)); dessertRepository.deleteById(dessertIdx); -// dessertRepository.save(dessert); + } catch (BaseException e) { + throw e; } catch (Exception e) { throw new BaseException(DATABASE_ERROR); } @@ -148,7 +150,7 @@ public void deleteDessert(Long userIdx, Long dessertIdx) throws BaseException { public void modifyDessert(PatchDessertReq patchDessertReq, Long dessertIdx, Long userIdx) throws BaseException { try { checkStore(userIdx); - Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); + Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); if (patchDessertReq.getDessertImg() != null) { if (!patchDessertReq.getDessertImg().equals("") && !patchDessertReq.getDessertImg().equals(" ")) @@ -188,7 +190,7 @@ public void modifyDessert(PatchDessertReq patchDessertReq, Long dessertIdx, Long public GetStoreDessertRes getStoreDessert(Long userIdx, Long dessertIdx) throws BaseException { try { checkStore(userIdx); - Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); + Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); return new GetStoreDessertRes(dessert.getDessertImg(), dessert.getDessertName(), dessert.getDessertPrice(), dessert.getDessertDescription()); } catch (BaseException e) { @@ -200,7 +202,7 @@ public GetStoreDessertRes getStoreDessert(Long userIdx, Long dessertIdx) throws private void checkStore(Long userIdx) throws BaseException { try { - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); if (!Role.getRoleByName(user.getRole()).equals(Role.STORE)) throw new BaseException(NO_STORE_ROLE); } catch (BaseException e) { throw e; From 278879cdaa760d612539cfcd7bbc31c6b29a5092 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Sun, 12 Feb 2023 20:00:39 +0900 Subject: [PATCH 04/55] =?UTF-8?q?#135=20feature:=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/common/entityListener/PostEntityListener.java | 6 +++++- .../com/codepatissier/keki/history/entity/PostHistory.java | 6 ++++-- .../codepatissier/keki/history/entity/SearchHistory.java | 2 +- .../keki/history/repository/PostHistoryRepository.java | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java index 8060201..e1e92a7 100644 --- a/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java +++ b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java @@ -1,6 +1,7 @@ package com.codepatissier.keki.common.entityListener; import com.codepatissier.keki.common.BeanUtils; +import com.codepatissier.keki.history.repository.PostHistoryRepository; import com.codepatissier.keki.post.entity.Post; import com.codepatissier.keki.post.repository.PostLikeRepository; @@ -12,5 +13,8 @@ public class PostEntityListener { public void onUpdate(Post post){ PostLikeRepository postLikeRepository = BeanUtils.getBean(PostLikeRepository.class); postLikeRepository.deleteByPost(post); + + PostHistoryRepository postHistoryRepository = BeanUtils.getBean(PostHistoryRepository.class); + postHistoryRepository.deleteAllByPost(post); } -} +} \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java b/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java index 3b2ccfc..9092c3e 100644 --- a/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java +++ b/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -14,16 +15,17 @@ @NoArgsConstructor @DynamicInsert @Getter +@SQLDelete(sql = "UPDATE post_history SET status = 'inactive', last_modified_date = current_timestamp WHERE post_idx = ?") public class PostHistory extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long postHistoryIdx; - @OneToOne + @ManyToOne @JoinColumn(nullable = false, name = "userIdx") private User user; - @OneToOne + @ManyToOne @JoinColumn(nullable = false, name = "postIdx") private Post post; diff --git a/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java b/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java index 8ac4b93..bf304c1 100644 --- a/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java +++ b/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java @@ -19,7 +19,7 @@ public class SearchHistory extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long searchHistoryIdx; - @OneToOne + @ManyToOne @JoinColumn(nullable = false, name = "userIdx") private User user; diff --git a/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java b/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java index f1e99ef..49fac80 100644 --- a/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java +++ b/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java @@ -1,10 +1,12 @@ package com.codepatissier.keki.history.repository; import com.codepatissier.keki.history.entity.PostHistory; +import com.codepatissier.keki.post.entity.Post; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface PostHistoryRepository extends JpaRepository, PostHistoryCustom{ int countByPostPostIdxEquals(Long postIdx); -} + void deleteAllByPost(Post post); +} \ No newline at end of file From 172f37a2158db072b224904566f08341019548c1 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Tue, 14 Feb 2023 22:02:15 +0900 Subject: [PATCH 05/55] =?UTF-8?q?#135=20fix:=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=20=EC=82=AD=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/common/entityListener/PostEntityListener.java | 2 +- .../keki/history/repository/PostHistoryRepository.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java index e1e92a7..1f10606 100644 --- a/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java +++ b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java @@ -15,6 +15,6 @@ public void onUpdate(Post post){ postLikeRepository.deleteByPost(post); PostHistoryRepository postHistoryRepository = BeanUtils.getBean(PostHistoryRepository.class); - postHistoryRepository.deleteAllByPost(post); + postHistoryRepository.deleteByPost(post); } } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java b/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java index 49fac80..e4ba348 100644 --- a/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java +++ b/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java @@ -8,5 +8,5 @@ @Repository public interface PostHistoryRepository extends JpaRepository, PostHistoryCustom{ int countByPostPostIdxEquals(Long postIdx); - void deleteAllByPost(Post post); + void deleteByPost(Post post); } \ No newline at end of file From b314e96c97b2c2a61f7dd41b0cce0dc1c39a3e62 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Tue, 14 Feb 2023 22:26:38 +0900 Subject: [PATCH 06/55] =?UTF-8?q?#12=20fix:=20=ED=94=BC=EB=93=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=B5=9C=EC=8B=A0?= =?UTF-8?q?=EC=88=9C=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/post/controller/PostController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/post/controller/PostController.java b/src/main/java/com/codepatissier/keki/post/controller/PostController.java index fee78e6..ef16b23 100644 --- a/src/main/java/com/codepatissier/keki/post/controller/PostController.java +++ b/src/main/java/com/codepatissier/keki/post/controller/PostController.java @@ -51,7 +51,7 @@ public BaseResponse getPosts(@RequestParam(required = false) Long s return new BaseResponse<>(MANY_PARAMETER); if(sortType != null && storeIdx != null) return new BaseResponse<>(DO_NOT_STORE_SORT_TYPE); if(sortType == null) sortType = NEW_SORT_TYPE; - if(cursorIdx != null){ + if(cursorIdx != null && !sortType.equals(NEW_SORT_TYPE)){ if (cursorPrice == null && cursorPopularNum == null) return new BaseResponse<>(NULL_CURSOR); if ((sortType.equals(LOW_PRICE_SORT_TYPE) && cursorPrice == null) || (sortType.equals(POPULAR_SORT_TYPE) && cursorPopularNum == null)) From 2e42d611b4f14ea0e69a7e28882f1ddc0d4edcaf Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Tue, 14 Feb 2023 22:53:53 +0900 Subject: [PATCH 07/55] =?UTF-8?q?#135=20feat:=20=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EC=96=B4=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=83=81=ED=92=88?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entityListener/StoreEntityListener.java | 16 ++++++++++++++++ .../dessert/repository/DessertRepository.java | 1 + .../codepatissier/keki/store/entity/Store.java | 4 ++++ 3 files changed, 21 insertions(+) create mode 100644 src/main/java/com/codepatissier/keki/common/entityListener/StoreEntityListener.java diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/StoreEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/StoreEntityListener.java new file mode 100644 index 0000000..8dcc438 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/entityListener/StoreEntityListener.java @@ -0,0 +1,16 @@ +package com.codepatissier.keki.common.entityListener; + +import com.codepatissier.keki.common.BeanUtils; +import com.codepatissier.keki.dessert.repository.DessertRepository; +import com.codepatissier.keki.store.entity.Store; + +import javax.persistence.PreRemove; + +public class StoreEntityListener { + + @PreRemove + public void onUpdate(Store store){ + DessertRepository dessertRepository = BeanUtils.getBean(DessertRepository.class); + dessertRepository.deleteByStore(store); + } +} diff --git a/src/main/java/com/codepatissier/keki/dessert/repository/DessertRepository.java b/src/main/java/com/codepatissier/keki/dessert/repository/DessertRepository.java index 57f688b..ea69b03 100644 --- a/src/main/java/com/codepatissier/keki/dessert/repository/DessertRepository.java +++ b/src/main/java/com/codepatissier/keki/dessert/repository/DessertRepository.java @@ -17,5 +17,6 @@ public interface DessertRepository extends JpaRepository { Page findByStoreAndStatusAndDessertIdxLessThanOrderByDessertIdxDesc(Store store, String activeStatus, Long cursorIdx, Pageable page); boolean existsByStatusAndDessertIdxLessThan(String activeStatus, Long dessertIdx); Optional findByDessertIdxAndStatus(Long dessertIdx, String activeStatus); + void deleteByStore(Store store); } diff --git a/src/main/java/com/codepatissier/keki/store/entity/Store.java b/src/main/java/com/codepatissier/keki/store/entity/Store.java index 7e0ec68..9407424 100644 --- a/src/main/java/com/codepatissier/keki/store/entity/Store.java +++ b/src/main/java/com/codepatissier/keki/store/entity/Store.java @@ -1,11 +1,13 @@ package com.codepatissier.keki.store.entity; import com.codepatissier.keki.common.BaseEntity; +import com.codepatissier.keki.common.entityListener.StoreEntityListener; import com.codepatissier.keki.user.entity.User; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -13,6 +15,8 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE store SET status = 'inactive', last_modified_date = current_timestamp WHERE store_idx = ?") +@EntityListeners(StoreEntityListener.class) public class Store extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From 483e8cc136a27857637bd5e988258a6eb1acc15b Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Wed, 15 Feb 2023 01:11:08 +0900 Subject: [PATCH 08/55] =?UTF-8?q?#10=20fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20api=20=ED=95=B4=EC=8B=9C=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=82=AD=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codepatissier/keki/calendar/service/CalendarService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 1e26add..ebf9b05 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -262,8 +262,6 @@ public void modifyCalendar(Long userIdx, CalendarReq calendarReq, Long calendarI Calendar calendar = this.findCalendarByCalendarIdx(calendarIdx); if (calendar.getUser() != user) throw new BaseException(BaseResponseStatus.NO_MATCH_CALENDAR_USER); - - // TODO: 현재 수정 시 TAG의 경우에는 INACTIVE 후 새로 받은 것을 ACTIVE로 함 => DELETE로 변경? if (calendarReq.getTitle() != null){ if(calendarReq.getTitle().equals("") || calendarReq.getTitle().equals(" ")) throw new BaseException(BaseResponseStatus.NULL_CALENDAR_TITLE); @@ -278,9 +276,8 @@ public void modifyCalendar(Long userIdx, CalendarReq calendarReq, Long calendarI throw new BaseException(BaseResponseStatus.NULL_CALENDAR_CATEGORY); calendar.setCalendarCategory(CalendarCategory.getCalendarCategoryByName(calendarReq.getKindOfCalendar())); } - + this.changeCalendarTagStatus(calendar, INACTIVE_STATUS); if (calendarReq.getHashTags() != null && calendarReq.getHashTags().size() != 0) { - this.changeCalendarTagStatus(calendar, INACTIVE_STATUS); for (CalendarHashTag hashTag : calendarReq.getHashTags()) { CalendarTag calendarTag = this.calendarTagRepository.findByCalendarAndTag(calendar, this.findByTagName(hashTag)); if(calendarTag == null) saveHashTags(calendar, hashTag); From b7e1471e2f894b09bd9205c072acc56c2887d0ae Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Wed, 15 Feb 2023 02:04:30 +0900 Subject: [PATCH 09/55] =?UTF-8?q?#135=20feat:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4=EC=8B=9C=20=EC=8A=A4=ED=86=A0=EC=96=B4=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codepatissier/keki/user/service/UserService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 668bc9c..5b89d82 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -4,6 +4,7 @@ import com.codepatissier.keki.common.BaseResponseStatus; import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.common.Role; +import com.codepatissier.keki.store.repository.StoreRepository; import com.codepatissier.keki.user.dto.*; import com.codepatissier.keki.user.entity.Provider; import com.codepatissier.keki.user.entity.User; @@ -21,6 +22,7 @@ @RequiredArgsConstructor public class UserService { private final UserRepository userRepository; + private final StoreRepository storeRepository; private final AuthService authService; // 로그인 @@ -105,6 +107,7 @@ public void modifyProfile(Long userIdx, PatchProfileReq patchProfileReq) throws public void signout(Long userIdx) throws BaseException { try{ User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + storeRepository.findByUser(user).ifPresent(storeRepository::delete); user.signout(); // TODO redis 사용해 토큰 관리 } catch (BaseException e) { From c535bc8aa11640666dbc5dc6261d8dd1b73b01a8 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Wed, 15 Feb 2023 10:35:24 +0900 Subject: [PATCH 10/55] =?UTF-8?q?#10=20fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contoller/CalendarController.java | 2 +- .../keki/calendar/dto/CalendarEditRes.java | 22 +++++++++++++++++++ .../calendar/service/CalendarService.java | 21 +++++------------- 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/calendar/dto/CalendarEditRes.java diff --git a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java index 5306e03..1d325b8 100644 --- a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java +++ b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java @@ -56,7 +56,7 @@ public BaseResponse modifyCalendar(@RequestBody CalendarReq calendarReq, // 캘린더 수정 조회 @ResponseBody @GetMapping("/{calendarIdx}/edit") - public BaseResponse getEditCalendar(@PathVariable("calendarIdx") Long calendarIdx){ + public BaseResponse getEditCalendar(@PathVariable("calendarIdx") Long calendarIdx){ try{ return new BaseResponse<>(this.calendarService.getEditCalendar(this.authService.getUserIdx(), calendarIdx)); }catch (BaseException e){ diff --git a/src/main/java/com/codepatissier/keki/calendar/dto/CalendarEditRes.java b/src/main/java/com/codepatissier/keki/calendar/dto/CalendarEditRes.java new file mode 100644 index 0000000..63f6339 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/calendar/dto/CalendarEditRes.java @@ -0,0 +1,22 @@ +package com.codepatissier.keki.calendar.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter + +public class CalendarEditRes { + private String kindOfCalendar; // 캘린더 종류 + private String title; + private String date; + + private List hashTags; + private List addHashTags; +} diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index ebf9b05..2eb7316 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -293,22 +293,11 @@ public void modifyCalendar(Long userIdx, CalendarReq calendarReq, Long calendarI } // 캘린더 수정 조회 api - public CalendarRes getEditCalendar(Long userIdx, Long calendarIdx) throws BaseException{ - User user = findUserByUserIdx(userIdx); - Calendar calendar = findCalendarByCalendarIdx(calendarIdx); - List tags = this.tagRepository.findByStatus(ACTIVE_STATUS); - - if (calendar.getUser() != user) throw new BaseException(BaseResponseStatus.NO_MATCH_CALENDAR_USER); - - try { - return new CalendarRes(calendar.getCalendarCategory().getName(), - calendar.getCalendarTitle(), - calendar.getCalendarDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), - calculateDateReturnString(calculateDate(calendar)), - tags.stream().map(tag -> new CalendarHashTag(tag.getTagName())).collect(Collectors.toList())); - } catch (Exception e) { - throw new BaseException(BaseResponseStatus.DATABASE_ERROR); - } + public CalendarEditRes getEditCalendar(Long userIdx, Long calendarIdx) throws BaseException{ + CalendarRes calendar = this.getCalendar(userIdx, calendarIdx); + return new CalendarEditRes(calendar.getKindOfCalendar(), calendar.getTitle(), calendar.getDate(), + calendar.getHashTags(), this.tagRepository.findByStatus(ACTIVE_STATUS).stream() + .map(tag -> new CalendarHashTag(tag.getTagName())).collect(Collectors.toList())); } From 3498a5971d8f008a7e77a18ababb2b8fa705f0df Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Wed, 15 Feb 2023 11:45:36 +0900 Subject: [PATCH 11/55] =?UTF-8?q?#10=20fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20api=20=EC=88=98=EC=A0=95=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=8B=A4=EC=88=98=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codepatissier/keki/calendar/service/CalendarService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 2eb7316..605196e 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -294,7 +294,7 @@ public void modifyCalendar(Long userIdx, CalendarReq calendarReq, Long calendarI // 캘린더 수정 조회 api public CalendarEditRes getEditCalendar(Long userIdx, Long calendarIdx) throws BaseException{ - CalendarRes calendar = this.getCalendar(userIdx, calendarIdx); + CalendarRes calendar = this.getCalendar(calendarIdx, userIdx); return new CalendarEditRes(calendar.getKindOfCalendar(), calendar.getTitle(), calendar.getDate(), calendar.getHashTags(), this.tagRepository.findByStatus(ACTIVE_STATUS).stream() .map(tag -> new CalendarHashTag(tag.getTagName())).collect(Collectors.toList())); From a6c3f72bac9a1188b858c9e5120c8e4068730bb6 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Wed, 15 Feb 2023 22:53:59 +0900 Subject: [PATCH 12/55] =?UTF-8?q?#10=20fix:=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EA=B8=B0=EB=85=90=EC=9D=BC=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Calendar/CalendarRepositoryImpl.java | 16 +++++++++++++++- .../keki/calendar/service/CalendarService.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java index ec62a97..35352a1 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java @@ -1,5 +1,6 @@ package com.codepatissier.keki.calendar.repository.Calendar; +import com.codepatissier.keki.calendar.CalendarCategory; import com.codepatissier.keki.calendar.dto.HomePostRes; import com.codepatissier.keki.calendar.dto.QHomePostRes; import com.codepatissier.keki.calendar.entity.Calendar; @@ -10,6 +11,8 @@ import lombok.RequiredArgsConstructor; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; import java.util.List; import static com.codepatissier.keki.calendar.entity.QCalendar.calendar; @@ -25,7 +28,18 @@ public class CalendarRepositoryImpl implements CalendarCustom { public Calendar getRecentDateCalendar(User userEntity) { LocalDate beginTimePath = LocalDate.now(); return jpaQueryFactory.selectFrom(calendar) - .where(calendar.calendarDate.after(beginTimePath)) + // 과거의 시간이거나 + .where(calendar.calendarDate.after(beginTimePath).or( + // 만약 날짜가 같은 경우에는 + // 디데이 일경우: 같은 날짜, 년도인 경우 + // 매년 반복: 같은 날짜인경우 + calendar.calendarDate.month().eq(beginTimePath.getMonth().getValue()).and( + calendar.calendarDate.dayOfMonth().eq(beginTimePath.getDayOfMonth()) + ).and(calendar.calendarCategory.eq(CalendarCategory.EVERY_YEAR)) + ).or( + calendar.calendarDate.eq(beginTimePath) + .and(calendar.calendarCategory.eq(CalendarCategory.D_DAY)) + )) .where(calendar.user.userIdx.eq(userEntity.getUserIdx())) .where(calendar.status.eq(Constant.ACTIVE_STATUS)) .orderBy(calendar.calendarDate.asc()) diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 605196e..c9d6968 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -208,7 +208,7 @@ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ String title = null; if(calendar != null){ title = calendar.getCalendarTitle(); - day = (int) Duration.between(calendar.getCalendarDate().atStartOfDay(), LocalDate.now().atStartOfDay()).toDays(); + day = calculateDate(calendar); } // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 List listCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); From bc040a3504ea6de11abe6951645efe5d9255aafa Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Wed, 15 Feb 2023 22:57:29 +0900 Subject: [PATCH 13/55] =?UTF-8?q?#10=20fix:=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EA=B8=B0=EB=85=90=EC=9D=BC=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(+=EB=82=A0=EC=A7=9C=EC=88=98=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/repository/Calendar/CalendarRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java index 35352a1..a22c5db 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java @@ -33,12 +33,12 @@ public Calendar getRecentDateCalendar(User userEntity) { // 만약 날짜가 같은 경우에는 // 디데이 일경우: 같은 날짜, 년도인 경우 // 매년 반복: 같은 날짜인경우 + // 날짜 수: 같은 날짜, 같은 년도인 경우 calendar.calendarDate.month().eq(beginTimePath.getMonth().getValue()).and( calendar.calendarDate.dayOfMonth().eq(beginTimePath.getDayOfMonth()) ).and(calendar.calendarCategory.eq(CalendarCategory.EVERY_YEAR)) ).or( calendar.calendarDate.eq(beginTimePath) - .and(calendar.calendarCategory.eq(CalendarCategory.D_DAY)) )) .where(calendar.user.userIdx.eq(userEntity.getUserIdx())) .where(calendar.status.eq(Constant.ACTIVE_STATUS)) From 5efbf36261fd81898d80ebccfa27f4c79d418237 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Wed, 15 Feb 2023 23:35:50 +0900 Subject: [PATCH 14/55] =?UTF-8?q?#10=20fix:=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EA=B8=B0=EB=85=90=EC=9D=BC=20=EB=82=A0=EC=A7=9C=EC=88=98=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/service/CalendarService.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index c9d6968..4ecf7be 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -200,26 +200,26 @@ public void patchTag(TagStatus tag) throws BaseException{ } } + // TODO: 날짜수의 경우에는 100일, 200일, 일년 주기로 꾸며지게 되는데 일단 그 기능을 구현하지는 못함 public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ User user = this.findUserByUserIdx(userIdx); try{ Calendar calendar = this.calendarRepository.getRecentDateCalendar(user); // 현재 가장 가까운 캘린더 불러오기 - int day = 0; - String title = null; if(calendar != null){ - title = calendar.getCalendarTitle(); + int day = 0; day = calculateDate(calendar); - } - // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 - List listCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); - for(Calendar cal: listCalendars){ - if(this.calculateDate(cal) > day){ - title = cal.getCalendarTitle(); - day = this.calculateDate(cal); + // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 + List listCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); + for(Calendar cal: listCalendars){ + if(this.calculateDate(cal) > day){ + calendar = cal; + } } + day = this.calculateDate(calendar); + if(calendar.getCalendarCategory().equals(CalendarCategory.DATE_COUNT)) day--; // 값을 하나 빼줌 + return new HomeRes(user.getUserIdx(), user.getNickname(), calendar.getCalendarTitle(), Math.abs(day), null); } - return new HomeRes(user.getUserIdx(), user.getNickname(), title, Math.abs(day), null); - + return new HomeRes(user.getUserIdx(), user.getNickname(), null, 0, null); }catch (Exception e){ throw new BaseException(BaseResponseStatus.DATABASE_ERROR); } From 642b9482ce83b7533eb25ffdab9943daa327df6a Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Thu, 16 Feb 2023 13:52:50 +0900 Subject: [PATCH 15/55] =?UTF-8?q?#10=20fix:=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CalendarTag/CalendarTagRepositoryImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java index e88c0e6..ed1d59c 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java @@ -45,6 +45,7 @@ public List getPopularCalendarTagByUser(User userEntity) { .leftJoin(user).on(calendar.user.eq(user)) .where(user.userIdx.eq(userEntity.getUserIdx())) .where(tag.status.eq(Constant.ACTIVE_STATUS)) + .where(calendarTag.status.eq(Constant.ACTIVE_STATUS)) .groupBy(tag.tagIdx) .orderBy(tag.tagIdx.count().desc()) .limit(Constant.Home.HOME_RETURN_TAG_COUNT) From 18c1ebe93cab464ff340efa5c9c420fac4dce059 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Mon, 20 Feb 2023 19:03:55 +0900 Subject: [PATCH 16/55] =?UTF-8?q?#135=20test:=20=ED=8C=90=EB=A7=A4?= =?UTF-8?q?=EC=9E=90=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/CascadeTests.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/java/com/codepatissier/keki/CascadeTests.java diff --git a/src/test/java/com/codepatissier/keki/CascadeTests.java b/src/test/java/com/codepatissier/keki/CascadeTests.java new file mode 100644 index 0000000..46c90ac --- /dev/null +++ b/src/test/java/com/codepatissier/keki/CascadeTests.java @@ -0,0 +1,48 @@ +package com.codepatissier.keki; + +import com.codepatissier.keki.common.BaseException; +import com.codepatissier.keki.dessert.entity.Dessert; +import com.codepatissier.keki.dessert.repository.DessertRepository; +import com.codepatissier.keki.store.entity.Store; +import com.codepatissier.keki.store.repository.StoreRepository; +import com.codepatissier.keki.user.entity.User; +import com.codepatissier.keki.user.repository.UserRepository; +import com.codepatissier.keki.user.service.UserService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static com.codepatissier.keki.common.Constant.*; +import static org.assertj.core.api.Assertions.*; + +@SpringBootTest +@Transactional +public class CascadeTests { + @Autowired + UserService userService; + @Autowired + UserRepository userRepository; + @Autowired + StoreRepository storeRepository; + @Autowired + DessertRepository dessertRepository; + + @Test + @DisplayName("판매자 회원탈퇴 시 관련 DB 전체 INACTIVE 처리") + void signOutStore_AllConnectedDB_INACTIVE() throws BaseException { + // given + User user = userRepository.findById(2L).orElseThrow(); + // when + userService.signout(user.getUserIdx()); + // then + Store store = storeRepository.findByUser(user).orElseThrow(); + List desserts = dessertRepository.findByStoreAndStatusOrderByDessertIdx(store,ACTIVE_STATUS); + assertThat(user.getStatus()).isEqualTo(INACTIVE_STATUS); + assertThat(store.getStatus()).isEqualTo(INACTIVE_STATUS); + assertThat(desserts.size()).isEqualTo(0); + } +} From 50891943ef25c2aafe3600953957c28aa1bcf408 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Tue, 21 Feb 2023 02:45:20 +0900 Subject: [PATCH 17/55] =?UTF-8?q?#135=20feat:=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=EC=9E=90=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4=20=EC=8B=9C=20?= =?UTF-8?q?=EC=97=B0=EC=87=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/entity/Calendar.java | 6 ++-- .../keki/calendar/entity/CalendarTag.java | 2 ++ .../Calendar/CalendarRepository.java | 2 ++ .../CalendarTag/CalendarTagRepository.java | 5 +++ .../CalendarEntityListener.java | 16 +++++++++ .../entityListener/UserEntityListener.java | 33 +++++++++++++++++++ .../keki/history/entity/PostHistory.java | 2 +- .../keki/history/entity/SearchHistory.java | 2 ++ .../repository/PostHistoryRepository.java | 6 ++++ .../repository/SearchHistoryRepository.java | 2 ++ .../post/repository/PostLikeRepository.java | 1 + .../store/repository/StoreRepository.java | 2 ++ .../codepatissier/keki/user/entity/User.java | 4 +++ .../keki/user/service/UserService.java | 3 +- .../com/codepatissier/keki/CascadeTests.java | 23 +++++++++++++ 15 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/common/entityListener/CalendarEntityListener.java create mode 100644 src/main/java/com/codepatissier/keki/common/entityListener/UserEntityListener.java diff --git a/src/main/java/com/codepatissier/keki/calendar/entity/Calendar.java b/src/main/java/com/codepatissier/keki/calendar/entity/Calendar.java index 7f689ff..4b7326d 100644 --- a/src/main/java/com/codepatissier/keki/calendar/entity/Calendar.java +++ b/src/main/java/com/codepatissier/keki/calendar/entity/Calendar.java @@ -2,22 +2,24 @@ import com.codepatissier.keki.calendar.CalendarCategory; import com.codepatissier.keki.common.BaseEntity; +import com.codepatissier.keki.common.entityListener.CalendarEntityListener; import com.codepatissier.keki.user.entity.User; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.time.LocalDate; -import java.util.Date; @Getter @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE calendar SET status = 'inactive', last_modified_date = current_timestamp WHERE calendar_idx = ?") +@EntityListeners(CalendarEntityListener.class) public class Calendar extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java b/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java index 9e17e58..7156b90 100644 --- a/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java +++ b/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -13,6 +14,7 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE calendar_tag SET status = 'inactive', last_modified_date = current_timestamp WHERE calendar_tag_idx = ?") public class CalendarTag extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepository.java b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepository.java index e53fe68..8ee0f7c 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepository.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepository.java @@ -12,4 +12,6 @@ public interface CalendarRepository extends JpaRepository , Cale List findByUserAndStatus(User user, String status); Optional findByCalendarIdxAndStatus(Long calendarIdx, String status); List findByUserAndCalendarCategoryAndStatus(User user, CalendarCategory calendarCategory, String status); + + void deleteByUser(User user); } diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java index 281bcb9..db22d4a 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java @@ -2,10 +2,15 @@ import com.codepatissier.keki.calendar.entity.Calendar; import com.codepatissier.keki.calendar.entity.CalendarTag; +import com.codepatissier.keki.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface CalendarTagRepository extends JpaRepository, CalendarTagCustom{ List findByCalendarAndStatus(Calendar calendar, String activeStatus); + + void deleteByCalendar(Calendar calendar); + + List findByCalendarUserAndStatus(User user, String status); } diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/CalendarEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/CalendarEntityListener.java new file mode 100644 index 0000000..ec95c1f --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/entityListener/CalendarEntityListener.java @@ -0,0 +1,16 @@ +package com.codepatissier.keki.common.entityListener; + +import com.codepatissier.keki.calendar.entity.Calendar; +import com.codepatissier.keki.calendar.repository.CalendarTag.CalendarTagRepository; +import com.codepatissier.keki.common.BeanUtils; + +import javax.persistence.PreRemove; + +public class CalendarEntityListener { + + @PreRemove + public void onUpdate(Calendar calendar){ + CalendarTagRepository calendarTagRepository = BeanUtils.getBean(CalendarTagRepository.class); + calendarTagRepository.deleteByCalendar(calendar); + } +} diff --git a/src/main/java/com/codepatissier/keki/common/entityListener/UserEntityListener.java b/src/main/java/com/codepatissier/keki/common/entityListener/UserEntityListener.java new file mode 100644 index 0000000..36de0b6 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/entityListener/UserEntityListener.java @@ -0,0 +1,33 @@ +package com.codepatissier.keki.common.entityListener; + +import com.codepatissier.keki.calendar.repository.Calendar.CalendarRepository; +import com.codepatissier.keki.common.BeanUtils; +import com.codepatissier.keki.common.Role; +import com.codepatissier.keki.history.repository.PostHistoryRepository; +import com.codepatissier.keki.history.repository.SearchHistoryRepository; +import com.codepatissier.keki.post.repository.PostLikeRepository; +import com.codepatissier.keki.store.repository.StoreRepository; +import com.codepatissier.keki.user.entity.User; + +import javax.persistence.PreRemove; + +public class UserEntityListener { + + @PreRemove + public void onUpdate(User user){ + if(Role.getRoleByName(user.getRole())==Role.CUSTOMER){ + PostLikeRepository postLikeRepository = BeanUtils.getBean(PostLikeRepository.class); + postLikeRepository.deleteByUser(user); + PostHistoryRepository postHistoryRepository = BeanUtils.getBean(PostHistoryRepository.class); + postHistoryRepository.deleteByUser(user); + SearchHistoryRepository searchHistoryRepository = BeanUtils.getBean(SearchHistoryRepository.class); + searchHistoryRepository.deleteByUser(user); + CalendarRepository calendarRepository = BeanUtils.getBean(CalendarRepository.class); + calendarRepository.deleteByUser(user); + } else if(Role.getRoleByName(user.getRole())==Role.STORE){ + StoreRepository storeRepository = BeanUtils.getBean(StoreRepository.class); + storeRepository.deleteByUser(user); + } + user.signout(); + } +} diff --git a/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java b/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java index 9092c3e..5a04a5b 100644 --- a/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java +++ b/src/main/java/com/codepatissier/keki/history/entity/PostHistory.java @@ -15,7 +15,7 @@ @NoArgsConstructor @DynamicInsert @Getter -@SQLDelete(sql = "UPDATE post_history SET status = 'inactive', last_modified_date = current_timestamp WHERE post_idx = ?") +@SQLDelete(sql = "UPDATE post_history SET status = 'inactive', last_modified_date = current_timestamp WHERE post_history_idx = ?") public class PostHistory extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java b/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java index bf304c1..5f39b71 100644 --- a/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java +++ b/src/main/java/com/codepatissier/keki/history/entity/SearchHistory.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -13,6 +14,7 @@ @NoArgsConstructor @DynamicInsert @Getter +@SQLDelete(sql = "UPDATE search_history SET status = 'inactive', last_modified_date = current_timestamp WHERE search_history_idx = ?") public class SearchHistory extends BaseEntity { @Id diff --git a/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java b/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java index e4ba348..51d6d8d 100644 --- a/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java +++ b/src/main/java/com/codepatissier/keki/history/repository/PostHistoryRepository.java @@ -2,11 +2,17 @@ import com.codepatissier.keki.history.entity.PostHistory; import com.codepatissier.keki.post.entity.Post; +import com.codepatissier.keki.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface PostHistoryRepository extends JpaRepository, PostHistoryCustom{ int countByPostPostIdxEquals(Long postIdx); void deleteByPost(Post post); + void deleteByUser(User user); + + List findByUserAndStatus(User user, String status); } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/history/repository/SearchHistoryRepository.java b/src/main/java/com/codepatissier/keki/history/repository/SearchHistoryRepository.java index 17799f6..dd83bb6 100644 --- a/src/main/java/com/codepatissier/keki/history/repository/SearchHistoryRepository.java +++ b/src/main/java/com/codepatissier/keki/history/repository/SearchHistoryRepository.java @@ -10,4 +10,6 @@ @Repository public interface SearchHistoryRepository extends JpaRepository, SearchHistoryCustom { List findByUserAndStatus(User user, String activeStatus); + + void deleteByUser(User user); } diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java b/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java index 768b3e5..807fad3 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostLikeRepository.java @@ -19,4 +19,5 @@ public interface PostLikeRepository extends JpaRepository { boolean existsByUserAndStatusAndLastModifiedDateLessThan(User user, String status, LocalDateTime lastDate); void deleteByPost(Post post); + void deleteByUser(User user); } diff --git a/src/main/java/com/codepatissier/keki/store/repository/StoreRepository.java b/src/main/java/com/codepatissier/keki/store/repository/StoreRepository.java index 8d79dd9..fc655e1 100644 --- a/src/main/java/com/codepatissier/keki/store/repository/StoreRepository.java +++ b/src/main/java/com/codepatissier/keki/store/repository/StoreRepository.java @@ -12,4 +12,6 @@ public interface StoreRepository extends JpaRepository { Optional findByUser(User user); // TODO PostService에서 findByUserAndStatus로 변경 후 삭제 Optional findByUserAndStatus(User user, String activeStatus); Optional findByStoreIdxAndStatus(Long storeIdx, String activeStatus); + + void deleteByUser(User user); } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/user/entity/User.java b/src/main/java/com/codepatissier/keki/user/entity/User.java index b619d82..cbd526c 100644 --- a/src/main/java/com/codepatissier/keki/user/entity/User.java +++ b/src/main/java/com/codepatissier/keki/user/entity/User.java @@ -3,10 +3,12 @@ import com.codepatissier.keki.common.BaseEntity; import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.common.Role; +import com.codepatissier.keki.common.entityListener.UserEntityListener; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -14,6 +16,8 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE user SET status = 'inactive', last_modified_date = current_timestamp WHERE user_idx = ?") +@EntityListeners(UserEntityListener.class) public class User extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 5b89d82..909f158 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -107,8 +107,7 @@ public void modifyProfile(Long userIdx, PatchProfileReq patchProfileReq) throws public void signout(Long userIdx) throws BaseException { try{ User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); - storeRepository.findByUser(user).ifPresent(storeRepository::delete); - user.signout(); + userRepository.delete(user); // TODO redis 사용해 토큰 관리 } catch (BaseException e) { throw e; diff --git a/src/test/java/com/codepatissier/keki/CascadeTests.java b/src/test/java/com/codepatissier/keki/CascadeTests.java index 46c90ac..1ff4b83 100644 --- a/src/test/java/com/codepatissier/keki/CascadeTests.java +++ b/src/test/java/com/codepatissier/keki/CascadeTests.java @@ -1,8 +1,12 @@ package com.codepatissier.keki; +import com.codepatissier.keki.calendar.entity.CalendarTag; +import com.codepatissier.keki.calendar.repository.CalendarTag.CalendarTagRepository; import com.codepatissier.keki.common.BaseException; import com.codepatissier.keki.dessert.entity.Dessert; import com.codepatissier.keki.dessert.repository.DessertRepository; +import com.codepatissier.keki.history.entity.PostHistory; +import com.codepatissier.keki.history.repository.PostHistoryRepository; import com.codepatissier.keki.store.entity.Store; import com.codepatissier.keki.store.repository.StoreRepository; import com.codepatissier.keki.user.entity.User; @@ -30,6 +34,10 @@ public class CascadeTests { StoreRepository storeRepository; @Autowired DessertRepository dessertRepository; + @Autowired + PostHistoryRepository postHistoryRepository; + @Autowired + CalendarTagRepository calendarTagRepository; @Test @DisplayName("판매자 회원탈퇴 시 관련 DB 전체 INACTIVE 처리") @@ -45,4 +53,19 @@ void signOutStore_AllConnectedDB_INACTIVE() throws BaseException { assertThat(store.getStatus()).isEqualTo(INACTIVE_STATUS); assertThat(desserts.size()).isEqualTo(0); } + + @Test + @DisplayName("구매자 회원탈퇴 시 관련 DB 전체 INACTIVE 처리") + void signOutCustomer_AllConnectedDB_INACTIVE() throws BaseException { + // given + User user = userRepository.findById(3L).orElseThrow(); + // when + userService.signout(user.getUserIdx()); + // then + List postHistoryList = postHistoryRepository.findByUserAndStatus(user, ACTIVE_STATUS); + List calendarTagList = calendarTagRepository.findByCalendarUserAndStatus(user, ACTIVE_STATUS); + assertThat(user.getStatus()).isEqualTo(INACTIVE_STATUS); + assertThat(postHistoryList.size()).isEqualTo(0); + assertThat(calendarTagList.size()).isEqualTo(0); + } } From bd94091b420dac5f06ae820cc38b87d296626949 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sat, 25 Feb 2023 19:51:46 +0900 Subject: [PATCH 18/55] =?UTF-8?q?#12=20refactor:=20=ED=94=BC=EB=93=9C=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EB=82=B4=20dessertId?= =?UTF-8?q?x=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/codepatissier/keki/post/dto/GetPostRes.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/codepatissier/keki/post/dto/GetPostRes.java b/src/main/java/com/codepatissier/keki/post/dto/GetPostRes.java index a25afe8..ad7ed57 100644 --- a/src/main/java/com/codepatissier/keki/post/dto/GetPostRes.java +++ b/src/main/java/com/codepatissier/keki/post/dto/GetPostRes.java @@ -16,6 +16,7 @@ @NoArgsConstructor public class GetPostRes { private Long postIdx; + private Long dessertIdx; private String dessertName; private int dessertPrice; private String description; @@ -28,6 +29,7 @@ public class GetPostRes { public GetPostRes(Post post, boolean like){ this.postIdx = post.getPostIdx(); + this.dessertIdx = post.getDessert().getDessertIdx(); this.dessertName = post.getDessert().getDessertName(); this.dessertPrice = post.getDessert().getDessertPrice(); this.description = post.getPostDescription(); From 87948b7d6731764f62897a64f4c244657e532950 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sat, 25 Feb 2023 20:58:28 +0900 Subject: [PATCH 19/55] =?UTF-8?q?#135=20refactor:=20=EC=82=AD=EC=A0=9C,=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20api=20=ED=83=9C=EA=B7=B8&URL=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/contoller/CalendarController.java | 4 ++-- .../keki/calendar/service/CalendarService.java | 11 ++--------- .../keki/dessert/controller/DessertController.java | 4 ++-- .../keki/history/controller/HistoryController.java | 3 +-- .../keki/history/service/SearchHistoryService.java | 7 +------ .../keki/post/controller/PostController.java | 6 +++--- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java index 1d325b8..9f6817d 100644 --- a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java +++ b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java @@ -43,7 +43,7 @@ public BaseResponse createCalendar(@RequestBody CalendarReq calendarReq) // 캘린더 수정 @ResponseBody - @PatchMapping("/{calendarIdx}/edit") + @PatchMapping("/{calendarIdx}") public BaseResponse modifyCalendar(@RequestBody CalendarReq calendarReq, @PathVariable("calendarIdx") Long calendarIdx){ try{ this.calendarService.modifyCalendar(this.authService.getUserIdx(), calendarReq, calendarIdx); @@ -66,7 +66,7 @@ public BaseResponse getEditCalendar(@PathVariable("calendarIdx" // 캘린더 삭제 @ResponseBody - @PatchMapping("/{calendarIdx}") + @DeleteMapping("/{calendarIdx}") public BaseResponse deleteCalendar(@PathVariable("calendarIdx") Long calendarIdx){ try{ this.calendarService.deleteCalendar(calendarIdx, this.authService.getUserIdx()); diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 4ecf7be..f34bde4 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -90,8 +90,7 @@ public void deleteCalendar(Long calendarIdx, Long userIdx) throws BaseException{ if(!calendar.getUser().equals(user) || user.getStatus().equals(INACTIVE_STATUS)){ throw new BaseException(BaseResponseStatus.INVALID_USER_AND_STATUS); } - changeCalendarStatus(calendar, INACTIVE_STATUS); - changeCalendarTagStatus(calendar, INACTIVE_STATUS); + this.calendarRepository.delete(calendar); }catch (Exception e){ throw new BaseException(BaseResponseStatus.DATABASE_ERROR); } @@ -276,7 +275,7 @@ public void modifyCalendar(Long userIdx, CalendarReq calendarReq, Long calendarI throw new BaseException(BaseResponseStatus.NULL_CALENDAR_CATEGORY); calendar.setCalendarCategory(CalendarCategory.getCalendarCategoryByName(calendarReq.getKindOfCalendar())); } - this.changeCalendarTagStatus(calendar, INACTIVE_STATUS); + this.calendarTagRepository.deleteByCalendar(calendar); if (calendarReq.getHashTags() != null && calendarReq.getHashTags().size() != 0) { for (CalendarHashTag hashTag : calendarReq.getHashTags()) { CalendarTag calendarTag = this.calendarTagRepository.findByCalendarAndTag(calendar, this.findByTagName(hashTag)); @@ -339,12 +338,6 @@ private List getPostByTag(List popularTagRes) { .collect(Collectors.toList()); } - // 캘린더 상태 변경 [삭제 시] - private void changeCalendarStatus(Calendar calendar, String status) { - calendar.setStatus(status); - this.calendarRepository.save(calendar); - } - // tag 저장 private void saveHashTags(Calendar calendar, CalendarHashTag hashtag) throws BaseException { this.calendarTagRepository.save(CalendarTag.builder() diff --git a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java index 98c605b..5fe2f9a 100644 --- a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java +++ b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java @@ -94,10 +94,10 @@ public BaseResponse deleteDessert(@PathVariable("dessertIdx") Long desse /** * [판매자] 상품 수정 - * [PATCH] /desserts/:dessertIdx/editDessert + * [PATCH] /desserts/:dessertIdx */ @ResponseBody - @PatchMapping("/{dessertIdx}/editDessert") + @PatchMapping("/{dessertIdx}") public BaseResponse editDessert(@RequestBody PatchDessertReq patchDessertReq, @PathVariable("dessertIdx") Long dessertIdx) { try { dessertService.modifyDessert(patchDessertReq, dessertIdx, authService.getUserIdx()); diff --git a/src/main/java/com/codepatissier/keki/history/controller/HistoryController.java b/src/main/java/com/codepatissier/keki/history/controller/HistoryController.java index 370670e..8254ead 100644 --- a/src/main/java/com/codepatissier/keki/history/controller/HistoryController.java +++ b/src/main/java/com/codepatissier/keki/history/controller/HistoryController.java @@ -15,7 +15,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import javax.validation.Constraint; import java.util.List; @SecurityRequirement(name = "Bearer") @@ -53,7 +52,7 @@ public BaseResponse> recentSearchCake(){ // 최근 검색어 삭제 @ResponseBody - @PatchMapping("") + @DeleteMapping("") public BaseResponse deleteRecentHistories(){ try{ this.searchHistoryService.deleteRecentHistories(this.authService.getUserIdx()); diff --git a/src/main/java/com/codepatissier/keki/history/service/SearchHistoryService.java b/src/main/java/com/codepatissier/keki/history/service/SearchHistoryService.java index 4ffbe39..e6b6465 100644 --- a/src/main/java/com/codepatissier/keki/history/service/SearchHistoryService.java +++ b/src/main/java/com/codepatissier/keki/history/service/SearchHistoryService.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; import static com.codepatissier.keki.common.Constant.ACTIVE_STATUS; -import static com.codepatissier.keki.common.Constant.INACTIVE_STATUS; @Service @RequiredArgsConstructor @@ -39,11 +38,7 @@ public void deleteRecentHistories(Long userIdx) throws BaseException { try{ User user = this.userRepository.findById(userIdx) .orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_USER_IDX)); - this.searchHistoryRepository.findByUserAndStatus(user, ACTIVE_STATUS).stream() - .forEach(searches -> { - searches.setStatus(INACTIVE_STATUS); - this.searchHistoryRepository.save(searches); - }); + this.searchHistoryRepository.deleteAll(this.searchHistoryRepository.findByUserAndStatus(user, ACTIVE_STATUS)); }catch (Exception e){ throw new BaseException(BaseResponseStatus.DATABASE_ERROR); } diff --git a/src/main/java/com/codepatissier/keki/post/controller/PostController.java b/src/main/java/com/codepatissier/keki/post/controller/PostController.java index 993c9ad..a1c6db5 100644 --- a/src/main/java/com/codepatissier/keki/post/controller/PostController.java +++ b/src/main/java/com/codepatissier/keki/post/controller/PostController.java @@ -205,10 +205,10 @@ public BaseResponse getModifyPostView(@PathVariable Long postI /** * 게시물 수정 - * [PATCH] /posts/:postIdx/edit + * [PATCH] /posts/:postIdx */ @ResponseBody - @PatchMapping("/{postIdx}/edit") + @PatchMapping("/{postIdx}") public BaseResponse modifyPost(@RequestBody PatchPostReq patchPostReq, @PathVariable Long postIdx){ try{ if (patchPostReq.getPostImgUrls() != null && (patchPostReq.getPostImgUrls().size() > 5 || patchPostReq.getPostImgUrls().size() < 1)) @@ -224,7 +224,7 @@ public BaseResponse modifyPost(@RequestBody PatchPostReq patchPostReq, @ /** * 게시물 삭제 - * [PATCH] /posts/:postIdx + * [DELETE] /posts/:postIdx */ @ResponseBody @DeleteMapping("/{postIdx}") From 56f7acd58545b0f80573bedd4786b67daaaaddc7 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sat, 25 Feb 2023 21:33:32 +0900 Subject: [PATCH 20/55] =?UTF-8?q?#135=20refactor:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4=20api=20=ED=83=9C=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/user/controller/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/user/controller/UserController.java b/src/main/java/com/codepatissier/keki/user/controller/UserController.java index 1890854..3cdca26 100644 --- a/src/main/java/com/codepatissier/keki/user/controller/UserController.java +++ b/src/main/java/com/codepatissier/keki/user/controller/UserController.java @@ -107,7 +107,7 @@ public BaseResponse modifyProfile(@RequestBody PatchProfileReq patchProfileRe } // 회원 탈퇴 - @PatchMapping("/signout") + @DeleteMapping("/signout") public BaseResponse signout() { try{ Long userIdx = authService.getUserIdx(); From c625ada541200fc1e5f54e654e674007362c31cc Mon Sep 17 00:00:00 2001 From: sojungpp Date: Tue, 28 Feb 2023 22:36:15 +0900 Subject: [PATCH 21/55] =?UTF-8?q?#8=20feat:=20redis=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ .../keki/common/config/RedisConfig.java | 30 +++++++++++++++++++ src/main/resources/application.properties | 5 +++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/codepatissier/keki/common/config/RedisConfig.java diff --git a/build.gradle b/build.gradle index 2141db2..f0ce8f9 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,9 @@ dependencies { runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2' + // redis + implementation 'org.springframework.boot:spring-boot-starter-data-redis' + // QueryDsl implementation 'com.querydsl:querydsl-jpa' diff --git a/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java b/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java new file mode 100644 index 0000000..e8565d9 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java @@ -0,0 +1,30 @@ +package com.codepatissier.keki.common.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; + +@Configuration +public class RedisConfig { + + @Value("${spring.redis.host}") + private String host; + + @Value("${spring.redis.port}") + private int port; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(host, port); + } + + @Bean + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + return redisTemplate; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7686337..c956a0d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -12,4 +12,7 @@ jasypt.encryptor.bean= jasyptStringEncryptor # oauth spring.profiles.include=oauth - + +# redis +spring.redis.host=localhost +spring.redis.port=6379 From 5a5fcc3737954b81d7589261e0caca50d50027ca Mon Sep 17 00:00:00 2001 From: sojungpp Date: Wed, 1 Mar 2023 01:41:17 +0900 Subject: [PATCH 22/55] =?UTF-8?q?#8=20feat:=20refresh=20=ED=86=A0=ED=81=B0?= =?UTF-8?q?=20redis=EC=97=90=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/user/service/AuthService.java | 5 +++++ .../com/codepatissier/keki/user/service/UserService.java | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index 0760346..59f6977 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -1,5 +1,6 @@ package com.codepatissier.keki.user.service; +import java.time.Duration; import java.util.Date; @@ -13,6 +14,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; @@ -32,6 +34,8 @@ public class AuthService { private final int accessTokenExpiryDate = 604800000; private final int refreshTokenExpiryDate = 604800000; + private final RedisTemplate redisTemplate; + @Value("${auth.key}") private String key; @@ -91,6 +95,7 @@ public String createRefreshToken(Long userIdx) { .setExpiration(new Date(now.getTime() + refreshTokenExpiryDate)) .signWith(SignatureAlgorithm.HS256, key) .compact(); + redisTemplate.opsForValue().set(String.valueOf(userIdx), refreshToken, Duration.ofMillis(refreshTokenExpiryDate)); return refreshToken; } diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 909f158..7f0adf7 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -14,7 +14,6 @@ import org.springframework.transaction.annotation.Transactional; - import static com.codepatissier.keki.common.BaseResponseStatus.*; @@ -22,7 +21,6 @@ @RequiredArgsConstructor public class UserService { private final UserRepository userRepository; - private final StoreRepository storeRepository; private final AuthService authService; // 로그인 From 7c46b9a85345d1dfabbf8c5ecd35be96ecab2caf Mon Sep 17 00:00:00 2001 From: sojungpp Date: Wed, 1 Mar 2023 03:09:10 +0900 Subject: [PATCH 23/55] =?UTF-8?q?#8=20feat:=20accessToken=20=EC=9E=AC?= =?UTF-8?q?=EB=B0=9C=EA=B8=89=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/user/controller/UserController.java | 11 +++++++++++ .../keki/user/dto/PostTokenReq.java | 15 +++++++++++++++ .../keki/user/repository/UserRepository.java | 4 ++-- .../keki/user/service/AuthService.java | 5 +++++ .../keki/user/service/UserService.java | 19 ++++++++++++++----- 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/user/dto/PostTokenReq.java diff --git a/src/main/java/com/codepatissier/keki/user/controller/UserController.java b/src/main/java/com/codepatissier/keki/user/controller/UserController.java index 3cdca26..aa377a4 100644 --- a/src/main/java/com/codepatissier/keki/user/controller/UserController.java +++ b/src/main/java/com/codepatissier/keki/user/controller/UserController.java @@ -130,4 +130,15 @@ public BaseResponse logout() { } } + // AccessToken 재발급 + @ResponseBody + @PostMapping("/reissue") + public BaseResponse reissueToken(@RequestBody PostTokenReq postTokenReq) { + try{ + return new BaseResponse<>(userService.reissueToken(postTokenReq)); + }catch (BaseException e){ + return new BaseResponse<>(e.getStatus()); + } + } + } diff --git a/src/main/java/com/codepatissier/keki/user/dto/PostTokenReq.java b/src/main/java/com/codepatissier/keki/user/dto/PostTokenReq.java new file mode 100644 index 0000000..4f84425 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/user/dto/PostTokenReq.java @@ -0,0 +1,15 @@ +package com.codepatissier.keki.user.dto; + +import lombok.Getter; + +import javax.validation.constraints.NotBlank; + +@Getter +public class PostTokenReq { + @NotBlank + private String email; + @NotBlank + private String provider; + @NotBlank + private String refreshToken; +} diff --git a/src/main/java/com/codepatissier/keki/user/repository/UserRepository.java b/src/main/java/com/codepatissier/keki/user/repository/UserRepository.java index 155969c..a887bcc 100644 --- a/src/main/java/com/codepatissier/keki/user/repository/UserRepository.java +++ b/src/main/java/com/codepatissier/keki/user/repository/UserRepository.java @@ -11,7 +11,7 @@ public interface UserRepository extends JpaRepository { boolean existsByNickname(String nickname); Optional findByUserIdxAndStatusEquals(Long userIdx, String status); - User findByEmailAndProviderAndStatusEquals(String email, Provider provider, String activeStatus); - User findByEmailAndProvider(String email, Provider provider); + + Optional findByEmailAndProviderAndStatusEquals(String email, Provider provider, String status); } diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index 59f6977..5627445 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -110,4 +110,9 @@ public String createAccessToken(Long userIdx) { return accessToken; } + public String validateRefreshToken(Long userIdx, String refreshTokenReq) throws BaseException { + String refreshToken = (String) redisTemplate.opsForValue().get(String.valueOf(userIdx)); + if(!refreshToken.equals(refreshTokenReq)) throw new BaseException(INVALID_TOKEN); + return refreshToken; + } } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 7f0adf7..99883c7 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -15,6 +15,7 @@ import static com.codepatissier.keki.common.BaseResponseStatus.*; +import static com.codepatissier.keki.common.Constant.ACTIVE_STATUS; @Service @@ -59,7 +60,7 @@ private User signup(String email, Provider provider) { @Transactional // TODO @Transactional(rollbackFor = Exception.class) 수정 public PostUserRes signupCustomer(Long userIdx, PostCustomerReq postCustomerReq) throws BaseException{ try { - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); String accessToken = authService.createAccessToken(userIdx); String refreshToken = authService.createRefreshToken(userIdx); @@ -83,14 +84,14 @@ public void checkNickname(PostNicknameReq postNicknameReq) throws BaseException{ // 구매자 마이페이지 조회 public GetProfileRes getProfile() throws BaseException { Long userIdx = authService.getUserIdx(); - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); return new GetProfileRes(user.getEmail(), user.getNickname(), user.getProfileImg());} // 구매자 프로필 수정 @Transactional public void modifyProfile(Long userIdx, PatchProfileReq patchProfileReq) throws BaseException{ try { - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); if (patchProfileReq.getNickname() != null) user.modifyNickname(patchProfileReq.getNickname()); if (patchProfileReq.getProfileImg() != null) user.modifyProfileImg(patchProfileReq.getProfileImg()); } catch (BaseException e) { @@ -104,7 +105,7 @@ public void modifyProfile(Long userIdx, PatchProfileReq patchProfileReq) throws @Transactional public void signout(Long userIdx) throws BaseException { try{ - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); userRepository.delete(user); // TODO redis 사용해 토큰 관리 } catch (BaseException e) { @@ -118,7 +119,7 @@ public void signout(Long userIdx) throws BaseException { @Transactional public void logout(Long userIdx) throws BaseException { try{ - User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); user.logout(); // TODO redis 사용해 토큰 관리 } catch (BaseException e) { @@ -128,4 +129,12 @@ public void logout(Long userIdx) throws BaseException { } } + // AccessToken 재발급 + @Transactional + public PostUserRes reissueToken(PostTokenReq postTokenReq) throws BaseException{ + User user = userRepository.findByEmailAndProviderAndStatusEquals(postTokenReq.getEmail(), Provider.getProviderByName(postTokenReq.getProvider()), ACTIVE_STATUS) + .orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + authService.validateRefreshToken(user.getUserIdx(), postTokenReq.getRefreshToken()); + return authService.createToken(user); + } } \ No newline at end of file From 7e136af22806f1b96fcf5fe607a4f8913d586a30 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Wed, 1 Mar 2023 18:40:21 +0900 Subject: [PATCH 24/55] =?UTF-8?q?#8=20fix:=20transactional=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codepatissier/keki/user/service/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 99883c7..3b45589 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -57,7 +57,7 @@ private User signup(String email, Provider provider) { } // 구매자 회원가입 - @Transactional // TODO @Transactional(rollbackFor = Exception.class) 수정 + @Transactional(rollbackFor = Exception.class) public PostUserRes signupCustomer(Long userIdx, PostCustomerReq postCustomerReq) throws BaseException{ try { User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); From 8cd5312e214f9c3631da5cf5d4b8f13fc123d420 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Wed, 1 Mar 2023 20:44:36 +0900 Subject: [PATCH 25/55] =?UTF-8?q?#8=20fix:=20redis=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../codepatissier/keki/common/config/RedisConfig.java | 10 +++++++++- src/main/resources/application.properties | 8 ++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 787780c..58e2d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ application-oauth.properties +application-redis.properties HELP.md .gradle build/ diff --git a/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java b/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java index e8565d9..413f5e6 100644 --- a/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java +++ b/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java @@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; @@ -16,9 +17,16 @@ public class RedisConfig { @Value("${spring.redis.port}") private int port; + @Value("${spring.redis.password}") + private String password; + @Bean public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(host, port); + RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); + redisStandaloneConfiguration.setHostName(host); + redisStandaloneConfiguration.setPort(port); + redisStandaloneConfiguration.setPassword(password); + return new LettuceConnectionFactory(redisStandaloneConfiguration); } @Bean diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c956a0d..0436071 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,9 +10,5 @@ spring.jpa.database=mysql jasypt.encryptor.bean= jasyptStringEncryptor -# oauth -spring.profiles.include=oauth - -# redis -spring.redis.host=localhost -spring.redis.port=6379 +# oauth, redis +spring.profiles.include=oauth, redis From 40b7662f9490f39e0baef17f5b7dfa906176d87c Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Thu, 2 Mar 2023 00:33:16 +0900 Subject: [PATCH 26/55] =?UTF-8?q?#11=20fix:=20=ED=99=88=20api=20=EA=B8=B0?= =?UTF-8?q?=EB=85=90=EC=9D=BC=20=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=A7=A4=EB=85=84=20=EB=B0=98?= =?UTF-8?q?=EB=B3=B5=20=EA=B3=84=EC=82=B0=20=EC=B6=94=EA=B0=80(100?= =?UTF-8?q?=EC=9D=BC,=20200=EC=9D=BC=20=EB=93=B1=EB=93=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/DateCountCategory.java | 28 +++++++++++ .../keki/calendar/dto/CalendarDateReturn.java | 14 ++++++ .../calendar/service/CalendarService.java | 49 +++++++++++++++---- 3 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java create mode 100644 src/main/java/com/codepatissier/keki/calendar/dto/CalendarDateReturn.java diff --git a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java new file mode 100644 index 0000000..2fa3d6e --- /dev/null +++ b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java @@ -0,0 +1,28 @@ +package com.codepatissier.keki.calendar; + +import lombok.Getter; + +@Getter +public enum DateCountCategory { + ONE_HUNDRED(100), + TWO_HUNDRED(200), + THREE_HUNDRED(300), + ONE_YEAR(365), + FOUR_HUNDRED(400), + FIVE_HUNDRED(500), + SIX_HUNDRED(600), + SEVEN_HUNDRED(700), + TWO_YEAR(730), + EIGHT_HUNDRED(800), + NINE_HUNDRED(900), + ONE_THOUSAND(1000), + THREE_YEAR(1095), + FOUR_YEAR(1460), + FIVE_YEAR(1825), + THO_THOUSAND(2000); + private int count; + + DateCountCategory(int count){ + this.count = count; + } +} diff --git a/src/main/java/com/codepatissier/keki/calendar/dto/CalendarDateReturn.java b/src/main/java/com/codepatissier/keki/calendar/dto/CalendarDateReturn.java new file mode 100644 index 0000000..afff3e6 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/calendar/dto/CalendarDateReturn.java @@ -0,0 +1,14 @@ +package com.codepatissier.keki.calendar.dto; + +import com.codepatissier.keki.calendar.DateCountCategory; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class CalendarDateReturn { + private int calDate; + private DateCountCategory dateCountCategory; +} diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index f34bde4..860af74 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -1,6 +1,7 @@ package com.codepatissier.keki.calendar.service; import com.codepatissier.keki.calendar.CalendarCategory; +import com.codepatissier.keki.calendar.DateCountCategory; import com.codepatissier.keki.calendar.dto.*; import com.codepatissier.keki.calendar.entity.Calendar; import com.codepatissier.keki.calendar.entity.CalendarTag; @@ -14,6 +15,7 @@ import com.codepatissier.keki.user.entity.User; import com.codepatissier.keki.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,6 +30,7 @@ @Service @RequiredArgsConstructor +@Slf4j public class CalendarService { private final CalendarRepository calendarRepository; private final CalendarTagRepository calendarTagRepository; @@ -139,6 +142,16 @@ private int calculateDate(Calendar calendar) { return returnCalendar; } + // 날짜 수 기념일 계산 (100일, 200일, 300일 등등) + // 현재 2000일 미만으로 불러오도록 생성 + private CalendarDateReturn calculateDateForDateCount(Calendar cal) { + int day = this.calculateDate(cal); // 날짜수를 구해서 + for(DateCountCategory count: DateCountCategory.values()){ + if(day < count.getCount()) return new CalendarDateReturn(count.getCount()-day, count); + } + return new CalendarDateReturn(day, null); + } + // 기념일 계산 return String private String calculateDateReturnString(int day){ String returnCalendar; @@ -199,21 +212,35 @@ public void patchTag(TagStatus tag) throws BaseException{ } } - // TODO: 날짜수의 경우에는 100일, 200일, 일년 주기로 꾸며지게 되는데 일단 그 기능을 구현하지는 못함 + // 홈 기념일 조회 public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ User user = this.findUserByUserIdx(userIdx); try{ Calendar calendar = this.calendarRepository.getRecentDateCalendar(user); // 현재 가장 가까운 캘린더 불러오기 - if(calendar != null){ - int day = 0; - day = calculateDate(calendar); - // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 - List listCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); - for(Calendar cal: listCalendars){ - if(this.calculateDate(cal) > day){ - calendar = cal; - } + List listEYCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); + int day = Integer.MAX_VALUE; + + // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 + for(Calendar cal: listEYCalendars){ + int calDay = this.calculateDate(cal); + if(calDay < Math.abs(day)){ + calendar = cal; + day = calDay; } + } + + // 날짜 수인 경우 100일, 200일 불러오기 + List listDCCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.DATE_COUNT, ACTIVE_STATUS); + for (Calendar cal : listDCCalendars) { + CalendarDateReturn calDateReturn = this.calculateDateForDateCount(cal); + if (calDateReturn.getCalDate() Date: Thu, 2 Mar 2023 00:56:29 +0900 Subject: [PATCH 27/55] =?UTF-8?q?#11=20fix:=20=EA=B8=B0=EB=85=90=EC=9D=BC?= =?UTF-8?q?=20=ED=83=9C=EA=B7=B8=EC=97=90=20=EB=A7=9E=EC=B6=B0=20=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EB=B3=84=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/contoller/CalendarController.java | 4 ++-- .../com/codepatissier/keki/calendar/dto/HomeRes.java | 4 ++++ .../repository/CalendarTag/CalendarTagCustom.java | 1 + .../CalendarTag/CalendarTagRepositoryImpl.java | 3 +++ .../keki/calendar/service/CalendarService.java | 12 ++++++------ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java index 9f6817d..ce2078e 100644 --- a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java +++ b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java @@ -119,8 +119,8 @@ public BaseResponse getHome(){ } // 아닌 경우에는 가장 가까운 기념일을 불러오고 HomeRes home = this.calendarService.getHomeCalendar(this.authService.getUserIdx()); - // 기념일의 태그가 3개 미만이면 다 랜덤으로 불러오고 - // 태그가 3개 이상이면 태그별로 랜덤하게 불러오기 + // 기념일의 태그가 없으면 랜덤으로 + // 아니면 기념일 태그의 게시물만 return new BaseResponse<>(this.calendarService.getHomeTagPost(home)); } catch (BaseException e) { return new BaseResponse<>(e.getStatus()); diff --git a/src/main/java/com/codepatissier/keki/calendar/dto/HomeRes.java b/src/main/java/com/codepatissier/keki/calendar/dto/HomeRes.java index 678c4cd..f310659 100644 --- a/src/main/java/com/codepatissier/keki/calendar/dto/HomeRes.java +++ b/src/main/java/com/codepatissier/keki/calendar/dto/HomeRes.java @@ -1,5 +1,7 @@ package com.codepatissier.keki.calendar.dto; +import com.codepatissier.keki.calendar.entity.Calendar; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.querydsl.core.annotations.QueryProjection; import lombok.AllArgsConstructor; import lombok.Getter; @@ -17,4 +19,6 @@ public class HomeRes { private String calendarTitle; private int calendarDate; private List homeTagResList; + @JsonIgnore + private Calendar calendar; } diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagCustom.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagCustom.java index f2e50d7..6bca136 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagCustom.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagCustom.java @@ -3,6 +3,7 @@ import com.codepatissier.keki.calendar.dto.PopularTagRes; import com.codepatissier.keki.user.entity.User; +import java.util.Calendar; import java.util.List; public interface CalendarTagCustom { diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java index ed1d59c..3c2efee 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java @@ -2,6 +2,7 @@ import com.codepatissier.keki.calendar.dto.PopularTagRes; import com.codepatissier.keki.calendar.dto.QPopularTagRes; +import com.codepatissier.keki.calendar.entity.Calendar; import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.user.entity.User; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -35,6 +36,7 @@ public List getPopularCalendarTag() { /** * 사용자 별 인기 Tag 3개 + * 다음에 쓸수 있으니, 혹시 몰라서 지우지 않고 남겨둘게요! */ @Override public List getPopularCalendarTagByUser(User userEntity) { @@ -51,4 +53,5 @@ public List getPopularCalendarTagByUser(User userEntity) { .limit(Constant.Home.HOME_RETURN_TAG_COUNT) .fetch(); } + } diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 860af74..27ff18a 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -243,9 +243,9 @@ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ // 날짜 계산 day = this.calculateDate(calendar); if(calendar.getCalendarCategory().equals(CalendarCategory.DATE_COUNT)) day--; // 값을 하나 빼줌 - return new HomeRes(user.getUserIdx(), user.getNickname(), calendar.getCalendarTitle(), Math.abs(day), null); + return new HomeRes(user.getUserIdx(), user.getNickname(), calendar.getCalendarTitle(), Math.abs(day), null, calendar); } - return new HomeRes(user.getUserIdx(), user.getNickname(), null, 0, null); + return new HomeRes(user.getUserIdx(), user.getNickname(), null, 0, null, null); }catch (Exception e){ throw new BaseException(BaseResponseStatus.DATABASE_ERROR); } @@ -257,7 +257,7 @@ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ public HomeRes getHomeCalendarAndPostLogout() throws BaseException{ try{ return new HomeRes(null, null, null, 0, - getPostByTag(this.calendarTagRepository.getPopularCalendarTag())); + getPostByTag(this.calendarTagRepository.getPopularCalendarTag()),null); }catch (Exception e){ throw new BaseException(BaseResponseStatus.DATABASE_ERROR); } @@ -266,11 +266,11 @@ public HomeRes getHomeCalendarAndPostLogout() throws BaseException{ // home api public HomeRes getHomeTagPost(HomeRes home) throws BaseException{ - User user = this.findUserByUserIdx(home.getUserIdx()); try{ - List tags = this.calendarTagRepository.getPopularCalendarTagByUser(user); + List tags = this.calendarTagRepository.findByCalendarAndStatus(home.getCalendar(), ACTIVE_STATUS).stream() + .map(cal -> new PopularTagRes(cal.getTag().getTagIdx(), cal.getTag().getTagName())).collect(Collectors.toList()); // 기념일의 태그가 3개 미만이면 다 랜덤으로 불러오고 - if(tags.size()< Constant.Home.HOME_RETURN_TAG_COUNT){ + if(tags.size()==0){ home.setHomeTagResList(this.getPostByTag(this.calendarTagRepository.getPopularCalendarTag())); }else{ // 태그가 3개 이상이면 태그별로 랜덤하게 불러오기 home.setHomeTagResList(this.getPostByTag(tags)); From b3a3142e059cdbcfdbd51c476e99c605b43b2256 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Thu, 2 Mar 2023 01:03:14 +0900 Subject: [PATCH 28/55] =?UTF-8?q?#11=20fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94(?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=20=EC=88=98)=20return=20=EB=82=B4=EC=9A=A9?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/DateCountCategory.java | 36 ++++++++++--------- .../calendar/service/CalendarService.java | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java index 2fa3d6e..166cab9 100644 --- a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java +++ b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java @@ -4,25 +4,27 @@ @Getter public enum DateCountCategory { - ONE_HUNDRED(100), - TWO_HUNDRED(200), - THREE_HUNDRED(300), - ONE_YEAR(365), - FOUR_HUNDRED(400), - FIVE_HUNDRED(500), - SIX_HUNDRED(600), - SEVEN_HUNDRED(700), - TWO_YEAR(730), - EIGHT_HUNDRED(800), - NINE_HUNDRED(900), - ONE_THOUSAND(1000), - THREE_YEAR(1095), - FOUR_YEAR(1460), - FIVE_YEAR(1825), - THO_THOUSAND(2000); + ONE_HUNDRED(100, "100일"), + TWO_HUNDRED(200, "200일"), + THREE_HUNDRED(300, "200일"), + ONE_YEAR(365, "1주년"), + FOUR_HUNDRED(400, "400일"), + FIVE_HUNDRED(500, "500일"), + SIX_HUNDRED(600, "600일"), + SEVEN_HUNDRED(700, "700일"), + TWO_YEAR(730, "2주년"), + EIGHT_HUNDRED(800, "800일"), + NINE_HUNDRED(900, "900일"), + ONE_THOUSAND(1000, "1000일"), + THREE_YEAR(1095, "3주년"), + FOUR_YEAR(1460, "4주년"), + FIVE_YEAR(1825, "5주년"), + THO_THOUSAND(2000, "200일"); private int count; + private String date; - DateCountCategory(int count){ + DateCountCategory(int count, String date){ this.count = count; + this.date = date; } } diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 27ff18a..efd884b 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -235,7 +235,7 @@ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ CalendarDateReturn calDateReturn = this.calculateDateForDateCount(cal); if (calDateReturn.getCalDate() Date: Thu, 2 Mar 2023 01:20:05 +0900 Subject: [PATCH 29/55] =?UTF-8?q?#11=20fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94(?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=20=EC=88=98)=20=EA=B3=84=EC=82=B0=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/service/CalendarService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index efd884b..d366c42 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -145,9 +145,9 @@ private int calculateDate(Calendar calendar) { // 날짜 수 기념일 계산 (100일, 200일, 300일 등등) // 현재 2000일 미만으로 불러오도록 생성 private CalendarDateReturn calculateDateForDateCount(Calendar cal) { - int day = this.calculateDate(cal); // 날짜수를 구해서 + int day = this.calculateDate(cal) - 1; // 날짜수를 구함 -> 기존에 +1 을 해서 return 하기 때문에 +1을 해줌 for(DateCountCategory count: DateCountCategory.values()){ - if(day < count.getCount()) return new CalendarDateReturn(count.getCount()-day, count); + if(day <= count.getCount()) return new CalendarDateReturn(count.getCount()-day, count); } return new CalendarDateReturn(day, null); } @@ -236,13 +236,12 @@ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ if (calDateReturn.getCalDate() Date: Thu, 2 Mar 2023 12:56:37 +0900 Subject: [PATCH 30/55] =?UTF-8?q?#11=20fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94?= =?UTF-8?q?=20=EA=B3=84=EC=82=B0=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/DateCountCategory.java | 2 +- .../calendar/service/CalendarService.java | 20 +++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java index 166cab9..737a982 100644 --- a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java +++ b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java @@ -19,7 +19,7 @@ public enum DateCountCategory { THREE_YEAR(1095, "3주년"), FOUR_YEAR(1460, "4주년"), FIVE_YEAR(1825, "5주년"), - THO_THOUSAND(2000, "200일"); + THO_THOUSAND(2000, "2000일"); private int count; private String date; diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index d366c42..31902f8 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -216,9 +216,13 @@ public void patchTag(TagStatus tag) throws BaseException{ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ User user = this.findUserByUserIdx(userIdx); try{ + int day = Integer.MAX_VALUE; Calendar calendar = this.calendarRepository.getRecentDateCalendar(user); // 현재 가장 가까운 캘린더 불러오기 + if(calendar != null){ + day = this.calculateDate(calendar); + } List listEYCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); - int day = Integer.MAX_VALUE; + // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 for(Calendar cal: listEYCalendars){ @@ -241,7 +245,6 @@ public HomeRes getHomeCalendar(Long userIdx) throws BaseException{ } if(calendar != null){ - // 날짜 계산 return new HomeRes(user.getUserIdx(), user.getNickname(), calendar.getCalendarTitle(), Math.abs(day), null, calendar); } return new HomeRes(user.getUserIdx(), user.getNickname(), null, 0, null, null); @@ -345,19 +348,6 @@ private Calendar findCalendarByCalendarIdx(Long calendarIdx) throws BaseExceptio .orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_CALENDAR_IDX)); } - // 태그 상태 변경 - private void changeCalendarTagStatus(Calendar calendar, String status){ - String getStatus = null; - if(status.equals(ACTIVE_STATUS)) getStatus = INACTIVE_STATUS; - else getStatus = ACTIVE_STATUS; - - this.calendarTagRepository.findByCalendarAndStatus(calendar, getStatus).stream() - .forEach(tag -> { - tag.setStatus(status); - this.calendarTagRepository.save(tag); - }); - } - // tag 별 게시물 찾기 private List getPostByTag(List popularTagRes) { return popularTagRes.stream() From df481905d12aed1ae4b1c8d7930a7c8284fde98e Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Thu, 2 Mar 2023 13:00:48 +0900 Subject: [PATCH 31/55] =?UTF-8?q?#11=20fix:=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codepatissier/keki/calendar/DateCountCategory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java index 737a982..e467c1c 100644 --- a/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java +++ b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java @@ -19,7 +19,7 @@ public enum DateCountCategory { THREE_YEAR(1095, "3주년"), FOUR_YEAR(1460, "4주년"), FIVE_YEAR(1825, "5주년"), - THO_THOUSAND(2000, "2000일"); + TWO_THOUSAND(2000, "2000일"); private int count; private String date; From 5be9626f55c3ac4d0d3bf969d967725af184ee7d Mon Sep 17 00:00:00 2001 From: sojungpp Date: Fri, 3 Mar 2023 21:11:20 +0900 Subject: [PATCH 32/55] =?UTF-8?q?#8=20feat:=20provider=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codepatissier/keki/user/entity/Provider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/user/entity/Provider.java b/src/main/java/com/codepatissier/keki/user/entity/Provider.java index e544d02..a759137 100644 --- a/src/main/java/com/codepatissier/keki/user/entity/Provider.java +++ b/src/main/java/com/codepatissier/keki/user/entity/Provider.java @@ -9,7 +9,9 @@ public enum Provider { KAKAO(1, "카카오"), NAVER(2, "네이버"), GOOGLE(3, "구글"), - ANONYMOUS(4,"비회원"); + + APPLE(4, "애플"), + ANONYMOUS(5,"비회원"); private int number; private String name; From 0199474ab6fb34167c3fea62230bdfb99083acfd Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Fri, 3 Mar 2023 23:01:00 +0900 Subject: [PATCH 33/55] =?UTF-8?q?#10=20fix:=20StringUtils=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B3=B5=EB=B0=B1=20=EB=B0=8F=20?= =?UTF-8?q?null=20=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/contoller/CalendarController.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java index ce2078e..75e4f9f 100644 --- a/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java +++ b/src/main/java/com/codepatissier/keki/calendar/contoller/CalendarController.java @@ -10,12 +10,11 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import java.util.List; -// TODO STATUS 처리를 해줘야 함. - @SecurityRequirement(name = "Bearer") @Tag(name = "calendars", description = "기념일 API") @RestController @@ -30,9 +29,9 @@ public class CalendarController { @PostMapping("") public BaseResponse createCalendar(@RequestBody CalendarReq calendarReq){ try{ - if(calendarReq.getTitle().equals("") || calendarReq.getTitle() == null) return new BaseResponse<>(BaseResponseStatus.NULL_TITLE); - if(calendarReq.getDate() == null || calendarReq.getDate().toString().equals("")) return new BaseResponse<>(BaseResponseStatus.NULL_DATE); - if(calendarReq.getKindOfCalendar() == null) return new BaseResponse<>(BaseResponseStatus.NULL_KIND_OF_CALENDARS); + if(!StringUtils.hasText(calendarReq.getTitle())) return new BaseResponse<>(BaseResponseStatus.NULL_TITLE); + if(!StringUtils.hasText(calendarReq.getDate().toString())) return new BaseResponse<>(BaseResponseStatus.NULL_DATE); + if(!StringUtils.hasText(calendarReq.getKindOfCalendar())) return new BaseResponse<>(BaseResponseStatus.NULL_KIND_OF_CALENDARS); this.calendarService.createCalendar(this.authService.getUserIdx(), calendarReq); return new BaseResponse<>(BaseResponseStatus.SUCCESS); @@ -132,7 +131,7 @@ public BaseResponse getHome(){ @PostMapping("/categories") public BaseResponse createTag(@RequestBody CalendarHashTag tag){ try{ - if(tag.getCalendarHashTag() == null) return new BaseResponse<>(BaseResponseStatus.NULL_TAG); + if(!StringUtils.hasText(tag.getCalendarHashTag())) return new BaseResponse<>(BaseResponseStatus.NULL_TAG); this.calendarService.createTag(tag); return new BaseResponse<>(BaseResponseStatus.SUCCESS); }catch (BaseException e){ @@ -145,7 +144,7 @@ public BaseResponse createTag(@RequestBody CalendarHashTag tag){ @PatchMapping("/categories") public BaseResponse patchTag(@RequestBody TagStatus tag){ try{ - if(tag.getCalendarHashTag() == null) return new BaseResponse<>(BaseResponseStatus.NULL_TAG); + if(!StringUtils.hasText(tag.getCalendarHashTag())) return new BaseResponse<>(BaseResponseStatus.NULL_TAG); this.calendarService.patchTag(tag); return new BaseResponse<>(BaseResponseStatus.SUCCESS); From 4922e748c28be97a5963740a1b611819f1f0b06e Mon Sep 17 00:00:00 2001 From: joonghyun Date: Fri, 3 Mar 2023 23:01:50 +0900 Subject: [PATCH 34/55] =?UTF-8?q?#7=20fix:=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=20images=20?= =?UTF-8?q?=EB=A6=AC=ED=84=B4=EA=B0=92=EC=9D=84=20=EC=83=81=ED=94=94=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=9D=B4=EB=AF=B8=EC=A7=80(1=EC=9E=A5)+?= =?UTF-8?q?=ED=94=BC=EB=93=9C=20=EB=8C=80=ED=91=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80(=EC=B5=9C=EB=8C=80=204=EC=9E=A5)=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/dessert/dto/GetDessertRes.java | 4 ++-- .../keki/dessert/service/DessertService.java | 18 +++++++++++++----- .../keki/post/repository/PostRepository.java | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java b/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java index f8d7aa0..8ea4f63 100644 --- a/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java +++ b/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java @@ -21,7 +21,7 @@ public class GetDessertRes { @AllArgsConstructor @NoArgsConstructor public static class Image { - private Long postIdx; - private String postImgUrl; + private Long imgIdx; + private String imgUrl; } } diff --git a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java index 73369c1..8da5ca2 100644 --- a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java +++ b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java @@ -15,6 +15,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -80,9 +81,12 @@ public GetDessertRes getDessert(Long dessertIdx) throws BaseException { try { Dessert dessert = dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_DESSERT_IDX)); - List imgList = getPostImgList(dessert); + ArrayList imgList = new ArrayList<>(); + imgList.add(getDessertImg(dessert)); + ArrayList postImgList = getPostImgList(dessert); + imgList.addAll(postImgList); - // nickname, dessertName, dessertPrice, dessertDescription, imgList + // nickname, dessertName, dessertPrice, dessertDescription, imgList(상품 상세 이미지 1장, 피드 이미지 4장) return new GetDessertRes(dessert.getStore().getUser().getNickname(), dessert.getDessertName(), dessert.getDessertPrice(), dessert.getDessertDescription(), imgList); } catch (BaseException e) { throw e; @@ -91,9 +95,13 @@ public GetDessertRes getDessert(Long dessertIdx) throws BaseException { } } - // 특정 dessert가 들어간 post 5개를 가져와 postIdx와 대표 postImg를 반환 - private List getPostImgList(Dessert dessert) { - return postRepository.findTop5ByDessertAndStatusOrderByPostIdxDesc(dessert, ACTIVE_STATUS).stream() + private GetDessertRes.Image getDessertImg(Dessert dessert) { + return new GetDessertRes.Image(dessert.getDessertIdx(), dessert.getDessertImg()); + } + + // 특정 dessert가 들어간 post 4개를 가져와 postIdx와 대표 postImg를 반환 + private ArrayList getPostImgList(Dessert dessert) { + return (ArrayList) postRepository.findTop4ByDessertAndStatusOrderByPostIdxDesc(dessert, ACTIVE_STATUS).stream() .map(posts -> new GetDessertRes.Image(posts.getPostIdx(), representPostImgUrl(posts.getImages()))).collect(Collectors.toList()); } diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java b/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java index d137d9c..9bb3198 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.ArrayList; import java.util.List; @Repository @@ -21,7 +22,7 @@ public interface PostRepository extends JpaRepository, PostCustom { boolean existsByStoreAndStatusAndPostIdxLessThan(Store store, String status, Long postIdx); boolean existsByDessertDessertNameContainingAndStatusAndPostIdxLessThan(String word, String status, Long postIdx); - List findTop5ByDessertAndStatusOrderByPostIdxDesc(Dessert dessert, String activeStatus); + ArrayList findTop4ByDessertAndStatusOrderByPostIdxDesc(Dessert dessert, String activeStatus); void deleteByDessert(Dessert dessert); } \ No newline at end of file From 5b8289d58525919b7dddf274eb20cd60054d5ea3 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Sat, 4 Mar 2023 19:34:51 +0900 Subject: [PATCH 35/55] =?UTF-8?q?#8=20fix:=20refreshToken=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codepatissier/keki/store/service/StoreService.java | 2 +- .../java/com/codepatissier/keki/user/entity/User.java | 10 ++-------- .../codepatissier/keki/user/service/UserService.java | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/store/service/StoreService.java b/src/main/java/com/codepatissier/keki/store/service/StoreService.java index 3cef9e3..67d72bc 100644 --- a/src/main/java/com/codepatissier/keki/store/service/StoreService.java +++ b/src/main/java/com/codepatissier/keki/store/service/StoreService.java @@ -31,7 +31,7 @@ public PostStoreRes signUpStore(Long userIdx, PostStoreReq postStoreReq) throws String refreshToken = authService.createRefreshToken(userIdx); User user = userRepository.findByUserIdxAndStatusEquals(userIdx, Constant.ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); - user.storeSignUp(postStoreReq.getNickname(), postStoreReq.getStoreImgUrl(), refreshToken, Role.STORE); + user.storeSignUp(postStoreReq.getNickname(), postStoreReq.getStoreImgUrl(), Role.STORE); userRepository.save(user); Store store = Store.builder() diff --git a/src/main/java/com/codepatissier/keki/user/entity/User.java b/src/main/java/com/codepatissier/keki/user/entity/User.java index cbd526c..8f72ad9 100644 --- a/src/main/java/com/codepatissier/keki/user/entity/User.java +++ b/src/main/java/com/codepatissier/keki/user/entity/User.java @@ -36,8 +36,6 @@ public class User extends BaseEntity { @Column(length = 300) private String profileImg; - private String refreshToken; - @Enumerated(EnumType.STRING) @Column(nullable = false) private Role role; @@ -49,9 +47,8 @@ public User(String email, Provider provider, Role role) { this.role = role; } - public void signup(String nickname, String refreshToken, Role role, String profileImg) { + public void signup(String nickname, Role role, String profileImg) { this.nickname = nickname; - this.refreshToken = refreshToken; this.role = role; this.profileImg = profileImg; } @@ -60,10 +57,9 @@ public String getRole() { return this.role.getName(); } - public void storeSignUp(String nickname, String profileImg, String refreshToken, Role role) { + public void storeSignUp(String nickname, String profileImg, Role role) { this.nickname = nickname; this.profileImg = profileImg; - this.refreshToken = refreshToken; this.role = role; } @@ -89,7 +85,6 @@ public void signout() { this.email = "anonymous@keki.store"; this.provider = Provider.ANONYMOUS; this.profileImg = null; - this.refreshToken = null; this.role = Role.ANONYMOUS; this.setStatus(Constant.INACTIVE_STATUS); // TODO status enum으로 변경 @@ -97,7 +92,6 @@ public void signout() { // 회원 로그아웃 public void logout() { - this.refreshToken = null; this.setStatus(Constant.LOGOUT_STATUS); } diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 3b45589..74a348f 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -64,7 +64,7 @@ public PostUserRes signupCustomer(Long userIdx, PostCustomerReq postCustomerReq) String accessToken = authService.createAccessToken(userIdx); String refreshToken = authService.createRefreshToken(userIdx); - user.signup(postCustomerReq.getNickname(), refreshToken, Role.CUSTOMER, postCustomerReq.getProfileImg()); + user.signup(postCustomerReq.getNickname(),Role.CUSTOMER, postCustomerReq.getProfileImg()); userRepository.save(user); return new PostUserRes(accessToken, refreshToken, user.getRole()); From b187229b940ab0a4f203d63d151240c7627b1fda Mon Sep 17 00:00:00 2001 From: sojungpp Date: Sat, 4 Mar 2023 20:52:02 +0900 Subject: [PATCH 36/55] =?UTF-8?q?#8=20feat:=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20api=20redis=20=EC=9D=B4=EC=9A=A9=ED=95=9C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EA=B4=80=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/common/BaseResponseStatus.java | 8 +++--- .../keki/user/service/AuthService.java | 27 ++++++++++++++++++- .../keki/user/service/UserService.java | 4 +-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java index f1a2b02..c659a27 100644 --- a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java +++ b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java @@ -14,11 +14,12 @@ public enum BaseResponseStatus { * 2000: Request 오류 */ // users(2000~2099) - NULL_TOKEN(false, 2000, "토큰 값을 입력해주세요."), + NULL_TOKEN(false, 2000, "토큰 값을 입력해주세요."), NULL_EMAIL(false, 2001, "이메일을 입력해주세요."), NULL_PROVIDER(false, 2002, "소셜 이름을 입력해주세요."), INVALID_PROVIDER(false, 2003, "잘못된 소셜 이름입니다."), - ALREADY_WITHDRAW_USER(false, 2003, "이미 삭제된 회원입니다."), + ALREADY_WITHDRAW_USER(false, 2004, "이미 삭제된 회원입니다."), + INVALID_TOKEN(false, 2005, "유효하지 않은 토큰 값입니다."), // stores(2100~2199) NULL_ADDRESS(false, 2100, "주소를 입력해주세요."), @@ -68,8 +69,7 @@ public enum BaseResponseStatus { INVALID_EMAIL(false, 3002, "존재하지 않는 이메일입니다."), NO_STORE_ROLE(false, 3003, "판매자가 아닙니다."), INVALID_USER_STATUS(false, 3004, "비활성화된 사용자입니다."), - INVALID_TOKEN(false, 3005, "잘못된 토큰 값입니다."), - EXPIRED_TOKEN(false, 3006, "만료된 토큰 값입니다."), + EXPIRED_TOKEN(false, 3005, "만료된 토큰 값입니다."), // stores(3100~3199) INVALID_STORE_IDX(false, 3100, "존재하지 않는 스토어입니다."), diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index 5627445..b12bbf7 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -62,9 +62,10 @@ public Long getUserIdx() throws BaseException{ } // 토큰 추출 - private static String getToken() { + private String getToken() throws BaseException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); String token = request.getHeader(REQUEST_HEADER_NAME); + if(redisTemplate.opsForValue().get(token)!=null) throw new BaseException(INVALID_TOKEN); return token; } @@ -115,4 +116,28 @@ public String validateRefreshToken(Long userIdx, String refreshTokenReq) throws if(!refreshToken.equals(refreshTokenReq)) throw new BaseException(INVALID_TOKEN); return refreshToken; } + + // refreshToken 삭제 + public void deleteToken(Long userIdx) { + String key = String.valueOf(userIdx); + if(redisTemplate.opsForValue().get(key)!=null) redisTemplate.delete(key); + } + + public Long getExpiration(String token) { + token = token.replaceAll(TOKEN_REGEX, TOKEN_REPLACEMENT); + Date expiration = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody().getExpiration(); + long now = (new Date()).getTime(); + return (expiration.getTime() - now); + } + + public void logout(Long userIdx) throws BaseException { + String token = getToken(); + deleteToken(userIdx); + Long expiration = getExpiration(token); + registerBlackList(token, expiration); + } + + private void registerBlackList(String token, Long expiration) { + redisTemplate.opsForValue().set(token, "logout", Duration.ofMillis(expiration)); + } } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index 74a348f..cf95fb3 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -64,7 +64,7 @@ public PostUserRes signupCustomer(Long userIdx, PostCustomerReq postCustomerReq) String accessToken = authService.createAccessToken(userIdx); String refreshToken = authService.createRefreshToken(userIdx); - user.signup(postCustomerReq.getNickname(),Role.CUSTOMER, postCustomerReq.getProfileImg()); + user.signup(postCustomerReq.getNickname(), Role.CUSTOMER, postCustomerReq.getProfileImg()); userRepository.save(user); return new PostUserRes(accessToken, refreshToken, user.getRole()); @@ -120,8 +120,8 @@ public void signout(Long userIdx) throws BaseException { public void logout(Long userIdx) throws BaseException { try{ User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + authService.logout(userIdx); user.logout(); - // TODO redis 사용해 토큰 관리 } catch (BaseException e) { throw e; } catch (Exception e) { From a6d110917b2ad1f4c845e0e1ada9a3603a3f0309 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Sat, 4 Mar 2023 20:59:35 +0900 Subject: [PATCH 37/55] =?UTF-8?q?#8=20refactor:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20api=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/user/service/AuthService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index b12bbf7..6cb70b1 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -5,6 +5,7 @@ import com.codepatissier.keki.common.BaseException; +import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.user.dto.PostUserRes; import io.jsonwebtoken.*; @@ -117,12 +118,21 @@ public String validateRefreshToken(Long userIdx, String refreshTokenReq) throws return refreshToken; } + // 회원 로그아웃 + public void logout(Long userIdx) throws BaseException { + deleteToken(userIdx); + String token = getToken(); + Long expiration = getExpiration(token); + registerBlackList(token, expiration); + } + // refreshToken 삭제 public void deleteToken(Long userIdx) { String key = String.valueOf(userIdx); if(redisTemplate.opsForValue().get(key)!=null) redisTemplate.delete(key); } + // 토큰 유효시간 구하기 public Long getExpiration(String token) { token = token.replaceAll(TOKEN_REGEX, TOKEN_REPLACEMENT); Date expiration = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody().getExpiration(); @@ -130,14 +140,8 @@ public Long getExpiration(String token) { return (expiration.getTime() - now); } - public void logout(Long userIdx) throws BaseException { - String token = getToken(); - deleteToken(userIdx); - Long expiration = getExpiration(token); - registerBlackList(token, expiration); - } - + // blacklist로 등록 private void registerBlackList(String token, Long expiration) { - redisTemplate.opsForValue().set(token, "logout", Duration.ofMillis(expiration)); + redisTemplate.opsForValue().set(token, Constant.LOGOUT_STATUS, Duration.ofMillis(expiration)); } } \ No newline at end of file From 4dc78a3a700eb073699d047c46b4f8b01d36e172 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Sat, 4 Mar 2023 22:37:35 +0900 Subject: [PATCH 38/55] =?UTF-8?q?#8=20feat:=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=20api=20=ED=86=A0=ED=81=B0=20=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/user/controller/UserController.java | 1 + .../java/com/codepatissier/keki/user/entity/User.java | 10 ++++------ .../codepatissier/keki/user/service/AuthService.java | 11 +++++++++++ .../codepatissier/keki/user/service/UserService.java | 5 ++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/user/controller/UserController.java b/src/main/java/com/codepatissier/keki/user/controller/UserController.java index aa377a4..45019ca 100644 --- a/src/main/java/com/codepatissier/keki/user/controller/UserController.java +++ b/src/main/java/com/codepatissier/keki/user/controller/UserController.java @@ -8,6 +8,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import com.codepatissier.keki.user.service.AuthService; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpSession; diff --git a/src/main/java/com/codepatissier/keki/user/entity/User.java b/src/main/java/com/codepatissier/keki/user/entity/User.java index 8f72ad9..17470e6 100644 --- a/src/main/java/com/codepatissier/keki/user/entity/User.java +++ b/src/main/java/com/codepatissier/keki/user/entity/User.java @@ -78,16 +78,14 @@ public void setProfileImg(String profileImg) { public void setNickname(String nickname) { this.nickname = nickname; } + public void setRole(Role role) {this.role = role;} // 회원 탈퇴 public void signout() { - this.nickname = "알 수 없음"; - this.email = "anonymous@keki.store"; - this.provider = Provider.ANONYMOUS; - this.profileImg = null; - this.role = Role.ANONYMOUS; + this.setNickname("알 수 없음"); + this.setProfileImg(null); + this.setRole(Role.ANONYMOUS); this.setStatus(Constant.INACTIVE_STATUS); - // TODO status enum으로 변경 } // 회원 로그아웃 diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index 6cb70b1..d255287 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -144,4 +144,15 @@ public Long getExpiration(String token) { private void registerBlackList(String token, Long expiration) { redisTemplate.opsForValue().set(token, Constant.LOGOUT_STATUS, Duration.ofMillis(expiration)); } + + private void registerSignout(String token, Long expiration) { + redisTemplate.opsForValue().set(token, Constant.INACTIVE_STATUS, Duration.ofMillis(expiration)); + } + + public void signout(Long userIdx) throws BaseException { + deleteToken(userIdx); + String token = getToken(); + Long expiration = getExpiration(token); + registerBlackList(token, expiration); + } } \ No newline at end of file diff --git a/src/main/java/com/codepatissier/keki/user/service/UserService.java b/src/main/java/com/codepatissier/keki/user/service/UserService.java index cf95fb3..bbfe8e9 100644 --- a/src/main/java/com/codepatissier/keki/user/service/UserService.java +++ b/src/main/java/com/codepatissier/keki/user/service/UserService.java @@ -4,7 +4,6 @@ import com.codepatissier.keki.common.BaseResponseStatus; import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.common.Role; -import com.codepatissier.keki.store.repository.StoreRepository; import com.codepatissier.keki.user.dto.*; import com.codepatissier.keki.user.entity.Provider; import com.codepatissier.keki.user.entity.User; @@ -102,12 +101,12 @@ public void modifyProfile(Long userIdx, PatchProfileReq patchProfileReq) throws } // 회원 탈퇴 - @Transactional + @Transactional(rollbackFor = Exception.class) public void signout(Long userIdx) throws BaseException { try{ User user = userRepository.findByUserIdxAndStatusEquals(userIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); userRepository.delete(user); - // TODO redis 사용해 토큰 관리 + authService.signout(userIdx); } catch (BaseException e) { throw e; } catch (Exception e) { From 0684307cf27c7b75efe5a6e58e379489716d8037 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Sat, 4 Mar 2023 22:49:15 +0900 Subject: [PATCH 39/55] =?UTF-8?q?#8=20refactor:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=ED=83=88=ED=87=B4=20api=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/common/BaseResponseStatus.java | 2 +- .../keki/user/service/AuthService.java | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java index c659a27..afcccdd 100644 --- a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java +++ b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java @@ -18,7 +18,7 @@ public enum BaseResponseStatus { NULL_EMAIL(false, 2001, "이메일을 입력해주세요."), NULL_PROVIDER(false, 2002, "소셜 이름을 입력해주세요."), INVALID_PROVIDER(false, 2003, "잘못된 소셜 이름입니다."), - ALREADY_WITHDRAW_USER(false, 2004, "이미 삭제된 회원입니다."), + ALREADY_WITHDRAW_USER(false, 2004, "이미 탈퇴한 회원입니다."), INVALID_TOKEN(false, 2005, "유효하지 않은 토큰 값입니다."), // stores(2100~2199) diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index d255287..83452f2 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -122,8 +122,14 @@ public String validateRefreshToken(Long userIdx, String refreshTokenReq) throws public void logout(Long userIdx) throws BaseException { deleteToken(userIdx); String token = getToken(); - Long expiration = getExpiration(token); - registerBlackList(token, expiration); + registerBlackList(token, Constant.LOGOUT_STATUS); + } + + // 회원 탈퇴 + public void signout(Long userIdx) throws BaseException { + deleteToken(userIdx); + String token = getToken(); + registerBlackList(token, Constant.INACTIVE_STATUS); } // refreshToken 삭제 @@ -132,27 +138,14 @@ public void deleteToken(Long userIdx) { if(redisTemplate.opsForValue().get(key)!=null) redisTemplate.delete(key); } - // 토큰 유효시간 구하기 - public Long getExpiration(String token) { + // 유효한 토큰 blacklist로 등록 + private void registerBlackList(String token, String status) { token = token.replaceAll(TOKEN_REGEX, TOKEN_REPLACEMENT); - Date expiration = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody().getExpiration(); + Date AccessTokenExpiration = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody().getExpiration(); long now = (new Date()).getTime(); - return (expiration.getTime() - now); - } - // blacklist로 등록 - private void registerBlackList(String token, Long expiration) { - redisTemplate.opsForValue().set(token, Constant.LOGOUT_STATUS, Duration.ofMillis(expiration)); + Long expiration = AccessTokenExpiration.getTime() - now; + redisTemplate.opsForValue().set(token, status, Duration.ofMillis(expiration)); } - private void registerSignout(String token, Long expiration) { - redisTemplate.opsForValue().set(token, Constant.INACTIVE_STATUS, Duration.ofMillis(expiration)); - } - - public void signout(Long userIdx) throws BaseException { - deleteToken(userIdx); - String token = getToken(); - Long expiration = getExpiration(token); - registerBlackList(token, expiration); - } } \ No newline at end of file From 61ef29363f497711ccdd962b4a240465269bb5c4 Mon Sep 17 00:00:00 2001 From: sojungpp Date: Sat, 4 Mar 2023 22:56:34 +0900 Subject: [PATCH 40/55] =?UTF-8?q?#8=20feat:=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/common/BaseResponseStatus.java | 3 +++ .../java/com/codepatissier/keki/user/service/AuthService.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java index afcccdd..c865cde 100644 --- a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java +++ b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java @@ -20,6 +20,9 @@ public enum BaseResponseStatus { INVALID_PROVIDER(false, 2003, "잘못된 소셜 이름입니다."), ALREADY_WITHDRAW_USER(false, 2004, "이미 탈퇴한 회원입니다."), INVALID_TOKEN(false, 2005, "유효하지 않은 토큰 값입니다."), + UNSUPPORTED_TOKEN(false, 2006, "잘못된 형식의 토큰 값입니다."), + MALFORMED_TOKEN(false, 2007, "잘못된 구조의 토큰 값입니다."), + // stores(2100~2199) NULL_ADDRESS(false, 2100, "주소를 입력해주세요."), diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index 83452f2..65cd0f0 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -79,6 +79,10 @@ public Jws getClaims(String token) throws BaseException{ .parseClaimsJws(token); } catch (ExpiredJwtException expiredJwtException) { throw new BaseException(EXPIRED_TOKEN); + } catch (MalformedJwtException malformedJwtException) { + throw new BaseException(MALFORMED_TOKEN); + } catch (UnsupportedJwtException unsupportedJwtException) { + throw new BaseException(UNSUPPORTED_TOKEN); } catch (Exception e) { throw new BaseException(INVALID_TOKEN); } From 6d084426b1b25876e0317f2df583581ded27c8a4 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Sun, 5 Mar 2023 17:11:50 +0900 Subject: [PATCH 41/55] =?UTF-8?q?#7=20fix:=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/dessert/service/DessertService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java index 8da5ca2..2b79f34 100644 --- a/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java +++ b/src/main/java/com/codepatissier/keki/dessert/service/DessertService.java @@ -21,7 +21,6 @@ import static com.codepatissier.keki.common.BaseResponseStatus.*; import static com.codepatissier.keki.common.Constant.ACTIVE_STATUS; -import static com.codepatissier.keki.common.Constant.INACTIVE_STATUS; @Service @RequiredArgsConstructor @@ -142,7 +141,7 @@ public void addDessert(Long userIdx, PostDessertReq postDessertReq) throws BaseE public void deleteDessert(Long userIdx, Long dessertIdx) throws BaseException { try { checkStore(userIdx); - dessertRepository.findByDessertIdxAndStatus(dessertIdx, INACTIVE_STATUS).orElseThrow(() -> new BaseException(DELETED_DESSERT)); + dessertRepository.findByDessertIdxAndStatus(dessertIdx, ACTIVE_STATUS).orElseThrow(() -> new BaseException(DELETED_DESSERT)); dessertRepository.deleteById(dessertIdx); } catch (BaseException e) { throw e; From 282c718ba97fd596b6033d38f7746a9af86aa35e Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 19:02:32 +0900 Subject: [PATCH 42/55] =?UTF-8?q?#161=20rename:=20Tag=20=ED=8F=B4=EB=8D=94?= =?UTF-8?q?=EB=AA=85=20=EC=86=8C=EB=AC=B8=EC=9E=90=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/codepatissier/keki/calendar/entity/CalendarTag.java | 2 +- .../repository/CalendarTag/CalendarTagRepository.java | 2 +- .../repository/CalendarTag/CalendarTagRepositoryImpl.java | 3 +-- .../codepatissier/keki/calendar/service/CalendarService.java | 4 ++-- .../java/com/codepatissier/keki/common/{Tag => tag}/Tag.java | 2 +- .../keki/common/{Tag => tag}/TagRepository.java | 2 +- .../java/com/codepatissier/keki/post/entity/PostTag.java | 2 +- .../codepatissier/keki/post/repository/PostTagCustom.java | 2 +- .../keki/post/repository/PostTagRepository.java | 2 +- .../keki/post/repository/PostTagRepositoryImpl.java | 2 +- .../com/codepatissier/keki/post/service/PostService.java | 5 ++--- 11 files changed, 13 insertions(+), 15 deletions(-) rename src/main/java/com/codepatissier/keki/common/{Tag => tag}/Tag.java (92%) rename src/main/java/com/codepatissier/keki/common/{Tag => tag}/TagRepository.java (87%) diff --git a/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java b/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java index 7156b90..83098f5 100644 --- a/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java +++ b/src/main/java/com/codepatissier/keki/calendar/entity/CalendarTag.java @@ -1,7 +1,7 @@ package com.codepatissier.keki.calendar.entity; import com.codepatissier.keki.common.BaseEntity; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.common.tag.Tag; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java index 90b2ed7..855a7cc 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java @@ -3,7 +3,7 @@ import com.codepatissier.keki.calendar.entity.Calendar; import com.codepatissier.keki.calendar.entity.CalendarTag; import com.codepatissier.keki.user.entity.User; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.common.tag.Tag; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; diff --git a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java index 3c2efee..9d22983 100644 --- a/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java +++ b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepositoryImpl.java @@ -2,7 +2,6 @@ import com.codepatissier.keki.calendar.dto.PopularTagRes; import com.codepatissier.keki.calendar.dto.QPopularTagRes; -import com.codepatissier.keki.calendar.entity.Calendar; import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.user.entity.User; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -12,7 +11,7 @@ import static com.codepatissier.keki.calendar.entity.QCalendar.calendar; import static com.codepatissier.keki.calendar.entity.QCalendarTag.calendarTag; -import static com.codepatissier.keki.common.Tag.QTag.tag; +import static com.codepatissier.keki.common.tag.QTag.tag; import static com.codepatissier.keki.user.entity.QUser.user; @RequiredArgsConstructor diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index 31902f8..f7761e4 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -10,8 +10,8 @@ import com.codepatissier.keki.common.BaseException; import com.codepatissier.keki.common.BaseResponseStatus; import com.codepatissier.keki.common.Constant; -import com.codepatissier.keki.common.Tag.Tag; -import com.codepatissier.keki.common.Tag.TagRepository; +import com.codepatissier.keki.common.tag.Tag; +import com.codepatissier.keki.common.tag.TagRepository; import com.codepatissier.keki.user.entity.User; import com.codepatissier.keki.user.repository.UserRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/codepatissier/keki/common/Tag/Tag.java b/src/main/java/com/codepatissier/keki/common/tag/Tag.java similarity index 92% rename from src/main/java/com/codepatissier/keki/common/Tag/Tag.java rename to src/main/java/com/codepatissier/keki/common/tag/Tag.java index cc3204c..bcb9f8a 100644 --- a/src/main/java/com/codepatissier/keki/common/Tag/Tag.java +++ b/src/main/java/com/codepatissier/keki/common/tag/Tag.java @@ -1,4 +1,4 @@ -package com.codepatissier.keki.common.Tag; +package com.codepatissier.keki.common.tag; import com.codepatissier.keki.common.BaseEntity; import lombok.Builder; diff --git a/src/main/java/com/codepatissier/keki/common/Tag/TagRepository.java b/src/main/java/com/codepatissier/keki/common/tag/TagRepository.java similarity index 87% rename from src/main/java/com/codepatissier/keki/common/Tag/TagRepository.java rename to src/main/java/com/codepatissier/keki/common/tag/TagRepository.java index ae5006e..30604ab 100644 --- a/src/main/java/com/codepatissier/keki/common/Tag/TagRepository.java +++ b/src/main/java/com/codepatissier/keki/common/tag/TagRepository.java @@ -1,4 +1,4 @@ -package com.codepatissier.keki.common.Tag; +package com.codepatissier.keki.common.tag; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/com/codepatissier/keki/post/entity/PostTag.java b/src/main/java/com/codepatissier/keki/post/entity/PostTag.java index 75b65ae..fa4b8a7 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/PostTag.java +++ b/src/main/java/com/codepatissier/keki/post/entity/PostTag.java @@ -1,7 +1,7 @@ package com.codepatissier.keki.post.entity; import com.codepatissier.keki.common.BaseEntity; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.common.tag.Tag; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostTagCustom.java b/src/main/java/com/codepatissier/keki/post/repository/PostTagCustom.java index cc89c5f..b14c774 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostTagCustom.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostTagCustom.java @@ -1,6 +1,6 @@ package com.codepatissier.keki.post.repository; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.common.tag.Tag; import com.codepatissier.keki.post.entity.Post; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostTagRepository.java b/src/main/java/com/codepatissier/keki/post/repository/PostTagRepository.java index 2947c6f..7698fc9 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostTagRepository.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostTagRepository.java @@ -1,6 +1,6 @@ package com.codepatissier.keki.post.repository; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.common.tag.Tag; import com.codepatissier.keki.post.entity.Post; import com.codepatissier.keki.post.entity.PostTag; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/codepatissier/keki/post/repository/PostTagRepositoryImpl.java b/src/main/java/com/codepatissier/keki/post/repository/PostTagRepositoryImpl.java index 0e5304e..e59df33 100644 --- a/src/main/java/com/codepatissier/keki/post/repository/PostTagRepositoryImpl.java +++ b/src/main/java/com/codepatissier/keki/post/repository/PostTagRepositoryImpl.java @@ -1,6 +1,6 @@ package com.codepatissier.keki.post.repository; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.common.tag.Tag; import com.codepatissier.keki.post.entity.Post; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; diff --git a/src/main/java/com/codepatissier/keki/post/service/PostService.java b/src/main/java/com/codepatissier/keki/post/service/PostService.java index fcc1b5e..1fbaefc 100644 --- a/src/main/java/com/codepatissier/keki/post/service/PostService.java +++ b/src/main/java/com/codepatissier/keki/post/service/PostService.java @@ -1,11 +1,10 @@ package com.codepatissier.keki.post.service; -import com.codepatissier.keki.calendar.dto.TagRes; import com.codepatissier.keki.common.BaseException; import com.codepatissier.keki.common.Constant; import com.codepatissier.keki.common.Role; -import com.codepatissier.keki.common.Tag.Tag; -import com.codepatissier.keki.common.Tag.TagRepository; +import com.codepatissier.keki.common.tag.Tag; +import com.codepatissier.keki.common.tag.TagRepository; import com.codepatissier.keki.dessert.entity.Dessert; import com.codepatissier.keki.dessert.repository.DessertRepository; import com.codepatissier.keki.history.entity.PostHistory; From 71b0d6b647cbe0078170107402894ad831f1bbf7 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 19:35:40 +0900 Subject: [PATCH 43/55] =?UTF-8?q?#161=20feat:=20=EC=A3=BC=EB=AC=B8=20MVC?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/dessert/entity/Option.java | 28 +++++++ .../order/controller/OrderController.java | 15 ++++ .../keki/order/entity/OptionOrder.java | 26 +++++++ .../keki/order/entity/Order.java | 78 +++++++++++++++++++ .../keki/order/entity/OrderImg.java | 24 ++++++ .../order/repository/OrderRepository.java | 9 +++ .../keki/order/service/OrderService.java | 9 +++ 7 files changed, 189 insertions(+) create mode 100644 src/main/java/com/codepatissier/keki/dessert/entity/Option.java create mode 100644 src/main/java/com/codepatissier/keki/order/controller/OrderController.java create mode 100644 src/main/java/com/codepatissier/keki/order/entity/OptionOrder.java create mode 100644 src/main/java/com/codepatissier/keki/order/entity/Order.java create mode 100644 src/main/java/com/codepatissier/keki/order/entity/OrderImg.java create mode 100644 src/main/java/com/codepatissier/keki/order/repository/OrderRepository.java create mode 100644 src/main/java/com/codepatissier/keki/order/service/OrderService.java diff --git a/src/main/java/com/codepatissier/keki/dessert/entity/Option.java b/src/main/java/com/codepatissier/keki/dessert/entity/Option.java new file mode 100644 index 0000000..795f7eb --- /dev/null +++ b/src/main/java/com/codepatissier/keki/dessert/entity/Option.java @@ -0,0 +1,28 @@ +package com.codepatissier.keki.dessert.entity; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; + +@Table(name = "options") +@Getter +@Entity +@NoArgsConstructor +@DynamicInsert +public class Option { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long optionIdx; + + @ManyToOne + @JoinColumn(nullable = false, name = "dessertIdx") + private Dessert dessert; + + @Column(nullable = false, length = 100) + private String description; + + @Column(nullable = false) + private int price; +} diff --git a/src/main/java/com/codepatissier/keki/order/controller/OrderController.java b/src/main/java/com/codepatissier/keki/order/controller/OrderController.java new file mode 100644 index 0000000..2c413c5 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/order/controller/OrderController.java @@ -0,0 +1,15 @@ +package com.codepatissier.keki.order.controller; + +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@SecurityRequirement(name = "Bearer") +@Tag(name = "orders", description = "주문 API") +@RestController +@RequestMapping(value = "/orders") +@RequiredArgsConstructor +public class OrderController { +} diff --git a/src/main/java/com/codepatissier/keki/order/entity/OptionOrder.java b/src/main/java/com/codepatissier/keki/order/entity/OptionOrder.java new file mode 100644 index 0000000..3defbb2 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/order/entity/OptionOrder.java @@ -0,0 +1,26 @@ +package com.codepatissier.keki.order.entity; + +import com.codepatissier.keki.dessert.entity.Option; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor +@DynamicInsert +public class OptionOrder { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long optionOrderIdx; + + @ManyToOne + @JoinColumn(nullable = false, name = "orderIdx") + private Order order; + + @ManyToOne + @JoinColumn(nullable = false, name = "optionIdx") + private Option option; +} diff --git a/src/main/java/com/codepatissier/keki/order/entity/Order.java b/src/main/java/com/codepatissier/keki/order/entity/Order.java new file mode 100644 index 0000000..b80da01 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/order/entity/Order.java @@ -0,0 +1,78 @@ +package com.codepatissier.keki.order.entity; + +import com.codepatissier.keki.dessert.entity.Dessert; +import com.codepatissier.keki.store.entity.Store; +import com.codepatissier.keki.user.entity.User; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Table(name = "orders") +@Getter +@Entity +@NoArgsConstructor +@DynamicInsert +public class Order { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long orderIdx; + + @ManyToOne + @JoinColumn(nullable = false, name = "userIdx") + private User user; + + @ManyToOne + @JoinColumn(nullable = false, name = "storeIdx") + private Store store; + + @ManyToOne + @JoinColumn(nullable = false, name = "dessertIdx") + private Dessert dessert; + + @Column(nullable = false) + private LocalDateTime pickupDate; + + @Column(nullable = false, length = 30) + private String customerName; + + @Column(nullable = false, length = 12) + private String customerPhone; + + @Column(columnDefinition = "varchar(20) default 'waiting'") + private String orderStatus; + + @Column(nullable = false) + private int extraPrice; + + @Column(nullable = false) + private int totalPrice; + + @Column(nullable = false, length = 500) + private String request; + + @OneToMany(fetch = FetchType.EAGER, mappedBy = "order", orphanRemoval = true) + private List options = new ArrayList<>(); + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "order", orphanRemoval = true) + private List imgs = new ArrayList<>(); + + @Builder + public Order(User user, Store store, Dessert dessert, LocalDateTime pickupDate, String customerName, String customerPhone, int extraPrice, int totalPrice, String request) { + this.user = user; + this.store = store; + this.dessert = dessert; + this.pickupDate = pickupDate; + this.customerName = customerName; + this.customerPhone = customerPhone; + this.extraPrice = extraPrice; + this.totalPrice = totalPrice; + this.request = request; + } + +} diff --git a/src/main/java/com/codepatissier/keki/order/entity/OrderImg.java b/src/main/java/com/codepatissier/keki/order/entity/OrderImg.java new file mode 100644 index 0000000..8885ee7 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/order/entity/OrderImg.java @@ -0,0 +1,24 @@ +package com.codepatissier.keki.order.entity; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; + +@Getter +@Entity +@NoArgsConstructor +@DynamicInsert +public class OrderImg { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long orderImgIdx; + + @ManyToOne + @JoinColumn(nullable = false, name = "orderIdx") + private Order order; + + @Column(nullable = false, length = 300) + private String imgUrl; +} diff --git a/src/main/java/com/codepatissier/keki/order/repository/OrderRepository.java b/src/main/java/com/codepatissier/keki/order/repository/OrderRepository.java new file mode 100644 index 0000000..4c204a5 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/order/repository/OrderRepository.java @@ -0,0 +1,9 @@ +package com.codepatissier.keki.order.repository; + +import com.codepatissier.keki.order.entity.Order; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface OrderRepository extends JpaRepository { +} diff --git a/src/main/java/com/codepatissier/keki/order/service/OrderService.java b/src/main/java/com/codepatissier/keki/order/service/OrderService.java new file mode 100644 index 0000000..e5fccfb --- /dev/null +++ b/src/main/java/com/codepatissier/keki/order/service/OrderService.java @@ -0,0 +1,9 @@ +package com.codepatissier.keki.order.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OrderService { +} From 8d38beb7c3dccb022b9bb31ec09c97f75068993a Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 20:18:35 +0900 Subject: [PATCH 44/55] =?UTF-8?q?#161=20feat:=20OrderStatus=20Enum=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/order/entity/Order.java | 6 +++-- .../keki/post/entity/OrderStatus.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java diff --git a/src/main/java/com/codepatissier/keki/order/entity/Order.java b/src/main/java/com/codepatissier/keki/order/entity/Order.java index b80da01..2eabd49 100644 --- a/src/main/java/com/codepatissier/keki/order/entity/Order.java +++ b/src/main/java/com/codepatissier/keki/order/entity/Order.java @@ -1,6 +1,7 @@ package com.codepatissier.keki.order.entity; import com.codepatissier.keki.dessert.entity.Dessert; +import com.codepatissier.keki.post.entity.OrderStatus; import com.codepatissier.keki.store.entity.Store; import com.codepatissier.keki.user.entity.User; import lombok.Builder; @@ -44,8 +45,9 @@ public class Order { @Column(nullable = false, length = 12) private String customerPhone; - @Column(columnDefinition = "varchar(20) default 'waiting'") - private String orderStatus; + @Enumerated(EnumType.STRING) + @Column(columnDefinition = "varchar(20) default 'order_waiting'") + private OrderStatus orderStatus; @Column(nullable = false) private int extraPrice; diff --git a/src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java b/src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java new file mode 100644 index 0000000..28f4e23 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java @@ -0,0 +1,27 @@ +package com.codepatissier.keki.post.entity; + +import lombok.Getter; + +import java.util.Arrays; + +@Getter +public enum OrderStatus { + ORDER_WAITING(1, "주문대기"), + PROGRESSING(2, "제작중"), + PICKUP_WAITING(3, "픽업대기"), + COMPLETED(4, "픽업완료"), + CANCEL(5, "주문취소"); + + private int number; + private String name; + OrderStatus(int number, String name){ + this.number = number; + this.name = name; + } + + public static OrderStatus getOrderStatusByName(String name){ + return Arrays.stream(OrderStatus.values()) + .filter(r -> r.getName().equals(name)) + .findAny().orElse(null); + } +} From 175f998f7c578c3490f10a68574a7dbbeb047d07 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 20:21:38 +0900 Subject: [PATCH 45/55] =?UTF-8?q?#161=20rename:=20OrderStatus=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=9C=84=EC=B9=98=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/codepatissier/keki/order/entity/Order.java | 1 - .../codepatissier/keki/{post => order}/entity/OrderStatus.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) rename src/main/java/com/codepatissier/keki/{post => order}/entity/OrderStatus.java (93%) diff --git a/src/main/java/com/codepatissier/keki/order/entity/Order.java b/src/main/java/com/codepatissier/keki/order/entity/Order.java index 2eabd49..c814469 100644 --- a/src/main/java/com/codepatissier/keki/order/entity/Order.java +++ b/src/main/java/com/codepatissier/keki/order/entity/Order.java @@ -1,7 +1,6 @@ package com.codepatissier.keki.order.entity; import com.codepatissier.keki.dessert.entity.Dessert; -import com.codepatissier.keki.post.entity.OrderStatus; import com.codepatissier.keki.store.entity.Store; import com.codepatissier.keki.user.entity.User; import lombok.Builder; diff --git a/src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java b/src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java similarity index 93% rename from src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java rename to src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java index 28f4e23..64d4284 100644 --- a/src/main/java/com/codepatissier/keki/post/entity/OrderStatus.java +++ b/src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java @@ -1,4 +1,4 @@ -package com.codepatissier.keki.post.entity; +package com.codepatissier.keki.order.entity; import lombok.Getter; From bcd74112017deb8f914e4e5015176801cf630ead Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 20:51:03 +0900 Subject: [PATCH 46/55] =?UTF-8?q?#161=20style:=20orderStatus=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=EA=B0=92=20=EB=8C=80=EB=AC=B8=EC=9E=90=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/codepatissier/keki/order/entity/Order.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/order/entity/Order.java b/src/main/java/com/codepatissier/keki/order/entity/Order.java index c814469..e086c28 100644 --- a/src/main/java/com/codepatissier/keki/order/entity/Order.java +++ b/src/main/java/com/codepatissier/keki/order/entity/Order.java @@ -45,7 +45,7 @@ public class Order { private String customerPhone; @Enumerated(EnumType.STRING) - @Column(columnDefinition = "varchar(20) default 'order_waiting'") + @Column(columnDefinition = "varchar(20) default 'ORDER_WAITING'") private OrderStatus orderStatus; @Column(nullable = false) From 93876ecead35104a3c648418dfc80a93593271d4 Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 23:32:23 +0900 Subject: [PATCH 47/55] =?UTF-8?q?#161=20fix:=20=EC=A3=BC=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=20=ED=95=B8=EB=93=9C=ED=8F=B0=EB=B2=88=ED=98=B8=20=EA=B8=B8?= =?UTF-8?q?=EC=9D=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/codepatissier/keki/order/entity/Order.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/order/entity/Order.java b/src/main/java/com/codepatissier/keki/order/entity/Order.java index e086c28..86402fb 100644 --- a/src/main/java/com/codepatissier/keki/order/entity/Order.java +++ b/src/main/java/com/codepatissier/keki/order/entity/Order.java @@ -41,7 +41,7 @@ public class Order { @Column(nullable = false, length = 30) private String customerName; - @Column(nullable = false, length = 12) + @Column(nullable = false, length = 20) private String customerPhone; @Enumerated(EnumType.STRING) From f461f04dd424d8b34edfa2f6b22e3e24bef025ac Mon Sep 17 00:00:00 2001 From: psyeon1120 Date: Sun, 5 Mar 2023 23:33:47 +0900 Subject: [PATCH 48/55] =?UTF-8?q?#161=20rename:=20OrderStatus=20=EB=8B=A8?= =?UTF-8?q?=EC=96=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codepatissier/keki/order/entity/OrderStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java b/src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java index 64d4284..9337a31 100644 --- a/src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java +++ b/src/main/java/com/codepatissier/keki/order/entity/OrderStatus.java @@ -10,7 +10,7 @@ public enum OrderStatus { PROGRESSING(2, "제작중"), PICKUP_WAITING(3, "픽업대기"), COMPLETED(4, "픽업완료"), - CANCEL(5, "주문취소"); + CANCELED(5, "주문취소"); private int number; private String name; From e587f211afdb097a2274cb003c3baccd1e5d1ef7 Mon Sep 17 00:00:00 2001 From: chaerlo127 Date: Mon, 6 Mar 2023 01:44:46 +0900 Subject: [PATCH 49/55] =?UTF-8?q?#11=20fix:=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20500=20=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/calendar/service/CalendarService.java | 18 +++++++++++------- .../keki/user/service/AuthService.java | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java index f7761e4..0b589d6 100644 --- a/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java +++ b/src/main/java/com/codepatissier/keki/calendar/service/CalendarService.java @@ -269,14 +269,18 @@ public HomeRes getHomeCalendarAndPostLogout() throws BaseException{ // home api public HomeRes getHomeTagPost(HomeRes home) throws BaseException{ try{ - List tags = this.calendarTagRepository.findByCalendarAndStatus(home.getCalendar(), ACTIVE_STATUS).stream() - .map(cal -> new PopularTagRes(cal.getTag().getTagIdx(), cal.getTag().getTagName())).collect(Collectors.toList()); - // 기념일의 태그가 3개 미만이면 다 랜덤으로 불러오고 - if(tags.size()==0){ - home.setHomeTagResList(this.getPostByTag(this.calendarTagRepository.getPopularCalendarTag())); - }else{ // 태그가 3개 이상이면 태그별로 랜덤하게 불러오기 - home.setHomeTagResList(this.getPostByTag(tags)); + if(home.getCalendar() == null) home.setHomeTagResList(this.getPostByTag(this.calendarTagRepository.getPopularCalendarTag())); + else{ + List tags = this.calendarTagRepository.findByCalendarAndStatus(home.getCalendar(), ACTIVE_STATUS).stream() + .map(cal -> new PopularTagRes(cal.getTag().getTagIdx(), cal.getTag().getTagName())).collect(Collectors.toList()); + // 기념일의 태그가 3개 미만이면 다 랜덤으로 불러오고 + if(tags.size()==0){ + home.setHomeTagResList(this.getPostByTag(this.calendarTagRepository.getPopularCalendarTag())); + }else{ // 태그가 3개 이상이면 태그별로 랜덤하게 불러오기 + home.setHomeTagResList(this.getPostByTag(tags)); + } } + return home; }catch (Exception e){ throw new BaseException(BaseResponseStatus.DATABASE_ERROR); diff --git a/src/main/java/com/codepatissier/keki/user/service/AuthService.java b/src/main/java/com/codepatissier/keki/user/service/AuthService.java index 65cd0f0..f64ced4 100644 --- a/src/main/java/com/codepatissier/keki/user/service/AuthService.java +++ b/src/main/java/com/codepatissier/keki/user/service/AuthService.java @@ -66,6 +66,7 @@ public Long getUserIdx() throws BaseException{ private String getToken() throws BaseException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); String token = request.getHeader(REQUEST_HEADER_NAME); + if (token == null) return null; if(redisTemplate.opsForValue().get(token)!=null) throw new BaseException(INVALID_TOKEN); return token; } From d4d6e9d77dcacb4f663708b0e758243b7e3f4d4b Mon Sep 17 00:00:00 2001 From: joonghyun Date: Mon, 6 Mar 2023 20:56:39 +0900 Subject: [PATCH 50/55] =?UTF-8?q?#7=20feat:=20=EC=83=81=ED=92=88=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=EC=97=90=20?= =?UTF-8?q?=EB=94=94=EC=9E=90=EC=9D=B8=20=EC=9A=94=EA=B8=88=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keki/dessert/dto/GetDessertRes.java | 9 +++++++++ .../codepatissier/keki/dessert/entity/Option.java | 5 +++-- .../keki/dessert/repository/OptionRepository.java | 13 +++++++++++++ .../keki/dessert/service/DessertService.java | 13 +++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/codepatissier/keki/dessert/repository/OptionRepository.java diff --git a/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java b/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java index 8ea4f63..7024170 100644 --- a/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java +++ b/src/main/java/com/codepatissier/keki/dessert/dto/GetDessertRes.java @@ -16,6 +16,7 @@ public class GetDessertRes { private Integer dessertPrice; private String dessertDescription; private List images; + private List