Skip to content

Commit

Permalink
Merge pull request #190 from Kek-i/develop
Browse files Browse the repository at this point in the history
[Update] 1차 및 2차 최종 업데이트
  • Loading branch information
sojungpp authored Mar 20, 2023
2 parents 03fbf40 + f0f2712 commit 940f897
Show file tree
Hide file tree
Showing 74 changed files with 912 additions and 527 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
application-oauth.properties
application-redis.properties
HELP.md
.gradle
build/
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,9 +29,9 @@ public class CalendarController {
@PostMapping("")
public BaseResponse<String> 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);
Expand All @@ -43,7 +42,7 @@ public BaseResponse<String> createCalendar(@RequestBody CalendarReq calendarReq)

// 캘린더 수정
@ResponseBody
@PatchMapping("/{calendarIdx}/edit")
@PatchMapping("/{calendarIdx}")
public BaseResponse<String> modifyCalendar(@RequestBody CalendarReq calendarReq, @PathVariable("calendarIdx") Long calendarIdx){
try{
this.calendarService.modifyCalendar(this.authService.getUserIdx(), calendarReq, calendarIdx);
Expand All @@ -56,7 +55,7 @@ public BaseResponse<String> modifyCalendar(@RequestBody CalendarReq calendarReq,
// 캘린더 수정 조회
@ResponseBody
@GetMapping("/{calendarIdx}/edit")
public BaseResponse<CalendarRes> getEditCalendar(@PathVariable("calendarIdx") Long calendarIdx){
public BaseResponse<CalendarEditRes> getEditCalendar(@PathVariable("calendarIdx") Long calendarIdx){
try{
return new BaseResponse<>(this.calendarService.getEditCalendar(this.authService.getUserIdx(), calendarIdx));
}catch (BaseException e){
Expand All @@ -66,7 +65,7 @@ public BaseResponse<CalendarRes> getEditCalendar(@PathVariable("calendarIdx") Lo

// 캘린더 삭제
@ResponseBody
@PatchMapping("/{calendarIdx}")
@DeleteMapping("/{calendarIdx}")
public BaseResponse<String> deleteCalendar(@PathVariable("calendarIdx") Long calendarIdx){
try{
this.calendarService.deleteCalendar(calendarIdx, this.authService.getUserIdx());
Expand Down Expand Up @@ -119,8 +118,8 @@ public BaseResponse<HomeRes> 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());
Expand All @@ -132,7 +131,7 @@ public BaseResponse<HomeRes> getHome(){
@PostMapping("/categories")
public BaseResponse<String> 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){
Expand All @@ -145,7 +144,7 @@ public BaseResponse<String> createTag(@RequestBody CalendarHashTag tag){
@PatchMapping("/categories")
public BaseResponse<String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<CalendarHashTag> hashTags;
private List<CalendarHashTag> addHashTags;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,4 +19,6 @@ public class HomeRes {
private String calendarTitle;
private int calendarDate;
private List<HomeTagRes> homeTagResList;
@JsonIgnore
private Calendar calendar;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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.*;

@Getter
@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface CalendarRepository extends JpaRepository<Calendar, Long> , Cale
List<Calendar> findByUserAndStatus(User user, String status);
Optional<Calendar> findByCalendarIdxAndStatus(Long calendarIdx, String status);
List<Calendar> findByUserAndCalendarCategoryAndStatus(User user, CalendarCategory calendarCategory, String status);

void deleteByUser(User user);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CalendarTag, Long>, CalendarTagCustom{
List<CalendarTag> findByCalendarAndStatus(Calendar calendar, String activeStatus);
List<CalendarTag> findByCalendarUserAndStatus(User user, String status);
CalendarTag findByCalendarAndTag(Calendar calendar, Tag byTagName);
void deleteByCalendar(Calendar calendar);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +35,7 @@ public List<PopularTagRes> getPopularCalendarTag() {

/**
* 사용자 별 인기 Tag 3개
* 다음에 쓸수 있으니, 혹시 몰라서 지우지 않고 남겨둘게요!
*/
@Override
public List<PopularTagRes> getPopularCalendarTagByUser(User userEntity) {
Expand All @@ -45,9 +46,11 @@ public List<PopularTagRes> 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();
}

}
Loading

0 comments on commit 940f897

Please sign in to comment.