diff --git a/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java b/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java index 2e25783..51fedc0 100644 --- a/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java +++ b/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java @@ -11,11 +11,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.UUID; @Component @Slf4j -//todo: 파일명 중복 처리 public class FileHandler { @Value("${spring.fileStorage.dir}") private String fileStorageDir; @@ -25,13 +25,13 @@ public String saveFile(MultipartFile file) { return null; } try { - String fileName = file.getOriginalFilename(); + String fileName = getUniqueFileName(file.getOriginalFilename()); File dest = new File(fileStorageDir + File.separator + fileName); file.transferTo(dest); return fileName; } catch (IOException e) { - e.printStackTrace(); + log.error(e.getMessage()); return "이미지 업로드 오류 발생"; } } @@ -51,4 +51,9 @@ private byte[] readFileBytes(String filePath) throws IOException { throw new CustomException("파일이 존재하지 않습니다.", ErrorCode.FILE_NOT_FOUND); } } + + private String getUniqueFileName(String fileName) { + return UUID.randomUUID() + fileName; + } + } diff --git a/src/main/java/com/sideProject/PlanIT/common/response/ErrorCode.java b/src/main/java/com/sideProject/PlanIT/common/response/ErrorCode.java index 5e3882f..52cfe6e 100644 --- a/src/main/java/com/sideProject/PlanIT/common/response/ErrorCode.java +++ b/src/main/java/com/sideProject/PlanIT/common/response/ErrorCode.java @@ -41,6 +41,7 @@ public enum ErrorCode { TrainerSchedule_NOT_FOUND(404, "트레이너 일정을 찾을 수 없습니다"), NOT_SUSPEND_PROGRAM(422, "일시정지 요청이 거부되었습니다."), + IS_WORK_TIME(422, "근무 시간에는 예약설정이 불가능합니다."), SUSPEND_REQUEST_DENIED(422, "일시정지 요청이 거부되었습니다."); diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java index 9b0ee18..0bf34e3 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.java @@ -5,12 +5,13 @@ import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto; import com.sideProject.PlanIT.domain.post.service.BannerService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.util.List; - @RestController @RequestMapping("/admin/banner") @Slf4j @@ -36,7 +37,9 @@ public ApiResponse deleteBanner(@PathVariable Long banner_id) { } @GetMapping - public ApiResponse> findAllBanners() { - return ApiResponse.ok(bannerService.findAllBanners()); + public ApiResponse> findAllBanners( + @PageableDefault(size = 10) Pageable pageable + ) { + return ApiResponse.ok(bannerService.findAllBanners(pageable)); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java index 71c8d90..27ff4fb 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.java @@ -4,13 +4,14 @@ import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto; import com.sideProject.PlanIT.domain.post.service.BannerService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - //todo: Banner, Notice 둘 다 Edit 발생 시 기존 첨부파일 삭제 후 다시 저장 @RestController @@ -21,8 +22,10 @@ public class BannerController { private final BannerService bannerService; @GetMapping - public ApiResponse> findAllBannersInTime() { - return ApiResponse.ok(bannerService.findAllBannersInTime()); + public ApiResponse> findAllBannersInTime( + @PageableDefault(size = 10) Pageable pageable + ) { + return ApiResponse.ok(bannerService.findAllBannersInTime(pageable)); } @GetMapping("/{banner_id}") diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java index c073d88..f51c41c 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.java @@ -5,10 +5,11 @@ import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto; import com.sideProject.PlanIT.domain.post.service.NoticeService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.*; -import java.util.List; - @RestController @RequestMapping("/admin/notice") @RequiredArgsConstructor @@ -31,7 +32,9 @@ public ApiResponse deleteNotice(@PathVariable Long notice_id) { } @GetMapping - public ApiResponse> findAllNotices() { - return ApiResponse.ok(noticeService.findAllNotices()); + public ApiResponse> findAllNotices( + @PageableDefault(size = 10) Pageable pageable + ) { + return ApiResponse.ok(noticeService.findAllNotices(pageable)); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java index 5590407..8b58ef9 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeController.java @@ -5,13 +5,14 @@ import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto; import com.sideProject.PlanIT.domain.post.service.NoticeService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - @RestController @RequiredArgsConstructor @RequestMapping("/notice") @@ -19,8 +20,10 @@ public class NoticeController { private final NoticeService noticeService; @GetMapping - public ApiResponse> findAllNoticesInTime() { - return ApiResponse.ok(noticeService.findAllNoticesInTime()); + public ApiResponse> findAllNoticesInTime( + @PageableDefault(size = 10) Pageable pageable + ) { + return ApiResponse.ok(noticeService.findAllNoticesInTime(pageable)); } @GetMapping("/{notice_id}") diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/repository/BannerRepository.java b/src/main/java/com/sideProject/PlanIT/domain/post/repository/BannerRepository.java index 0ef6097..d40d182 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/repository/BannerRepository.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/repository/BannerRepository.java @@ -1,15 +1,14 @@ package com.sideProject.PlanIT.domain.post.repository; import com.sideProject.PlanIT.domain.post.entity.Banner; -import com.sideProject.PlanIT.domain.post.entity.Notice; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import java.util.List; - @Repository public interface BannerRepository extends JpaRepository { @Query("SELECT b FROM Banner b WHERE b.startAt <= CURRENT_TIMESTAMP AND b.endAt >= CURRENT_TIMESTAMP ") - List findByStartAtBeforeAndEndAtAfter(); + Page findByStartAtBeforeAndEndAtAfter(Pageable pageable); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/repository/NoticeRepository.java b/src/main/java/com/sideProject/PlanIT/domain/post/repository/NoticeRepository.java index 5cb245f..d9dcca5 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/repository/NoticeRepository.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/repository/NoticeRepository.java @@ -1,14 +1,14 @@ package com.sideProject.PlanIT.domain.post.repository; import com.sideProject.PlanIT.domain.post.entity.Notice; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import java.util.List; - @Repository public interface NoticeRepository extends JpaRepository { @Query("SELECT n FROM Notice n WHERE n.startAt <= CURRENT_TIMESTAMP AND n.endAt >= CURRENT_TIMESTAMP ") - List findByStartAtBeforeAndEndAtAfter(); + Page findByStartAtBeforeAndEndAtAfter(Pageable pageable); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java index d8d40df..a9c8d13 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerService.java @@ -2,15 +2,14 @@ import com.sideProject.PlanIT.domain.post.dto.request.BannerRequestDto; import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto; -import com.sideProject.PlanIT.domain.post.entity.Banner; - -import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; public interface BannerService { String createBanner(BannerRequestDto bannerRequestDto); String editBanner(Long banner_id, BannerRequestDto bannerRequestDto); String deleteBanner(Long banner_id); - List findAllBanners(); - List findAllBannersInTime(); + Page findAllBanners(Pageable pageable); + Page findAllBannersInTime(Pageable pageable); BannerResponseDto findBanner(Long banner_id); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java index 40025ac..d895fac 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/BannerServiceImpl.java @@ -9,11 +9,10 @@ import com.sideProject.PlanIT.domain.post.repository.BannerRepository; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.stream.Collectors; - @Service @RequiredArgsConstructor public class BannerServiceImpl implements BannerService{ @@ -47,19 +46,15 @@ public String deleteBanner(Long banner_id) { } @Override - public List findAllBanners() { - List banners = bannerRepository.findAll(); - return banners.stream() - .map(BannerResponseDto::of) - .collect(Collectors.toList()); + public Page findAllBanners(Pageable pageable) { + Page banners = bannerRepository.findAll(pageable); + return banners.map(BannerResponseDto::of); } @Override - public List findAllBannersInTime() { - List banners = bannerRepository.findByStartAtBeforeAndEndAtAfter(); - return banners.stream() - .map(BannerResponseDto::of) - .collect(Collectors.toList()); + public Page findAllBannersInTime(Pageable pageable) { + Page banners = bannerRepository.findByStartAtBeforeAndEndAtAfter(pageable); + return banners.map(BannerResponseDto::of); } @Override diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java index ef1f6c1..b4eaa38 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeService.java @@ -3,16 +3,15 @@ import com.sideProject.PlanIT.domain.post.dto.request.NoticeRequestDto; import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto; -import com.sideProject.PlanIT.domain.post.entity.Notice; - -import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; public interface NoticeService { String createNotice(NoticeRequestDto noticeRequestDto); String editNotice(Long notice_id, NoticeRequestDto noticeRequestDto); String deleteNotice(Long notice_id); - List findAllNotices(); - List findAllNoticesInTime(); + Page findAllNotices(Pageable pageable); + Page findAllNoticesInTime(Pageable pageable); public NoticeResponseDto findNotice(Long notice_id); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java index 28aaf66..cea8f9e 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/post/service/NoticeServiceImpl.java @@ -10,11 +10,10 @@ import com.sideProject.PlanIT.domain.post.repository.NoticeRepository; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.stream.Collectors; - @Service @RequiredArgsConstructor public class NoticeServiceImpl implements NoticeService{ @@ -56,19 +55,15 @@ public String deleteNotice(Long notice_id) { } @Override - public List findAllNotices() { - List notices = noticeRepository.findAll(); - return notices.stream() - .map(NoticeResponseDto::of) - .collect(Collectors.toList()); + public Page findAllNotices(Pageable pageable) { + Page notices = noticeRepository.findAll(pageable); + return notices.map(NoticeResponseDto::of); } @Override - public List findAllNoticesInTime() { - List notices = noticeRepository.findByStartAtBeforeAndEndAtAfter(); - return notices.stream() - .map(NoticeResponseDto::of) - .collect(Collectors.toList()); + public Page findAllNoticesInTime(Pageable pageable) { + Page notices = noticeRepository.findByStartAtBeforeAndEndAtAfter(pageable); + return notices.map(NoticeResponseDto::of); } public NoticeResponseDto findNotice(Long notice_id) { diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java index eb8dafe..d1eb41c 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramAdminController.java @@ -1,10 +1,10 @@ package com.sideProject.PlanIT.domain.program.controller; import com.sideProject.PlanIT.common.response.ApiResponse; -import com.sideProject.PlanIT.domain.program.dto.request.ApproveRequest; -import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequest; -import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponse; -import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponse; +import com.sideProject.PlanIT.domain.program.dto.request.ApproveRequestDto; +import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequestDto; +import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponseDto; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; import com.sideProject.PlanIT.domain.program.service.ProgramService; @@ -31,12 +31,10 @@ public class ProgramAdminController { //어드민이 전부 검색 @GetMapping("") - public ApiResponse> find( + public ApiResponse> find( @RequestParam(value = "option", required = false, defaultValue = "VALID") ProgramSearchStatus option, @PageableDefault(size = 10) Pageable pageable, Principal principal) { - //todo : spring security 개발 후 토큰에서 userID를 전달해 줘야함. - Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication(); Long id = Long.parseLong(principal.getName()); return ApiResponse.ok( @@ -46,18 +44,17 @@ public ApiResponse> find( //어드민이 유저 id로 검색 @GetMapping("/by-user/{id}") - public ApiResponse> find( + public ApiResponse> find( @PathVariable("id") Long id, @PageableDefault(size = 10) Pageable pageable, @RequestParam(value = "option", required = false, defaultValue = "VALID") ProgramSearchStatus option) { - //todo : spring security 개발 후 토큰에서 userID를 전달해 줘야함. return ApiResponse.ok( programService.findByUser(id, option, pageable) ); } @GetMapping("/{id}") - public ApiResponse find( + public ApiResponse find( @PathVariable("id") Long id) { Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication(); Long userId = Long.parseLong(loggedInUser.getName()); @@ -78,14 +75,14 @@ public ApiResponse refund(@PathVariable("id") Long id) { @PutMapping("/{id}") public ApiResponse modify( @PathVariable("id") Long id, - ProgramModifyRequest request) { + ProgramModifyRequestDto request) { return ApiResponse.ok( programService.modify(id, request) ); } @PostMapping("/approve/{id}") - public ApiResponse approve(@PathVariable("id") Long id, @RequestBody ApproveRequest request) { + public ApiResponse approve(@PathVariable("id") Long id, @RequestBody ApproveRequestDto request) { LocalDateTime now = LocalDateTime.now(); return ApiResponse.ok( programService.approve(id, request.getTrainer(), now) @@ -93,7 +90,7 @@ public ApiResponse approve(@PathVariable("id") Long id, @RequestBody Appro } @GetMapping("/registration") - public ApiResponse> findRegistration( + public ApiResponse> findRegistration( @RequestParam(value = "option", required = false, defaultValue = "READY") RegistrationSearchStatus option, @PageableDefault(size = 10) Pageable pageable, Principal principal) { @@ -105,7 +102,7 @@ public ApiResponse> findRegistration( @GetMapping("/registration/{id}") - public ApiResponse> findRegistrationByUser( + public ApiResponse> findRegistrationByUser( @PathVariable("id") Long id, @PageableDefault(size = 10) Pageable pageable, @RequestParam(value = "option", required = false, defaultValue = "READY") RegistrationSearchStatus option) { diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java index 364c019..c0233b0 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/controller/ProgramController.java @@ -1,9 +1,9 @@ package com.sideProject.PlanIT.domain.program.controller; import com.sideProject.PlanIT.common.response.ApiResponse; -import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequest; -import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponse; -import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponse; +import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequestDto; +import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponseDto; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; import com.sideProject.PlanIT.domain.program.service.ProgramService; @@ -27,14 +27,14 @@ public class ProgramController { private final ProgramService programService; @PostMapping("/registration") - public ApiResponse registration(@RequestBody RegistrationRequest request, Principal principal){ + public ApiResponse registration(@RequestBody RegistrationRequestDto request, Principal principal){ LocalDateTime now = LocalDateTime.now(); Long id = Long.parseLong(principal.getName()); return ApiResponse.ok(programService.registration(request, id, now)); } @GetMapping - public ApiResponse> find( + public ApiResponse> find( @RequestParam(value = "option", required = false, defaultValue = "VALID") ProgramSearchStatus option, @PageableDefault(size = 10, sort = "id", direction = Sort.Direction.ASC) Pageable pageable, Principal principal) { @@ -45,7 +45,7 @@ public ApiResponse> find( } @GetMapping("/{id}") - public ApiResponse findById( + public ApiResponse findById( @PathVariable("id") Long id, Principal principal) { //todo : spring security 개발 후 토큰에서 userID를 전달해 줘야함. @@ -56,7 +56,7 @@ public ApiResponse findById( } @GetMapping("/registration") - public ApiResponse> findRegistration( + public ApiResponse> findRegistration( @RequestParam(value = "option", required = false, defaultValue = "ALL") RegistrationSearchStatus option, @PageableDefault(size = 10, sort = "id", direction = Sort.Direction.DESC) Pageable pageable, Principal principal) { diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequest.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java similarity index 75% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequest.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java index cc60648..1fda05e 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequest.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ApproveRequestDto.java @@ -6,11 +6,11 @@ @Getter @NoArgsConstructor -public class ApproveRequest { +public class ApproveRequestDto { Long trainer; @Builder - public ApproveRequest(Long trainer) { + public ApproveRequestDto(Long trainer) { this.trainer = trainer; } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequest.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java similarity index 71% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequest.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java index f5aae37..165fdc2 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequest.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramModifyRequestDto.java @@ -4,7 +4,7 @@ import lombok.Getter; @Getter -public class ProgramModifyRequest { +public class ProgramModifyRequestDto { String startTime; String endTime; @@ -12,7 +12,7 @@ public class ProgramModifyRequest { Long employId; @Builder - public ProgramModifyRequest(String startTime, String endTime, Long memberId, Long employId) { + public ProgramModifyRequestDto(String startTime, String endTime, Long memberId, Long employId) { this.startTime = startTime; this.endTime = endTime; this.memberId = memberId; diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraion.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java similarity index 95% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraion.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java index dd9da58..001cc7e 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraion.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/ProgramRegistraionDto.java @@ -7,7 +7,7 @@ import java.time.LocalDateTime; -public class ProgramRegistraion { +public class ProgramRegistraionDto { @Getter @AllArgsConstructor public static class programRegistrationrequest { diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequest.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java similarity index 71% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequest.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java index 1e0c6b7..11c170e 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequest.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/request/RegistrationRequestDto.java @@ -5,17 +5,16 @@ import lombok.NoArgsConstructor; import java.time.LocalDate; -import java.time.LocalDateTime; @Getter @NoArgsConstructor -public class RegistrationRequest { +public class RegistrationRequestDto { Long productId; Long trainerId; LocalDate registrationAt; @Builder - public RegistrationRequest(Long productId, Long trainerId, LocalDate registrationAt) { + public RegistrationRequestDto(Long productId, Long trainerId, LocalDate registrationAt) { this.productId = productId; this.trainerId = trainerId; this.registrationAt = registrationAt; diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponse.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java similarity index 82% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponse.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java index 6b385f1..5aac4ad 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/FindRegistrationResponseDto.java @@ -10,7 +10,7 @@ @Getter @NoArgsConstructor -public class FindRegistrationResponse { +public class FindRegistrationResponseDto { private Long id; private String registrationAt; private String refundAt; @@ -22,7 +22,7 @@ public class FindRegistrationResponse { private Long trainerId; @Builder - public FindRegistrationResponse(Long id, String registrationAt, String refundAt, RegistrationStatus status, int discount, int totalPrice, ProductResponseDto product, MemberSemiResponseDto member, Long trainerId) { + public FindRegistrationResponseDto(Long id, String registrationAt, String refundAt, RegistrationStatus status, int discount, int totalPrice, ProductResponseDto product, MemberSemiResponseDto member, Long trainerId) { this.id = id; this.registrationAt = registrationAt; this.refundAt = refundAt; @@ -34,14 +34,14 @@ public FindRegistrationResponse(Long id, String registrationAt, String refundAt, this.trainerId = trainerId; } - public static FindRegistrationResponse of(Registration registration){ + public static FindRegistrationResponseDto of(Registration registration){ //환불 여부 null 체크 String registrationAt = registration.getRefundAt() != null ? registration.getRefundAt().toString() : ""; - return FindRegistrationResponse.builder() + return FindRegistrationResponseDto.builder() .id(registration.getId()) .registrationAt(registration.getRegistrationAt().toString()) .refundAt(registrationAt) diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponseDto.java similarity index 93% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponseDto.java index e3742ee..458f02a 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/ProgramResponseDto.java @@ -14,7 +14,7 @@ import java.util.Optional; @Getter -public class ProgramResponse { +public class ProgramResponseDto { long id; String productName; ProductType type; @@ -28,7 +28,7 @@ public class ProgramResponse { EmployeeSemiResponseDto employee; @Builder - public ProgramResponse( + public ProgramResponseDto( long id, int remainedNumber, String startAt, @@ -52,8 +52,8 @@ public ProgramResponse( this.resumeAt = resumeAt; } - public static ProgramResponse of(Program program){ - return ProgramResponse.builder() + public static ProgramResponseDto of(Program program){ + return ProgramResponseDto.builder() .id(program.getId()) .remainedNumber(program.getRemainedNumber()) .status(program.getStatus()) diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/RegistrationResponse.java b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/RegistrationResponseDto.java similarity index 53% rename from src/main/java/com/sideProject/PlanIT/domain/program/dto/response/RegistrationResponse.java rename to src/main/java/com/sideProject/PlanIT/domain/program/dto/response/RegistrationResponseDto.java index 6d9cf70..98b8743 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/RegistrationResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/dto/response/RegistrationResponseDto.java @@ -1,22 +1,21 @@ package com.sideProject.PlanIT.domain.program.dto.response; -import com.sideProject.PlanIT.domain.program.entity.Registration; import lombok.Builder; import lombok.Getter; @Getter -public class RegistrationResponse { +public class RegistrationResponseDto { Long id; String message; @Builder - public RegistrationResponse(Long id, String message) { + public RegistrationResponseDto(Long id, String message) { this.id = id; this.message = message; } - public static RegistrationResponse of(Long id, String message) { - return RegistrationResponse.builder() + public static RegistrationResponseDto of(Long id, String message) { + return RegistrationResponseDto.builder() .id(id) .message(message) .build(); diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramService.java b/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramService.java index 92a3960..22182d8 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramService.java @@ -1,10 +1,10 @@ package com.sideProject.PlanIT.domain.program.service; -import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequest; -import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequest; -import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponse; -import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponse; -import com.sideProject.PlanIT.domain.program.dto.response.RegistrationResponse; +import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequestDto; +import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequestDto; +import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.RegistrationResponseDto; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; @@ -16,15 +16,15 @@ import java.time.LocalDateTime; public interface ProgramService { - public RegistrationResponse registration(RegistrationRequest request, Long memberId, LocalDateTime now); + public RegistrationResponseDto registration(RegistrationRequestDto request, Long memberId, LocalDateTime now); public String refund(long programId, LocalDateTime now); - public String modify(long programId, ProgramModifyRequest request); - public Page find(long adminId, ProgramSearchStatus option, Pageable pageable); - public Page findByUser(long userId, ProgramSearchStatus option, Pageable pageable); - public ProgramResponse findByProgramId(long programId, long userId); + public String modify(long programId, ProgramModifyRequestDto request); + public Page find(long adminId, ProgramSearchStatus option, Pageable pageable); + public Page findByUser(long userId, ProgramSearchStatus option, Pageable pageable); + public ProgramResponseDto findByProgramId(long programId, long userId); public Long approve(Long programId, Long trainerId,LocalDateTime now); - public Page findRegistrationsByAdmin(long adminId, RegistrationSearchStatus option, Pageable pageable); - public Page findRegistrationsByUser(long userId, RegistrationSearchStatus option, Pageable pageable); + public Page findRegistrationsByAdmin(long adminId, RegistrationSearchStatus option, Pageable pageable); + public Page findRegistrationsByUser(long userId, RegistrationSearchStatus option, Pageable pageable); public Long suspendProgram(Long id, LocalDate now); public Long resumeProgram(Long id, LocalDate now); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java index 9ea23c9..54dfd22 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceImpl.java @@ -5,10 +5,10 @@ import com.sideProject.PlanIT.domain.product.entity.enums.ProductType; import com.sideProject.PlanIT.domain.product.entity.Product; import com.sideProject.PlanIT.domain.product.repository.ProductRepository; -import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequest; -import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponse; -import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponse; -import com.sideProject.PlanIT.domain.program.dto.response.RegistrationResponse; +import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequestDto; +import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.RegistrationResponseDto; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; @@ -17,7 +17,7 @@ import com.sideProject.PlanIT.domain.program.entity.Registration; import com.sideProject.PlanIT.domain.program.repository.ProgramRepository; import com.sideProject.PlanIT.domain.program.repository.RegistrationRepository; -import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequest; +import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequestDto; import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.repository.EmployeeRepository; @@ -54,7 +54,7 @@ public class ProgramServiceImpl implements ProgramService { private final RegistrationRepository registrationRepository; private final ProductRepository productRepository; @Override - public RegistrationResponse registration(RegistrationRequest request, Long memberId, LocalDateTime now){ + public RegistrationResponseDto registration(RegistrationRequestDto request, Long memberId, LocalDateTime now){ Member member = memberRepository.findById(memberId).orElseThrow(() -> new CustomException(memberId + "는 존재하지 않는 회원입니다.", ErrorCode.MEMBER_NOT_FOUND) ); @@ -87,10 +87,10 @@ public RegistrationResponse registration(RegistrationRequest request, Long membe if(resultRegistration.getProduct().getType() == ProductType.MEMBERSHIP) { approve(resultRegistration.getId(),null,now); - return RegistrationResponse.of(resultRegistration.getId(),"회원권 등록이 완료되었습니다."); + return RegistrationResponseDto.of(resultRegistration.getId(),"회원권 등록이 완료되었습니다."); } - return RegistrationResponse.of(resultRegistration.getId(),"PT권 등록이 요청되었습니다."); + return RegistrationResponseDto.of(resultRegistration.getId(),"PT권 등록이 요청되었습니다."); } @Override public String refund(long programId, LocalDateTime localDateTime) { @@ -137,7 +137,7 @@ private Program getProgramById(long programId) { } @Override - public String modify(long programId, ProgramModifyRequest request) { + public String modify(long programId, ProgramModifyRequestDto request) { Program program = getProgramById(programId); Member member = memberRepository.findById(request.getMemberId()).orElseThrow(() -> @@ -271,10 +271,10 @@ public void checkProgramExistenceByRegistration(Long registrationId) { * 프로그램을 조회하여 리스트를 반환하는 메서드(어드민 만 사용 가능) * * @param option 조회 옵션(ALL : 전부, VAILD : 유효한 프로그램, UNVAILD : 유효하지 않은 프로그램) - * @return List + * @return List */ @Override - public Page find(long adminId, ProgramSearchStatus option, Pageable pageable) { + public Page find(long adminId, ProgramSearchStatus option, Pageable pageable) { Member admin = memberRepository.findById(adminId).orElseThrow(() -> new CustomException("존재하지 않는 회원입니다.", ErrorCode.MEMBER_NOT_FOUND) ); @@ -289,11 +289,11 @@ public Page find(long adminId, ProgramSearchStatus option, Page throw new CustomException("프로그램을 찾을 수 없습니다",ErrorCode.PROGRAM_NOT_FOUND); } - return programs.map(ProgramResponse::of); + return programs.map(ProgramResponseDto::of); } @Override - public Page findByUser(long userId, ProgramSearchStatus option, Pageable pageable) { + public Page findByUser(long userId, ProgramSearchStatus option, Pageable pageable) { Member member = memberRepository.findById(userId).orElseThrow(() -> new CustomException(userId + "는 존재하지 않는 회원입니다.", ErrorCode.MEMBER_NOT_FOUND) ); @@ -309,10 +309,10 @@ public Page findByUser(long userId, ProgramSearchStatus option, throw new CustomException("프로그램을 찾을 수 없습니다.",ErrorCode.PROGRAM_NOT_FOUND); } - return programs.map(ProgramResponse::of); + return programs.map(ProgramResponseDto::of); } - public ProgramResponse findByProgramId(long programId, long userId) { + public ProgramResponseDto findByProgramId(long programId, long userId) { Member member = memberRepository.findById(userId).orElseThrow(() -> new CustomException(userId + "은 존재하지 않는 회원입니다.", ErrorCode.MEMBER_NOT_FOUND) ); @@ -327,7 +327,7 @@ public ProgramResponse findByProgramId(long programId, long userId) { validMemberAccess(member,program); } - return ProgramResponse.of(program); + return ProgramResponseDto.of(program); } private void validTrainerAccess(Member member, Program program) { @@ -381,7 +381,7 @@ private Page findProgram(ProgramSearchStatus option,Pageable pageable) } @Override - public Page findRegistrationsByAdmin(long adminId, RegistrationSearchStatus option, Pageable pageable) { + public Page findRegistrationsByAdmin(long adminId, RegistrationSearchStatus option, Pageable pageable) { // 회원 검증 및 권한 확인 validateMemberAndAuthority(adminId, MemberRole.ADMIN); // Registration 조회 및 변환 @@ -389,7 +389,7 @@ public Page findRegistrationsByAdmin(long adminId, Reg } @Override - public Page findRegistrationsByUser(long userId, RegistrationSearchStatus option, Pageable pageable) { + public Page findRegistrationsByUser(long userId, RegistrationSearchStatus option, Pageable pageable) { // 회원 검증 Member member = validateMemberAndAuthority(userId, null); // Registration 조회 및 변환 @@ -405,7 +405,7 @@ private Member validateMemberAndAuthority(long memberId, MemberRole requiredRole return member; } - private Page findAndConvertRegistrations(RegistrationSearchStatus option, Pageable pageable, Member member) { + private Page findAndConvertRegistrations(RegistrationSearchStatus option, Pageable pageable, Member member) { Page registrations; if (member == null) { registrations = findRegistration(option, pageable); @@ -417,7 +417,7 @@ private Page findAndConvertRegistrations(RegistrationS throw new CustomException("조건을 만족하는 Registration이 없습니다.", ErrorCode.REGISTRATION_NOT_FOUND); } - return registrations.map(FindRegistrationResponse::of); + return registrations.map(FindRegistrationResponseDto::of); } //todo : 리팩토링 여부 생각, INVALID 조회 추가 diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java index 08ea95f..d7e282a 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/controller/ReservationController.java @@ -2,9 +2,9 @@ import com.sideProject.PlanIT.common.response.ApiResponse; import com.sideProject.PlanIT.domain.reservation.controller.ENUM.ReservationFindOption; -import com.sideProject.PlanIT.domain.reservation.dto.reqeust.ChangeReservationRequest; -import com.sideProject.PlanIT.domain.reservation.dto.reqeust.ReservationRequest; -import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponse; +import com.sideProject.PlanIT.domain.reservation.dto.reqeust.ChangeReservationRequestDto; +import com.sideProject.PlanIT.domain.reservation.dto.reqeust.ReservationRequestDto; +import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponseDto; import com.sideProject.PlanIT.domain.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -27,7 +27,7 @@ public class ReservationController { @PutMapping("/change") public ApiResponse changeAvailability( Principal principal, - @RequestBody ChangeReservationRequest request + @RequestBody ChangeReservationRequestDto request ) { return ApiResponse.ok( reservationService.changeAvailability( @@ -42,7 +42,7 @@ public ApiResponse changeAvailability( public ApiResponse reservation( Principal principal, @PathVariable("reservationId") Long reservationId, - @RequestBody ReservationRequest request + @RequestBody ReservationRequestDto request ) { LocalDateTime now = LocalDateTime.now(); return ApiResponse.ok( @@ -56,7 +56,7 @@ public ApiResponse reservation( } @GetMapping("") - public ApiResponse>> findReservation( + public ApiResponse>> findReservation( @RequestParam(value = "date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date, @RequestParam(value = "option", defaultValue = "ALL") ReservationFindOption option, @@ -75,7 +75,7 @@ public ApiResponse>> findReservation( } @GetMapping("/trainer/{employeeId}") - public ApiResponse> findReservationByEmployee( + public ApiResponse> findReservationByEmployee( @RequestParam(value = "date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date, @PathVariable("employeeId") Long employeeId diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequest.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java similarity index 76% rename from src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequest.java rename to src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java index b3b18b4..10ac689 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequest.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ChangeReservationRequestDto.java @@ -1,16 +1,14 @@ package com.sideProject.PlanIT.domain.reservation.dto.reqeust; import lombok.Getter; -import org.springframework.cglib.core.Local; import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; @Getter -public class ChangeReservationRequest { +public class ChangeReservationRequestDto { @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate reservationDate; diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequest.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java similarity index 75% rename from src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequest.java rename to src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java index e96308f..10ef7b9 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequest.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/reqeust/ReservationRequestDto.java @@ -3,6 +3,6 @@ import lombok.Getter; @Getter -public class ReservationRequest { +public class ReservationRequestDto { Long programId; } diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/response/ReservationResponse.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/response/ReservationResponseDto.java similarity index 91% rename from src/main/java/com/sideProject/PlanIT/domain/reservation/dto/response/ReservationResponse.java rename to src/main/java/com/sideProject/PlanIT/domain/reservation/dto/response/ReservationResponseDto.java index 7c7c7c3..f43782d 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/response/ReservationResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/dto/response/ReservationResponseDto.java @@ -16,7 +16,7 @@ @Slf4j @Getter -public class ReservationResponse { +public class ReservationResponseDto { Long id; MemberSemiResponseDto member; EmployeeSemiResponseDto employee; @@ -27,7 +27,7 @@ public class ReservationResponse { ReservationStatus status; @Builder - public ReservationResponse( + public ReservationResponseDto( Long id, MemberSemiResponseDto member, EmployeeSemiResponseDto employee, @@ -47,9 +47,9 @@ public ReservationResponse( this.status = status; } - public static ReservationResponse of(Reservation reservation) { + public static ReservationResponseDto of(Reservation reservation) { if(reservation.getStatus() == ReservationStatus.POSSIBLE) { - return ReservationResponse.builder() + return ReservationResponseDto.builder() .id(reservation.getId()) .reservationTime(reservation.getReservedTime()) .employee(EmployeeSemiResponseDto.of(reservation.getEmployee())) @@ -57,7 +57,7 @@ public static ReservationResponse of(Reservation reservation) { .build(); } - return ReservationResponse.builder() + return ReservationResponseDto.builder() .id(reservation.getId()) .member(Optional.ofNullable(reservation.getMember()) .map(MemberSemiResponseDto::of) diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/entity/Reservation.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/entity/Reservation.java index a244ced..84efb11 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/entity/Reservation.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/entity/Reservation.java @@ -6,18 +6,24 @@ import com.sideProject.PlanIT.domain.reservation.entity.ENUM.ReservationStatus; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.entity.Member; +import com.sideProject.PlanIT.domain.user.entity.WorkTime; +import com.sideProject.PlanIT.domain.user.entity.enums.Week; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.catalina.User; import java.sql.Time; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; @Entity +@Slf4j @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class Reservation { @@ -100,4 +106,23 @@ private boolean isPastReservationThreshold(LocalDateTime now) { return now.isAfter(reservedTime.minusMinutes(RESERVATION_THRESHOLD_MINUTES)); } + // 예약 시간이 출근 시간 안에 포함 되는지 체크 + public boolean isWithinEmployeeWorkTime(List employeeWorkTimes) { + LocalDate reservationDate = reservedTime.toLocalDate(); + LocalTime reservationTime = reservedTime.toLocalTime(); + + for (WorkTime workTime : employeeWorkTimes) { + if (workTime.getWeek().getDayOfWeek() == reservationDate.getDayOfWeek()) { + if ( isWithinTime(workTime.getStartAt(), workTime.getEndAt(), reservationTime) ) { + return true; // 예약 시간이 직원의 근무 시간 내 + } + } + } + return false; // 근무 시간 외 + } + + // 특정 시간이 사이에 존재하는지 확인 + private boolean isWithinTime(LocalTime start, LocalTime end, LocalTime reservedTime) { + return (reservedTime.isAfter(start) && reservedTime.isBefore(end)) || reservedTime.equals(start) || reservedTime.equals(end); + } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationService.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationService.java index 8748e06..dd62cb3 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationService.java @@ -1,7 +1,7 @@ package com.sideProject.PlanIT.domain.reservation.service; import com.sideProject.PlanIT.domain.reservation.controller.ENUM.ReservationFindOption; -import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponse; +import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponseDto; import java.time.LocalDate; import java.time.LocalDateTime; @@ -12,7 +12,7 @@ public interface ReservationService { String changeAvailability(LocalDate date,List times, Long userId); String reservation(Long reservationId, Long userId, Long programId, LocalDateTime now); - Map> findReservationForWeekByMember(LocalDate day, Long id, ReservationFindOption option); - List findReservationForDayByEmployee(LocalDate day, Long id); + Map> findReservationForWeekByMember(LocalDate day, Long id, ReservationFindOption option); + List findReservationForDayByEmployee(LocalDate day, Long id); String cancel(Long userId, Long reservationId, LocalDateTime now); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceImpl.java index 0501312..0f310cf 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceImpl.java @@ -2,20 +2,21 @@ import com.sideProject.PlanIT.common.response.CustomException; import com.sideProject.PlanIT.common.response.ErrorCode; -import com.sideProject.PlanIT.domain.product.entity.Product; -import com.sideProject.PlanIT.domain.product.entity.enums.ProductType; import com.sideProject.PlanIT.domain.program.entity.Program; import com.sideProject.PlanIT.domain.program.repository.ProgramRepository; import com.sideProject.PlanIT.domain.reservation.controller.ENUM.ReservationFindOption; -import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponse; +import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponseDto; import com.sideProject.PlanIT.domain.reservation.entity.ENUM.ReservationStatus; import com.sideProject.PlanIT.domain.reservation.entity.Reservation; import com.sideProject.PlanIT.domain.reservation.repository.ReservationRepository; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.entity.Member; +import com.sideProject.PlanIT.domain.user.entity.WorkTime; import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; +import com.sideProject.PlanIT.domain.user.entity.enums.Week; import com.sideProject.PlanIT.domain.user.repository.EmployeeRepository; import com.sideProject.PlanIT.domain.user.repository.MemberRepository; +import com.sideProject.PlanIT.domain.user.repository.WorkTimeRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -40,6 +41,7 @@ public class ReservationServiceImpl implements ReservationService { private final MemberRepository memberRepository; private final EmployeeRepository employeeRepository; private final ProgramRepository programRepository; + private final WorkTimeRepository workTimeRepository; @Override @Transactional @@ -51,11 +53,21 @@ public String changeAvailability(LocalDate reservedDate,List reserved new CustomException(member.getId() + "은 직원이 아닙니다.", ErrorCode.NO_AUTHORITY) ); + // 해당 직원의 해당 요일의 근무 시간 조회 + Week week = Week.from(reservedDate); + List workTimesForDay = workTimeRepository.findByEmployeeIdAndWeek(employee.getId(), week); + List reservedDateTimes = createLocalDateTimes(reservedDate, reservedTimes); List existingReservations = reservationRepository.findByEmployeeAndReservedTimeIn(employee, reservedDateTimes); + //근무시간 내인지 체크 + for(LocalDateTime dateTime: reservedDateTimes) { + if(isAvailableForReservation(dateTime, workTimesForDay)) { + throw new CustomException(employee.getId() + " " + dateTime + "은 근무시간 입니다.", ErrorCode.EMPLOYEE_NOT_FOUND); + } + } // 기존 예약 삭제 List reservedReservations = existingReservations.stream() @@ -81,6 +93,16 @@ public String changeAvailability(LocalDate reservedDate,List reserved return "ok"; } + // 예약 가능성 확인: 지정된 예약 시간이 직원의 근무 시간 외인지 확인 + private boolean isAvailableForReservation(LocalDateTime dateTime, List workTimesForDay) { + LocalTime time = dateTime.toLocalTime(); + + return workTimesForDay.stream() + .noneMatch(workTime -> + (time.isAfter(workTime.getStartAt()) || time.equals(workTime.getStartAt())) && + (time.isBefore(workTime.getEndAt()) || time.equals(workTime.getEndAt()))); + } + public static List createLocalDateTimes(LocalDate date, List times) { // Stream을 사용하여 각 LocalTime 요소에 대해 LocalDate와 결합 return times.stream() @@ -119,7 +141,7 @@ public String reservation(Long reservationId, Long userId, Long programId, Local @Override - public Map> findReservationForWeekByMember( + public Map> findReservationForWeekByMember( LocalDate date, Long userId, ReservationFindOption option @@ -138,13 +160,19 @@ public Map> findReservationForWeekByMember( new CustomException("존재하지 않는 트레이너입니다.", ErrorCode.MEMBER_NOT_FOUND) ); reservations = findReservationByEmployee(employee,startOfWeek,endOfWeek,option); + + //예약 시간이 출퇴근 시간 사이에 존재하는지 확인 + List workTimes = workTimeRepository.findByEmployeeId(employee.getId()); + reservations = reservations.stream() + .filter(reservation -> !reservation.isWithinEmployeeWorkTime(workTimes)) + .toList(); } else { reservations = findReservationByMember(member,startOfWeek,endOfWeek,option); } return reservations.stream() - .map(ReservationResponse::of) + .map(ReservationResponseDto::of) .collect(Collectors.groupingBy(response -> response.getReservationTime().toLocalDate())); } @@ -183,18 +211,20 @@ private List findReservationByMember( } @Override - public List findReservationForDayByEmployee(LocalDate date, Long employeeId) { + public List findReservationForDayByEmployee(LocalDate date, Long employeeId) { LocalDateTime startOfWeek = calStartOfDay(date); LocalDateTime endOfWeek = calEndOfDay(date); - List reservations; //트레이너이면 Employee employee = employeeRepository.findById(employeeId).orElseThrow(() -> new CustomException("존재하지 않는 트레이너입니다.", ErrorCode.MEMBER_NOT_FOUND) ); - reservations = reservationRepository.findByEmployeeAndDateTimeBetween(employee,startOfWeek,endOfWeek); + List workTimes = workTimeRepository.findByEmployeeId(employeeId); + List reservations = reservationRepository.findByEmployeeAndDateTimeBetween(employee,startOfWeek,endOfWeek); + return reservations.stream() + .filter(reservation -> !reservation.isWithinEmployeeWorkTime(workTimes)) .map(ReservationResponse::of) .toList(); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerScheduleRegistrationResponse.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerScheduleRegistrationResponse.java deleted file mode 100644 index 4f99929..0000000 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerScheduleRegistrationResponse.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.sideProject.PlanIT.domain.user.dto.employee.response; - -import lombok.Builder; -import lombok.Getter; - -@Getter -public class TrainerScheduleRegistrationResponse { - Long trainer_id ; - - String message; - - @Builder - public TrainerScheduleRegistrationResponse(Long trainer_id, String message){ - this.trainer_id = trainer_id; - this.message = message; - - } - - public static TrainerScheduleRegistrationResponse of(Long trainer_id, String message){ - return TrainerScheduleRegistrationResponse.builder().trainer_id(trainer_id).message(message).build(); - } - - -} diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerScheduleRegistrationResponseDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerScheduleRegistrationResponseDto.java new file mode 100644 index 0000000..823fa3c --- /dev/null +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerScheduleRegistrationResponseDto.java @@ -0,0 +1,24 @@ +package com.sideProject.PlanIT.domain.user.dto.employee.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class TrainerScheduleRegistrationResponseDto { + Long trainer_id ; + + String message; + + @Builder + public TrainerScheduleRegistrationResponseDto(Long trainer_id, String message){ + this.trainer_id = trainer_id; + this.message = message; + + } + + public static TrainerScheduleRegistrationResponseDto of(Long trainer_id, String message){ + return TrainerScheduleRegistrationResponseDto.builder().trainer_id(trainer_id).message(message).build(); + } + + +} diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerSubResponseDto.java similarity index 75% rename from src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java rename to src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerSubResponseDto.java index fa22513..0f3186f 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerResponse.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/employee/response/TrainerSubResponseDto.java @@ -10,21 +10,21 @@ // 특정 멤버 조회 시 멤버 Dto에 포함 @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class TrainerResponse { +public class TrainerSubResponseDto { private Long id; private String career; private String trainerMessage; @Builder - public TrainerResponse(Long id, String career, String trainerMessage) { + public TrainerSubResponseDto(Long id, String career, String trainerMessage) { this.id = id; this.career = career; this.trainerMessage = trainerMessage; } - public static TrainerResponse of(Employee employee) { - return TrainerResponse.builder() + public static TrainerSubResponseDto of(Employee employee) { + return TrainerSubResponseDto.builder() .id(employee.getId()) .career(employee.getCareer()) .trainerMessage(employee.getTrainerMessage()) diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/response/MemberResponseDto.java b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/response/MemberResponseDto.java index 400705e..11a828a 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/response/MemberResponseDto.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/dto/member/response/MemberResponseDto.java @@ -1,6 +1,6 @@ package com.sideProject.PlanIT.domain.user.dto.member.response; -import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerResponse; +import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerSubResponseDto; import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; import com.sideProject.PlanIT.domain.user.entity.Member; import lombok.AccessLevel; @@ -20,10 +20,10 @@ public class MemberResponseDto { private LocalDate birth; private String address; private MemberRole role; - private TrainerResponse trainerInfo; + private TrainerSubResponseDto trainerInfo; @Builder - public MemberResponseDto(Long id, String email, String name, String phone_number, LocalDate birth, String address, MemberRole role, TrainerResponse trainerInfo) { + public MemberResponseDto(Long id, String email, String name, String phone_number, LocalDate birth, String address, MemberRole role, TrainerSubResponseDto trainerInfo) { this.id = id; this.email = email; this.name = name; @@ -34,7 +34,7 @@ public MemberResponseDto(Long id, String email, String name, String phone_number this.trainerInfo = trainerInfo; } - public static MemberResponseDto of(Member member, TrainerResponse trainerResponse) { + public static MemberResponseDto of(Member member, TrainerSubResponseDto trainerSubResponseDto) { return MemberResponseDto.builder() .id(member.getId()) .email(member.getEmail()) @@ -43,7 +43,7 @@ public static MemberResponseDto of(Member member, TrainerResponse trainerRespons .birth(member.getBirth()) .address(member.getAddress()) .role(member.getRole()) - .trainerInfo(trainerResponse) + .trainerInfo(trainerSubResponseDto) .build(); } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/entity/enums/Week.java b/src/main/java/com/sideProject/PlanIT/domain/user/entity/enums/Week.java index 4578443..d121709 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/entity/enums/Week.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/entity/enums/Week.java @@ -1,19 +1,36 @@ package com.sideProject.PlanIT.domain.user.entity.enums; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.LocalDateTime; + public enum Week { + //todo : week 양식 수정 + Mon(DayOfWeek.MONDAY), // 월 + Tue(DayOfWeek.TUESDAY), // 화 + wed(DayOfWeek.WEDNESDAY), // 수 + thu(DayOfWeek.THURSDAY), // 목 + fri(DayOfWeek.FRIDAY), // 금 + sat(DayOfWeek.SATURDAY), // 토 + sun(DayOfWeek.SUNDAY); // 일 + + private final DayOfWeek dayOfWeek; + + Week(DayOfWeek dayOfWeek) { + this.dayOfWeek = dayOfWeek; + } + + public DayOfWeek getDayOfWeek() { + return this.dayOfWeek; + } - //월 - Mon, - //화 - Tue, - //수 - wed, - //목 - thu, - //금 - fri, - //토 - sat, - //일 - sun + public static Week from(LocalDate dateTime) { + DayOfWeek dayOfWeek = dateTime.getDayOfWeek(); + for (Week week : Week.values()) { + if (week.getDayOfWeek() == dayOfWeek) { + return week; + } + } + throw new IllegalArgumentException("No Week enum for DayOfWeek: " + dayOfWeek); + } } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/repository/WorktimeRepository.java b/src/main/java/com/sideProject/PlanIT/domain/user/repository/WorkTimeRepository.java similarity index 62% rename from src/main/java/com/sideProject/PlanIT/domain/user/repository/WorktimeRepository.java rename to src/main/java/com/sideProject/PlanIT/domain/user/repository/WorkTimeRepository.java index 9beafe7..db4f3dd 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/repository/WorktimeRepository.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/repository/WorkTimeRepository.java @@ -2,11 +2,13 @@ import com.sideProject.PlanIT.domain.user.entity.WorkTime; +import com.sideProject.PlanIT.domain.user.entity.enums.Week; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface WorktimeRepository extends JpaRepository { +public interface WorkTimeRepository extends JpaRepository { List findByEmployeeId(Long employee_id); + List findByEmployeeIdAndWeek(Long employeeId, Week week); } diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java index bd06ee4..113b3f5 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/service/MemberServiceImpl.java @@ -5,7 +5,7 @@ import com.sideProject.PlanIT.common.util.JwtTokenProvider; import com.sideProject.PlanIT.domain.user.controller.enums.MemberSearchOption; import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerRequestDto; -import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerResponse; +import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerSubResponseDto; import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerResponseDto; import com.sideProject.PlanIT.domain.user.dto.member.request.MemberChangePasswordRequestDto; import com.sideProject.PlanIT.domain.user.dto.member.request.MemberEditRequestDto; @@ -117,14 +117,14 @@ public MemberResponseDto findMember(Long member_id) { new CustomException(ErrorCode.MEMBER_NOT_FOUND)); //트레이너면 트레이너 정보 조회 - TrainerResponse trainerResponse = null; + TrainerSubResponseDto trainerSubResponseDto = null; if(member.getRole().equals(MemberRole.TRAINER)) { Employee trainer = employeeRepository.findByMemberId(member.getId()).orElseThrow(() -> new CustomException(ErrorCode.EMPLOYEE_NOT_FOUND)); - trainerResponse = TrainerResponse.of(trainer); + trainerSubResponseDto = TrainerSubResponseDto.of(trainer); } - return MemberResponseDto.of(member,trainerResponse); + return MemberResponseDto.of(member, trainerSubResponseDto); } @Override diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeService.java b/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeService.java index 6db7839..af78e29 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeService.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeService.java @@ -1,11 +1,9 @@ package com.sideProject.PlanIT.domain.user.service; -import com.sideProject.PlanIT.domain.product.dto.response.ProductResponseDto; import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto; import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto; -import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponse; +import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponseDto; import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto; -import com.sideProject.PlanIT.domain.user.entity.WorkTime; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -13,7 +11,7 @@ public interface WorktimeService { // 트레이너 출퇴근 등록 - public TrainerScheduleRegistrationResponse trainerScheduleRegistration(List request, Long id); + public TrainerScheduleRegistrationResponseDto trainerScheduleRegistration(List request, Long id); // 트레이너 출퇴근 수정 public String trainerScheduleChange(TrainerSchduleChangeRequestDto request, Long schedule_id); // 트레이너 출퇴근 전체 조회 diff --git a/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeServiceImpl.java b/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeServiceImpl.java index 4c5caaf..aba527f 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeServiceImpl.java +++ b/src/main/java/com/sideProject/PlanIT/domain/user/service/WorktimeServiceImpl.java @@ -3,11 +3,9 @@ import com.sideProject.PlanIT.common.response.CustomException; import com.sideProject.PlanIT.common.response.ErrorCode; -import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto; -import com.sideProject.PlanIT.domain.product.dto.response.ProductResponseDto; import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerSchduleChangeRequestDto; import com.sideProject.PlanIT.domain.user.dto.employee.request.TrainerScheduleRequestDto; -import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponse; +import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleRegistrationResponseDto; import com.sideProject.PlanIT.domain.user.dto.employee.response.TrainerScheduleResponseDto; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.entity.Member; @@ -15,7 +13,7 @@ import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; import com.sideProject.PlanIT.domain.user.repository.EmployeeRepository; import com.sideProject.PlanIT.domain.user.repository.MemberRepository; -import com.sideProject.PlanIT.domain.user.repository.WorktimeRepository; +import com.sideProject.PlanIT.domain.user.repository.WorkTimeRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -23,8 +21,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; import java.util.List; import java.util.stream.Collectors; @@ -37,18 +33,22 @@ public class WorktimeServiceImpl implements WorktimeService { // 트레이너 출퇴근 등록 private final EmployeeRepository employeeRepository; private final MemberRepository memberRepository; - private final WorktimeRepository worktimeRepository; + private final WorkTimeRepository worktimeRepository; @Override - public TrainerScheduleRegistrationResponse trainerScheduleRegistration(List request, Long id){ + public TrainerScheduleRegistrationResponseDto trainerScheduleRegistration(List request, Long id){ Member member = memberRepository.findById(id).orElseThrow(() -> new CustomException("존재하지 않는 회원입니다.", ErrorCode.MEMBER_NOT_FOUND)); Employee trainer = employeeRepository.findByMemberId(member.getId()).orElseThrow(() -> new CustomException("존재하지 않는 직원입니다", ErrorCode.EMPLOYEE_NOT_FOUND)); - for (TrainerScheduleRequestDto requestdto : request){ - worktimeRepository.save(WorkTime.builder().week(requestdto.getWeek()).startAt(requestdto.getStartAt()).endAt(requestdto.getEndAt()).employee(trainer).build()); + for (TrainerScheduleRequestDto requestdto : request){ + worktimeRepository.save(WorkTime.builder() + .week(requestdto.getWeek()) + .startAt(requestdto.getStartAt()) + .endAt(requestdto.getEndAt()) + .employee(trainer) + .build()); - } return TrainerScheduleRegistrationResponse.of(trainer.getId(),"출퇴근시간이 등록되었습니다."); } diff --git a/src/test/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceTest.java b/src/test/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceTest.java index 61b0e2d..c462153 100644 --- a/src/test/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceTest.java +++ b/src/test/java/com/sideProject/PlanIT/domain/program/service/ProgramServiceTest.java @@ -4,10 +4,10 @@ import com.sideProject.PlanIT.domain.product.entity.enums.ProductType; import com.sideProject.PlanIT.domain.product.entity.Product; import com.sideProject.PlanIT.domain.product.repository.ProductRepository; -import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequest; -import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponse; -import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponse; -import com.sideProject.PlanIT.domain.program.dto.response.RegistrationResponse; +import com.sideProject.PlanIT.domain.program.dto.request.RegistrationRequestDto; +import com.sideProject.PlanIT.domain.program.dto.response.ProgramResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.FindRegistrationResponseDto; +import com.sideProject.PlanIT.domain.program.dto.response.RegistrationResponseDto; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.ProgramStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationSearchStatus; @@ -16,7 +16,7 @@ import com.sideProject.PlanIT.domain.program.entity.Registration; import com.sideProject.PlanIT.domain.program.repository.ProgramRepository; import com.sideProject.PlanIT.domain.program.repository.RegistrationRepository; -import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequest; +import com.sideProject.PlanIT.domain.program.dto.request.ProgramModifyRequestDto; import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.repository.EmployeeRepository; @@ -117,13 +117,13 @@ void registerMembership(){ Member member = initMember("tester1",MemberRole.MEMBER); Pageable pageable = PageRequest.of(0, 10); - RegistrationRequest request = RegistrationRequest.builder() + RegistrationRequestDto request = RegistrationRequestDto.builder() .productId(product.getId()) .registrationAt(LocalDate.now()) .build(); //when - RegistrationResponse result = programService.registration(request,member.getId(),LocalDateTime.now()); + RegistrationResponseDto result = programService.registration(request,member.getId(),LocalDateTime.now()); Page programs = programRepository.findByMemberId(member.getId(),pageable); List registrations = registrationRepository.findByMemberId(member.getId()); @@ -143,13 +143,13 @@ void registerPT(){ Pageable pageable = PageRequest.of(0, 10); - RegistrationRequest request = RegistrationRequest.builder() + RegistrationRequestDto request = RegistrationRequestDto.builder() .productId(product.getId()) .registrationAt(LocalDate.now()) .build(); //when - RegistrationResponse result = programService.registration(request,member.getId(),LocalDateTime.now()); + RegistrationResponseDto result = programService.registration(request,member.getId(),LocalDateTime.now()); Page programs = programRepository.findByMemberId(member.getId(),pageable); List registrations = registrationRepository.findByMemberId(member.getId()); @@ -170,14 +170,14 @@ void registerPTaddTrainer(){ Pageable pageable = PageRequest.of(0, 10); - RegistrationRequest request = RegistrationRequest.builder() + RegistrationRequestDto request = RegistrationRequestDto.builder() .productId(product.getId()) .registrationAt(LocalDate.now()) .trainerId(employee.getId()) .build(); //when - RegistrationResponse result = programService.registration(request,member.getId(),LocalDateTime.now()); + RegistrationResponseDto result = programService.registration(request,member.getId(),LocalDateTime.now()); Page programs = programRepository.findByMemberId(member.getId(),pageable); List registrations = registrationRepository.findByMemberId(member.getId()); @@ -197,7 +197,7 @@ void register_non_existent_user(){ Product product = initProduct("회원권 1달", periodOfTenDays,30,ProductType.PT); Member member = initMember("tester1",MemberRole.MEMBER); - RegistrationRequest request = RegistrationRequest.builder() + RegistrationRequestDto request = RegistrationRequestDto.builder() .productId(product.getId()) .registrationAt(LocalDate.now()) .build(); @@ -217,7 +217,7 @@ void register_non_existent_Employee(){ Product product = initProduct("PT권 30회", periodOfTenDays,30,ProductType.PT); Member member = initMember("tester1",MemberRole.MEMBER); - RegistrationRequest request = RegistrationRequest.builder() + RegistrationRequestDto request = RegistrationRequestDto.builder() .productId(product.getId()) .registrationAt(LocalDate.now()) .trainerId(0L) @@ -238,7 +238,7 @@ void register_non_existent_product(){ Product product = initProduct("회원권 1달", periodOfTenDays,30,ProductType.PT); Member member = initMember("tester1",MemberRole.MEMBER); - RegistrationRequest request = RegistrationRequest.builder() + RegistrationRequestDto request = RegistrationRequestDto.builder() .productId(product.getId()+1) .registrationAt(LocalDate.now()) .build(); @@ -293,7 +293,7 @@ void modifyProgram(){ Member member2 = initMember("tester2",MemberRole.MEMBER); //when - ProgramModifyRequest request = ProgramModifyRequest.builder() + ProgramModifyRequestDto request = ProgramModifyRequestDto.builder() .employId(trainer2.getId()) .memberId(member2.getId()) .startTime("2023-03-06") @@ -322,7 +322,7 @@ void modifyProgram(){ @Test void modifyProgram2(){ //given //when - ProgramModifyRequest request = ProgramModifyRequest.builder() + ProgramModifyRequestDto request = ProgramModifyRequestDto.builder() .employId(1L) .memberId(1L) .startTime("2023-03-06") @@ -369,7 +369,7 @@ void modifyProgram3(){ .build(); Program result = programRepository.save(program); - ProgramModifyRequest request = ProgramModifyRequest.builder() + ProgramModifyRequestDto request = ProgramModifyRequestDto.builder() .employId(1L) .memberId(member.getId()+1) .startTime("2023-03-06") @@ -416,7 +416,7 @@ void modifyProgram4(){ .build(); Program result = programRepository.save(program);; - ProgramModifyRequest request = ProgramModifyRequest.builder() + ProgramModifyRequestDto request = ProgramModifyRequestDto.builder() .employId(trainer.getId()+1) .memberId(member.getId()) .startTime("2023-03-06") @@ -878,7 +878,7 @@ void findAllInProcessProgram(){ programRepository.save(program3); //when - Page results1 = programService.find(admin.getId(), ProgramSearchStatus.ALL, pageable); + Page results1 = programService.find(admin.getId(), ProgramSearchStatus.ALL, pageable); //then assertThat(results1.getContent().size()).isEqualTo(3); @@ -982,7 +982,7 @@ void findAllProgram(){ programRepository.save(program3); //when - Page results1 = programService.find(admin.getId(), ProgramSearchStatus.ALL, pageable); + Page results1 = programService.find(admin.getId(), ProgramSearchStatus.ALL, pageable); //then assertThat(results1.getContent().size()).isEqualTo(3); @@ -1086,7 +1086,7 @@ void findInValidProgram(){ programRepository.save(program3); //when - Page results1 = programService.find(admin.getId(), ProgramSearchStatus.INVALID, pageable); + Page results1 = programService.find(admin.getId(), ProgramSearchStatus.INVALID, pageable); //then assertThat(results1.getContent().size()).isEqualTo(1); @@ -1290,8 +1290,8 @@ void findInProgressProgramByUser(){ programRepository.save(program3); //when - Page results1 = programService.findByUser(member1.getId(), ProgramSearchStatus.VALID, pageable); - Page results2 = programService.findByUser(member2.getId(), ProgramSearchStatus.VALID, pageable); + Page results1 = programService.findByUser(member1.getId(), ProgramSearchStatus.VALID, pageable); + Page results2 = programService.findByUser(member2.getId(), ProgramSearchStatus.VALID, pageable); //then assertThat(results1.getContent().size()).isEqualTo(2); @@ -1387,8 +1387,8 @@ void findInProgressProgramByEmployee(){ programRepository.save(program3); //when - Page results1 = programService.findByUser(trainer.getMember().getId(), ProgramSearchStatus.INVALID,pageable); - Page results2 = programService.findByUser(trainer2.getMember().getId(), ProgramSearchStatus.INVALID,pageable); + Page results1 = programService.findByUser(trainer.getMember().getId(), ProgramSearchStatus.INVALID,pageable); + Page results2 = programService.findByUser(trainer2.getMember().getId(), ProgramSearchStatus.INVALID,pageable); //then assertThat(results1.getContent().size()).isEqualTo(2); @@ -1485,7 +1485,7 @@ void findAllProgramByUser(){ programRepository.save(program3); //when - Page results1 = programService.findByUser(member1.getId(), ProgramSearchStatus.ALL, pageable); + Page results1 = programService.findByUser(member1.getId(), ProgramSearchStatus.ALL, pageable); //then assertThat(results1.getContent().size()).isEqualTo(3); @@ -1625,7 +1625,7 @@ void findInvalidProgramByUser(){ //when - Page results1 = programService.findByUser(member1.getId(), ProgramSearchStatus.INVALID, pageable); + Page results1 = programService.findByUser(member1.getId(), ProgramSearchStatus.INVALID, pageable); //then assertThat(results1.getContent().size()).isEqualTo(4); @@ -1719,7 +1719,7 @@ void findAllProgramByEmployee(){ programRepository.save(program3); //when - Page results1 = programService.findByUser(trainer.getMember().getId(), ProgramSearchStatus.ALL,pageable); + Page results1 = programService.findByUser(trainer.getMember().getId(), ProgramSearchStatus.ALL,pageable); //then assertThat(results1.getContent().size()).isEqualTo(3); @@ -1935,8 +1935,8 @@ void FindAllRegistrationByUser(){ registrationRepository.save(registration5); //when - Page result1 = programService.findRegistrationsByUser(member1.getId(), RegistrationSearchStatus.ALL, pageable); - Page result2 = programService.findRegistrationsByUser(member2.getId(), RegistrationSearchStatus.ALL, pageable); + Page result1 = programService.findRegistrationsByUser(member1.getId(), RegistrationSearchStatus.ALL, pageable); + Page result2 = programService.findRegistrationsByUser(member2.getId(), RegistrationSearchStatus.ALL, pageable); //then assertThat(result1.getContent()).hasSize(4); @@ -2022,8 +2022,8 @@ void findReadyRegistrationByUser(){ registrationRepository.save(registration5); //when - Page result1 = programService.findRegistrationsByUser(member1.getId(), RegistrationSearchStatus.READY, pageable); - Page result2 = programService.findRegistrationsByUser(member2.getId(), RegistrationSearchStatus.READY, pageable); + Page result1 = programService.findRegistrationsByUser(member1.getId(), RegistrationSearchStatus.READY, pageable); + Page result2 = programService.findRegistrationsByUser(member2.getId(), RegistrationSearchStatus.READY, pageable); //then assertThat(result1.getContent()).hasSize(2); @@ -2181,7 +2181,7 @@ void adminIsFindAllRegistration(){ registrationRepository.save(registration5); //when - Page result1 = programService.findRegistrationsByAdmin(admin.getId(), RegistrationSearchStatus.ALL, pageable); + Page result1 = programService.findRegistrationsByAdmin(admin.getId(), RegistrationSearchStatus.ALL, pageable); //then assertThat(result1.getContent()).hasSize(5); @@ -2267,7 +2267,7 @@ void adminIsFindReadyRegistration(){ registrationRepository.save(registration5); //when - Page result1 = programService.findRegistrationsByAdmin(admin.getId(), RegistrationSearchStatus.READY, pageable); + Page result1 = programService.findRegistrationsByAdmin(admin.getId(), RegistrationSearchStatus.READY, pageable); //then assertThat(result1.getContent()).hasSize(3); @@ -2626,7 +2626,7 @@ void findByProgramId(){ //when - ProgramResponse results1 = programService.findByProgramId(program.getId(),member1.getId()); + ProgramResponseDto results1 = programService.findByProgramId(program.getId(),member1.getId()); //then assertThat(results1).extracting("startAt","endAt","status") @@ -2667,7 +2667,7 @@ void findByProgramId2(){ //when - ProgramResponse results1 = programService.findByProgramId(program.getId(),trainer.getMember().getId()); + ProgramResponseDto results1 = programService.findByProgramId(program.getId(),trainer.getMember().getId()); //then assertThat(results1).extracting("id","startAt","endAt","status") @@ -2733,8 +2733,8 @@ void findByProgramId3(){ //when - ProgramResponse results1 = programService.findByProgramId(program.getId(),admin.getId()); - ProgramResponse results2 = programService.findByProgramId(program2.getId(),admin.getId()); + ProgramResponseDto results1 = programService.findByProgramId(program.getId(),admin.getId()); + ProgramResponseDto results2 = programService.findByProgramId(program2.getId(),admin.getId()); //then assertThat(results1).extracting("id","startAt","endAt","status") diff --git a/src/test/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceTest.java b/src/test/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceTest.java index 88bc710..5e5bc4f 100644 --- a/src/test/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/sideProject/PlanIT/domain/reservation/service/ReservationServiceTest.java @@ -6,20 +6,22 @@ import com.sideProject.PlanIT.domain.product.repository.ProductRepository; import com.sideProject.PlanIT.domain.program.entity.Program; import com.sideProject.PlanIT.domain.program.entity.Registration; -import com.sideProject.PlanIT.domain.program.entity.enums.ProgramSearchStatus; import com.sideProject.PlanIT.domain.program.entity.enums.RegistrationStatus; import com.sideProject.PlanIT.domain.program.repository.ProgramRepository; import com.sideProject.PlanIT.domain.program.repository.RegistrationRepository; import com.sideProject.PlanIT.domain.reservation.controller.ENUM.ReservationFindOption; -import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponse; +import com.sideProject.PlanIT.domain.reservation.dto.response.ReservationResponseDto; import com.sideProject.PlanIT.domain.reservation.entity.ENUM.ReservationStatus; import com.sideProject.PlanIT.domain.reservation.entity.Reservation; import com.sideProject.PlanIT.domain.reservation.repository.ReservationRepository; import com.sideProject.PlanIT.domain.user.entity.Employee; import com.sideProject.PlanIT.domain.user.entity.Member; +import com.sideProject.PlanIT.domain.user.entity.WorkTime; import com.sideProject.PlanIT.domain.user.entity.enums.MemberRole; +import com.sideProject.PlanIT.domain.user.entity.enums.Week; import com.sideProject.PlanIT.domain.user.repository.EmployeeRepository; import com.sideProject.PlanIT.domain.user.repository.MemberRepository; +import com.sideProject.PlanIT.domain.user.repository.WorkTimeRepository; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; @@ -60,11 +62,14 @@ class ReservationServiceTest { ReservationRepository reservationRepository; @Autowired ReservationService reservationService; + @Autowired + WorkTimeRepository worktimeRepository; DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd H:mm"); @AfterEach void tearDown() { + worktimeRepository.deleteAllInBatch(); reservationRepository.deleteAllInBatch(); programRepository.deleteAllInBatch(); registrationRepository.deleteAllInBatch(); @@ -266,6 +271,34 @@ void addReservation5() { .isInstanceOf(CustomException.class) .hasMessage(trainer.getId() + "은 직원이 아닙니다."); } + + @DisplayName("실패 : 근무시간 내에는 예약이 설정이 불가능하다") + @Test + void addReservation6() { + //given + Employee trainer = initTrainer("trainer"); + + WorkTime workTime = WorkTime.builder() + .employee(trainer) + .week(Week.Tue) + .startAt(LocalTime.of(10,0,0)) + .endAt(LocalTime.of(11,0,0)) + .build(); + worktimeRepository.save(workTime); + + LocalDate date = LocalDate.of(2023,3,19); + LocalTime time1 = LocalTime.of(10, 0); + LocalTime time2 = LocalTime.of(11, 0, 0); + LocalTime time3 = LocalTime.of(12, 0, 0); + LocalTime time4 = LocalTime.of(13, 0, 0); + + List times = List.of(time1, time2, time3, time4); + //when + //then + assertThatThrownBy(() -> reservationService.changeAvailability(date,times, trainer.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(trainer.getId() + " 2023-03-19T10:00은 근무시간 입니다."); + } } @Nested @@ -766,8 +799,8 @@ void findReservationByMemberTest(){ List reservations = List.of(reservation1,reservation2,reservation3); reservationRepository.saveAll(reservations); //when - Map>result1 = reservationService.findReservationForWeekByMember(today, member1.getId(), ReservationFindOption.ALL); - Map> result2 = reservationService.findReservationForWeekByMember(today2, member1.getId(), ReservationFindOption.ALL); + Map>result1 = reservationService.findReservationForWeekByMember(today, member1.getId(), ReservationFindOption.ALL); + Map> result2 = reservationService.findReservationForWeekByMember(today2, member1.getId(), ReservationFindOption.ALL); //then @@ -863,8 +896,8 @@ void findReservationByMemberTes2t(){ List reservations = List.of(reservation1,reservation2,reservation3); reservationRepository.saveAll(reservations); //when - Map>result1 = reservationService.findReservationForWeekByMember(today, member1.getId(), ReservationFindOption.FINISHED); - Map> result2 = reservationService.findReservationForWeekByMember(today2, member1.getId(), ReservationFindOption.FINISHED); + Map>result1 = reservationService.findReservationForWeekByMember(today, member1.getId(), ReservationFindOption.FINISHED); + Map> result2 = reservationService.findReservationForWeekByMember(today2, member1.getId(), ReservationFindOption.FINISHED); //then @@ -951,8 +984,8 @@ void findReservationByEmployeeTest(){ List reservations = List.of(reservation1,reservation2,reservation3); reservationRepository.saveAll(reservations); //when - Map> result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.ALL); - Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.ALL); + Map> result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.ALL); + Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.ALL); //then assertThat(result1).hasSize(2); @@ -1034,8 +1067,8 @@ void findEmptyReservation(){ List reservations = List.of(reservation1,reservation2); List reservationList = reservationRepository.saveAll(reservations); //when - Map> result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.ALL); - Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.ALL); + Map> result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.ALL); + Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.ALL); //then @@ -1122,8 +1155,8 @@ void findReservationByMemberTest3(){ List reservations = List.of(reservation1,reservation2,reservation3); reservationRepository.saveAll(reservations); //when - Map>result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.RESERVED); - Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.RESERVED); + Map>result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.RESERVED); + Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.RESERVED); //then @@ -1209,8 +1242,8 @@ void findReservationByMemberTest4(){ List reservations = List.of(reservation1,reservation2,reservation3); reservationRepository.saveAll(reservations); //when - Map>result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.POSSIBLE); - Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.POSSIBLE); + Map>result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.POSSIBLE); + Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.POSSIBLE); //then @@ -1297,8 +1330,8 @@ void findReservationByMemberTest5(){ List reservations = List.of(reservation1,reservation2,reservation3); reservationRepository.saveAll(reservations); //when - Map>result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.FINISHED); - Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.FINISHED); + Map>result1 = reservationService.findReservationForWeekByMember(today, trainer.getMember().getId(), ReservationFindOption.FINISHED); + Map> result2 = reservationService.findReservationForWeekByMember(today2, trainer.getMember().getId(), ReservationFindOption.FINISHED); //then @@ -1535,8 +1568,8 @@ void findReservationForDayByEmployee(){ List reservations = List.of(reservation1,reservation2,reservation3,reservation4); reservationRepository.saveAll(reservations); //when - List result1 = reservationService.findReservationForDayByEmployee(today, trainer.getId()); - List result2 = reservationService.findReservationForDayByEmployee(today2, trainer.getId()); + List result1 = reservationService.findReservationForDayByEmployee(today, trainer.getId()); + List result2 = reservationService.findReservationForDayByEmployee(today2, trainer.getId()); //then @@ -1554,5 +1587,104 @@ void findReservationForDayByEmployee(){ ).containsExactly( null,reservationTime4, ReservationStatus.POSSIBLE); } + + @DisplayName("트레이너의 출근 시간 외의 예약을 조회 가능하다") + @Test + void findReservationForDayByEmployee2(){ + //given + Period periodOfTenDays = Period.ofMonths(0); + Product product = initProduct("PT 30회권", periodOfTenDays,30,ProductType.PT); + Employee trainer = initTrainer("trainer"); + Member member1 = initMember("tester1",MemberRole.MEMBER); + + Registration registration = Registration.builder() + .product(product) + .member(member1) + .discount(0) + .totalPrice(30000) + .status(RegistrationStatus.ACCEPTED) + .paymentAt(LocalDateTime.parse("2024-03-10 00:00", DATE_TIME_FORMATTER)) + .registrationAt(LocalDateTime.parse("2000-03-10 00:00", DATE_TIME_FORMATTER)) + .refundAt(null) + .build(); + Registration saveRegistration = registrationRepository.save(registration); + + Program program = Program.builder() + .registration(saveRegistration) + .product(saveRegistration.getProduct()) + .member(saveRegistration.getMember()) + .employee(trainer) + .status(IN_PROGRESS) + .startAt(LocalDate.parse("2024-03-10", DateTimeFormatter.ISO_DATE)) + .build(); + Program program1 = programRepository.save(program); + + WorkTime workTime = WorkTime.builder() + .employee(trainer) + .week(Week.Tue) + .startAt(LocalTime.of(10,0,0)) + .endAt(LocalTime.of(11,0,0)) + .build(); + worktimeRepository.save(workTime); + + LocalDateTime reservationTime1 = LocalDateTime.of(2024, 3, 19, 10, 0, 0); + Reservation reservation1 = Reservation.builder() + .reservedTime(reservationTime1) + .employee(trainer) + .status(ReservationStatus.POSSIBLE) + .classTime(LocalTime.of(1,0)) + .build(); + + LocalDateTime reservationTime2= LocalDateTime.of(2024, 3, 19, 11, 0, 0); + Reservation reservation2 = Reservation.builder() + .reservedTime(reservationTime2) + .employee(trainer) + .status(ReservationStatus.POSSIBLE) + .classTime(LocalTime.of(1,0)) + .build(); + + LocalDateTime reservationTime3 = LocalDateTime.of(2024, 3, 19, 12, 0, 0); + Reservation reservation3 = Reservation.builder() + .reservedTime(reservationTime3) + .employee(trainer) + .status(ReservationStatus.POSSIBLE) + .classTime(LocalTime.of(1,0)) + .build(); + + LocalDateTime reservationTime4 = LocalDateTime.of(2024, 3, 20, 12, 0, 0); + Reservation reservation4 = Reservation.builder() + .reservedTime(reservationTime4) + .employee(trainer) + .status(ReservationStatus.POSSIBLE) + .classTime(LocalTime.of(1,0)) + .build(); + + LocalDateTime reservationTime = LocalDateTime.of(2024, 3, 16, 10, 0, 0); + + reservation1.reservation(program1,member1,reservationTime); + + LocalDate today = LocalDate.of(2024, 3, 19); + LocalDate today2 = LocalDate.of(2024, 3, 20); + + List reservations = List.of(reservation1,reservation2,reservation3,reservation4); + reservationRepository.saveAll(reservations); + //when + List result1 = reservationService.findReservationForDayByEmployee(today, trainer.getId()); + List result2 = reservationService.findReservationForDayByEmployee(today2, trainer.getId()); + + + //then + assertThat(result1).hasSize(1); + assertThat(result1).extracting( + "programId","reservationTime", "status" + ).contains( + tuple(null,reservationTime3, ReservationStatus.POSSIBLE) + ); + assertThat(result2).hasSize(1); + assertThat(result2.get(0)).extracting( + "programId","reservationTime", "status" + ).containsExactly( + null,reservationTime4, ReservationStatus.POSSIBLE); + } } } \ No newline at end of file