Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
573c6c8
[FEAT] 파일 생성 Request
Chan531 Oct 29, 2024
7f39e78
[FEAT] 파일 생성 Response
Chan531 Oct 29, 2024
61ec22a
[FEAT] 팀 소속 멤버 여부 체크
Chan531 Oct 29, 2024
b8713ff
[CHORE] 클래스 멤버 순서 변경
Chan531 Oct 29, 2024
86264da
[FEAT] 파일 생성자 추가
Chan531 Oct 29, 2024
8b2b306
[FEAT] DocumentSaver 의존성 주입 추가
Chan531 Oct 29, 2024
71f7474
[FEAT] Document 생성
Chan531 Oct 29, 2024
d17977d
[REFACTOR] DocumentSaver 수정
Chan531 Oct 29, 2024
8dd00df
[FEAT] Document 저장
Chan531 Oct 29, 2024
db4fb38
[REFACTOR] Document에 teamId 추가
Chan531 Oct 29, 2024
b949b3b
[REFACTOR] Document 생성자 수정
Chan531 Oct 29, 2024
96ca9fa
[FEAT] 기존 api 에러 대응
Chan531 Oct 29, 2024
e4771d3
[REFACTOR] Document 생성 시, teamId 추가로 전달
Chan531 Oct 29, 2024
333dc2c
[FEAT] DocumentCreateResponse 생성 후 반환
Chan531 Oct 29, 2024
06dae1a
[REFACTOR] Document 생성 및 저장 로직 메소드 분리
Chan531 Oct 29, 2024
19af5b0
[FEAT] Document 생성 api 파라미터 설정
Chan531 Oct 29, 2024
25e09e3
[FEAT] memberId 추출
Chan531 Oct 29, 2024
1c74d3d
[FEAT] Document 생성 로직 호출
Chan531 Oct 29, 2024
bb17105
[FEAT] 파일 생성 성공 메세지 추가
Chan531 Oct 29, 2024
c4a0777
[FEAT] 파일 생성 api 응답 반환
Chan531 Oct 29, 2024
1a91f6d
[FEAT] FolderFinder 의존성 주입 추가
Chan531 Oct 29, 2024
3ee4dda
[FEAT] 폴더 유효성 검증
Chan531 Oct 29, 2024
03dc712
[FIX] 최상단에 파일 추가 안되는 버그 수정
Chan531 Oct 29, 2024
dd3f58e
[REFACTOR] RequestBody 누락 추가
Chan531 Oct 29, 2024
1e9f2de
[CHORE] 파일 생성 메세지 수정
Chan531 Oct 29, 2024
0cb20e4
[REFACTOR] 파일 생성 Request folderId 삭제
Chan531 Oct 29, 2024
6dabca8
[FEAT] 복수 파일 생성 Request
Chan531 Oct 29, 2024
7a826c9
[REFACTOR] 파일 생성 api 수정
Chan531 Oct 29, 2024
0ccc8a2
[REFACTOR] 메소드명 수정
Chan531 Oct 29, 2024
3885da3
[REFACTOR] Document 생성 Response 수정
Chan531 Oct 29, 2024
17fa27d
[REFACTOR] Document 생성 로직 수정
Chan531 Oct 29, 2024
677db76
[REFACTOR] Document 생성 api Response 수정 내용 반영
Chan531 Oct 29, 2024
fb9b425
[REFACTOR] Request 변수명 수정
Chan531 Oct 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DocumentSaver {

private final DocumentRepository documentRepository;

public void save(Document document) {
documentRepository.save(document);
public Document save(Document document) {
return documentRepository.save(document);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tiki.server.document.controller;

import static com.tiki.server.document.message.SuccessMessage.SUCCESS_CREATE_DOCUMENTS;
import static com.tiki.server.document.message.SuccessMessage.SUCCESS_GET_DOCUMENTS;

import java.security.Principal;
Expand All @@ -8,12 +9,18 @@
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.common.support.UriGenerator;
import com.tiki.server.document.controller.docs.DocumentControllerDocs;
import com.tiki.server.document.dto.request.DocumentsCreateRequest;
import com.tiki.server.document.dto.response.DocumentsCreateResponse;
import com.tiki.server.document.dto.response.DocumentsGetResponse;
import com.tiki.server.document.service.DocumentService;

Expand Down Expand Up @@ -49,4 +56,16 @@ public ResponseEntity<?> deleteDocument(
documentService.deleteDocument(memberId, teamId, documentId);
return ResponseEntity.noContent().build();
}

@PostMapping
public ResponseEntity<SuccessResponse<DocumentsCreateResponse>> createDocuments(
Principal principal,
@RequestHeader("team-id") long teamId,
@RequestBody DocumentsCreateRequest request
) {
long memberId = Long.parseLong(principal.getName());
DocumentsCreateResponse response = documentService.createDocuments(memberId, teamId, request);
return ResponseEntity.created(UriGenerator.getUri("api/v1/documents"))
.body(SuccessResponse.success(SUCCESS_CREATE_DOCUMENTS.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tiki.server.document.dto.request;

import lombok.NonNull;

public record DocumentCreateRequest(
@NonNull String fileName,
@NonNull String fileUrl,
double capacity
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tiki.server.document.dto.request;

import java.util.List;

public record DocumentsCreateRequest(
List<DocumentCreateRequest> documents,
Long folderId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.tiki.server.document.dto.response;

import static lombok.AccessLevel.PRIVATE;

import java.util.List;

import lombok.Builder;

@Builder(access = PRIVATE)
public record DocumentsCreateResponse(
List<DocumentCreateResponse> response
) {

public static DocumentsCreateResponse from(List<Long> documentIds) {
return DocumentsCreateResponse.builder()
.response(documentIds.stream().map(DocumentCreateResponse::from).toList())
.build();
}

@Builder(access = PRIVATE)
private record DocumentCreateResponse(
long documentId
) {

public static DocumentCreateResponse from(long documentId) {
return DocumentCreateResponse.builder()
.documentId(documentId)
.build();
}
}
}
20 changes: 18 additions & 2 deletions src/main/java/com/tiki/server/document/entity/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public class Document extends BaseTime {

private String fileUrl;

private Long folderId;

private double capacity;

private long teamId;

private Long folderId;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "block_id")
private TimeBlock timeBlock;
Expand All @@ -47,7 +49,21 @@ public static Document of(String fileName, String fileUrl, TimeBlock timeBlock)
return Document.builder()
.fileName(fileName)
.fileUrl(fileUrl)
.capacity(0) // TODO : 타임 블록 생성 api 수정 후 제거 예정
.teamId(1) // TODO : 타임 블록 생성 api 수정 후 제거 예정
.folderId(null) // TODO : 타임 블록 생성 api 수정 후 제거 예정
.timeBlock(timeBlock)
.build();
}

public static Document of(String fileName, String fileUrl, double capacity, long teamId, Long folderId) {
return Document.builder()
.fileName(fileName)
.fileUrl(fileUrl)
.capacity(capacity)
.teamId(teamId)
.folderId(folderId)
.timeBlock(null) // TODO : 타임 블록 생성 api 수정 후 제거 예정
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@RequiredArgsConstructor
public enum SuccessMessage {

SUCCESS_CREATE_DOCUMENTS("파일 생성 성공"),
SUCCESS_GET_DOCUMENTS("전체 문서 조회 성공");

private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import com.tiki.server.common.entity.Position;
import com.tiki.server.document.adapter.DocumentDeleter;
import com.tiki.server.document.adapter.DocumentFinder;
import com.tiki.server.document.adapter.DocumentSaver;
import com.tiki.server.document.dto.request.DocumentCreateRequest;
import com.tiki.server.document.dto.request.DocumentsCreateRequest;
import com.tiki.server.document.dto.response.DocumentsCreateResponse;
import com.tiki.server.document.dto.response.DocumentsGetResponse;
import com.tiki.server.document.entity.Document;
import com.tiki.server.folder.adapter.FolderFinder;
import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder;
import com.tiki.server.memberteammanager.entity.MemberTeamManager;

Expand All @@ -20,8 +25,10 @@
@Transactional(readOnly = true)
public class DocumentService {

private final DocumentSaver documentSaver;
private final DocumentFinder documentFinder;
private final DocumentDeleter documentDeleter;
private final FolderFinder folderFinder;
private final MemberTeamManagerFinder memberTeamManagerFinder;

public DocumentsGetResponse getAllDocuments(long memberId, long teamId, String type) {
Expand All @@ -39,8 +46,31 @@ public void deleteDocument(long memberId, long teamId, long documentId) {
documentDeleter.delete(document);
}

@Transactional
public DocumentsCreateResponse createDocuments(long memberId, long teamId, DocumentsCreateRequest request) {
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
checkFolderIsExist(request.folderId());
List<Long> documentIds = request.documents().stream()
.map(document -> saveDocument(teamId, request.folderId(), document).getId())
.toList();
return DocumentsCreateResponse.from(documentIds);
}

private DocumentsGetResponse getAllDocumentsByType(long teamId, Position accessiblePosition) {
List<Document> documents = documentFinder.findAllByTeamIdAndAccessiblePosition(teamId, accessiblePosition);
return DocumentsGetResponse.from(documents);
}

private void checkFolderIsExist(Long folderId) {
if (folderId == null) {
return;
}
folderFinder.findById(folderId);
}

private Document saveDocument(long teamId, Long folderId, DocumentCreateRequest request) {
Document document = Document.of(
request.fileName(), request.fileUrl(), request.capacity(), teamId, folderId);
return documentSaver.save(document);
}
}
Loading