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/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/calendar/DateCountCategory.java b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java new file mode 100644 index 0000000..e467c1c --- /dev/null +++ b/src/main/java/com/codepatissier/keki/calendar/DateCountCategory.java @@ -0,0 +1,30 @@ +package com.codepatissier.keki.calendar; + +import lombok.Getter; + +@Getter +public enum DateCountCategory { + 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주년"), + TWO_THOUSAND(2000, "2000일"); + private int count; + private String date; + + DateCountCategory(int count, String date){ + this.count = count; + this.date = date; + } +} 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..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); @@ -43,7 +42,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); @@ -56,7 +55,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){ @@ -66,7 +65,7 @@ public BaseResponse getEditCalendar(@PathVariable("calendarIdx") Lo // 캘린더 삭제 @ResponseBody - @PatchMapping("/{calendarIdx}") + @DeleteMapping("/{calendarIdx}") public BaseResponse deleteCalendar(@PathVariable("calendarIdx") Long calendarIdx){ try{ this.calendarService.deleteCalendar(calendarIdx, this.authService.getUserIdx()); @@ -119,8 +118,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()); @@ -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); 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/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/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/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..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,11 +1,12 @@ 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; 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/Calendar/CalendarRepositoryImpl.java b/src/main/java/com/codepatissier/keki/calendar/repository/Calendar/CalendarRepositoryImpl.java index ec62a97..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 @@ -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) + )) .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/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/CalendarTagRepository.java b/src/main/java/com/codepatissier/keki/calendar/repository/CalendarTag/CalendarTagRepository.java index 0554ba2..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 @@ -2,12 +2,15 @@ import com.codepatissier.keki.calendar.entity.Calendar; import com.codepatissier.keki.calendar.entity.CalendarTag; -import com.codepatissier.keki.common.Tag.Tag; +import com.codepatissier.keki.user.entity.User; +import com.codepatissier.keki.common.tag.Tag; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; public interface CalendarTagRepository extends JpaRepository, CalendarTagCustom{ List findByCalendarAndStatus(Calendar calendar, String activeStatus); + List findByCalendarUserAndStatus(User user, String status); CalendarTag findByCalendarAndTag(Calendar calendar, Tag byTagName); + void deleteByCalendar(Calendar calendar); } 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..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 @@ -11,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 @@ -35,6 +35,7 @@ public List getPopularCalendarTag() { /** * 사용자 별 인기 Tag 3개 + * 다음에 쓸수 있으니, 혹시 몰라서 지우지 않고 남겨둘게요! */ @Override public List getPopularCalendarTagByUser(User userEntity) { @@ -45,9 +46,11 @@ 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) .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 1e26add..0b589d6 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; @@ -9,11 +10,12 @@ 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; +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; @@ -90,8 +93,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); } @@ -140,6 +142,16 @@ private int calculateDate(Calendar calendar) { return returnCalendar; } + // 날짜 수 기념일 계산 (100일, 200일, 300일 등등) + // 현재 2000일 미만으로 불러오도록 생성 + private CalendarDateReturn calculateDateForDateCount(Calendar 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); + } + return new CalendarDateReturn(day, null); + } + // 기념일 계산 return String private String calculateDateReturnString(int day){ String returnCalendar; @@ -200,36 +212,54 @@ 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); // 현재 가장 가까운 캘린더 불러오기 - int day = 0; - String title = null; if(calendar != null){ - title = calendar.getCalendarTitle(); - day = (int) Duration.between(calendar.getCalendarDate().atStartOfDay(), LocalDate.now().atStartOfDay()).toDays(); + day = this.calculateDate(calendar); } + List listEYCalendars = this.calendarRepository.findByUserAndCalendarCategoryAndStatus(user, CalendarCategory.EVERY_YEAR, ACTIVE_STATUS); + + // 사용자의 매년 반복 캘린더 불러와서 하나씩 비교해보고, 값이 더 가까우면? 매년 반복으로 홈 화면 기념일 불러오기 - 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); + for(Calendar cal: listEYCalendars){ + int calDay = this.calculateDate(cal); + if(calDay < Math.abs(day)){ + calendar = cal; + day = calDay; } } - return new HomeRes(user.getUserIdx(), user.getNickname(), title, Math.abs(day), null); + // 날짜 수인 경우 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() tags = this.calendarTagRepository.getPopularCalendarTagByUser(user); - // 기념일의 태그가 3개 미만이면 다 랜덤으로 불러오고 - if(tags.size()< Constant.Home.HOME_RETURN_TAG_COUNT){ - 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); @@ -262,8 +296,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 +310,8 @@ public void modifyCalendar(Long userIdx, CalendarReq calendarReq, Long calendarI throw new BaseException(BaseResponseStatus.NULL_CALENDAR_CATEGORY); calendar.setCalendarCategory(CalendarCategory.getCalendarCategoryByName(calendarReq.getKindOfCalendar())); } - + this.calendarTagRepository.deleteByCalendar(calendar); 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); @@ -296,22 +327,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(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())); } @@ -332,19 +352,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() @@ -353,12 +360,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/common/BaseResponseStatus.java b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java index 07a1d55..c865cde 100644 --- a/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java +++ b/src/main/java/com/codepatissier/keki/common/BaseResponseStatus.java @@ -14,14 +14,24 @@ 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, "유효하지 않은 토큰 값입니다."), + UNSUPPORTED_TOKEN(false, 2006, "잘못된 형식의 토큰 값입니다."), + MALFORMED_TOKEN(false, 2007, "잘못된 구조의 토큰 값입니다."), - // stores(2100~2199) + // 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 이상이어야 합니다."), @@ -38,7 +48,11 @@ public enum BaseResponseStatus { INVALID_TAG_NUM(false, 2210, "태그는 1개~3개로 등록해주세요."), // 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, "캘린더 제목을 입력해주세요."), @@ -58,18 +72,10 @@ 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, "존재하지 않는 스토어입니다."), - 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, "존재하지 않는 피드입니다."), @@ -77,10 +83,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/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/config/RedisConfig.java b/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java new file mode 100644 index 0000000..413f5e6 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/config/RedisConfig.java @@ -0,0 +1,38 @@ +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.RedisStandaloneConfiguration; +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; + + @Value("${spring.redis.password}") + private String password; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); + redisStandaloneConfiguration.setHostName(host); + redisStandaloneConfiguration.setPort(port); + redisStandaloneConfiguration.setPassword(password); + return new LettuceConnectionFactory(redisStandaloneConfiguration); + } + + @Bean + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + return redisTemplate; + } +} 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/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..1f10606 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/common/entityListener/PostEntityListener.java @@ -0,0 +1,20 @@ +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; + +import javax.persistence.PreRemove; + +public class PostEntityListener { + + @PreRemove + public void onUpdate(Post post){ + PostLikeRepository postLikeRepository = BeanUtils.getBean(PostLikeRepository.class); + postLikeRepository.deleteByPost(post); + + PostHistoryRepository postHistoryRepository = BeanUtils.getBean(PostHistoryRepository.class); + postHistoryRepository.deleteByPost(post); + } +} \ No newline at end of file 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/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/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/dessert/controller/DessertController.java b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java index 71e0d72..f40603b 100644 --- a/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java +++ b/src/main/java/com/codepatissier/keki/dessert/controller/DessertController.java @@ -45,7 +45,6 @@ public BaseResponse getDessertList(Long storeIdx, @RequestP } catch (BaseException e) { return new BaseResponse<>(e.getStatus()); } - } /** @@ -79,10 +78,10 @@ public BaseResponse addDessert(@Valid @RequestBody PostDessertReq postDe /** * [판매자] 상품 삭제 - * [PATCH] /desserts/:dessertIdx + * [DELETE] /desserts/:dessertIdx */ @ResponseBody - @PatchMapping("/{dessertIdx}") + @DeleteMapping("/{dessertIdx}") public BaseResponse deleteDessert(@PathVariable("dessertIdx") Long dessertIdx) { try { dessertService.deleteDessert(authService.getUserIdx(), dessertIdx); @@ -94,10 +93,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/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/dto/OptionDTO.java b/src/main/java/com/codepatissier/keki/dessert/dto/OptionDTO.java new file mode 100644 index 0000000..79b4280 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/dessert/dto/OptionDTO.java @@ -0,0 +1,13 @@ +package com.codepatissier.keki.dessert.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class OptionDTO { + private String optionDescription; + private Integer optionPrice; +} diff --git a/src/main/java/com/codepatissier/keki/dessert/dto/PostDessertReq.java b/src/main/java/com/codepatissier/keki/dessert/dto/PostDessertReq.java index 4837a86..4ce3135 100644 --- a/src/main/java/com/codepatissier/keki/dessert/dto/PostDessertReq.java +++ b/src/main/java/com/codepatissier/keki/dessert/dto/PostDessertReq.java @@ -1,10 +1,14 @@ package com.codepatissier.keki.dessert.dto; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.PositiveOrZero; +import java.util.List; @Data public class PostDessertReq { @@ -17,4 +21,5 @@ public class PostDessertReq { private String dessertDescription; @NotBlank(message = "디저트 이미지는 필수 항목입니다.") private String dessertImg; + } \ No newline at end of file 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 990d5eb..d7e7955 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.*; @@ -13,6 +15,8 @@ @Entity @NoArgsConstructor @DynamicInsert +@SQLDelete(sql = "UPDATE dessert SET status = 'inactive', last_modified_date = current_timestamp 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/entity/Option.java b/src/main/java/com/codepatissier/keki/dessert/entity/Option.java new file mode 100644 index 0000000..b910bfc --- /dev/null +++ b/src/main/java/com/codepatissier/keki/dessert/entity/Option.java @@ -0,0 +1,38 @@ +package com.codepatissier.keki.dessert.entity; + +import com.codepatissier.keki.common.BaseEntity; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; + +import javax.persistence.*; + +@Table(name = "options") +@Getter +@Entity +@NoArgsConstructor +@DynamicInsert +public class Option extends BaseEntity { + @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 Integer price; + + @Builder + public Option(Dessert dessert, String description, Integer price) { + this.dessert = dessert; + this.description = description; + this.price = price; + } +} 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/dessert/repository/OptionRepository.java b/src/main/java/com/codepatissier/keki/dessert/repository/OptionRepository.java new file mode 100644 index 0000000..af47ef7 --- /dev/null +++ b/src/main/java/com/codepatissier/keki/dessert/repository/OptionRepository.java @@ -0,0 +1,13 @@ +package com.codepatissier.keki.dessert.repository; + +import com.codepatissier.keki.dessert.entity.Dessert; +import com.codepatissier.keki.dessert.entity.Option; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface OptionRepository extends JpaRepository { + List