Skip to content

Commit

Permalink
Merge pull request #195 from Team-Tiki/feat/#190-team
Browse files Browse the repository at this point in the history
[FEAT] 팀 구독 정보 추가 및 기타 기능 처리
  • Loading branch information
Chan531 authored Dec 11, 2024
2 parents ace7dd1 + b9ff1b0 commit a6e6ad6
Show file tree
Hide file tree
Showing 25 changed files with 526 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public interface AuthControllerDocs {
@ApiResponse(responseCode = "201", description = "성공"),
@ApiResponse(
responseCode = "401",
description = "유효하지 않은 키",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
@ApiResponse(
responseCode = "401",
description = "인증되지 않은 사용자",
description = "유효하지 않은 키, 인증되지 않은 사용자",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
@ApiResponse(
responseCode = "404",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.tiki.server.document.controller.docs;

import java.security.Principal;
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.tiki.server.common.dto.ErrorResponse;
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.DocumentsGetResponse;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -50,12 +54,12 @@ ResponseEntity<SuccessResponse<DocumentsGetResponse>> getAllDocuments(
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
)
@PathVariable long teamId,
) @PathVariable long teamId,
@Parameter(
name = "type",
description = "타임라인 타입",
in = ParameterIn.QUERY,
required = true,
example = "executive, member"
) @RequestParam String type
);
Expand Down Expand Up @@ -89,14 +93,190 @@ ResponseEntity<?> deleteDocument(
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
)
@PathVariable long teamId,
) @PathVariable long teamId,
@Parameter(
name = "documentId",
description = "문서 id",
in = ParameterIn.PATH,
example = "1"
)
@PathVariable long documentId
) @PathVariable long documentId
);

