Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INIT] Note 도메인 생성, 노트 생성 API 추가 및 에러 핸들러 추가 #159

Merged
merged 60 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b4482b3
NoteController note 생성 api 추가
paragon0107 Oct 31, 2024
6dc26d3
메세지 추가
paragon0107 Oct 31, 2024
1bc3c4b
Note Entity 추가
paragon0107 Oct 31, 2024
dee3a72
누락된 team 추가
paragon0107 Oct 31, 2024
8d16299
request DTO 추가
paragon0107 Oct 31, 2024
bf9b75d
NoteCreateResponse 추가
paragon0107 Oct 31, 2024
6a1cb2e
NoteRepository 추가
paragon0107 Oct 31, 2024
0c2f939
NoteService 추가
paragon0107 Oct 31, 2024
4ffd98a
NoteAdapter 추가
paragon0107 Oct 31, 2024
c0930a9
NoteControllerDocs추가
paragon0107 Oct 31, 2024
6bde536
[FEAT] NoteController 추가
paragon0107 Nov 3, 2024
9920c8b
[FEAT] Note도메인 request, response DTO추가
paragon0107 Nov 3, 2024
87fef43
[FEAT] NoteFree 엔티티 추가
paragon0107 Nov 3, 2024
bb653e0
[FEAT] NoteTemplate 엔티티 추가
paragon0107 Nov 3, 2024
5bb11b4
[FEAT] NoteService 구현
paragon0107 Nov 3, 2024
aaf298a
[FEAT] NoteSaver 구현
paragon0107 Nov 3, 2024
b3f0e41
[FEAT] NoteRepository 구현
paragon0107 Nov 3, 2024
eab7fb4
[FEAT] SuccessMessage 추가
paragon0107 Nov 3, 2024
c3afbf2
[FEAT] NoteException 추가
paragon0107 Nov 3, 2024
ef3a303
[FEAT] Note ErrorCode 추가
paragon0107 Nov 3, 2024
385975d
[FEAT] 잘못된 json 형식 에러 핸들러 추가
paragon0107 Nov 3, 2024
c6755eb
[FEAT] 잘못된 json 형식 에러 핸들러 추가
paragon0107 Nov 3, 2024
ff6ec4a
[CHORE] 임시 커밋
paragon0107 Nov 3, 2024
598dc92
[FEAT] 글로벌 핸들러에 NoteException 추가
paragon0107 Nov 3, 2024
9b951a3
[CHORE] NoteException 잘못된 메서드 네이밍 수정
paragon0107 Nov 4, 2024
990bd9d
[CHORE] Note Entity, Base time 상속
paragon0107 Nov 4, 2024
ec26d31
[CHORE] 원시값을 레퍼값으로 포장
paragon0107 Nov 4, 2024
558526e
[FEAT] 에러 코드 추가
paragon0107 Nov 4, 2024
0b996f1
[FEAT] Note 엔티티 원시값을 레퍼값으로 변경
paragon0107 Nov 4, 2024
0cae74f
[CHORE] 검증 방식을 Valid에서 VO로 변경
paragon0107 Nov 4, 2024
65b7e62
[CHORE] 서비스단 DTO 추가, 역의존성 제거
paragon0107 Nov 4, 2024
5d74b27
[CHORE] 서비스단 DTO 추가
paragon0107 Nov 4, 2024
4cd3509
[CHORE] 기존 DTO 컨트롤러 부분으로 경로 변경
paragon0107 Nov 4, 2024
b9166f3
[CHORE] 기존 ResponseDTO 삭제
paragon0107 Nov 4, 2024
14e0f13
[CHORE] 포맷팅 적용
paragon0107 Nov 4, 2024
9f816fb
[CHORE] VO 삭제
paragon0107 Nov 5, 2024
94f0cf0
[CHORE] VO 삭제 및 Note 부모 엔티티 생성
paragon0107 Nov 5, 2024
db1396a
[CHORE] VO 삭제 반영
paragon0107 Nov 5, 2024
c460514
[CHORE] Note Entity 단일화
paragon0107 Nov 5, 2024
5c8f9ca
[CHORE] Note Entity 단일화
paragon0107 Nov 5, 2024
09c1d52
[CHORE] Note Entity 단일화
paragon0107 Nov 5, 2024
2369248
[CHORE] Note Entity 단일화
paragon0107 Nov 5, 2024
1d37f80
[CHORE] NoteCreateDTO DocumentIds, TimeBlockIds 추가
paragon0107 Nov 5, 2024
5270da1
[CHORE] NoteDocumentManager 엔티티 추가
paragon0107 Nov 5, 2024
5ae5d59
[FEAT] NoteDocumentManagerRepository 추가
paragon0107 Nov 5, 2024
fc104fd
[FEAT] NoteDocumentManagerSaver 추가
paragon0107 Nov 5, 2024
9af9281
[FEAT] NoteTimeBlockManager 추가
paragon0107 Nov 5, 2024
53b92f0
[FEAT] NoteTimeBlockManagerRepository 추가
paragon0107 Nov 5, 2024
142658b
[FEAT] NoteTimeBlockManagerSaver 추가
paragon0107 Nov 5, 2024
de6fe11
[FEAT] NoteService 구현
paragon0107 Nov 5, 2024
5aba62f
[CHORE] 포맷팅 적용
paragon0107 Nov 5, 2024
9fb449c
[CHORE] 일부 메서드, 변수 네이밍 수정
paragon0107 Nov 5, 2024
b603399
[CHORE] 컨트롤러단 Free, Template 재분리
paragon0107 Nov 5, 2024
ff29329
[CHORE] 컨트롤러단 Free, Template DTO 재분리
paragon0107 Nov 5, 2024
0f6459a
[CHORE] 서비스단 Free, Template DTO 재분리
paragon0107 Nov 5, 2024
18e5611
[CHORE] Note Entity 누락된 필드 추가
paragon0107 Nov 5, 2024
bc40f76
[FEAT] NoteEntity 추가
paragon0107 Nov 5, 2024
5e505ec
[FEAT] 노트 서비스 로직 수정
paragon0107 Nov 5, 2024
0a9c49d
[FEAT] 서비스 레이어 내 DTO 추가
paragon0107 Nov 5, 2024
f5491f5
[FEAT] 컨벤션 적용
paragon0107 Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/tiki/server/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class Constants {
public static final String AUTHORIZATION = "Authorization";
public static final String BEARER = "Bearer ";
public static final String WRONG_INPUT = "잘못된 JSON 형식입니다.";
}
20 changes: 19 additions & 1 deletion src/main/java/com/tiki/server/common/handler/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.tiki.server.auth.exception.AuthException;
import com.tiki.server.common.dto.ErrorCodeResponse;
import com.tiki.server.emailverification.exception.EmailVerificationException;
import com.tiki.server.note.exception.NoteException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand All @@ -20,6 +23,7 @@
import lombok.val;

