From 8ab4253460503e83cd0e2c9c2aaaa0a55c1330cb Mon Sep 17 00:00:00 2001 From: Chan531 Date: Sat, 6 Jul 2024 01:59:56 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[DEL]=20=ED=8C=8C=EC=9D=BC=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=20=EB=B0=8F=20StringListConverter=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/support/StringListConverter.java | 25 ------------------- .../server/timeblock/entity/TimeBlock.java | 6 ----- 2 files changed, 31 deletions(-) delete mode 100644 src/main/java/com/tiki/server/common/support/StringListConverter.java diff --git a/src/main/java/com/tiki/server/common/support/StringListConverter.java b/src/main/java/com/tiki/server/common/support/StringListConverter.java deleted file mode 100644 index c2bccb70..00000000 --- a/src/main/java/com/tiki/server/common/support/StringListConverter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.tiki.server.common.support; - -import static java.util.Collections.emptyList; - -import java.util.Arrays; -import java.util.List; - -import jakarta.persistence.AttributeConverter; -import jakarta.persistence.Converter; - -@Converter -public class StringListConverter implements AttributeConverter, String> { - - private static final String SPLIT_CHAR = ","; - - @Override - public String convertToDatabaseColumn(List attribute) { - return attribute != null ? String.join(SPLIT_CHAR, attribute) : ""; - } - - @Override - public List convertToEntityAttribute(String dbData) { - return dbData != null ? Arrays.asList(dbData.split(SPLIT_CHAR)) : emptyList(); - } -} diff --git a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java index fd0d9b5e..9ce8bd8a 100644 --- a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java +++ b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java @@ -4,14 +4,11 @@ import static jakarta.persistence.GenerationType.IDENTITY; import java.time.LocalDate; -import java.util.List; import com.tiki.server.common.entity.BaseTime; -import com.tiki.server.common.support.StringListConverter; import com.tiki.server.team.entity.Team; import jakarta.persistence.Column; -import jakarta.persistence.Convert; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; @@ -41,7 +38,4 @@ public class TimeBlock extends BaseTime { private LocalDate startDate; private LocalDate endDate; - - @Convert(converter = StringListConverter.class) - private List filesUrl; } From f530edc69d3cc2c4b37aa44c453abdb31dc91d61 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Sat, 6 Jul 2024 03:23:09 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[INIT]=20Document=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=B4=88=EA=B8=B0=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/common/handler/ErrorHandler.java | 8 ++++ .../document/adapter/DocumentFinder.java | 13 ++++++ .../controller/DocumentController.java | 16 +++++++ .../tiki/server/document/entity/Document.java | 43 +++++++++++++++++++ .../document/entity/DocumentStatus.java | 5 +++ .../document/exception/DocumentException.java | 16 +++++++ .../server/document/message/ErrorCode.java | 19 ++++++++ .../document/message/SuccessMessage.java | 13 ++++++ .../repository/DocumentRepository.java | 8 ++++ .../document/service/DocumentService.java | 16 +++++++ .../memberteammanager/entity/Position.java | 5 --- 11 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/tiki/server/document/adapter/DocumentFinder.java create mode 100644 src/main/java/com/tiki/server/document/controller/DocumentController.java create mode 100644 src/main/java/com/tiki/server/document/entity/Document.java create mode 100644 src/main/java/com/tiki/server/document/entity/DocumentStatus.java create mode 100644 src/main/java/com/tiki/server/document/exception/DocumentException.java create mode 100644 src/main/java/com/tiki/server/document/message/ErrorCode.java create mode 100644 src/main/java/com/tiki/server/document/message/SuccessMessage.java create mode 100644 src/main/java/com/tiki/server/document/repository/DocumentRepository.java create mode 100644 src/main/java/com/tiki/server/document/service/DocumentService.java delete mode 100644 src/main/java/com/tiki/server/memberteammanager/entity/Position.java diff --git a/src/main/java/com/tiki/server/common/handler/ErrorHandler.java b/src/main/java/com/tiki/server/common/handler/ErrorHandler.java index 00d4dfd2..5bfe5194 100644 --- a/src/main/java/com/tiki/server/common/handler/ErrorHandler.java +++ b/src/main/java/com/tiki/server/common/handler/ErrorHandler.java @@ -6,6 +6,7 @@ import com.tiki.server.common.dto.BaseResponse; import com.tiki.server.common.dto.ErrorResponse; +import com.tiki.server.document.exception.DocumentException; import com.tiki.server.member.exception.MemberException; import com.tiki.server.memberteammanager.exception.MemberTeamManagerException; import com.tiki.server.team.exception.TeamException; @@ -45,4 +46,11 @@ public ResponseEntity timeBlockException(TimeBlockException except val errorCode = exception.getErrorCode(); return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); } + + @ExceptionHandler(DocumentException.class) + public ResponseEntity documentException(DocumentException exception) { + log.error(exception.getMessage()); + val errorCode = exception.getErrorCode(); + return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage())); + } } diff --git a/src/main/java/com/tiki/server/document/adapter/DocumentFinder.java b/src/main/java/com/tiki/server/document/adapter/DocumentFinder.java new file mode 100644 index 00000000..78c425d3 --- /dev/null +++ b/src/main/java/com/tiki/server/document/adapter/DocumentFinder.java @@ -0,0 +1,13 @@ +package com.tiki.server.document.adapter; + +import com.tiki.server.common.support.RepositoryAdapter; +import com.tiki.server.document.repository.DocumentRepository; + +import lombok.RequiredArgsConstructor; + +@RepositoryAdapter +@RequiredArgsConstructor +public class DocumentFinder { + + private final DocumentRepository documentRepository; +} diff --git a/src/main/java/com/tiki/server/document/controller/DocumentController.java b/src/main/java/com/tiki/server/document/controller/DocumentController.java new file mode 100644 index 00000000..afd37bc0 --- /dev/null +++ b/src/main/java/com/tiki/server/document/controller/DocumentController.java @@ -0,0 +1,16 @@ +package com.tiki.server.document.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.tiki.server.document.service.DocumentService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("api/v1/documents") +public class DocumentController { + + private final DocumentService documentService; +} diff --git a/src/main/java/com/tiki/server/document/entity/Document.java b/src/main/java/com/tiki/server/document/entity/Document.java new file mode 100644 index 00000000..91e13950 --- /dev/null +++ b/src/main/java/com/tiki/server/document/entity/Document.java @@ -0,0 +1,43 @@ +package com.tiki.server.document.entity; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import com.tiki.server.common.entity.BaseTime; +import com.tiki.server.timeblock.entity.TimeBlock; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor +public class Document extends BaseTime { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "document_id") + private Long id; + + private String fileUrl; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "block_id") + private TimeBlock timeBlock; + + @Enumerated(value = STRING) + private DocumentStatus status; + + private LocalDate deletedDate; +} diff --git a/src/main/java/com/tiki/server/document/entity/DocumentStatus.java b/src/main/java/com/tiki/server/document/entity/DocumentStatus.java new file mode 100644 index 00000000..a55db05b --- /dev/null +++ b/src/main/java/com/tiki/server/document/entity/DocumentStatus.java @@ -0,0 +1,5 @@ +package com.tiki.server.document.entity; + +public enum DocumentStatus { + BASIC, DELETED +} diff --git a/src/main/java/com/tiki/server/document/exception/DocumentException.java b/src/main/java/com/tiki/server/document/exception/DocumentException.java new file mode 100644 index 00000000..51b73102 --- /dev/null +++ b/src/main/java/com/tiki/server/document/exception/DocumentException.java @@ -0,0 +1,16 @@ +package com.tiki.server.document.exception; + +import com.tiki.server.document.message.ErrorCode; + +import lombok.Getter; + +@Getter +public class DocumentException extends RuntimeException { + + private final ErrorCode errorCode; + + public DocumentException(ErrorCode errorCode) { + super("[DocumentException] : " + errorCode.getMessage()); + this.errorCode = errorCode; + } +} diff --git a/src/main/java/com/tiki/server/document/message/ErrorCode.java b/src/main/java/com/tiki/server/document/message/ErrorCode.java new file mode 100644 index 00000000..36bc798c --- /dev/null +++ b/src/main/java/com/tiki/server/document/message/ErrorCode.java @@ -0,0 +1,19 @@ +package com.tiki.server.document.message; + +import static org.springframework.http.HttpStatus.NOT_FOUND; + +import org.springframework.http.HttpStatus; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ErrorCode { + + /* 404 NOT_FOUND : 자원을 찾을 수 없음 */ + INVALID_DOCUMENT(NOT_FOUND, "유효하지 않은 문서입니다."); + + private final HttpStatus httpStatus; + private final String message; +} diff --git a/src/main/java/com/tiki/server/document/message/SuccessMessage.java b/src/main/java/com/tiki/server/document/message/SuccessMessage.java new file mode 100644 index 00000000..194dbc42 --- /dev/null +++ b/src/main/java/com/tiki/server/document/message/SuccessMessage.java @@ -0,0 +1,13 @@ +package com.tiki.server.document.message; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum SuccessMessage { + + TEMP("컴파일 에러 방지용"); + + private final String message; +} diff --git a/src/main/java/com/tiki/server/document/repository/DocumentRepository.java b/src/main/java/com/tiki/server/document/repository/DocumentRepository.java new file mode 100644 index 00000000..35777833 --- /dev/null +++ b/src/main/java/com/tiki/server/document/repository/DocumentRepository.java @@ -0,0 +1,8 @@ +package com.tiki.server.document.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.tiki.server.document.entity.Document; + +public interface DocumentRepository extends JpaRepository { +} diff --git a/src/main/java/com/tiki/server/document/service/DocumentService.java b/src/main/java/com/tiki/server/document/service/DocumentService.java new file mode 100644 index 00000000..c7613e30 --- /dev/null +++ b/src/main/java/com/tiki/server/document/service/DocumentService.java @@ -0,0 +1,16 @@ +package com.tiki.server.document.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.tiki.server.document.adapter.DocumentFinder; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class DocumentService { + + private final DocumentFinder documentFinder; +} diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/Position.java b/src/main/java/com/tiki/server/memberteammanager/entity/Position.java deleted file mode 100644 index fcdbecf1..00000000 --- a/src/main/java/com/tiki/server/memberteammanager/entity/Position.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.tiki.server.memberteammanager.entity; - -public enum Position { - ADMIN, EXECUTIVE, MEMBER, -} From b385412dc7ec9520fecdcf8402f239f4a322d9ec Mon Sep 17 00:00:00 2001 From: Chan531 Date: Sat, 6 Jul 2024 03:23:33 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[REFACTOR]=20Position=20=EC=9D=B4=EB=8F=99?= =?UTF-8?q?=20=EB=B0=8F=20TimeBlock=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tiki/server/common/entity/Position.java | 5 +++++ .../server/memberteammanager/entity/MemberTeamManager.java | 1 + .../java/com/tiki/server/timeblock/entity/TimeBlock.java | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 src/main/java/com/tiki/server/common/entity/Position.java diff --git a/src/main/java/com/tiki/server/common/entity/Position.java b/src/main/java/com/tiki/server/common/entity/Position.java new file mode 100644 index 00000000..4148eda9 --- /dev/null +++ b/src/main/java/com/tiki/server/common/entity/Position.java @@ -0,0 +1,5 @@ +package com.tiki.server.common.entity; + +public enum Position { + ADMIN, EXECUTIVE, MEMBER, +} diff --git a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java index eb63bfa7..f263d8f3 100644 --- a/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java +++ b/src/main/java/com/tiki/server/memberteammanager/entity/MemberTeamManager.java @@ -5,6 +5,7 @@ import static jakarta.persistence.GenerationType.IDENTITY; import com.tiki.server.common.entity.BaseTime; +import com.tiki.server.common.entity.Position; import com.tiki.server.member.entity.Member; import com.tiki.server.team.entity.Team; diff --git a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java index 9ce8bd8a..57622663 100644 --- a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java +++ b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java @@ -1,15 +1,18 @@ package com.tiki.server.timeblock.entity; +import static jakarta.persistence.EnumType.STRING; import static jakarta.persistence.FetchType.LAZY; import static jakarta.persistence.GenerationType.IDENTITY; import java.time.LocalDate; import com.tiki.server.common.entity.BaseTime; +import com.tiki.server.common.entity.Position; import com.tiki.server.team.entity.Team; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; @@ -35,6 +38,9 @@ public class TimeBlock extends BaseTime { private String name; + @Enumerated(value = STRING) + private Position accessiblePosition; + private LocalDate startDate; private LocalDate endDate;