@Operation(
summary = "문서 생성",
description = "문서를 여러 개 생성한다.",
responses = {
@ApiResponse(responseCode = "201", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<?>> createDocuments(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "폴더 id",
description = "생성할 파일이 속할 폴더 id",
in = ParameterIn.QUERY,
example = "1"
) @RequestParam Long folderId,
@RequestBody final DocumentsCreateRequest request
);

@Operation(
summary = "문서 조회",
description = "문서를 조회한다.",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<DocumentsGetResponse>> getDocuments(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "폴더 id",
description = "조회할 폴더 id",
in = ParameterIn.QUERY,
example = "1"
) @RequestParam Long folderId
);

@Operation(
summary = "문서 삭제",
description = "문서를 여러 개 삭제한다.",
responses = {
@ApiResponse(responseCode = "204", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<?> delete(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "파일 id",
description = "삭제할 파일 id 리스트",
in = ParameterIn.QUERY,
required = true,
example = "[1, 2]"
) @RequestParam("documentId") List<Long> documentIds
);

@Operation(
summary = "휴지통 문서 삭제",
description = "휴지통 속 문서를 여러 개 삭제한다.",
responses = {
@ApiResponse(responseCode = "204", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<?> deleteTrash(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "파일 id",
description = "삭제할 파일 id 리스트",
in = ParameterIn.QUERY,
required = true,
example = "[1, 2]"
) @RequestParam("documentId") List<Long> deletedDocumentIds
);

@Operation(
summary = "휴지통 문서 복구",
description = "휴지통 속 문서를 여러 개 복구한다.",
responses = {
@ApiResponse(responseCode = "204", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<?> restore(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "파일 id",
description = "복구할 파일 id 리스트",
in = ParameterIn.QUERY,
required = true,
example = "[1, 2]"
) @RequestParam("documentId") List<Long> deletedDocumentIds
);

@Operation(
summary = "휴지통 조회",
description = "휴지통을 조회한다.",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<DeletedDocumentsGetResponse>> getTrash(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId
);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.tiki.server.document.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.NonNull;

public record DocumentCreateRequest(
@Schema(description = "파일 이름", example = "tiki.jpg")
@NonNull String fileName,
@Schema(description = "파일 url", example = "https://.../tiki.jpg")
@NonNull String fileUrl,
@Schema(description = "파일 용량", example = "1.23")
double capacity
) {
}
10 changes: 5 additions & 5 deletions src/main/java/com/tiki/server/document/entity/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static lombok.AccessLevel.PROTECTED;

import com.tiki.server.common.entity.BaseTime;
import com.tiki.server.document.dto.request.DocumentCreateRequest;
import com.tiki.server.timeblock.entity.TimeBlock;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -56,12 +57,11 @@ public static Document of(final String fileName, final String fileUrl, final Tim
.build();
}

public static Document of(final String fileName, final String fileUrl,
final double capacity, final long teamId, final Long folderId) {
public static Document of(final DocumentCreateRequest request, final long teamId, final Long folderId) {
return Document.builder()
.fileName(fileName)
.fileUrl(fileUrl)
.capacity(capacity)
.fileName(request.fileName())
.fileUrl(request.fileUrl())
.capacity(request.capacity())
.teamId(teamId)
.folderId(folderId)
.timeBlock(null) // TODO : 타임 블록 생성 api 수정 후 제거 예정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
import com.tiki.server.document.entity.DeletedDocument;
import com.tiki.server.document.entity.Document;
import com.tiki.server.document.exception.DocumentException;
import com.tiki.server.external.util.S3Handler;
import com.tiki.server.folder.adapter.FolderFinder;
import com.tiki.server.folder.entity.Folder;
import com.tiki.server.memberteammanager.adapter.MemberTeamManagerFinder;
import com.tiki.server.memberteammanager.entity.MemberTeamManager;
import com.tiki.server.team.adapter.TeamFinder;
import com.tiki.server.team.entity.Team;

import lombok.RequiredArgsConstructor;

Expand All @@ -37,6 +40,8 @@ public class DocumentService {
private final FolderFinder folderFinder;
private final MemberTeamManagerFinder memberTeamManagerFinder;
private final DeletedDocumentAdapter deletedDocumentAdapter;
private final TeamFinder teamFinder;
private final S3Handler s3Handler;

public DocumentsGetResponse getAllDocuments(final long memberId, final long teamId, final String type) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Expand Down Expand Up @@ -80,6 +85,8 @@ public void delete(final long memberId, final long teamId, final List<Long> docu
public void deleteTrash(final long memberId, final long teamId, final List<Long> documentIds) {
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<DeletedDocument> deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId);
restoreTeamUsage(teamId, deletedDocuments);
deletedDocuments.forEach(deletedDocument -> s3Handler.deleteFile(deletedDocument.getFileName()));
deletedDocumentAdapter.deleteAll(deletedDocuments);
}

Expand Down Expand Up @@ -122,12 +129,18 @@ private void checkFileNameIsDuplicated(final String fileName, final DocumentsCre
}

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

private void saveDocument(final long teamId, final Long folderId, final DocumentCreateRequest request) {
Document document = Document.of(
request.fileName(), request.fileUrl(), request.capacity(), teamId, folderId);
private void 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);
}

private void restoreTeamUsage(final long teamId, final List<DeletedDocument> deletedDocuments) {
Team team = teamFinder.findById(teamId);
team.restoreUsage(deletedDocuments.stream().mapToDouble(DeletedDocument::getCapacity).sum());
}
}
1 change: 0 additions & 1 deletion src/main/java/com/tiki/server/external/util/S3Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.stereotype.Component;

import com.tiki.server.external.config.AWSConfig;
import com.tiki.server.external.dto.request.S3DeleteRequest;
import com.tiki.server.external.dto.response.PreSignedUrlResponse;
import com.tiki.server.external.exception.ExternalException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.common.support.UriGenerator;
import com.tiki.server.folder.controller.docs.FolderControllerDocs;
import com.tiki.server.folder.dto.request.FolderCreateRequest;
import com.tiki.server.folder.dto.request.FolderNameUpdateRequest;
import com.tiki.server.folder.dto.response.FolderCreateResponse;
Expand All @@ -32,7 +33,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1")
public class FolderController {
public class FolderController implements FolderControllerDocs {

private final FolderService folderService;

Expand Down
Loading

0 comments on commit a6e6ad6

Please sign in to comment.