From 612f16e87871f7a1ee2375d04299a1151c964b14 Mon Sep 17 00:00:00 2001 From: swandevson Date: Thu, 5 Sep 2024 19:53:18 +0900 Subject: [PATCH 1/5] =?UTF-8?q?:heavy=5Fplus=5Fsign:=20QueryDSL5.0=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- build.gradle | 20 +++++++++++++++++++ .../chattodo/configure/QuerydslConfig.java | 20 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/demo/chattodo/configure/QuerydslConfig.java diff --git a/.gitignore b/.gitignore index 953c3b3..78b6987 100644 --- a/.gitignore +++ b/.gitignore @@ -142,4 +142,6 @@ gradle-app.setting # Java heap dump *.hprof -# End of https://www.toptal.com/developers/gitignore/api/intellij+all,java,gradle \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/intellij+all,java,gradle + +**/main/generated \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8fe15fe..b16768e 100644 --- a/build.gradle +++ b/build.gradle @@ -41,8 +41,28 @@ dependencies { // Database runtimeOnly 'com.h2database:h2' runtimeOnly 'com.mysql:mysql-connector-j' + + // Querydsl + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta' + annotationProcessor 'jakarta.annotation:jakarta.annotation-api' + annotationProcessor 'jakarta.persistence:jakarta.persistence-api' } tasks.named('test') { useJUnitPlatform() } + +def querydslDir = "src/main/generated" + +sourceSets { + main.java.srcDirs += [ querydslDir ] +} + +tasks.withType(JavaCompile).configureEach { + options.getGeneratedSourceOutputDirectory().set(file(querydslDir)) +} + +clean { + delete file(querydslDir) +} \ No newline at end of file diff --git a/src/main/java/com/demo/chattodo/configure/QuerydslConfig.java b/src/main/java/com/demo/chattodo/configure/QuerydslConfig.java new file mode 100644 index 0000000..6837ea3 --- /dev/null +++ b/src/main/java/com/demo/chattodo/configure/QuerydslConfig.java @@ -0,0 +1,20 @@ +package com.demo.chattodo.configure; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + +@Configuration +public class QuerydslConfig { + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} \ No newline at end of file From a300fa267ee00f9262daef4d6b822791cca4903f Mon Sep 17 00:00:00 2001 From: swandevson Date: Thu, 5 Sep 2024 22:01:02 +0900 Subject: [PATCH 2/5] =?UTF-8?q?init.sql=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/init.sql | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 12f02e0..55f8e99 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -42,4 +42,27 @@ VALUES (27, 'c1d2e3f4-g5h6-7890-i1j2-k3l4m5n6o7p8', 'Vendor Meeting', '2024-09-12 14:28:34', '2024-09-12 15:32:01', 'Vendor Room'), (28, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Product Launch', '2024-09-10 09:17:55', '2024-09-10 10:29:18', 'Main Hall'), (29, 'b1c2d3e4-f5g6-7890-h1i2-j3k4l5m6n7o8', 'Team Outing', '2024-09-06 15:43:27', '2024-09-06 17:12:58', 'Outdoor Garden'), - (30, 'c1d2e3f4-g5h6-7890-i1j2-k3l4m5n6o7p8', 'Training Workshop', '2024-09-08 10:50:31', '2024-09-08 12:39:42', 'Training Room'); \ No newline at end of file + (30, 'c1d2e3f4-g5h6-7890-i1j2-k3l4m5n6o7p8', 'Training Workshop', '2024-09-08 10:50:31', '2024-09-08 12:39:42', 'Training Room'); + +-- 시작 시간이 00:00:00인 경우 (3개) +INSERT INTO schedule (id, member_id, title, start_date_time, end_date_time, place) +VALUES + (31, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Early Morning Meeting', '2024-09-15 00:00:00', '2024-09-15 10:30:00', 'Conference Room A'), + (32, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Day-long Workshop', '2024-09-20 00:00:00', '2024-09-20 18:00:00', 'Training Center'), + (33, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Overnight Project Kickoff', '2024-09-25 00:00:00', '2024-09-26 08:00:00', 'Main Office'); + +-- 종료 시간이 23:59:59인 경우 (3개) +INSERT INTO schedule (id, member_id, title, start_date_time, end_date_time, place) +VALUES + (34, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Late Night Coding Session', '2024-09-18 20:00:00', '2024-09-18 23:59:59', 'Development Lab'), + (35, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'End-of-Month Review', '2024-09-30 14:00:00', '2024-09-30 23:59:59', 'Board Room'), + (36, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'International Conference Call', '2024-09-22 22:00:00', '2024-09-22 23:59:59', 'Virtual Meeting Room'); + +-- 9월 1일부터 30일 중 랜덤으로 5개의 일정 추가 +INSERT INTO schedule (id, member_id, title, start_date_time, end_date_time, place) +VALUES + (37, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Quarterly Planning', '2024-09-03 09:30:00', '2024-09-03 12:30:00', 'Strategy Room'), + (38, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Client Lunch Meeting', '2024-09-17 12:00:00', '2024-09-17 14:00:00', 'Fancy Restaurant'), + (39, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Team Building Exercise', '2024-09-24 14:00:00', '2024-09-24 17:00:00', 'City Park'), + (40, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Product Development Review', '2024-09-11 10:00:00', '2024-09-11 11:30:00', 'Innovation Lab'), + (41, 'a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8', 'Annual Performance Evaluation', '2024-09-29 13:00:00', '2024-09-29 16:00:00', 'HR Office'); \ No newline at end of file From fcf5d63b3258ffb21d59a3c3855c5c4b301c558e Mon Sep 17 00:00:00 2001 From: swandevson Date: Thu, 5 Sep 2024 22:04:22 +0900 Subject: [PATCH 3/5] =?UTF-8?q?:sparkles:=20=EB=8B=A4=EC=A4=91=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EA=B2=80=EC=83=89=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/controller/ScheduleController.java | 10 +++ .../domain/dto/request/ScheduleCreateDTO.java | 33 +++++----- .../dto/response/ScheduleInfoResponseDTO.java | 16 +++++ .../domain/repository/ScheduleRepository.java | 6 +- .../repository/ScheduleRepositoryCustom.java | 12 ++++ .../repository/ScheduleRepositoryImpl.java | 61 +++++++++++++++++++ .../domain/service/ScheduleService.java | 25 ++++++++ 7 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/demo/chattodo/domain/dto/response/ScheduleInfoResponseDTO.java create mode 100644 src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java create mode 100644 src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java diff --git a/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java b/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java index 8ed9fc2..7c17a4f 100644 --- a/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java +++ b/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java @@ -18,6 +18,7 @@ import com.demo.chattodo.domain.dto.response.ScheduleCountResponseDTO; +import com.demo.chattodo.domain.dto.response.ScheduleInfoResponseDTO; import com.demo.chattodo.domain.service.ScheduleService; import lombok.RequiredArgsConstructor; @@ -41,6 +42,15 @@ public ResponseEntity createSchedule( @RequestHeader("member_id") String memberId, @RequestBody ScheduleCreateDTO dto) { return ResponseEntity.ok().body(scheduleService.saveSchedule(memberId, dto)); + } + @GetMapping("/search") + public List searchAllByConditions( + @RequestHeader("member_id") String memberId, + @RequestParam(value = "start_date", required = false) LocalDate startDateTime, + @RequestParam(value = "end_date", required = false) LocalDate endDateTime, + @RequestParam(value = "title", required = false) String title, + @RequestParam(value = "place", required = false) String place) { + return scheduleService.searchAllByConditions(memberId, startDateTime, endDateTime, title, place); } } diff --git a/src/main/java/com/demo/chattodo/domain/dto/request/ScheduleCreateDTO.java b/src/main/java/com/demo/chattodo/domain/dto/request/ScheduleCreateDTO.java index fb1a8fc..0033429 100644 --- a/src/main/java/com/demo/chattodo/domain/dto/request/ScheduleCreateDTO.java +++ b/src/main/java/com/demo/chattodo/domain/dto/request/ScheduleCreateDTO.java @@ -1,13 +1,16 @@ package com.demo.chattodo.domain.dto.request; -import com.demo.chattodo.domain.entity.Schedule; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.*; - import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + @Getter @Setter @NoArgsConstructor @@ -15,20 +18,20 @@ @ToString public class ScheduleCreateDTO { - String title; + String title; - @JsonProperty("start_date") - LocalDate startDate; + @JsonProperty("start_date") + LocalDate startDate; - @JsonProperty("start_time") - LocalTime startTime; + @JsonProperty("start_time") + LocalTime startTime; - @JsonProperty("end_date") - LocalDate endDate; + @JsonProperty("end_date") + LocalDate endDate; - @JsonProperty("end_time") - LocalTime endTime; + @JsonProperty("end_time") + LocalTime endTime; - String place; + String place; } diff --git a/src/main/java/com/demo/chattodo/domain/dto/response/ScheduleInfoResponseDTO.java b/src/main/java/com/demo/chattodo/domain/dto/response/ScheduleInfoResponseDTO.java new file mode 100644 index 0000000..94e3875 --- /dev/null +++ b/src/main/java/com/demo/chattodo/domain/dto/response/ScheduleInfoResponseDTO.java @@ -0,0 +1,16 @@ +package com.demo.chattodo.domain.dto.response; + +import java.time.LocalDateTime; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class ScheduleInfoResponseDTO { + private Long id; + private String title; + private LocalDateTime startDateTime; + private LocalDateTime endDateTime; + private String place; +} diff --git a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepository.java b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepository.java index b91462b..d3e48c0 100644 --- a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepository.java +++ b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepository.java @@ -1,6 +1,5 @@ package com.demo.chattodo.domain.repository; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; @@ -10,8 +9,9 @@ import com.demo.chattodo.domain.entity.Schedule; -public interface ScheduleRepository extends JpaRepository { +public interface ScheduleRepository extends JpaRepository, ScheduleRepositoryCustom { // 유저의 일정기간내 모든 일정 가져오기 @Query("SELECT s FROM Schedule s WHERE s.memberId = :memberId AND s.startDateTime >= :startDate AND s.endDateTime < :endDate") - List findAllByDateRangeAndMemberId(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate, @Param("memberId") String memberId); + List findAllByDateRangeAndMemberId(@Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate, @Param("memberId") String memberId); } diff --git a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java new file mode 100644 index 0000000..f336e43 --- /dev/null +++ b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java @@ -0,0 +1,12 @@ +package com.demo.chattodo.domain.repository; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +import com.demo.chattodo.domain.entity.Schedule; + +public interface ScheduleRepositoryCustom { + // 여러 조건들을 통해 일정 가져오기 + List searchAllByConditions(String memberId, LocalDate startDate, LocalDate endDate, String title, String place); +} diff --git a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java new file mode 100644 index 0000000..5a6c009 --- /dev/null +++ b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java @@ -0,0 +1,61 @@ +package com.demo.chattodo.domain.repository; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.demo.chattodo.domain.entity.QSchedule; +import com.demo.chattodo.domain.entity.Schedule; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import lombok.RequiredArgsConstructor; + +@Repository +@RequiredArgsConstructor +public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom { + private final JPAQueryFactory queryFactory; + + // 여러 조건들을 통해 일정 가져오기 + @Override + public List searchAllByConditions(String memberId, LocalDate startDate, LocalDate endDate, String title, + String place) { + QSchedule schedule = QSchedule.schedule; + + BooleanBuilder builder = new BooleanBuilder(); + + // 멤버 ID는 필수 조건 + builder.and(schedule.memberId.eq(memberId)); + + // 시작일시 조건 + if (startDate != null) { + LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.MIN); + builder.and(schedule.startDateTime.goe(startDateTime)); + } + + // 종료일시 조건 + if (endDate != null) { + LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.MAX); + builder.and(schedule.endDateTime.loe(endDateTime)); + } + + // 제목 조건 (부분 일치) + if (title != null && !title.isEmpty()) { + builder.and(schedule.title.containsIgnoreCase(title)); + } + + // 장소 조건 (부분 일치) + if (place != null && !place.isEmpty()) { + builder.and(schedule.place.containsIgnoreCase(place)); + } + + return queryFactory + .selectFrom(schedule) + .where(builder) + .orderBy(schedule.startDateTime.asc()) + .fetch(); + } +} diff --git a/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java b/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java index 531115a..a0b285c 100644 --- a/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java +++ b/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java @@ -9,6 +9,7 @@ import com.demo.chattodo.domain.dto.request.ScheduleCreateDTO; +import com.demo.chattodo.domain.dto.response.ScheduleInfoResponseDTO; import com.demo.chattodo.domain.entity.Schedule; import com.demo.chattodo.domain.utils.DateTimeUtil; @@ -72,4 +73,28 @@ public Long saveSchedule(String memberId, ScheduleCreateDTO dto) { return schedule.getId(); } + + public List searchAllByConditions(String memberId, LocalDate startDate, LocalDate endDate, String title, String place) { + List schedules = scheduleRepository.searchAllByConditions( + memberId, + startDate, + endDate, + title, + place + ); + + List response = new ArrayList<>(); + for (Schedule schedule : schedules) { + response.add(ScheduleInfoResponseDTO.builder() + .id(schedule.getId()) + .title(schedule.getTitle()) + .startDateTime(schedule.getStartDateTime()) + .endDateTime(schedule.getEndDateTime()) + .place(schedule.getPlace()) + .build()); + } + + return response; + } + } From a5930b10fd7e27133593968338ae8b873bddf8c4 Mon Sep 17 00:00:00 2001 From: swandevson Date: Fri, 6 Sep 2024 09:41:41 +0900 Subject: [PATCH 4/5] =?UTF-8?q?:sparkles:=20=EB=82=A0=EC=A7=9C=EB=BF=90?= =?UTF-8?q?=EB=A7=8C=20=EC=95=84=EB=8B=88=EB=9D=BC,=20=EA=B0=81=EA=B0=81?= =?UTF-8?q?=EC=9D=98=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C=EA=B0=84=20=EB=B0=8F?= =?UTF-8?q?=20=EC=A2=85=EB=A3=8C=20=EC=8B=9C=EA=B0=84=EB=8F=84=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/controller/ScheduleController.java | 26 ++++++++++- .../repository/ScheduleRepositoryCustom.java | 4 +- .../repository/ScheduleRepositoryImpl.java | 11 ++--- .../domain/service/ScheduleService.java | 44 +++++++++---------- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java b/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java index 56d9ef8..adc60cd 100644 --- a/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java +++ b/src/main/java/com/demo/chattodo/domain/controller/ScheduleController.java @@ -1,6 +1,8 @@ package com.demo.chattodo.domain.controller; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; import org.springframework.http.ResponseEntity; @@ -73,10 +75,30 @@ public ResponseEntity createSchedule( @GetMapping("/search") public List searchAllByConditions( @RequestHeader("member_id") String memberId, - @RequestParam(value = "start_date", required = false) LocalDate startDateTime, - @RequestParam(value = "end_date", required = false) LocalDate endDateTime, + @RequestParam(value = "start_date", required = false) LocalDate startDate, + @RequestParam(value = "start_time", required = false) LocalTime startTime, + @RequestParam(value = "end_date", required = false) LocalDate endDate, + @RequestParam(value = "end_time", required = false) LocalTime endTime, @RequestParam(value = "title", required = false) String title, @RequestParam(value = "place", required = false) String place) { + + LocalDateTime startDateTime = null; + + if (startDate != null) { + startDateTime = LocalDateTime.of(startDate, LocalTime.MIN); + if (startTime != null) { + startDateTime = LocalDateTime.of(startDate, startTime); + } + } + + LocalDateTime endDateTime = null; + if (endDate != null) { + endDateTime = LocalDateTime.of(endDate, LocalTime.MAX); + if (endTime != null) { + endDateTime = LocalDateTime.of(endDate, endTime); + } + } + return scheduleService.searchAllByConditions(memberId, startDateTime, endDateTime, title, place); } } diff --git a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java index f336e43..ecc9189 100644 --- a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java +++ b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryCustom.java @@ -1,6 +1,5 @@ package com.demo.chattodo.domain.repository; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; @@ -8,5 +7,6 @@ public interface ScheduleRepositoryCustom { // 여러 조건들을 통해 일정 가져오기 - List searchAllByConditions(String memberId, LocalDate startDate, LocalDate endDate, String title, String place); + List searchAllByConditions(String memberId, LocalDateTime startDateTime, LocalDateTime endDateTime, + String title, String place); } diff --git a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java index 5a6c009..6da4439 100644 --- a/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java +++ b/src/main/java/com/demo/chattodo/domain/repository/ScheduleRepositoryImpl.java @@ -1,8 +1,6 @@ package com.demo.chattodo.domain.repository; -import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.List; import org.springframework.stereotype.Repository; @@ -21,7 +19,8 @@ public class ScheduleRepositoryImpl implements ScheduleRepositoryCustom { // 여러 조건들을 통해 일정 가져오기 @Override - public List searchAllByConditions(String memberId, LocalDate startDate, LocalDate endDate, String title, + public List searchAllByConditions(String memberId, LocalDateTime startDateTime, LocalDateTime endDateTime, + String title, String place) { QSchedule schedule = QSchedule.schedule; @@ -31,14 +30,12 @@ public List searchAllByConditions(String memberId, LocalDate startDate builder.and(schedule.memberId.eq(memberId)); // 시작일시 조건 - if (startDate != null) { - LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.MIN); + if (startDateTime != null) { builder.and(schedule.startDateTime.goe(startDateTime)); } // 종료일시 조건 - if (endDate != null) { - LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.MAX); + if (endDateTime != null) { builder.and(schedule.endDateTime.loe(endDateTime)); } diff --git a/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java b/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java index 931f849..a6dcaff 100644 --- a/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java +++ b/src/main/java/com/demo/chattodo/domain/service/ScheduleService.java @@ -1,6 +1,5 @@ package com.demo.chattodo.domain.service; - import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -8,31 +7,27 @@ import java.util.List; import java.util.Optional; - -import com.demo.chattodo.domain.dto.request.ScheduleCreateDTO; -import com.demo.chattodo.domain.dto.response.ScheduleInfoResponseDTO; -import com.demo.chattodo.domain.dto.request.ScheduleUpdateDTO; -import com.demo.chattodo.domain.entity.Schedule; -import com.demo.chattodo.domain.utils.DateTimeUtil; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.demo.chattodo.domain.dto.request.ScheduleCreateDTO; +import com.demo.chattodo.domain.dto.request.ScheduleUpdateDTO; import com.demo.chattodo.domain.dto.response.ScheduleCountResponseDTO; +import com.demo.chattodo.domain.dto.response.ScheduleInfoResponseDTO; +import com.demo.chattodo.domain.entity.Schedule; import com.demo.chattodo.domain.repository.ScheduleRepository; +import com.demo.chattodo.domain.utils.DateTimeUtil; import lombok.RequiredArgsConstructor; - - @Service @Transactional(readOnly = true) @RequiredArgsConstructor public class ScheduleService { private final ScheduleRepository scheduleRepository; - - public List countScheduleOfEachDay(String memberId, LocalDate startDate, LocalDate endDate) { + public List countScheduleOfEachDay(String memberId, LocalDate startDate, + LocalDate endDate) { List schedules = scheduleRepository.findAllByDateRangeAndMemberId( LocalDateTime.of(startDate, LocalTime.MIN), LocalDateTime.of(endDate, LocalTime.MIN).plusDays(1), @@ -64,11 +59,11 @@ public List countScheduleOfEachDay(String memberId, Lo public Long saveSchedule(String memberId, ScheduleCreateDTO dto) { Schedule schedule = new Schedule( - memberId, - dto.getTitle(), - DateTimeUtil.getStartLocalDateTime(dto.getStartDate(), dto.getStartTime()), - DateTimeUtil.getEndLocalDateTime(dto.getEndDate(), dto.getEndTime()), - dto.getPlace() + memberId, + dto.getTitle(), + DateTimeUtil.getStartLocalDateTime(dto.getStartDate(), dto.getStartTime()), + DateTimeUtil.getEndLocalDateTime(dto.getEndDate(), dto.getEndTime()), + dto.getPlace() ); scheduleRepository.save(schedule); @@ -91,17 +86,18 @@ public boolean deleteSchedule(String memberId, Long scheduleId) { @Transactional public void updateSchedule(String memberId, Long scheduleId, ScheduleUpdateDTO dto) { scheduleRepository.findByIdAndMemberId(scheduleId, memberId) - .ifPresent(schedule -> schedule.update(dto.getTitle(), - DateTimeUtil.getStartLocalDateTime(dto.getStartDate(), dto.getStartTime()), - DateTimeUtil.getEndLocalDateTime(dto.getEndDate(), dto.getEndTime()), - dto.getPlace())); + .ifPresent(schedule -> schedule.update(dto.getTitle(), + DateTimeUtil.getStartLocalDateTime(dto.getStartDate(), dto.getStartTime()), + DateTimeUtil.getEndLocalDateTime(dto.getEndDate(), dto.getEndTime()), + dto.getPlace())); } - public List searchAllByConditions(String memberId, LocalDate startDate, LocalDate endDate, String title, String place) { + public List searchAllByConditions(String memberId, LocalDateTime startDateTime, + LocalDateTime endDateTime, String title, String place) { List schedules = scheduleRepository.searchAllByConditions( memberId, - startDate, - endDate, + startDateTime, + endDateTime, title, place ); From a2c0299925f01f848e8a3a0dc99c900f89042b47 Mon Sep 17 00:00:00 2001 From: swandevson Date: Fri, 6 Sep 2024 09:53:32 +0900 Subject: [PATCH 5/5] =?UTF-8?q?:wrench:=20dev=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=EC=84=9C=20JPA=20logging=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 2e7a773..322d862 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -11,10 +11,14 @@ spring: database-platform: org.hibernate.dialect.H2Dialect hibernate: ddl-auto: update + show-sql: true + properties: + hibernate: + format_sql: true sql: init: mode: always schema-locations: classpath:init.sql h2: console: - enabled: true \ No newline at end of file + enabled: true