Skip to content

Commit

Permalink
feat: 업무일지 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjm9841 committed Feb 13, 2024
1 parent a267e23 commit a6ae11e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/on/worklog")
public class WorklogController {
private final WorklogService worklogService;


@GetMapping("/")
@Operation(summary = "업무일지 조회 API")
public ApiResponse<List<WorklogResponse.WorklogDTO>> getWorklog(@RequestParam(name = "date") LocalDate date){
List<Worklog> worklogList = worklogService.getWorklog(date);
return ApiResponse.onSuccess(WorklogConverter.toWorklogViewDTO(worklogList));
}


@PostMapping("/")
@Operation(summary = "업무일지 추가 API")
public ApiResponse<WorklogResponse.AddResultDTO> addWorklog(@RequestBody @Valid WorklogRequest.AddWorklogDTO request){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import com.onnoff.onnoff.domain.on.worklog.dto.WorklogResponse;
import com.onnoff.onnoff.domain.on.worklog.entity.Worklog;

import java.util.List;
import java.util.stream.Collectors;

public class WorklogConverter {
//request to entity
public static Worklog toAddWorklog(WorklogRequest.AddWorklogDTO request){
public static Worklog toAddWorklog(WorklogRequest.AddWorklogDTO request) {
return Worklog.builder()
.date(request.getDate())
.content(request.getContent())
Expand All @@ -16,7 +19,17 @@ public static Worklog toAddWorklog(WorklogRequest.AddWorklogDTO request){


//entity to response
public static WorklogResponse.AddResultDTO toAddWorklogResultDTO(Worklog worklog){
public static List<WorklogResponse.WorklogDTO> toWorklogViewDTO(List<Worklog> worklogList) {
return worklogList.stream()
.map(worklog -> WorklogResponse.WorklogDTO.builder()
.worklogId(worklog.getId())
.content(worklog.getContent())
.isChecked(worklog.getIsChecked())
.build())
.collect(Collectors.toList());
}

public static WorklogResponse.AddResultDTO toAddWorklogResultDTO(Worklog worklog) {
return WorklogResponse.AddResultDTO.builder()
.worklogId(worklog.getId())
.content(worklog.getContent())
Expand All @@ -25,7 +38,7 @@ public static WorklogResponse.AddResultDTO toAddWorklogResultDTO(Worklog worklog
.build();
}

public static WorklogResponse.ModifyResultDTO toModifyWorklogResultDTO(Worklog worklog){
public static WorklogResponse.ModifyResultDTO toModifyWorklogResultDTO(Worklog worklog) {
return WorklogResponse.ModifyResultDTO.builder()
.worklogId(worklog.getId())
.content(worklog.getContent())
Expand All @@ -34,4 +47,5 @@ public static WorklogResponse.ModifyResultDTO toModifyWorklogResultDTO(Worklog w
.updatedAt(worklog.getUpdatedAt())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

import com.onnoff.onnoff.domain.on.worklog.dto.WorklogRequest;
import com.onnoff.onnoff.domain.on.worklog.entity.Worklog;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

public interface WorklogService {

List<Worklog> getWorklog(LocalDate date);

Worklog addWorklog(WorklogRequest.AddWorklogDTO request);

Worklog modifyContent(Long worklogId, WorklogRequest.ModifyWorklogDTO request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class WorklogServiceImpl implements WorklogService{
private final WorklogRepository worklogRepository;

@Override
@Transactional
public List<Worklog> getWorklog(LocalDate date){
User user = UserContext.getUser();

return worklogRepository.findAllByUserAndDateOrderByCreatedAt(user, date);
}

@Override
@Transactional
public Worklog addWorklog(WorklogRequest.AddWorklogDTO request){
Expand Down

0 comments on commit a6ae11e

Please sign in to comment.