From d8841583e932629e0533b88016671f03c8709b55 Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 02:35:20 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[PDS-11]=20feat:=ED=9A=8C=EC=9D=98=EC=8B=A4?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API=EC=83=9D?= =?UTF-8?q?=EC=84=B1,exceptionHandler=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 +++ .../global/exception/BaseException.java | 10 ++++ .../global/exception/BaseResponseCode.java | 32 +++++++++++++ .../exception/ExceptionHandlerAdvice.java | 31 +++++++++++++ .../global/response/ResponseCustom.java | 40 ++++++++++++++++ .../office/controller/OfficeController.java | 31 ++++++++++++- .../office/dto/OfficeFacilityRes.java | 20 ++++++++ .../pladialmserver/office/dto/OfficeRes.java | 26 +++++++++++ .../pladialmserver/office/entity/Office.java | 1 + .../repository/OfficeBookingRepository.java | 12 +++++ .../office/repository/OfficeRepository.java | 2 + .../office/service/OfficeService.java | 43 +++++++++++++++++ src/main/resources/application-dev.yml | 44 +++++++++--------- src/main/resources/application-prod.yml | 46 +++++++++---------- 14 files changed, 297 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/example/pladialmserver/global/exception/BaseException.java create mode 100644 src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java create mode 100644 src/main/java/com/example/pladialmserver/global/exception/ExceptionHandlerAdvice.java create mode 100644 src/main/java/com/example/pladialmserver/global/response/ResponseCustom.java create mode 100644 src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java create mode 100644 src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java diff --git a/build.gradle b/build.gradle index 8aacacd2..8ce9ac21 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,8 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.boot:spring-boot-starter-validation' + // mysql runtimeOnly 'com.mysql:mysql-connector-j' @@ -42,3 +44,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + + + + diff --git a/src/main/java/com/example/pladialmserver/global/exception/BaseException.java b/src/main/java/com/example/pladialmserver/global/exception/BaseException.java new file mode 100644 index 00000000..6a2d7f41 --- /dev/null +++ b/src/main/java/com/example/pladialmserver/global/exception/BaseException.java @@ -0,0 +1,10 @@ +package com.example.pladialmserver.global.exception; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class BaseException extends RuntimeException { + private BaseResponseCode baseResponseCode; +} \ No newline at end of file diff --git a/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java b/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java new file mode 100644 index 00000000..3d87fcd2 --- /dev/null +++ b/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java @@ -0,0 +1,32 @@ +package com.example.pladialmserver.global.exception; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +import java.util.Arrays; + + +@Getter +@AllArgsConstructor +public enum BaseResponseCode { + + SUCCESS("S0001", HttpStatus.OK, "요청에 성공했습니다."), + + BAD_REQUEST("G0001", HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), + + //office + OFFICE_NOT_FOUND_DATE_TIME("OF0001", HttpStatus.NOT_FOUND,"날짜나 시간을 모두 입력해주세요"); + + + public final String code; + public final HttpStatus status; + public final String message; + + public static BaseResponseCode findByCode(String code) { + return Arrays.stream(BaseResponseCode.values()) + .filter(b -> b.getCode().equals(code)) + .findAny().orElseThrow(() -> new BaseException(BAD_REQUEST)); + } + +} diff --git a/src/main/java/com/example/pladialmserver/global/exception/ExceptionHandlerAdvice.java b/src/main/java/com/example/pladialmserver/global/exception/ExceptionHandlerAdvice.java new file mode 100644 index 00000000..f5d56782 --- /dev/null +++ b/src/main/java/com/example/pladialmserver/global/exception/ExceptionHandlerAdvice.java @@ -0,0 +1,31 @@ +package com.example.pladialmserver.global.exception; + +import com.example.pladialmserver.global.response.ResponseCustom; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.Objects; + +@RestControllerAdvice +public class ExceptionHandlerAdvice { + @ExceptionHandler(BaseException.class) + protected ResponseEntity handleBaseException(BaseException e) { + BaseResponseCode baseResponseCode = e.getBaseResponseCode(); + return ResponseEntity.status(baseResponseCode.getStatus()) + .body(ResponseCustom.error(baseResponseCode.getStatus().value(), baseResponseCode.getCode(), baseResponseCode.getMessage())); + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MethodArgumentNotValidException.class) + protected ResponseCustom handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + FieldError fieldError = Objects.requireNonNull(e.getFieldError()); + BaseResponseCode baseResponseCode = BaseResponseCode.findByCode(fieldError.getDefaultMessage()); + return ResponseCustom.error(baseResponseCode.getStatus().value(), baseResponseCode.getCode(), baseResponseCode.getMessage()); + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/pladialmserver/global/response/ResponseCustom.java b/src/main/java/com/example/pladialmserver/global/response/ResponseCustom.java new file mode 100644 index 00000000..17354837 --- /dev/null +++ b/src/main/java/com/example/pladialmserver/global/response/ResponseCustom.java @@ -0,0 +1,40 @@ +package com.example.pladialmserver.global.response; + + + +import com.example.pladialmserver.global.exception.BaseResponseCode; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.lang.Nullable; + +@Getter +@RequiredArgsConstructor +@AllArgsConstructor +public class ResponseCustom{ + + private final int status; + + private final String code; + + private final String message; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private T data; + + public static ResponseCustom OK() { + BaseResponseCode baseResponseCode = BaseResponseCode.SUCCESS; + return new ResponseCustom<>(baseResponseCode.getStatus().value(), baseResponseCode.getCode(), baseResponseCode.getMessage()); + } + + public static ResponseCustom OK(@Nullable T data) { + BaseResponseCode baseResponseCode = BaseResponseCode.SUCCESS; + return new ResponseCustom(baseResponseCode.getStatus().value(), baseResponseCode.getCode(), baseResponseCode.getMessage(), data); + } + + public static ResponseCustom error(int status, String code, String message) { + return new ResponseCustom<>(status, code, message); + } + +} diff --git a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java index 1aede785..d45e7a8b 100644 --- a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java +++ b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java @@ -1,10 +1,24 @@ package com.example.pladialmserver.office.controller; +import com.example.pladialmserver.global.exception.BaseException; +import com.example.pladialmserver.global.exception.BaseResponseCode; +import com.example.pladialmserver.global.response.ResponseCustom; +import com.example.pladialmserver.office.dto.OfficeRes; +import com.example.pladialmserver.office.entity.Office; import com.example.pladialmserver.office.service.OfficeService; +import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.apache.coyote.Response; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/offices") @@ -13,13 +27,26 @@ public class OfficeController { private final OfficeService officeService; /** - * 회의실 목록 조회 + * 전체 회의실 목록 조회 and 예약 가능한 회의실 목록 조회 */ - + @GetMapping() + public ResponseCustom> searchOffice( + @RequestParam(required = false ) @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate date, + @RequestParam(required = false) @DateTimeFormat(pattern = "HH:mm:ss") LocalTime startTime, + @RequestParam(required = false) @DateTimeFormat(pattern = "HH:mm:ss") LocalTime endTime + ) + { + // 날짜와 시작 시간 또는 종료 시간 중 하나라도 입력되지 않았다면 에러 반환 + if (date == null || startTime == null || endTime == null) { + throw new BaseException(BaseResponseCode.OFFICE_NOT_FOUND_DATE_TIME); + } + return ResponseCustom.OK(officeService.findAvailableOffices(date, startTime, endTime)); + } /** * 회의실 개별 조회 */ + /** * 회의실 일자별 예약 현황 조회 */ diff --git a/src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java b/src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java new file mode 100644 index 00000000..16cf05cb --- /dev/null +++ b/src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java @@ -0,0 +1,20 @@ +package com.example.pladialmserver.office.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor +@Builder +@AllArgsConstructor +public class OfficeFacilityRes { + private String officeFacility; + + public static OfficeFacilityRes toDto(String officeFacility){ + return OfficeFacilityRes.builder() + .officeFacility(officeFacility) + .build(); + } +} diff --git a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java new file mode 100644 index 00000000..7cab7bc6 --- /dev/null +++ b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java @@ -0,0 +1,26 @@ +package com.example.pladialmserver.office.dto; + +import com.example.pladialmserver.office.entity.Facility; +import com.example.pladialmserver.office.entity.Office; +import lombok.*; + +import java.util.List; +import java.util.stream.Collectors; + +@Data +public class OfficeRes { + private String name; + private String location; + private Integer capacity; + private List facilityList; + private String description; + + public static OfficeRes toDto(Office office, List facilities){ + OfficeRes officeRes=new OfficeRes(); + officeRes.name=office.getName(); + officeRes.location=office.getLocation(); + officeRes.capacity=office.getCapacity(); + officeRes.facilityList=facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList()); + return officeRes; + } +} diff --git a/src/main/java/com/example/pladialmserver/office/entity/Office.java b/src/main/java/com/example/pladialmserver/office/entity/Office.java index 7a0c762c..a92e9b67 100644 --- a/src/main/java/com/example/pladialmserver/office/entity/Office.java +++ b/src/main/java/com/example/pladialmserver/office/entity/Office.java @@ -2,6 +2,7 @@ import com.example.pladialmserver.global.entity.BaseEntity; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/example/pladialmserver/office/repository/OfficeBookingRepository.java b/src/main/java/com/example/pladialmserver/office/repository/OfficeBookingRepository.java index a90996bd..e628d710 100644 --- a/src/main/java/com/example/pladialmserver/office/repository/OfficeBookingRepository.java +++ b/src/main/java/com/example/pladialmserver/office/repository/OfficeBookingRepository.java @@ -2,6 +2,18 @@ import com.example.pladialmserver.office.entity.OfficeBooking; 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.LocalDate; +import java.time.LocalTime; +import java.util.List; + +@Repository public interface OfficeBookingRepository extends JpaRepository { + @Query("SELECT ob FROM OfficeBooking ob WHERE ob.date = :date AND ((ob.startTime <= :startTime AND ob.endTime > :startTime) OR (ob.startTime < :endTime AND ob.endTime >= :endTime))") + List findByDateAndTime(@Param("date") LocalDate date, @Param("startTime") LocalTime startTime, @Param("endTime") LocalTime endTime); + } + diff --git a/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java b/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java index d5d8c6a3..adbeaa6d 100644 --- a/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java +++ b/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java @@ -3,5 +3,7 @@ import com.example.pladialmserver.office.entity.Office; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface OfficeRepository extends JpaRepository { } diff --git a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java index f828b01d..cc135945 100644 --- a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java +++ b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java @@ -1,10 +1,20 @@ package com.example.pladialmserver.office.service; +import com.example.pladialmserver.office.dto.OfficeRes; +import com.example.pladialmserver.office.entity.Facility; +import com.example.pladialmserver.office.entity.Office; +import com.example.pladialmserver.office.entity.OfficeBooking; import com.example.pladialmserver.office.repository.OfficeBookingRepository; import com.example.pladialmserver.office.repository.OfficeRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor public class OfficeService { @@ -12,4 +22,37 @@ public class OfficeService { private final OfficeRepository officeRepository; private final OfficeBookingRepository officeBookingRepository; + + public List findAvailableOffices(LocalDate date, LocalTime startTime, LocalTime endTime) { + List allOffices = officeRepository.findAll(); + + if (date != null && startTime != null && endTime != null) { + // 입력된 날짜와 시간에 이미 예약된 회의실을 조회 + List bookedOffices = officeBookingRepository.findByDateAndTime(date, startTime, endTime); + System.out.println("Booked Offices Size: " + bookedOffices.size()); + + // 이미 예약된 회의실의 ID 목록을 추출 + List bookedOfficeIds = bookedOffices.stream() + .map(booking -> booking.getOffice().getOfficeId()) + .collect(Collectors.toList()); + + // 예약된 회의실을 제외한 회의실 목록을 필터링 + allOffices = allOffices.stream() + .filter(office -> !bookedOfficeIds.contains(office.getOfficeId())) + .collect(Collectors.toList()); + } + + // 반환할 결과 리스트를 생성 + List result = new ArrayList<>(); + + for (Office office : allOffices) { + List facilities = office.getFacilityList().stream() + .map(officeFacility -> officeFacility.getFacility()) + .collect(Collectors.toList()); + + result.add(OfficeRes.toDto(office, facilities)); + } + + return result; + } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 071b78ee..2b3c566b 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,22 +1,22 @@ -spring: - config: - activate: - on-profile: dev - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) - username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) - password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) - - jpa: - database: mysql - hibernate: - ddl-auto: update - generate-ddl: true - show-sql: true - properties: - hibernate: - format_sql: true - -server: - port: 8080 +#spring: +# config: +# activate: +# on-profile: dev +# datasource: +# driver-class-name: com.mysql.cj.jdbc.Driver +# url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) +# username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) +# password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) +# +# jpa: +# database: mysql +# hibernate: +# ddl-auto: update +# generate-ddl: true +# show-sql: true +# properties: +# hibernate: +# format_sql: true +# +#server: +# port: 8080 diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 5d7f5903..803c3286 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -1,25 +1,25 @@ -spring: - config: - activate: - on-profile: prod - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) - username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) - password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) - - jpa: - database: mysql - hibernate: - ddl-auto: update - generate-ddl: true - show-sql: true - properties: - hibernate: - format_sql: true - -server: - port: 8080 - +#spring: +# config: +# activate: +# on-profile: prod +# datasource: +# driver-class-name: com.mysql.cj.jdbc.Driver +# url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) +# username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) +# password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) +# +# jpa: +# database: mysql +# hibernate: +# ddl-auto: update +# generate-ddl: true +# show-sql: true +# properties: +# hibernate: +# format_sql: true +# +#server: +# port: 8080 +# From a216ee8b4ae9862e84ffa509193794eeb35f67ad Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 02:49:25 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[PDS-11]=20fix:=EC=B2=98=EC=9D=8C=EC=97=90?= =?UTF-8?q?=20=EC=A0=84=EC=B2=B4=20=ED=9A=8C=EC=9D=98=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EB=8A=94=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pladialmserver/office/controller/OfficeController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java index d45e7a8b..1b396301 100644 --- a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java +++ b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java @@ -37,7 +37,8 @@ public ResponseCustom> searchOffice( ) { // 날짜와 시작 시간 또는 종료 시간 중 하나라도 입력되지 않았다면 에러 반환 - if (date == null || startTime == null || endTime == null) { + if ((date != null && (startTime == null || endTime == null)) || + (date == null && (startTime != null || endTime != null))){ throw new BaseException(BaseResponseCode.OFFICE_NOT_FOUND_DATE_TIME); } return ResponseCustom.OK(officeService.findAvailableOffices(date, startTime, endTime)); From 25f47c4fc755bbd0202d233bbddba3f07b1cb19a Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 15:24:39 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[PDS-11]=20fix:=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20import=EC=82=AD=EC=A0=9C,=20yml=EC=A3=BC=EC=84=9D?= =?UTF-8?q?=20=ED=92=80=EA=B8=B0,dto=20builder=ED=8C=A8=ED=84=B4=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/BaseResponseCode.java | 2 +- .../office/controller/OfficeController.java | 6 +-- .../pladialmserver/office/dto/OfficeRes.java | 20 +++++--- .../pladialmserver/office/entity/Office.java | 1 - .../office/repository/OfficeRepository.java | 2 - .../office/service/OfficeService.java | 2 + src/main/resources/application-dev.yml | 44 +++++++++--------- src/main/resources/application-prod.yml | 46 +++++++++---------- 8 files changed, 64 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java b/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java index 3d87fcd2..2fa964e7 100644 --- a/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java +++ b/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java @@ -16,7 +16,7 @@ public enum BaseResponseCode { BAD_REQUEST("G0001", HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), //office - OFFICE_NOT_FOUND_DATE_TIME("OF0001", HttpStatus.NOT_FOUND,"날짜나 시간을 모두 입력해주세요"); + OFFICE_NOT_FOUND_DATE_TIME("B0001", HttpStatus.BAD_REQUEST,"날짜나 시간을 모두 입력해주세요"); public final String code; diff --git a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java index 1b396301..88c02643 100644 --- a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java +++ b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java @@ -10,10 +10,7 @@ import lombok.RequiredArgsConstructor; import org.apache.coyote.Response; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.time.LocalDate; import java.time.LocalTime; @@ -48,6 +45,7 @@ public ResponseCustom> searchOffice( */ + /** * 회의실 일자별 예약 현황 조회 */ diff --git a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java index 7cab7bc6..aaab94bb 100644 --- a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java +++ b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java @@ -8,6 +8,7 @@ import java.util.stream.Collectors; @Data +@Builder public class OfficeRes { private String name; private String location; @@ -16,11 +17,18 @@ public class OfficeRes { private String description; public static OfficeRes toDto(Office office, List facilities){ - OfficeRes officeRes=new OfficeRes(); - officeRes.name=office.getName(); - officeRes.location=office.getLocation(); - officeRes.capacity=office.getCapacity(); - officeRes.facilityList=facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList()); - return officeRes; + return OfficeRes.builder() + .name(office.getName()) + .location(office.getLocation()) + .capacity(office.getCapacity()) + .facilityList(facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList())) + .description(office.getDescription()) + .build(); +// OfficeRes officeRes=new OfficeRes(); +// officeRes.name=office.getName(); +// officeRes.location=office.getLocation(); +// officeRes.capacity=office.getCapacity(); +// officeRes.facilityList=facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList()); +// return officeRes; } } diff --git a/src/main/java/com/example/pladialmserver/office/entity/Office.java b/src/main/java/com/example/pladialmserver/office/entity/Office.java index a92e9b67..7a0c762c 100644 --- a/src/main/java/com/example/pladialmserver/office/entity/Office.java +++ b/src/main/java/com/example/pladialmserver/office/entity/Office.java @@ -2,7 +2,6 @@ import com.example.pladialmserver.global.entity.BaseEntity; import lombok.AccessLevel; -import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java b/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java index adbeaa6d..d5d8c6a3 100644 --- a/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java +++ b/src/main/java/com/example/pladialmserver/office/repository/OfficeRepository.java @@ -3,7 +3,5 @@ import com.example.pladialmserver.office.entity.Office; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; - public interface OfficeRepository extends JpaRepository { } diff --git a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java index cc135945..d836fdc3 100644 --- a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java +++ b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java @@ -23,6 +23,7 @@ public class OfficeService { private final OfficeBookingRepository officeBookingRepository; + public List findAvailableOffices(LocalDate date, LocalTime startTime, LocalTime endTime) { List allOffices = officeRepository.findAll(); @@ -55,4 +56,5 @@ public List findAvailableOffices(LocalDate date, LocalTime startTime, return result; } + } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 2b3c566b..071b78ee 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,22 +1,22 @@ -#spring: -# config: -# activate: -# on-profile: dev -# datasource: -# driver-class-name: com.mysql.cj.jdbc.Driver -# url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) -# username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) -# password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) -# -# jpa: -# database: mysql -# hibernate: -# ddl-auto: update -# generate-ddl: true -# show-sql: true -# properties: -# hibernate: -# format_sql: true -# -#server: -# port: 8080 +spring: + config: + activate: + on-profile: dev + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) + username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) + password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) + + jpa: + database: mysql + hibernate: + ddl-auto: update + generate-ddl: true + show-sql: true + properties: + hibernate: + format_sql: true + +server: + port: 8080 diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 803c3286..5d7f5903 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -1,25 +1,25 @@ -#spring: -# config: -# activate: -# on-profile: prod -# datasource: -# driver-class-name: com.mysql.cj.jdbc.Driver -# url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) -# username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) -# password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) -# -# jpa: -# database: mysql -# hibernate: -# ddl-auto: update -# generate-ddl: true -# show-sql: true -# properties: -# hibernate: -# format_sql: true -# -#server: -# port: 8080 -# +spring: + config: + activate: + on-profile: prod + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ENC(825oUKfuPvdkOo3krx8Ct544Z3sc9aNhpSJPJL339pK8zSJ10TDjM90AueqQPSO+KazbAYQ1yDsOu2khyebB7GJgY4/5NMRJ9U6R0MJ8f0u5t9DMJ7k8KZd7fLM5zVLAty5v9dvH3G4mMpdoUTsAlyteBVWyCRMjnqM5VEAAe9y/nQ/hon1FHBAjo0B745jeUwtDyZXQFiE=) + username: ENC(qxQC1gaOQKdq3TwxC9ubEg1h0X5+/7Sb) + password: ENC(9fFgGo8Q1JBmh+UqiGOh83ExkCZDvMuM) + + jpa: + database: mysql + hibernate: + ddl-auto: update + generate-ddl: true + show-sql: true + properties: + hibernate: + format_sql: true + +server: + port: 8080 + From 1c205e7818e76b630a18669936074770e9c5b01b Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 15:28:46 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[PDS-11]=20fix:=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/pladialmserver/office/dto/OfficeRes.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java index aaab94bb..34a85345 100644 --- a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java +++ b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java @@ -24,11 +24,5 @@ public static OfficeRes toDto(Office office, List facilities){ .facilityList(facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList())) .description(office.getDescription()) .build(); -// OfficeRes officeRes=new OfficeRes(); -// officeRes.name=office.getName(); -// officeRes.location=office.getLocation(); -// officeRes.capacity=office.getCapacity(); -// officeRes.facilityList=facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList()); -// return officeRes; } } From e694e0982a8648c6c8eb4f5b7aa522d488c0069c Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 15:30:51 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[PDS-11]=20fix:=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pladialmserver/global/exception/BaseResponseCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java b/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java index 2fa964e7..376a5b7f 100644 --- a/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java +++ b/src/main/java/com/example/pladialmserver/global/exception/BaseResponseCode.java @@ -16,7 +16,7 @@ public enum BaseResponseCode { BAD_REQUEST("G0001", HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), //office - OFFICE_NOT_FOUND_DATE_TIME("B0001", HttpStatus.BAD_REQUEST,"날짜나 시간을 모두 입력해주세요"); + NOT_DATE_TIME("B0001", HttpStatus.BAD_REQUEST,"날짜나 시간을 모두 입력해주세요"); public final String code; From aa774a8b735a963159b606fccf035d2e4ae0b39c Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 15:31:31 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[PDS-11]=20fix:=EB=B3=80=EA=B2=BD=EB=90=9C?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pladialmserver/office/controller/OfficeController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java index 88c02643..0c145474 100644 --- a/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java +++ b/src/main/java/com/example/pladialmserver/office/controller/OfficeController.java @@ -36,7 +36,7 @@ public ResponseCustom> searchOffice( // 날짜와 시작 시간 또는 종료 시간 중 하나라도 입력되지 않았다면 에러 반환 if ((date != null && (startTime == null || endTime == null)) || (date == null && (startTime != null || endTime != null))){ - throw new BaseException(BaseResponseCode.OFFICE_NOT_FOUND_DATE_TIME); + throw new BaseException(BaseResponseCode.NOT_DATE_TIME); } return ResponseCustom.OK(officeService.findAvailableOffices(date, startTime, endTime)); } From 1e9b6d320ec691c04dc367ce5d6f92409ad09735 Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 15:39:45 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[PDS-11]=20fix:sys=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/pladialmserver/office/service/OfficeService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java index d836fdc3..7b8a284b 100644 --- a/src/main/java/com/example/pladialmserver/office/service/OfficeService.java +++ b/src/main/java/com/example/pladialmserver/office/service/OfficeService.java @@ -30,7 +30,6 @@ public List findAvailableOffices(LocalDate date, LocalTime startTime, if (date != null && startTime != null && endTime != null) { // 입력된 날짜와 시간에 이미 예약된 회의실을 조회 List bookedOffices = officeBookingRepository.findByDateAndTime(date, startTime, endTime); - System.out.println("Booked Offices Size: " + bookedOffices.size()); // 이미 예약된 회의실의 ID 목록을 추출 List bookedOfficeIds = bookedOffices.stream() From ec58640884914a842a6dfabef38e2592f3a14058 Mon Sep 17 00:00:00 2001 From: iseunghag Date: Tue, 19 Sep 2023 15:59:15 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[PDS-11]=20fix:dto=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=A5=BC=20list=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../office/dto/OfficeFacilityRes.java | 20 ------------------- .../pladialmserver/office/dto/OfficeRes.java | 4 ++-- 2 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java diff --git a/src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java b/src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java deleted file mode 100644 index 16cf05cb..00000000 --- a/src/main/java/com/example/pladialmserver/office/dto/OfficeFacilityRes.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.example.pladialmserver.office.dto; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; - -@Data -@RequiredArgsConstructor -@Builder -@AllArgsConstructor -public class OfficeFacilityRes { - private String officeFacility; - - public static OfficeFacilityRes toDto(String officeFacility){ - return OfficeFacilityRes.builder() - .officeFacility(officeFacility) - .build(); - } -} diff --git a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java index 34a85345..50830473 100644 --- a/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java +++ b/src/main/java/com/example/pladialmserver/office/dto/OfficeRes.java @@ -13,7 +13,7 @@ public class OfficeRes { private String name; private String location; private Integer capacity; - private List facilityList; + private List facilityList; private String description; public static OfficeRes toDto(Office office, List facilities){ @@ -21,7 +21,7 @@ public static OfficeRes toDto(Office office, List facilities){ .name(office.getName()) .location(office.getLocation()) .capacity(office.getCapacity()) - .facilityList(facilities.stream().map(m -> OfficeFacilityRes.toDto(m.getName())).collect(Collectors.toList())) + .facilityList(facilities.stream().map(Facility::getName).collect(Collectors.toList())) .description(office.getDescription()) .build(); }