diff --git a/build.gradle b/build.gradle index 2dc2605..beb208e 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,9 @@ dependencies { //validation implementation 'org.springframework.boot:spring-boot-starter-validation' + //envers + implementation 'org.springframework.data:spring-data-envers' + } tasks.named('test') { diff --git a/src/main/java/com/umc/commonplant/domain/calendar/controller/CalendarController.java b/src/main/java/com/umc/commonplant/domain/calendar/controller/CalendarController.java new file mode 100644 index 0000000..37acf38 --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/calendar/controller/CalendarController.java @@ -0,0 +1,80 @@ +package com.umc.commonplant.domain.calendar.controller; + +import com.umc.commonplant.domain.Jwt.JwtService; +import com.umc.commonplant.domain.calendar.dto.CalendarDto; +import com.umc.commonplant.domain.calendar.service.CalendarService; +import com.umc.commonplant.domain.memo.dto.MemoDto; +import com.umc.commonplant.domain.place.dto.PlaceDto; +import com.umc.commonplant.domain.plant.dto.PlantDto; +import com.umc.commonplant.domain.user.entity.User; +import com.umc.commonplant.domain.user.service.UserService; +import com.umc.commonplant.global.dto.JsonResponse; +import io.swagger.v3.core.util.Json; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Slf4j +@RequestMapping("/calendar") +@RequiredArgsConstructor +@RestController +public class CalendarController { + + private final CalendarService calendarService; + private final JwtService jwtService; + private final UserService userService; + + @GetMapping + public ResponseEntity getCalendarByDate(@RequestParam("year") String year, + @RequestParam("month") String month, + @RequestParam("day") String day) { + + return ResponseEntity.ok(new JsonResponse(true, 200, "getCalendarByDate", null)); + } + + @GetMapping("/monthly") + public ResponseEntity getCalendarByMonth(@RequestParam("year") String year, + @RequestParam("month") String month) { + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + CalendarDto.getMyCalendarRes monthlyCalendar = calendarService.getMyCalendar(user, year, month); + + return ResponseEntity.ok(new JsonResponse(true, 200, "getCalendarByMonth", monthlyCalendar)); + } + + @GetMapping("/place") + public ResponseEntity getCalendarByPlace() { + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + List placeList = calendarService.getPlaceNameListByUser(user); + + return ResponseEntity.ok(new JsonResponse(true, 200, "getPlaceList", placeList)); + } + + @GetMapping("/place/plant") + public ResponseEntity getCalendarByPlaceAndPlant(@RequestParam("code") String code) { + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + List plantList = calendarService.getPlantListByPlace(user, code); + + return ResponseEntity.ok(new JsonResponse(true, 200, "getPlantList", plantList)); + } + + @GetMapping("/place/plant/memo") + public ResponseEntity getCalendarByPlaceAndPlantAndMemo(@RequestParam("code") String code, + @RequestParam("plant") Long plantIdx) { + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + List memoList = calendarService.getAllMemoByPlant(plantIdx); + + return ResponseEntity.ok(new JsonResponse(true, 200, "getMemoList", memoList)); + } + +} diff --git a/src/main/java/com/umc/commonplant/domain/calendar/dto/CalendarDto.java b/src/main/java/com/umc/commonplant/domain/calendar/dto/CalendarDto.java new file mode 100644 index 0000000..631e36f --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/calendar/dto/CalendarDto.java @@ -0,0 +1,107 @@ +package com.umc.commonplant.domain.calendar.dto; + +import com.umc.commonplant.domain.plant.entity.Plant; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.List; + +public class CalendarDto { + + /** + * 최종 My Calendar Response + */ + @NoArgsConstructor + @Getter + public static class getMyCalendarRes{ + private String year; + private String month; + + private List dateList; + + @Builder + public getMyCalendarRes(String year, String month, List dateList) { + this.year = year; + this.month = month; + this.dateList = dateList; + } + } + + /** + * 날짜 별로 불러오는 My Calendar 정보 + */ + @NoArgsConstructor + @Getter + public static class getMyCalendarEventRes { + private int parsedDate; +// @JsonFormat(pattern = "yyyy.MM.dd") +// private LocalDateTime date; + + private boolean nextWatered; + private boolean prevWatered; + private boolean joinPlant; + private boolean writeMemo; + + @Builder + public getMyCalendarEventRes(int parsedDate, boolean nextWatered, boolean prevWatered, + boolean joinPlant, boolean writeMemo) { + this.parsedDate = parsedDate; + this.nextWatered = nextWatered; + this.prevWatered = prevWatered; + this.joinPlant = joinPlant; + this.writeMemo = writeMemo; + } + } + + /** + * My Calendar에 보여줄 Place 리스트 + */ + @AllArgsConstructor + @NoArgsConstructor + @Getter + public static class getMyCalendarPlaceListRes{ + private String name; + } + + /** + * My Calendar에 보여줄 Plant 리스트 + */ + @AllArgsConstructor + @NoArgsConstructor + @Getter + public static class getMyCalendarPlantListRes{ + private String plantName; + private String nickname; + private String imgUrl; + + @Builder + public getMyCalendarPlantListRes(Plant plant){ + this.plantName = plant.getPlantName(); + this.nickname = plant.getNickname(); + this.imgUrl = plant.getImgUrl(); + } + } + + /** + * My Calendar에 보여줄 Memo 리스트 + */ + @NoArgsConstructor + @Getter + public static class getMyCalendarMemoRes { + private Long memo_idx; + private String content; + private String imgUrl; + private String writer; + private LocalDateTime created_at; + + @Builder + public getMyCalendarMemoRes(Long memo_idx, String content, String imgUrl, String writer, LocalDateTime created_at) { + this.memo_idx = memo_idx; + this.content = content; + this.imgUrl = imgUrl; + this.writer = writer; + this.created_at = created_at; + } + } + +} diff --git a/src/main/java/com/umc/commonplant/domain/calendar/service/CalendarService.java b/src/main/java/com/umc/commonplant/domain/calendar/service/CalendarService.java new file mode 100644 index 0000000..2badf70 --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/calendar/service/CalendarService.java @@ -0,0 +1,309 @@ +package com.umc.commonplant.domain.calendar.service; + +import com.umc.commonplant.domain.belong.entity.BelongRepository; +import com.umc.commonplant.domain.calendar.dto.CalendarDto; +import com.umc.commonplant.domain.memo.dto.MemoDto; +import com.umc.commonplant.domain.memo.entity.Memo; +import com.umc.commonplant.domain.memo.entity.MemoRepository; +import com.umc.commonplant.domain.memo.service.MemoService; +import com.umc.commonplant.domain.place.entity.Place; +import com.umc.commonplant.domain.place.entity.PlaceRepository; +import com.umc.commonplant.domain.place.service.PlaceService; +import com.umc.commonplant.domain.plant.dto.PlantDto; +import com.umc.commonplant.domain.plant.entity.Plant; +import com.umc.commonplant.domain.plant.entity.PlantRepository; +import com.umc.commonplant.domain.plant.service.PlantService; +import com.umc.commonplant.domain.user.entity.User; +import com.umc.commonplant.global.exception.BadRequestException; +import com.umc.commonplant.global.exception.ErrorResponseStatus; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.query.AuditEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.YearMonth; +import java.util.*; +import java.util.stream.Collectors; + +@Slf4j +@RequiredArgsConstructor +@Service +public class CalendarService { + + private final PlaceRepository placeRepository; + private final PlantRepository plantRepository; + private final MemoRepository memoRepository; + private final BelongRepository belongRepository; + + private final PlaceService placeService; + private final PlantService plantService; + private final MemoService memoService; + + private final AuditReader auditReader; + + private List getWateredDateByPlantIdx(Long plantIdx) { + List wateredDateHistory = auditReader.createQuery() + .forRevisionsOfEntity(Plant.class, false, true) + .add(AuditEntity.id().eq(plantIdx)) + //.add(AuditEntity.property("wateredDate").hasChanged()) + .addProjection(AuditEntity.property("wateredDate")) + .getResultList(); + + return wateredDateHistory; + } + + private List getLastWateredDateByPlantIdx(Long plantIdx) { + List lastWateredDate = auditReader.createQuery() + .forRevisionsOfEntity(Plant.class, false, true) + .add(AuditEntity.id().eq(plantIdx)) + .addProjection(AuditEntity.property("wateredDate")) + .addOrder(AuditEntity.revisionNumber().desc()) + .setMaxResults(1) + .getResultList(); + + return lastWateredDate; + } + + @Transactional(readOnly = true) + public CalendarDto.getMyCalendarRes getMyCalendar(User user, String year, String month){ + int parsedYear = Integer.parseInt(year); + int parsedMonth = Integer.parseInt(month); + + if(parsedMonth < 1 || parsedMonth > 12) { + throw new BadRequestException(ErrorResponseStatus.INVALID_MONTH_VALUE); + } + + YearMonth yearMonth = YearMonth.of(parsedYear, parsedMonth); + + int lengthOfMonth = yearMonth.lengthOfMonth(); + LocalDate startDate = yearMonth.atDay(1); + LocalDate endDate = yearMonth.atEndOfMonth(); + + LocalDateTime firstDate = startDate.atStartOfDay(); + LocalDateTime lastDate = endDate.atTime(LocalTime.MAX); + + // TODO: 유저가 속한 장소 리스트 + List placeListByUser = placeService.getPlaceListByUser(user); + List myCalendarPlantList = new ArrayList<>(); + + for(Place place : placeListByUser) { + String placeCode = place.getCode(); + myCalendarPlantList.addAll(plantService.getPlantListByPlace(user, placeCode)); + } + + // TODO: 날짜 정보 별로 각 Repo에 boolean으로 접근해서 정보 설정 + // TODO: 식물을 처음 데려온 날 + // List createdAtOfPlantList = plantRepository.getDateListOfPlant(firstDate, lastDate); + List joinPlantList = new ArrayList<>(Collections.nCopies(lengthOfMonth + 1, false)); + List createdAtOfPlantList = new ArrayList<>(); + List memoList = new ArrayList<>(); + + for(PlantDto.getMyCalendarPlantListRes plantOfPlace : myCalendarPlantList) { + Long plantIdx = plantOfPlace.getPlantIdx(); + + Plant plant = plantRepository.findByPlantIdx(plantIdx) + .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT));; + + LocalDateTime createdAt = plant.getCreatedAt(); + createdAtOfPlantList.add(createdAt); + + List memoOfPlantList = memoService.getAllMemoByPlant(plantIdx); + memoList.addAll(memoOfPlantList); + } + + for (LocalDateTime createdAt : createdAtOfPlantList) { + YearMonth joinPlantYearMonth = YearMonth.from(createdAt); + int date = createdAt.toLocalDate().getDayOfMonth(); + + if (joinPlantYearMonth.equals(yearMonth)) { + joinPlantList.set(date, true); + } + } + + // TODO: 물을 준 날 + List wateredDateOfPlantList = new ArrayList<>(); + + List lastWateredDateofPlantList = new ArrayList<>(); + List waterCycleOfPlantList = new ArrayList<>(); + + for(PlantDto.getMyCalendarPlantListRes plantOfPlace: myCalendarPlantList) { + Long plantIdx = plantOfPlace.getPlantIdx(); + + Plant plant = plantRepository.findByPlantIdx(plantIdx) + .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT));; + + List wateredDateRevisionList = getWateredDateByPlantIdx(plantIdx); + wateredDateOfPlantList.addAll(wateredDateRevisionList); + + List lastWateredDateRevisionList = getLastWateredDateByPlantIdx(plantIdx); + lastWateredDateofPlantList.addAll(lastWateredDateRevisionList); + + waterCycleOfPlantList.add(plant.getWaterCycle()); + } + + List prevWateredList = new ArrayList<>(Collections.nCopies(lengthOfMonth + 1, false)); + List nextWateredList = new ArrayList<>(Collections.nCopies(lengthOfMonth + 1, false)); + List nextWateredDateList = new ArrayList<>(); + + for(LocalDateTime prevWatered : wateredDateOfPlantList) { + YearMonth prevWateredYearMonth = YearMonth.from(prevWatered); + int date = prevWatered.toLocalDate().getDayOfMonth(); + + if(prevWateredYearMonth.equals(yearMonth)) { + prevWateredList.set(date, true); + } + } + + for(int i = 0; i < lastWateredDateofPlantList.size(); i++) { + LocalDateTime nextWatered = lastWateredDateofPlantList.get(i); + Calendar calendar = Calendar.getInstance(); + // calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)); + Date lastWateredDate = Timestamp.valueOf(nextWatered); + calendar.setTime(lastWateredDate); + + Calendar limit = Calendar.getInstance(); + limit.add(Calendar.MONTH, 2); + limit.set(Calendar.DAY_OF_MONTH, limit.getActualMaximum(Calendar.DAY_OF_MONTH)); + // limit.add(Calendar.MONTH, 2); + + int waterCycle = waterCycleOfPlantList.get(i); + + while(calendar.before(limit)) { + calendar.add(Calendar.DAY_OF_MONTH, waterCycle); + + if(calendar.before(limit)) { + Date tempDate = calendar.getTime(); + LocalDateTime tempLDTime = new Timestamp(tempDate.getTime()).toLocalDateTime(); + nextWateredDateList.add(tempLDTime); + } + } + + } + + for(LocalDateTime nextWatered : nextWateredDateList) { + YearMonth nextWateredYearMonth = YearMonth.from(nextWatered); + int date = nextWatered.toLocalDate().getDayOfMonth(); + + if(nextWateredYearMonth.equals(yearMonth)) { + nextWateredList.set(date, true); + } + } + + // TODO: 메모 있는 날 + List writeMemoList = new ArrayList<>(Collections.nCopies(lengthOfMonth + 1, false)); + List createdDateOfMemoList = new ArrayList<>(); + + for(MemoDto.GetAllMemo memo : memoList) { + LocalDateTime writeMemo = memo.getCreated_at(); + + createdDateOfMemoList.add(writeMemo); + } + + for(LocalDateTime writeMemo : createdDateOfMemoList) { + YearMonth writeMemoYearMonth = YearMonth.from(writeMemo); + int date = writeMemo.toLocalDate().getDayOfMonth(); + + if(writeMemoYearMonth.equals(yearMonth)) { + writeMemoList.set(date, true); + } + } + + // TODO: 월 정보 반환 + List getMyCalendarEventList = new ArrayList<>(); + + for(int parsedDate = 1; parsedDate <= lengthOfMonth; parsedDate++){ + CalendarDto.getMyCalendarEventRes getMyCalendarEventRes = CalendarDto.getMyCalendarEventRes.builder() + .parsedDate(parsedDate) + .joinPlant(joinPlantList.get(parsedDate)) + .prevWatered(prevWateredList.get(parsedDate)) + .nextWatered(nextWateredList.get(parsedDate)) + .writeMemo(writeMemoList.get(parsedDate)) + .build(); + + getMyCalendarEventList.add(getMyCalendarEventRes); + } + + CalendarDto.getMyCalendarRes getMyCalendarRes = CalendarDto.getMyCalendarRes.builder() + .year(year) + .month(month) + .dateList(getMyCalendarEventList) + .build(); + + return getMyCalendarRes; + } + + @Transactional(readOnly = true) + public List getPlaceNameListByUser(User user){ + List placeList = belongRepository.getPlaceListByUser(user.getUuid()); + + List placeNameList = new ArrayList<>(); + for(Place p: placeList){ + CalendarDto.getMyCalendarPlaceListRes placeName = new CalendarDto.getMyCalendarPlaceListRes(p.getName()); + placeNameList.add(placeName); + } + + return placeNameList; + } + + @Transactional(readOnly = true) + public List getPlantListByPlace(User user, String placeCode){ + Place plantPlace = placeService.getPlaceByCode(placeCode); + + List plants = plantRepository.findAllByPlace(plantPlace); + + List plantList = new ArrayList<>(); + + for(Plant plant: plants){ + plantList.add(new CalendarDto.getMyCalendarPlantListRes(plant)); + } + + return plantList; + } + + @Transactional(readOnly = true) + public List getAllMemoByPlant(Long plantIdx) { + List existingMemo = memoRepository.findByPlantIdx(plantIdx); + List sortedMemos = existingMemo.stream() + .sorted(Comparator.comparing(Memo::getCreatedAt).reversed()) + .collect(Collectors.toList()); + + List memoResponseList = new ArrayList<>(); + + for(Memo memo : sortedMemos) { + CalendarDto.getMyCalendarMemoRes getMemoRes = CalendarDto.getMyCalendarMemoRes.builder() + .memo_idx(memo.getMemoIdx()) + .content(memo.getContent()) + .imgUrl(memo.getUser().getImgUrl()) + .writer(memo.getUser().getName()) + .created_at(memo.getCreatedAt()) + .build(); + + memoResponseList.add(getMemoRes); + } + + return memoResponseList; + } + +// // TODO: 날짜 별 식물 불러오기 +// +// @Transactional(readOnly = true) +// public List getMyCalendarPlaceList(User user) { +// return placeService.getPlaceNameListByUser(user); +// } +// +// @Transactional(readOnly = true) +// public List getMyCalendarPlantList(User user, String placeCode) { +// return plantService.getPlantListByPlace(user, placeCode); +// } +// +// @Transactional(readOnly = true) +// public List getMyCalendarMemoList(Long plantIdx){ +// return memoService.getAllMemoByPlant(plantIdx); +// } +} diff --git a/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java b/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java index 4263da8..3fdaf86 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java +++ b/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java @@ -93,7 +93,7 @@ public static class getPlantRes{ } /** - * Main Page, My Calendar에 보여줄 Plant 리스트 + * Main Page에 보여줄 Plant 리스트 */ @AllArgsConstructor @NoArgsConstructor @@ -145,6 +145,27 @@ public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMem } } + /** + * My Calendar에 보여줄 Plant 리스트 + */ + @AllArgsConstructor + @NoArgsConstructor + @Getter + public static class getMyCalendarPlantListRes{ + private Long plantIdx; + private String plantName; + private String nickname; + private String imgUrl; + + @Builder + public getMyCalendarPlantListRes(Plant plant){ + this.plantIdx = plant.getPlantIdx(); + this.plantName = plant.getPlantName(); + this.nickname = plant.getNickname(); + this.imgUrl = plant.getImgUrl(); + } + } + @AllArgsConstructor @NoArgsConstructor @Data diff --git a/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java b/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java index ed6cce0..0fca92e 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java +++ b/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; +import org.hibernate.envers.Audited; import javax.persistence.*; import java.time.LocalDateTime; @@ -34,6 +35,7 @@ public class Plant extends BaseTime { @Column(nullable = false) private String imgUrl; private int waterCycle; + @Audited private LocalDateTime wateredDate; @Builder diff --git a/src/main/java/com/umc/commonplant/domain/plant/entity/PlantRepository.java b/src/main/java/com/umc/commonplant/domain/plant/entity/PlantRepository.java index 2220d7c..76c2576 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/entity/PlantRepository.java +++ b/src/main/java/com/umc/commonplant/domain/plant/entity/PlantRepository.java @@ -4,8 +4,10 @@ import com.umc.commonplant.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -20,4 +22,10 @@ public interface PlantRepository extends JpaRepository { List findAllByPlace(Place place); String countPlantsByPlace(Place place); + + @Query("SELECT DISTINCT p.createdAt FROM Plant p " + + "WHERE p.createdAt BETWEEN :firstDate AND :lastDate " + + "ORDER BY p.createdAt ASC ") + List getDateListOfPlant(@Param("firstDate") LocalDateTime firstDate, @Param("lastDate") LocalDateTime lastDate); + } diff --git a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java index 22dd247..2b36151 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java +++ b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java @@ -343,6 +343,22 @@ public List getMyGardenPlantList(String placeC return plantList; } + @Transactional(readOnly = true) + public List getPlantListByPlace(User user, String placeCode){ + + Place plantPlace = placeService.getPlaceByCode(placeCode); + + List plants = plantRepository.findAllByPlace(plantPlace); + + List plantList = new ArrayList<>(); + + for(Plant plant: plants){ + plantList.add(new PlantDto.getMyCalendarPlantListRes(plant)); + } + + return plantList; + } + /** * updatePlant: 식물 수정 * @param user diff --git a/src/main/java/com/umc/commonplant/domain/revision/entity/RevisionHistory.java b/src/main/java/com/umc/commonplant/domain/revision/entity/RevisionHistory.java new file mode 100644 index 0000000..e3130c1 --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/revision/entity/RevisionHistory.java @@ -0,0 +1,32 @@ +package com.umc.commonplant.domain.revision.entity; + +import com.umc.commonplant.domain.BaseTime; +import lombok.Getter; +import org.hibernate.envers.RevisionEntity; +import org.hibernate.envers.RevisionNumber; +import org.hibernate.envers.RevisionTimestamp; + +import javax.persistence.*; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; + +@Getter +@Table(name = "RevisionHistory") +@Entity +@RevisionEntity +public class RevisionHistory extends BaseTime { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column @RevisionNumber + private Long revisionId; + + @Column @RevisionTimestamp + private Long revisionTimeStamp; + + public LocalDateTime getRevisionTimeStamp() { + return LocalDateTime.ofInstant(Instant.ofEpochMilli(revisionTimeStamp), ZoneId.systemDefault()); + } + +} + diff --git a/src/main/java/com/umc/commonplant/global/config/DataEnversConfig.java b/src/main/java/com/umc/commonplant/global/config/DataEnversConfig.java new file mode 100644 index 0000000..f2cb298 --- /dev/null +++ b/src/main/java/com/umc/commonplant/global/config/DataEnversConfig.java @@ -0,0 +1,22 @@ +package com.umc.commonplant.global.config; + +import lombok.RequiredArgsConstructor; +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.AuditReaderFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.persistence.EntityManagerFactory; + +@Configuration +@RequiredArgsConstructor +public class DataEnversConfig { + + private final EntityManagerFactory entityManagerFactory; + + @Bean + public AuditReader auditReader() { + return AuditReaderFactory.get(entityManagerFactory.createEntityManager()); + } + +} diff --git a/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java b/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java index 352db69..92dd090 100644 --- a/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java +++ b/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java @@ -58,6 +58,7 @@ public enum ErrorResponseStatus { // 4500 : QnA // 4600 : Calendar + INVALID_MONTH_VALUE(false, 4600, "유효하지 않은 값입니다."), // 4700 : Alarm