Skip to content

Commit

Permalink
refactor: classSideNote 관련 dto, converter 통일화 (#56) (#92) (#93)
Browse files Browse the repository at this point in the history
* rename: modify ClassSideNoteRequest to ClassSideNoteRequestDTO

* rename: modify ClassSideNoteResponse to ClassSideNoteResponseDTO

* feat: create ClassSideNoteConverter

* feat: create ClassSideNoteConverter

* feat: apply modified ClassSideNoteService

* refactor: modify update function

* refactor: modify class name

* refactor: modify class name

* refactor: apply modified class name

* refactor: apply modified class name

* refactor: modify function name

* refactor: apply modified class name and function name
  • Loading branch information
genius00hwan authored Feb 14, 2024
1 parent b17606c commit 5684966
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package UMC.campusNote.classSideNote.controller;

import UMC.campusNote.classSideNote.dto.ClassSideNoteRequest;
import UMC.campusNote.classSideNote.dto.ClassSideNoteResponse;
import UMC.campusNote.classSideNote.converter.ClassSideNoteConverter;
import UMC.campusNote.classSideNote.dto.ClassSideNoteRequestDTO.ClassSideNoteCreateDTO;
import UMC.campusNote.classSideNote.dto.ClassSideNoteRequestDTO.ClassSideNoteUpdateDTO;
import UMC.campusNote.classSideNote.dto.ClassSideNoteResponseDTO.ClassSideNoteResultDTO;
import UMC.campusNote.classSideNote.entity.ClassSideNote;
import UMC.campusNote.classSideNote.service.ClassSideNoteService;

import UMC.campusNote.common.ApiResponse;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.AllArgsConstructor;
Expand All @@ -29,91 +30,65 @@
public class ClassSideNoteController {

ClassSideNoteService classSideNoteService;
ClassSideNoteConverter classSideNoteConverter;

@PostMapping("/create/")
public ApiResponse<ClassSideNoteResponse> createClassSideNote(
public ApiResponse<ClassSideNoteResultDTO> createClassSideNote(
@RequestParam Long userLessonId,
@RequestBody ClassSideNoteRequest request) {
ClassSideNote classSideNote = classSideNoteService.createClassSideNote(userLessonId, request);

ClassSideNoteResponse response = convert(classSideNote);
@RequestBody ClassSideNoteCreateDTO request) {
ClassSideNoteResultDTO response = classSideNoteService.createClassSideNote(userLessonId, request);

return ApiResponse.onSuccess(response);
}


@GetMapping("/{classSideNoteId}")
public ApiResponse<ClassSideNoteResponse> getClassSideNoteById(
public ApiResponse<ClassSideNoteResultDTO> getClassSideNoteById(
@PathVariable Long classSideNoteId) {
ClassSideNote classSideNote = classSideNoteService.getClassSideNoteById(classSideNoteId);

ClassSideNoteResponse response = convert(classSideNote);
ClassSideNoteResultDTO response = classSideNoteService.getClassSideNoteById(classSideNoteId);

return ApiResponse.onSuccess(response);

}

@GetMapping("/{userLessonId}/list")
public ApiResponse<Collection<ClassSideNoteResponse>> getClassSideNoteListByUserLessonId(
public ApiResponse<Collection<ClassSideNoteResultDTO>> getClassSideNoteListByUserLessonId(
@PathVariable("userLessonId") Long userLessonId
) {
List<ClassSideNote> classSideNotes =
List<ClassSideNote> classSideNoteList =
classSideNoteService.getClassSideNoteListByUserLessonId(userLessonId);

List<ClassSideNoteResponse> classSideNoteResponseList = new ArrayList<>();
for (ClassSideNote classSideNote : classSideNotes) {
classSideNoteResponseList.add(convert(classSideNote));
}
return ApiResponse.onSuccess(classSideNoteResponseList);
List<ClassSideNoteResultDTO> classSideNoteResultDTOList = classSideNoteConverter.toClassSideNoteResultDTOList(classSideNoteList);
return ApiResponse.onSuccess(classSideNoteResultDTOList);
}

@PutMapping("/{classSideNoteId}")
public ApiResponse<ClassSideNoteResponse> updateClassSideNote(
public ApiResponse<ClassSideNoteResultDTO> updateClassSideNote(
@PathVariable Long classSideNoteId,
@RequestBody ClassSideNoteRequest request) {
ClassSideNote classSideNote = classSideNoteService.updateClassSideNote(classSideNoteId, request);

ClassSideNoteResponse response = convert(classSideNote);
@RequestBody ClassSideNoteUpdateDTO request) {
ClassSideNoteResultDTO response = classSideNoteService.updateClassSideNote(classSideNoteId, request);

return ApiResponse.onSuccess(response);
}

@PatchMapping("/{classSideNoteId}")
public ApiResponse<ClassSideNoteResponse> updateClassSideNoteContent(
public ApiResponse<ClassSideNoteResultDTO> updateClassSideNoteContent(
@PathVariable Long classSideNoteId,
@RequestParam String content) {
ClassSideNote classSideNote = classSideNoteService.getClassSideNoteById(classSideNoteId);
classSideNote.updateContent(content);

ClassSideNoteResponse response = convert(classSideNote);
ClassSideNoteResultDTO response = classSideNoteService.updateClassSideNoteContent(classSideNoteId, content);

return ApiResponse.onSuccess(response);
}

@DeleteMapping("/{classSideNoteId}")
public ApiResponse<ClassSideNoteResponse> deleteClassSideNoteById(
public ApiResponse<ClassSideNoteResultDTO> deleteClassSideNoteById(
@PathVariable
Long classSideNoteId) {
ClassSideNote classSideNote = classSideNoteService.getClassSideNoteById(classSideNoteId);
ClassSideNoteResultDTO response = classSideNoteService.getClassSideNoteById(classSideNoteId);

classSideNoteService.deleteById(classSideNoteId);

ClassSideNoteResponse response = convert(classSideNote);

return ApiResponse.onSuccess(response); // 삭제된 내용 반환


}


private ClassSideNoteResponse convert(ClassSideNote classSideNote) {
return ClassSideNoteResponse.builder()
.id(classSideNote.getId())
.content(classSideNote.getContent())
.isTodo(classSideNote.getIsTodo())
.colorCode(classSideNote.getColorCode())
.deadline(classSideNote.getDeadline() != null ?
classSideNote.getDeadline().toString() : null)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package UMC.campusNote.classSideNote.converter;

import UMC.campusNote.classSideNote.dto.ClassSideNoteResponseDTO.ClassSideNoteResultDTO;
import UMC.campusNote.classSideNote.entity.ClassSideNote;

import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ClassSideNoteConverter {
public ClassSideNoteResultDTO toClassSideNoteResultDTO(ClassSideNote classSideNote) {
return ClassSideNoteResultDTO.builder()
.id(classSideNote.getId())
.content(classSideNote.getContent())
.isTodo(classSideNote.getIsTodo())
.colorCode(classSideNote.getColorCode())
.deadline(classSideNote.getDeadline() != null ?
classSideNote.getDeadline().toString() : null)
.build();
}

public List<ClassSideNoteResultDTO> toClassSideNoteResultDTOList(List<ClassSideNote> classSideNoteList) {
return classSideNoteList.stream()
.map(this::toClassSideNoteResultDTO)
.collect(Collectors.toList());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package UMC.campusNote.classSideNote.dto;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

import java.time.LocalDate;


public class ClassSideNoteRequestDTO {
@Getter
@Setter
@Builder
public static class ClassSideNoteCreateDTO {
@NotBlank
private String content;

@NonNull
private Boolean isTodo;

@NonNull
@Min(0x000000)
@Max(0xffffff)
private Integer colorCode;

private LocalDate deadline;
}

@Getter
@Setter
@Builder
public static class ClassSideNoteUpdateDTO {
@NonNull
private String content;

private LocalDate deadline;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package UMC.campusNote.classSideNote.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;


public class ClassSideNoteResponseDTO {

@Getter
@Setter
@Builder
@AllArgsConstructor
public static class ClassSideNoteResultDTO {
@NonNull
private Long id;

@NonNull
private String content;

@NonNull
private Boolean isTodo;

@NonNull
private Integer colorCode;

private String deadline;
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package UMC.campusNote.classSideNote.entity;

import UMC.campusNote.classSideNote.dto.ClassSideNoteRequest;
import UMC.campusNote.classSideNote.dto.ClassSideNoteRequestDTO.ClassSideNoteUpdateDTO;
import UMC.campusNote.common.BaseEntity;
import UMC.campusNote.mapping.UserLesson;
import jakarta.persistence.*;
Expand Down Expand Up @@ -39,15 +39,14 @@ public class ClassSideNote extends BaseEntity {
// 할일인 경우에는 deadline 을 받아오고
// 그냥 사이드 노트인 경우에는 deadline이 null 일 수 있다는 생각입니다.

public ClassSideNote updateContent(String content){
public ClassSideNote updateContent(String content) {
this.content = content;
return this;
}
public ClassSideNote update(ClassSideNoteRequest request) {
content = request.getContent();
isTodo = request.getIsTodo();
colorCode = request.getColorCode();
deadline = request.getDeadline();

public ClassSideNote update(ClassSideNoteUpdateDTO request) {
this.content = request.getContent();
this.deadline = request.getDeadline();
return this;
}
}
Loading

0 comments on commit 5684966

Please sign in to comment.