import static com.tiki.server.auth.message.ErrorCode.UNCAUGHT_SERVER_EXCEPTION;
import static com.tiki.server.common.Constants.WRONG_INPUT;

@Slf4j
@RestControllerAdvice
Expand Down Expand Up @@ -60,6 +64,13 @@ public ResponseEntity<BaseResponse> documentException(DocumentException exceptio
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(NoteException.class)
public ResponseEntity<BaseResponse> documentException(NoteException exception) {
paragon0107 marked this conversation as resolved.
Show resolved Hide resolved
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(ExternalException.class)
public ResponseEntity<BaseResponse> externalException(ExternalException exception) {
log.error(exception.getMessage());
Expand All @@ -79,7 +90,14 @@ public ResponseEntity<BaseResponse> AuthException(AuthException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(
ErrorCodeResponse.of(errorCode.getCode(), errorCode.getMessage()));
ErrorCodeResponse.of(errorCode.getCode(), errorCode.getMessage()));
}

@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<BaseResponse> HttpMessageNotReadableException(HttpMessageNotReadableException exception) {
paragon0107 marked this conversation as resolved.
Show resolved Hide resolved
log.error(exception.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(
ErrorResponse.of(WRONG_INPUT));
}

@ExceptionHandler(Exception.class)
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/tiki/server/note/adapter/NoteFreeSaver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tiki.server.note.adapter;

import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.note.entity.NoteFree;
import com.tiki.server.note.repository.NoteFreeRepository;
import lombok.RequiredArgsConstructor;

@RepositoryAdapter
@RequiredArgsConstructor
public class NoteFreeSaver {

private final NoteFreeRepository noteFreeRepository;

public NoteFree createNoteFree(final NoteFree noteFree){
return noteFreeRepository.save(noteFree);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/tiki/server/note/adapter/NoteTemplateSaver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tiki.server.note.adapter;

import com.tiki.server.common.support.RepositoryAdapter;

import com.tiki.server.note.entity.NoteTemplate;
import com.tiki.server.note.repository.NoteTemplateRepository;
import lombok.RequiredArgsConstructor;

@RepositoryAdapter
@RequiredArgsConstructor
public class NoteTemplateSaver {

private final NoteTemplateRepository noteTemplateRepository;

public NoteTemplate createNoteTemplate(final NoteTemplate note){
return noteTemplateRepository.save(note);
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/tiki/server/note/controller/NoteController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.tiki.server.note.controller;

import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.common.support.UriGenerator;
import com.tiki.server.note.dto.request.NoteFreeCreateRequest;
import com.tiki.server.note.dto.request.NoteTemplateCreateRequest;
import com.tiki.server.note.dto.response.NoteCreateResponse;
import com.tiki.server.note.service.NoteService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

import static com.tiki.server.common.dto.SuccessResponse.success;
import static com.tiki.server.note.message.SuccessMessage.CREATE_NOTE_FREE;
import static com.tiki.server.team.message.SuccessMessage.SUCCESS_CREATE_TEAM;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/notes")
public class NoteController {

private final NoteService noteService;

@PostMapping("/free")
public ResponseEntity<SuccessResponse<NoteCreateResponse>> createNoteFree(
final Principal principal,
@RequestBody final NoteFreeCreateRequest request
) {
long memberId = Long.parseLong(principal.getName());
NoteCreateResponse response = noteService.createNoteFree(memberId, request);
return ResponseEntity.created(
UriGenerator.getUri("/api/v1/notes/free" + response.noteId())
).body(success(CREATE_NOTE_FREE.getMessage(), response));
}

@PostMapping("/template")
public ResponseEntity<SuccessResponse<NoteCreateResponse>> createNoteTemplate(
final Principal principal,
@RequestBody final NoteTemplateCreateRequest request
) {
long memberId = Long.parseLong(principal.getName());
NoteCreateResponse response = noteService.createNoteTemplate(memberId, request);
return ResponseEntity.created(
UriGenerator.getUri("/api/v1/notes/free" + response.noteId())
).body(success(CREATE_NOTE_FREE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tiki.server.note.dto.request;

import jakarta.validation.constraints.Size;
import lombok.NonNull;

import java.time.LocalDate;

public record NoteFreeCreateRequest(
@NonNull @Size(max = 100, message = "제목은 100자 이하로 입력해야 합니다.")
String title,
boolean complete,
@NonNull LocalDate startDate,
@NonNull LocalDate endDate,
@NonNull String contents,
long teamId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.tiki.server.note.dto.request;

import jakarta.validation.constraints.Size;
import lombok.NonNull;

import java.time.LocalDate;

public record NoteTemplateCreateRequest(
@NonNull @Size(max = 100, message = "제목은 100자 이하로 입력해야 합니다.")
String title,
boolean complete,
@NonNull LocalDate startDate,
@NonNull LocalDate endDate,
@NonNull String answerWhatActivity,
@NonNull String answerHowToPrepare,
@NonNull String answerWhatIsDisappointedThing,
@NonNull String answerHowToFix,
long teamId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tiki.server.note.dto.response;

public record NoteCreateResponse(
long noteId
) {
public static NoteCreateResponse from(final long noteId){
return new NoteCreateResponse(noteId);
}
}
69 changes: 69 additions & 0 deletions src/main/java/com/tiki/server/note/entity/NoteFree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.tiki.server.note.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

import static lombok.AccessLevel.PRIVATE;
import static lombok.AccessLevel.PROTECTED;

@Entity
@Getter
@Builder(access = PRIVATE)
@AllArgsConstructor(access = PRIVATE)
@NoArgsConstructor(access = PROTECTED)
public class NoteFree {
paragon0107 marked this conversation as resolved.
Show resolved Hide resolved

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "note_id")
private Long id;

private String title;

private boolean complete;

private LocalDate startDate;

private LocalDate endDate;

private String contents;

private long teamId;

private NoteFree(
final String title,
final boolean complete,
final LocalDate startDate,
final LocalDate endDate,
final String contents,
final long teamId) {
this.title = title;
this.complete = complete;
this.startDate = startDate;
this.endDate = endDate;
this.contents = contents;
this.teamId = teamId;
}

public static NoteFree of(
final String title,
final boolean complete,
final LocalDate startDate,
final LocalDate endDate,
final String contents,
final long teamId) {
return NoteFree.builder()
.title(title)
.complete(complete)
.startDate(startDate)
.endDate(endDate)
.contents(contents)
.teamId(teamId)
.build();
}
}
96 changes: 96 additions & 0 deletions src/main/java/com/tiki/server/note/entity/NoteTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.tiki.server.note.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

import static lombok.AccessLevel.PRIVATE;
import static lombok.AccessLevel.PROTECTED;

@Entity
@Getter
@Builder(access = PRIVATE)
@AllArgsConstructor(access = PRIVATE)
@NoArgsConstructor(access = PROTECTED)
public class NoteTemplate{
paragon0107 marked this conversation as resolved.
Show resolved Hide resolved

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "note_id")
private Long id;

private String title;

private boolean complete;

private LocalDate startDate;

private LocalDate endDate;

private String answerWhatActivity;
paragon0107 marked this conversation as resolved.
Show resolved Hide resolved

private String answerHowToPrepare;

private String answerWhatIsDisappointedThing;

private String answerHowToFix;

private long teamId;

private NoteTemplate(
paragon0107 marked this conversation as resolved.
Show resolved Hide resolved
final String title,
final boolean complete,
final LocalDate endDate,
final LocalDate startDate,
final String answerWhatActivity,
final String answerHowToPrepare,
final String answerWhatIsDisappointedThing,
final String answerHowToFix,
final long teamId
) {
this.title = title;
this.complete = complete;
this.startDate = startDate;
this.endDate = endDate;
this.answerWhatActivity = answerWhatActivity;
this.answerHowToPrepare = answerHowToPrepare;
this.answerWhatIsDisappointedThing = answerWhatIsDisappointedThing;
this.answerHowToFix = answerHowToFix;
this.teamId = teamId;
}

public static NoteTemplate of(
final String title,
final boolean complete,
final LocalDate startDate,
final LocalDate endDate,
final String answerWhatActivity,
final String answerHowToPrepare,
final String answerWhatIsDisappointedThing,
final String answerHowToFix,
final long teamId
) {
return NoteTemplate.builder()
.title(title)
.complete(complete)
.startDate(startDate)
.endDate(endDate)
.answerWhatActivity(answerWhatActivity)
.answerHowToPrepare(answerHowToPrepare)
.answerWhatIsDisappointedThing(answerWhatIsDisappointedThing)
.answerHowToFix(answerHowToFix)
.teamId(teamId)
.build();
}

public String getContent() {
return this.answerWhatActivity + " " +
this.answerHowToPrepare + " " +
this.answerWhatIsDisappointedThing + " " +
this.answerHowToFix;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/tiki/server/note/exception/NoteException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tiki.server.note.exception;

import com.tiki.server.note.message.ErrorCode;
import lombok.Getter;

@Getter
public class NoteException extends RuntimeException {

private final ErrorCode errorCode;

public NoteException(final ErrorCode errorCode) {
super("[NoteException] : " + errorCode.getMessage());
this.errorCode = errorCode;
}
}
Loading
Loading