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

[FIX] 문서 도메인 추가 및 DB 수정 #17

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tiki.server.memberteammanager.entity;
package com.tiki.server.common.entity;

public enum Position {
ADMIN, EXECUTIVE, MEMBER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,4 +46,11 @@ public ResponseEntity<BaseResponse> timeBlockException(TimeBlockException except
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}

@ExceptionHandler(DocumentException.class)
public ResponseEntity<BaseResponse> documentException(DocumentException exception) {
log.error(exception.getMessage());
val errorCode = exception.getErrorCode();
return ResponseEntity.status(errorCode.getHttpStatus()).body(ErrorResponse.of(errorCode.getMessage()));
}
}

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/java/com/tiki/server/document/adapter/DocumentFinder.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
43 changes: 43 additions & 0 deletions src/main/java/com/tiki/server/document/entity/Document.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tiki.server.document.entity;

public enum DocumentStatus {
BASIC, DELETED
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/tiki/server/document/message/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions src/main/java/com/tiki/server/document/message/SuccessMessage.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Document, Long> {
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java
Original file line number Diff line number Diff line change
@@ -1,18 +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 java.util.List;

import com.tiki.server.common.entity.BaseTime;
import com.tiki.server.common.support.StringListConverter;
import com.tiki.server.common.entity.Position;
import com.tiki.server.team.entity.Team;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
Expand All @@ -38,10 +38,10 @@ public class TimeBlock extends BaseTime {

private String name;

@Enumerated(value = STRING)
private Position accessiblePosition;

private LocalDate startDate;

private LocalDate endDate;

@Convert(converter = StringListConverter.class)
private List<String> filesUrl;
}
Loading