Skip to content
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
Expand Up @@ -23,7 +23,7 @@ public List<DeletedDocument> get(final long teamId) {
}

public void save(final List<Document> documents) {
documents.forEach(document -> deletedDocumentRepository.save(create(document, document.getTeamId())));
documents.forEach(document -> deletedDocumentRepository.save(create(document)));
}

public List<DeletedDocument> get(final List<Long> deletedDocumentIds, final long teamId) {
Expand All @@ -36,8 +36,8 @@ public void deleteAll(final List<DeletedDocument> deletedDocuments) {
deletedDocumentRepository.deleteAll(deletedDocuments);
}

private DeletedDocument create(final Document document, final long teamId) {
return DeletedDocument.of(document.getFileName(), document.getFileUrl(), teamId, document.getCapacity());
private DeletedDocument create(final Document document) {
return DeletedDocument.of(document);
}

private DeletedDocument find(final long id, final long teamId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tiki.server.document.controller.docs.DocumentControllerDocs;
import com.tiki.server.document.dto.request.DocumentsCreateRequest;
import com.tiki.server.document.dto.response.DeletedDocumentsGetResponse;
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 @@ -50,15 +51,15 @@ public SuccessResponse<DocumentsGetResponse> getAllDocuments(
@Override
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/teams/{teamId}/documents")
public SuccessResponse<?> createDocuments(
public SuccessResponse<DocumentsCreateResponse> createDocuments(
final Principal principal,
@PathVariable final long teamId,
@RequestParam(required = false) final Long folderId,
@RequestBody final DocumentsCreateRequest request
) {
long memberId = Long.parseLong(principal.getName());
documentService.createDocuments(memberId, teamId, folderId, request);
return SuccessResponse.success(SUCCESS_CREATE_DOCUMENTS.getMessage());
DocumentsCreateResponse response = documentService.createDocuments(memberId, teamId, folderId, request);
return SuccessResponse.success(SUCCESS_CREATE_DOCUMENTS.getMessage(), response);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.document.dto.request.DocumentsCreateRequest;
import com.tiki.server.document.dto.response.DeletedDocumentsGetResponse;
import com.tiki.server.document.dto.response.DocumentsCreateResponse;
import com.tiki.server.document.dto.response.DocumentsGetResponse;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -77,7 +78,7 @@ SuccessResponse<DocumentsGetResponse> getAllDocuments(
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
SuccessResponse<?> createDocuments(
SuccessResponse<DocumentsCreateResponse> createDocuments(
@Parameter(hidden = true) final Principal principal,
@Parameter(
name = "teamId",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.tiki.server.document.dto.response;

import static lombok.AccessLevel.PRIVATE;

import java.util.List;

import jakarta.validation.constraints.NotNull;
import lombok.Builder;

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

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

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

public static DocumentCreateResponse from(final long documentId) {
return DocumentCreateResponse.builder()
.documentId(documentId)
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public class DeletedDocument extends BaseTime {
@Column(nullable = false)
private double capacity;

public static DeletedDocument of(
final String fileName, final String fileUrl, final long teamId, final double capacity) {
public static DeletedDocument of(final Document document) {
return DeletedDocument.builder()
.fileName(fileName)
.fileUrl(fileUrl)
.teamId(teamId)
.capacity(capacity)
.fileName(document.getFileName())
.fileUrl(document.getFileUrl())
.fileKey(document.getFileKey())
.teamId(document.getTeamId())
.capacity(document.getCapacity())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.tiki.server.document.dto.request.DocumentCreateRequest;
import com.tiki.server.document.dto.request.DocumentsCreateRequest;
import com.tiki.server.document.dto.response.DeletedDocumentsGetResponse;
import com.tiki.server.document.dto.response.DocumentsCreateResponse;
import com.tiki.server.document.dto.response.DocumentsGetResponse;
import com.tiki.server.document.entity.DeletedDocument;
import com.tiki.server.document.entity.Document;
Expand Down Expand Up @@ -54,12 +55,13 @@ public DocumentsGetResponse getAllDocuments(final long memberId, final long team
}

@Transactional
public void createDocuments(final long memberId, final long teamId,
public DocumentsCreateResponse createDocuments(final long memberId, final long teamId,
final Long folderId, final DocumentsCreateRequest request) {
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
validateFolder(folderId, teamId);
validateFileName(folderId, teamId, request);
saveDocuments(teamId, folderId, request);
List<Long> documentIds = saveDocuments(teamId, folderId, request);
return DocumentsCreateResponse.from(documentIds);
}

public DocumentsGetResponse get(final long memberId, final long teamId, final Long folderId) {
Expand Down Expand Up @@ -119,15 +121,17 @@ private void checkFileNameIsDuplicated(final String fileName, final DocumentsCre
}
}

private void saveDocuments(final long teamId, final Long folderId, final DocumentsCreateRequest request) {
private List<Long> saveDocuments(final long teamId, final Long folderId, final DocumentsCreateRequest request) {
Team team = teamFinder.findById(teamId);
request.documents().forEach(document -> saveDocument(team, folderId, document));
return request.documents().stream()
.map(document -> saveDocument(team, folderId, document).getId())
.toList();
}

private void saveDocument(final Team team, final Long folderId, final DocumentCreateRequest request) {
private Document saveDocument(final Team team, final Long folderId, final DocumentCreateRequest request) {
team.addUsage(request.capacity());
Document document = Document.of(request, team.getId(), folderId);
documentSaver.save(document);
return documentSaver.save(document);
}

private void restoreTeamUsage(final long teamId, final List<DeletedDocument> deletedDocuments) {
Expand Down
Loading