From b91ed0a09bab6486acf9486cd0c8d905fc21154a Mon Sep 17 00:00:00 2001 From: threeony Date: Fri, 2 Feb 2024 23:05:09 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20on=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/onnoff/auth/config/WebConfig.java | 2 +- .../onnoff/auth/jwt/filter/JwtAuthFilter.java | 2 +- .../controller/ResolutionController.java | 26 +++++++--------- .../converter/ResolutionConverter.java | 5 ++-- .../on/resolution/dto/ResolutionRequest.java | 7 ++--- .../on/resolution/dto/ResolutionResponse.java | 3 +- .../repository/ResolutionRepository.java | 2 +- .../resolution/service/ResolutionService.java | 8 ++--- .../service/ResolutionServiceImpl.java | 30 +++++++++---------- .../on/worklog/controller/OnController.java | 5 ++-- .../worklog/controller/WorklogController.java | 7 ++--- .../on/worklog/converter/OnConverter.java | 2 -- .../worklog/converter/WorklogConverter.java | 2 ++ .../domain/on/worklog/dto/OnResponse.java | 1 - .../domain/on/worklog/dto/WorklogRequest.java | 3 +- .../on/worklog/dto/WorklogResponse.java | 2 ++ .../worklog/repository/WorklogRepository.java | 2 +- .../domain/on/worklog/service/OnService.java | 2 +- .../on/worklog/service/OnServiceImpl.java | 12 ++++---- .../on/worklog/service/WorklogService.java | 2 +- .../worklog/service/WorklogServiceImpl.java | 6 ++-- 21 files changed, 62 insertions(+), 69 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/auth/config/WebConfig.java b/src/main/java/com/onnoff/onnoff/auth/config/WebConfig.java index 53610bb..9237095 100644 --- a/src/main/java/com/onnoff/onnoff/auth/config/WebConfig.java +++ b/src/main/java/com/onnoff/onnoff/auth/config/WebConfig.java @@ -39,6 +39,6 @@ public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new UserInterceptor(userService, jwtUtil)) .addPathPatterns("/**") // 스프링 경로는 /*와 /**이 다름 - .excludePathPatterns("/swagger-ui/**", "/v3/api-docs/**", "/oauth2/**", "/on/**", "/health", "/token/**" , "/message/**"); + .excludePathPatterns("/swagger-ui/**", "/v3/api-docs/**", "/oauth2/**", "/health", "/token/**" , "/message/**"); } } diff --git a/src/main/java/com/onnoff/onnoff/auth/jwt/filter/JwtAuthFilter.java b/src/main/java/com/onnoff/onnoff/auth/jwt/filter/JwtAuthFilter.java index c7ee977..7bc48bc 100644 --- a/src/main/java/com/onnoff/onnoff/auth/jwt/filter/JwtAuthFilter.java +++ b/src/main/java/com/onnoff/onnoff/auth/jwt/filter/JwtAuthFilter.java @@ -25,7 +25,7 @@ @RequiredArgsConstructor public class JwtAuthFilter extends OncePerRequestFilter { private final JwtTokenProvider jwtTokenProvider; - private final static String[] ignorePrefix = {"/swagger-ui", "/v3/api-docs", "/oauth2", "/on", "/health", "/token/validate" , "/message"}; + private final static String[] ignorePrefix = {"/swagger-ui", "/v3/api-docs", "/oauth2", "/health", "/token/validate" , "/message"}; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { log.info("url ={}", request.getRequestURI()); diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/controller/ResolutionController.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/controller/ResolutionController.java index 097dfe9..1401fe1 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/controller/ResolutionController.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/controller/ResolutionController.java @@ -22,34 +22,30 @@ public class ResolutionController { @GetMapping("/") @Operation(summary = "오늘의 다짐 조회 API") - public ApiResponse getResolutions(@RequestParam(name = "userId") Long userId, - @RequestParam(name = "date") LocalDate date){ - List resolutionList = resolutionService.getAll(userId, date); - return ApiResponse.onSuccess(ResolutionConverter.toResolutionViewDTO(userId, date, resolutionList)); + public ApiResponse getResolutions(@RequestParam(name = "date") LocalDate date){ + List resolutionList = resolutionService.getAll(date); + return ApiResponse.onSuccess(ResolutionConverter.toResolutionViewDTO(date, resolutionList)); } @PostMapping("/") @Operation(summary = "오늘의 다짐 추가 API") - public ApiResponse addResolution(@RequestParam(name = "userId") Long userId, - @RequestBody @Valid ResolutionRequest.AddResolutionDTO request){ - Resolution resolution = resolutionService.addResolution(userId, request); + public ApiResponse addResolution(@RequestBody @Valid ResolutionRequest.AddResolutionDTO request){ + Resolution resolution = resolutionService.addResolution(request); return ApiResponse.onSuccess(ResolutionConverter.toAddResolutionResultDTO(resolution)); } @PutMapping("/") @Operation(summary = "오늘의 다짐 수정 API") - public ApiResponse modifyResolution(@RequestParam(name = "userId") Long userId, - @RequestBody @Valid ResolutionRequest.ModifyResolutionDTO request){ - resolutionService.modifyResolution(userId, request); - return ApiResponse.onSuccess(null); + public ApiResponse modifyResolution(@RequestBody @Valid ResolutionRequest.ModifyResolutionDTO request){ + List modifiedResolutionList = resolutionService.modifyResolution(request); + return ApiResponse.onSuccess(ResolutionConverter.toResolutionViewDTO(request.getDate(), modifiedResolutionList)); } @DeleteMapping("/{resolutionId}") @Operation(summary = "오늘의 다짐 삭제 API") - public ApiResponse deleteResolution(@RequestParam(name = "userId") Long userId, - @RequestParam(name = "date") LocalDate date, - @PathVariable(name = "resolutionId") Long resolutionId){ - resolutionService.deleteResolution(userId, date, resolutionId); + public ApiResponse deleteResolution(@RequestParam(name = "date") LocalDate date, + @PathVariable(name = "resolutionId") Long resolutionId){ + resolutionService.deleteResolution(date, resolutionId); return ApiResponse.onSuccess(null); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/converter/ResolutionConverter.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/converter/ResolutionConverter.java index 8e58e53..0c7b4d2 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/converter/ResolutionConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/converter/ResolutionConverter.java @@ -24,11 +24,13 @@ public static Resolution toAddResolution(Long order, ResolutionRequest.AddResolu public static ResolutionResponse.AddResultDTO toAddResolutionResultDTO(Resolution resolution){ return ResolutionResponse.AddResultDTO.builder() .resolutionId(resolution.getId()) + .order(resolution.getOrder()) + .content(resolution.getContent()) .createdAt(resolution.getCreatedAt()) .build(); } - public static ResolutionResponse.ResolutionViewDTO toResolutionViewDTO(Long userId, LocalDate date, List resolutionList){ + public static ResolutionResponse.ResolutionViewDTO toResolutionViewDTO(LocalDate date, List resolutionList){ List resolutionDTOList = resolutionList.stream() .map(resolution -> ResolutionResponse.ResolutionDTO.builder() .resolutionId(resolution.getId()) @@ -38,7 +40,6 @@ public static ResolutionResponse.ResolutionViewDTO toResolutionViewDTO(Long user .collect(Collectors.toList()); return ResolutionResponse.ResolutionViewDTO.builder() - .userId(userId) .date(date) .resolutionDTOList(resolutionDTOList) .build(); diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionRequest.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionRequest.java index 627f3f6..19356e7 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionRequest.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionRequest.java @@ -2,10 +2,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.validation.Valid; -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.*; import lombok.Getter; import java.time.LocalDate; @@ -14,7 +11,7 @@ public class ResolutionRequest { @Getter public static class AddResolutionDTO{ - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + @PastOrPresent LocalDate date; @NotBlank @Size(max = 30) diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionResponse.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionResponse.java index e252eba..c7f27f2 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionResponse.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/dto/ResolutionResponse.java @@ -16,6 +16,8 @@ public class ResolutionResponse { @AllArgsConstructor public static class AddResultDTO{ Long resolutionId; + Integer order; + String content; LocalDateTime createdAt; } @@ -24,7 +26,6 @@ public static class AddResultDTO{ @NoArgsConstructor @AllArgsConstructor public static class ResolutionViewDTO{ - Long userId; LocalDate date; List resolutionDTOList; } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/repository/ResolutionRepository.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/repository/ResolutionRepository.java index 2dbe242..29f998b 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/repository/ResolutionRepository.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/repository/ResolutionRepository.java @@ -8,7 +8,7 @@ import java.util.List; public interface ResolutionRepository extends JpaRepository { - List findAllByUserAndDate(User user, LocalDate date); + List findAllByUserAndDateOrderByOrder(User user, LocalDate date); Long countByUserAndDate(User user, LocalDate date); } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionService.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionService.java index 5bf6d3e..79717ca 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionService.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionService.java @@ -8,11 +8,11 @@ public interface ResolutionService { - List getAll(Long userId, LocalDate date); + List getAll(LocalDate date); - Resolution addResolution(Long userId, ResolutionRequest.AddResolutionDTO request); + Resolution addResolution(ResolutionRequest.AddResolutionDTO request); - void modifyResolution(Long userId, ResolutionRequest.ModifyResolutionDTO request); + List modifyResolution(ResolutionRequest.ModifyResolutionDTO request); - void deleteResolution(Long userId, LocalDate date, Long resolutionId); + void deleteResolution(LocalDate date, Long resolutionId); } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionServiceImpl.java index bb85dcf..e2fbaad 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/resolution/service/ResolutionServiceImpl.java @@ -1,41 +1,38 @@ package com.onnoff.onnoff.domain.on.resolution.service; import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; -import com.onnoff.onnoff.apiPayload.exception.GeneralException; import com.onnoff.onnoff.apiPayload.exception.handler.ResolutionHandler; +import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.on.resolution.converter.ResolutionConverter; import com.onnoff.onnoff.domain.on.resolution.dto.ResolutionRequest; import com.onnoff.onnoff.domain.on.resolution.entity.Resolution; import com.onnoff.onnoff.domain.on.resolution.repository.ResolutionRepository; import com.onnoff.onnoff.domain.user.User; -import com.onnoff.onnoff.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; @Service @Transactional @RequiredArgsConstructor public class ResolutionServiceImpl implements ResolutionService{ - private final UserRepository userRepository; private final ResolutionRepository resolutionRepository; @Override - public List getAll(Long userId, LocalDate date){ - User user = userRepository.findById(userId) - .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); + public List getAll(LocalDate date){ + User user = UserContext.getUser(); - return resolutionRepository.findAllByUserAndDate(user, date).stream().toList(); + return resolutionRepository.findAllByUserAndDateOrderByOrder(user, date).stream().toList(); } @Override @Transactional - public Resolution addResolution(Long userId, ResolutionRequest.AddResolutionDTO request){ - User user = userRepository.findById(userId) - .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); + public Resolution addResolution(ResolutionRequest.AddResolutionDTO request){ + User user = UserContext.getUser(); Long order = resolutionRepository.countByUserAndDate(user, request.getDate()); @@ -47,25 +44,27 @@ public Resolution addResolution(Long userId, ResolutionRequest.AddResolutionDTO @Override @Transactional - public void modifyResolution(Long userId, ResolutionRequest.ModifyResolutionDTO requestList){ + public List modifyResolution(ResolutionRequest.ModifyResolutionDTO requestList){ + List modifiedResolutionList = new ArrayList<>(); for(ResolutionRequest.ResolutionDTO request : requestList.getResolutionDTOList()){ Resolution resolutionToModify = resolutionRepository.findById(request.getResolutionId()) .orElseThrow(() -> new ResolutionHandler(ErrorStatus.RESOLUTION_NOT_FOUND)); resolutionToModify.modifyResolution(request.getOrder(), request.getContent()); + modifiedResolutionList.add(resolutionToModify); } + return modifiedResolutionList; } @Override @Transactional - public void deleteResolution(Long userId, LocalDate date, Long resolutionId){ + public void deleteResolution(LocalDate date, Long resolutionId){ Resolution resolutionToDelete = resolutionRepository.findById(resolutionId) .orElseThrow(() -> new ResolutionHandler(ErrorStatus.RESOLUTION_NOT_FOUND)); //해당 resolution 아래 객체들 순서 당겨주기 - User user = userRepository.findById(userId) - .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); - List resolutionList = resolutionRepository.findAllByUserAndDate(user, date).stream().toList(); + User user = UserContext.getUser(); + List resolutionList = resolutionRepository.findAllByUserAndDateOrderByOrder(user, date).stream().toList(); for(Resolution resolution : resolutionList){ if(resolution.getOrder() > resolutionToDelete.getOrder()){ @@ -73,7 +72,6 @@ public void deleteResolution(Long userId, LocalDate date, Long resolutionId){ } } - resolutionRepository.delete(resolutionToDelete); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/OnController.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/OnController.java index 57b8922..671890a 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/OnController.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/OnController.java @@ -20,8 +20,7 @@ public class OnController { @GetMapping("/") @Operation(summary = "ON 화면 조회") - public ApiResponse getOn(@RequestParam(name = "userId") Long userId, - @RequestParam(name = "date", required = false) LocalDate date){ - return ApiResponse.onSuccess(onService.getOn(userId, date)); + public ApiResponse getOn(@RequestParam(name = "date", required = false) LocalDate date){ + return ApiResponse.onSuccess(onService.getOn(date)); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/WorklogController.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/WorklogController.java index 3dead95..c296a4d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/WorklogController.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/controller/WorklogController.java @@ -20,9 +20,8 @@ public class WorklogController { @PostMapping("/") @Operation(summary = "업무일지 추가 API") - public ApiResponse addWorklog(@RequestParam(name = "userId") Long userId, - @RequestBody @Valid WorklogRequest.AddWorklogDTO request){ - Worklog worklog = worklogService.addWorklog(userId, request); + public ApiResponse addWorklog(@RequestBody @Valid WorklogRequest.AddWorklogDTO request){ + Worklog worklog = worklogService.addWorklog(request); return ApiResponse.onSuccess(WorklogConverter.toAddWorklogResultDTO(worklog)); } @@ -54,7 +53,7 @@ public ApiResponse modifyWorklogIsChecked(@Path @DeleteMapping("/{worklogId}") @Operation(summary = "업무일지 삭제 API") - public ApiResponse deleteWorklog(@PathVariable(name = "worklogId") Long worklogId){ + public ApiResponse deleteWorklog(@PathVariable(name = "worklogId") Long worklogId){ worklogService.deleteWorklog(worklogId); return ApiResponse.onSuccess(null); } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/OnConverter.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/OnConverter.java index 6742979..d37a58a 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/OnConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/OnConverter.java @@ -1,6 +1,5 @@ package com.onnoff.onnoff.domain.on.worklog.converter; -import com.onnoff.onnoff.domain.on.resolution.converter.ResolutionConverter; import com.onnoff.onnoff.domain.on.resolution.dto.ResolutionResponse; import com.onnoff.onnoff.domain.on.resolution.entity.Resolution; import com.onnoff.onnoff.domain.on.worklog.dto.OnResponse; @@ -9,7 +8,6 @@ import java.time.LocalDate; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; public class OnConverter { diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/WorklogConverter.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/WorklogConverter.java index 087565b..9635ada 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/WorklogConverter.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/converter/WorklogConverter.java @@ -19,6 +19,8 @@ public static Worklog toAddWorklog(WorklogRequest.AddWorklogDTO request){ public static WorklogResponse.AddResultDTO toAddWorklogResultDTO(Worklog worklog){ return WorklogResponse.AddResultDTO.builder() .worklogId(worklog.getId()) + .content(worklog.getContent()) + .isChecked(worklog.getIsChecked()) .createdAt(worklog.getCreatedAt()) .build(); } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/OnResponse.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/OnResponse.java index 4795e22..32e90bb 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/OnResponse.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/OnResponse.java @@ -1,6 +1,5 @@ package com.onnoff.onnoff.domain.on.worklog.dto; -import com.onnoff.onnoff.domain.on.resolution.dto.ResolutionRequest; import com.onnoff.onnoff.domain.on.resolution.dto.ResolutionResponse; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogRequest.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogRequest.java index 1785227..550c1f6 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogRequest.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogRequest.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.PastOrPresent; import jakarta.validation.constraints.Size; import lombok.Getter; @@ -10,7 +11,7 @@ public class WorklogRequest { @Getter public static class AddWorklogDTO{ - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + @PastOrPresent LocalDate date; @NotBlank @Size(max = 30) diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogResponse.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogResponse.java index 449b14a..522bfd9 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogResponse.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/dto/WorklogResponse.java @@ -15,6 +15,8 @@ public class WorklogResponse { @AllArgsConstructor public static class AddResultDTO{ Long worklogId; + String content; + Boolean isChecked; LocalDateTime createdAt; } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/repository/WorklogRepository.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/repository/WorklogRepository.java index ff03c03..2811d58 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/repository/WorklogRepository.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/repository/WorklogRepository.java @@ -9,5 +9,5 @@ import java.util.List; public interface WorklogRepository extends JpaRepository { - List findAllByUserAndDate(User user, LocalDate date); + List findAllByUserAndDateOrderByCreatedAt(User user, LocalDate date); } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnService.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnService.java index f835a73..73a9be5 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnService.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnService.java @@ -5,5 +5,5 @@ import java.time.LocalDate; public interface OnService { - public OnResponse.OnViewDTO getOn(Long userId, LocalDate date); + public OnResponse.OnViewDTO getOn(LocalDate date); } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnServiceImpl.java index 40cb0cf..0ef8eae 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/OnServiceImpl.java @@ -2,6 +2,7 @@ import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; import com.onnoff.onnoff.apiPayload.exception.GeneralException; +import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.on.resolution.entity.Resolution; import com.onnoff.onnoff.domain.on.resolution.repository.ResolutionRepository; import com.onnoff.onnoff.domain.on.worklog.converter.OnConverter; @@ -27,17 +28,16 @@ public class OnServiceImpl implements OnService{ private final WorklogRepository worklogRepository; @Override - public OnResponse.OnViewDTO getOn(Long userId, LocalDate date){ + public OnResponse.OnViewDTO getOn(LocalDate date){ LocalDate localDate = Objects.requireNonNullElseGet(date, LocalDate::now); - User user = userRepository.findById(userId) - .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); + User user = UserContext.getUser(); - List resolutionList = resolutionRepository.findAllByUserAndDate(user, localDate); + List resolutionList = resolutionRepository.findAllByUserAndDateOrderByOrder(user, localDate); - List worklogList = worklogRepository.findAllByUserAndDate(user, localDate); + List worklogList = worklogRepository.findAllByUserAndDateOrderByCreatedAt(user, localDate); - return OnConverter.getOnDTO(userId, localDate, resolutionList, worklogList); + return OnConverter.getOnDTO(user.getId(), localDate, resolutionList, worklogList); } } diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogService.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogService.java index 8f3f912..0ba388d 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogService.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogService.java @@ -8,7 +8,7 @@ public interface WorklogService { - Worklog addWorklog(Long userId, WorklogRequest.AddWorklogDTO request); + Worklog addWorklog(WorklogRequest.AddWorklogDTO request); Worklog modifyContent(Long worklogId, WorklogRequest.ModifyWorklogDTO request); diff --git a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogServiceImpl.java b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogServiceImpl.java index 3df00b8..3d392f3 100644 --- a/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogServiceImpl.java +++ b/src/main/java/com/onnoff/onnoff/domain/on/worklog/service/WorklogServiceImpl.java @@ -3,6 +3,7 @@ import com.onnoff.onnoff.apiPayload.code.status.ErrorStatus; import com.onnoff.onnoff.apiPayload.exception.GeneralException; import com.onnoff.onnoff.apiPayload.exception.handler.WorklogHandler; +import com.onnoff.onnoff.auth.UserContext; import com.onnoff.onnoff.domain.on.worklog.converter.WorklogConverter; import com.onnoff.onnoff.domain.on.worklog.dto.WorklogRequest; import com.onnoff.onnoff.domain.on.worklog.entity.Worklog; @@ -24,9 +25,8 @@ public class WorklogServiceImpl implements WorklogService{ @Override @Transactional - public Worklog addWorklog(Long userId, WorklogRequest.AddWorklogDTO request){ - User user = userRepository.findById(userId) - .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); + public Worklog addWorklog(WorklogRequest.AddWorklogDTO request){ + User user = UserContext.getUser(); Worklog worklog = WorklogConverter.toAddWorklog(request); worklog.setUser(user);