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

[FEAT] 타임 블록 api 수정 #196

Merged
merged 65 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4e10157
feat(TimeBlockCreateRequest): 타임 블록 생성 dto 수정
Chan531 Dec 11, 2024
cf277e4
chore(TimeBlockService): 파라미터 final 키워드 적용
Chan531 Dec 11, 2024
9ae2d91
feat(TimeBlockService): 파일 id 검증 로직 추가
Chan531 Dec 11, 2024
1ec6fce
delete(TimeBlockService): 파일 생성 메소드 삭제
Chan531 Dec 11, 2024
07ca8e8
style(TimeBlockService): 불필요한 import문 제거
Chan531 Dec 11, 2024
902d226
feat(DTBManager): 파일 타임블록 다대다 테이블
Chan531 Dec 11, 2024
68c4e0f
feat(DTBRepository): 파일 타임 블록 리포지토리
Chan531 Dec 11, 2024
7d04e4e
feat(DTBAdapter): 파일 타임 블록 관계 데이터 저장
Chan531 Dec 11, 2024
b0c261a
chore(TimeBlockController): RequestMapping 수정
Chan531 Dec 11, 2024
8e49b70
feat(TimeBlockService): 파일 타임 블록 관계 데이터 저장
Chan531 Dec 11, 2024
1a45938
chore(TimeBlockController): 파라미터 final 키워드 적용
Chan531 Dec 11, 2024
f34589f
refactor(TimeBlockController): url 수정
Chan531 Dec 11, 2024
dd7981a
refactor: 메소드명 수정
Chan531 Dec 11, 2024
734229c
chore(TimeBlockFinder): 파라미터 final 키워드 적용
Chan531 Dec 11, 2024
7578c1b
feat(DTBRepository): 타임 블록과 연관된 데이터 제거
Chan531 Dec 11, 2024
c2a3c2c
feat(DTBAdapter): 타임 블록과 연관된 데이터 제거
Chan531 Dec 11, 2024
453ee55
delete(TimeBlockService): 파일 삭제 로직 제거
Chan531 Dec 11, 2024
516e939
feat(TimeBlockService): 타임 블록과 연관된 데이터 제거
Chan531 Dec 11, 2024
1e77ee9
refactor(DTBAdapter): 메소드명 수정
Chan531 Dec 11, 2024
2aa1184
feat(DTBRepository): 파일과 연관된 데이터 제거
Chan531 Dec 11, 2024
a2bacdb
feat(DTBAdapter): 파일과 연관된 데이터 제거
Chan531 Dec 11, 2024
bb0f8cc
feat(DocumentService): 파일과 연관된 데이터 삭제 로직 추가
Chan531 Dec 11, 2024
700fac5
delete(Document): 타임 블록 관련 데이터 제거
Chan531 Dec 11, 2024
a32fb56
chore(DocumentService): 미사용 메소드 로직 임시 주석 처리
Chan531 Dec 11, 2024
5f7f5b8
feat(DTBRepository): 타임 블록과 연관된 데이터 조회
Chan531 Dec 11, 2024
9b43c7a
feat(DTBAdapter): 타임 블록과 연관된 데이터 조회
Chan531 Dec 11, 2024
db712b5
delete: 미사용 메소드 제거
Chan531 Dec 11, 2024
46f75ee
feat(DTBManager): getter 추가
Chan531 Dec 11, 2024
5c0563d
refactor: 메소드명 수정
Chan531 Dec 11, 2024
f1f1286
feat(DocumentRepository): id 리스트로 조회
Chan531 Dec 11, 2024
432cf0d
feat(DocumentFinder): id 리스트로 조회
Chan531 Dec 11, 2024
a9de5ed
feat(TimeBlockService): 태그된 파일 조회
Chan531 Dec 11, 2024
5219880
refactor(TimeBlockDetailGetResponse): 파라미터 및 데이터 매핑 로직 수정
Chan531 Dec 11, 2024
34a688b
delete: DocumentVO 제거
Chan531 Dec 11, 2024
28aa41a
refactor(TimeBlockDetailGetResponse): 내부 record 접근 제한자 변경
Chan531 Dec 11, 2024
def6881
feat(DocumentTagInfo): 파일 태그 정보 dto
Chan531 Dec 11, 2024
aaff8f9
feat(TimeBlockService): 파일 태그 정보 생성
Chan531 Dec 11, 2024
70f68bd
refactor(TimeBlockDetailGetResponse): 파라미터 및 데이터 매핑 로직 수정
Chan531 Dec 11, 2024
a50bb07
chore(TimeBlockService): 불필요한 import문 제거
Chan531 Dec 11, 2024
9f4435b
feat(TimeBlockRepository): id와 팀 id로 조회
Chan531 Dec 11, 2024
d249eac
feat(TimeBlockFinder): id와 팀 id로 조회
Chan531 Dec 11, 2024
7ff2ae9
feat(SuccessMessage): 파일 태그 성공 메세지 추가
Chan531 Dec 11, 2024
c10a2dd
feat(TimeBlockService): 파일 태그
Chan531 Dec 11, 2024
af6f820
feat(TimeBlockController): 파일 태그 api
Chan531 Dec 11, 2024
3acf9af
fix(TimeBlockService): 팀에 속한 타임 블록만 조회할 수 있도록 수정
Chan531 Dec 11, 2024
6b45658
refactor: 메소드명 수정
Chan531 Dec 11, 2024
58b77b3
feat(DTBAdapter): id 리스트로 조회
Chan531 Dec 11, 2024
1425557
feat(DTBAdapter): 리스트로 삭제
Chan531 Dec 11, 2024
3104c46
feat(DTBManager): 타임 블록을 통해 유효성 검증
Chan531 Dec 11, 2024
aa2bfbf
feat(DTBRepository): id 리스트로 조회
Chan531 Dec 11, 2024
2db1ea3
feat(ErrorCode): 유효하지 않은 파일 태그 메세지 추가
Chan531 Dec 11, 2024
38aeb33
feat(TimeBlockService): 파일 태그 삭제
Chan531 Dec 11, 2024
cb792f9
feat(TimeBlockController): 파일 태그 삭제 api
Chan531 Dec 11, 2024
a2c65dc
delete: 기존 파일 삭제 api 제거
Chan531 Dec 11, 2024
75a77ae
chore(DocumentRepository): 팀 id로 파일 조회 수정
Chan531 Dec 11, 2024
c08bedb
refactor(DocumentService): 기존 파일 조회 로직 임시 수정
Chan531 Dec 11, 2024
fd58e4a
feat: key 컬럼 추가
Chan531 Dec 11, 2024
bfccd86
refactor: 파일 복구 파라미터 수정
Chan531 Dec 11, 2024
3d0829a
refactor: 기존 파일 조회 관련 로직 임시 주석 처리
Chan531 Dec 11, 2024
9fb0a62
fix(TimeBlockController): 파일 태그 삭제 api url 수정
Chan531 Dec 11, 2024
197e559
fix: s3 이미지 삭제되지 않는 버그 수정
Chan531 Dec 11, 2024
9894a9d
fix(DocumentControllerDocs): 스웨거 url 파라미터 매핑 오류 수정
Chan531 Dec 12, 2024
dc0ef56
fix(FolderControllerDocs): 스웨거 url 파라미터 매핑 오류 수정
Chan531 Dec 12, 2024
e62f596
feat(TimeBlockControllerDocs): 파일 태그 추가 및 삭제 스웨거 정보 추가
Chan531 Dec 12, 2024
0433a9f
delete: 주석 처리 메소드 제거
Chan531 Dec 13, 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 @@ -5,7 +5,6 @@
import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.document.entity.Document;
import com.tiki.server.document.repository.DocumentRepository;
import com.tiki.server.document.vo.DocumentVO;

import lombok.RequiredArgsConstructor;

Expand All @@ -15,15 +14,7 @@ public class DocumentDeleter {

private final DocumentRepository documentRepository;

public void delete(Document document) {
documentRepository.delete(document);
}

public void deleteAll(List<Document> documents) {
documentRepository.deleteAll(documents);
}

public void deleteAllByTimeBlockId(long timeBlockId) {
documentRepository.deleteAllByTimeBlockId(timeBlockId);
}
}
24 changes: 3 additions & 21 deletions src/main/java/com/tiki/server/document/adapter/DocumentFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import static com.tiki.server.document.message.ErrorCode.INVALID_DOCUMENT;

import java.util.List;
import java.util.Objects;

import com.tiki.server.common.entity.Position;
import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.document.entity.Document;
import com.tiki.server.document.exception.DocumentException;
import com.tiki.server.document.repository.DocumentRepository;
import com.tiki.server.document.vo.DocumentVO;

import lombok.RequiredArgsConstructor;

Expand All @@ -26,24 +23,9 @@ public List<Document> findAllByIdAndTeamId(final List<Long> documentIds, final l
.toList();
}

public Document findByIdOrElseThrow(final long documentId) {
return documentRepository.findById(documentId).orElseThrow(() -> new DocumentException(INVALID_DOCUMENT));
}

public Document findByIdWithTimeBlock(long documentId) {
Document document = documentRepository.findByIdWithTimeBlock(documentId);
if (Objects.isNull(document)) {
throw new DocumentException(INVALID_DOCUMENT);
}
return document;
}

public List<DocumentVO> findAllByTimeBlockId(long timeBlockId) {
return documentRepository.findAllByTimeBlockId(timeBlockId).stream().map(DocumentVO::from).toList();
}

public List<Document> findAllByTeamIdAndAccessiblePosition(long teamId, Position accessiblePosition) {
return documentRepository.findAllByTeamIdAndAccessiblePosition(teamId, accessiblePosition);
public Document findById(final long documentId) {
return documentRepository.findById(documentId)
.orElseThrow(() -> new DocumentException(INVALID_DOCUMENT));
}

public List<Document> findAllByTeamId(long teamId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public void restore(final List<DeletedDocument> deletedDocuments) {
}

private Document create(final DeletedDocument deletedDocument) {
return Document.restore(
deletedDocument.getFileName(),
deletedDocument.getFileUrl(),
deletedDocument.getCapacity(),
deletedDocument.getTeamId()
);
return Document.restore(deletedDocument);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ public ResponseEntity<SuccessResponse<DocumentsGetResponse>> getAllDocuments(
return ResponseEntity.ok(SuccessResponse.success(SUCCESS_GET_DOCUMENTS.getMessage(), response));
}

@Override
@DeleteMapping("/documents/team/{teamId}/document/{documentId}")
public ResponseEntity<?> deleteDocument(
final Principal principal,
@PathVariable final long teamId,
@PathVariable final long documentId
) {
long memberId = Long.parseLong(principal.getName());
documentService.deleteDocument(memberId, teamId, documentId);
return ResponseEntity.noContent().build();
}

@PostMapping("/teams/{teamId}/documents")
public ResponseEntity<SuccessResponse<?>> createDocuments(
final Principal principal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,6 @@ ResponseEntity<SuccessResponse<DocumentsGetResponse>> getAllDocuments(
) @RequestParam String type
);

@Operation(
summary = "문서 삭제",
description = "문서를 삭제한다.",
responses = {
@ApiResponse(responseCode = "204", description = "성공"),
@ApiResponse(
responseCode = "403",
description = "접근 권한 없음",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "404",
description = "팀에 존재하지 않는 회원, 유효하지 않은 문서",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<?> deleteDocument(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "documentId",
description = "문서 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long documentId
);

@Operation(
summary = "문서 생성",
description = "문서를 여러 개 생성한다.",
Expand All @@ -119,13 +81,13 @@ ResponseEntity<?> deleteDocument(
ResponseEntity<SuccessResponse<?>> createDocuments(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "폴더 id",
name = "folderId",
description = "생성할 파일이 속할 폴더 id",
in = ParameterIn.QUERY,
example = "1"
Expand All @@ -150,13 +112,13 @@ ResponseEntity<SuccessResponse<?>> createDocuments(
ResponseEntity<SuccessResponse<DocumentsGetResponse>> getDocuments(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "폴더 id",
name = "folderId",
description = "조회할 폴더 id",
in = ParameterIn.QUERY,
example = "1"
Expand All @@ -180,13 +142,13 @@ ResponseEntity<SuccessResponse<DocumentsGetResponse>> getDocuments(
ResponseEntity<?> delete(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "파일 id",
name = "documentId",
description = "삭제할 파일 id 리스트",
in = ParameterIn.QUERY,
required = true,
Expand All @@ -211,13 +173,13 @@ ResponseEntity<?> delete(
ResponseEntity<?> deleteTrash(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "파일 id",
name = "documentId",
description = "삭제할 파일 id 리스트",
in = ParameterIn.QUERY,
required = true,
Expand All @@ -242,13 +204,13 @@ ResponseEntity<?> deleteTrash(
ResponseEntity<?> restore(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
) @PathVariable long teamId,
@Parameter(
name = "파일 id",
name = "documentId",
description = "복구할 파일 id 리스트",
in = ParameterIn.QUERY,
required = true,
Expand All @@ -273,7 +235,7 @@ ResponseEntity<?> restore(
ResponseEntity<SuccessResponse<DeletedDocumentsGetResponse>> getTrash(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "팀 id",
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public record DocumentCreateRequest(
@NonNull String fileName,
@Schema(description = "파일 url", example = "https://.../tiki.jpg")
@NonNull String fileUrl,
@Schema(description = "파일 key", example = "....jpg")
@NonNull String fileKey,
@Schema(description = "파일 용량", example = "1.23")
double capacity
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class DeletedDocument extends BaseTime {

private String fileUrl;

private String fileKey;

private long teamId;

private double capacity;
Expand Down
32 changes: 9 additions & 23 deletions src/main/java/com/tiki/server/document/entity/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,33 @@ public class Document extends BaseTime {

private String fileUrl;

private String fileKey;

private double capacity;

private long teamId;

private Long folderId;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "block_id")
private TimeBlock timeBlock;

public static Document of(final String fileName, final String fileUrl, final 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(final DocumentCreateRequest request, final long teamId, final Long folderId) {
return Document.builder()
.fileName(request.fileName())
.fileUrl(request.fileUrl())
.capacity(request.capacity())
.fileKey(request.fileKey())
.teamId(teamId)
.folderId(folderId)
.timeBlock(null) // TODO : 타임 블록 생성 api 수정 후 제거 예정
.build();
}

public static Document restore(final String fileName, final String fileUrl,
final double capacity, final long teamId) {
public static Document restore(final DeletedDocument deletedDocument) {
return Document.builder()
.fileName(fileName)
.fileUrl(fileUrl)
.capacity(capacity)
.teamId(teamId)
.fileName(deletedDocument.getFileName())
.fileUrl(deletedDocument.getFileUrl())
.capacity(deletedDocument.getCapacity())
.fileKey(deletedDocument.getFileKey())
.teamId(deletedDocument.getTeamId())
.folderId(null)
.timeBlock(null)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,10 @@
import com.tiki.server.document.entity.Document;

public interface DocumentRepository extends JpaRepository<Document, Long> {

List<Document> findAllByTimeBlockId(long timeBlockId);

List<Document> findAllByFolderId(long folderId);

@Query("select d from Document d join fetch d.timeBlock t "
+ "where t.team.id = :teamId and t.accessiblePosition = :position order by d.createdAt asc")
List<Document> findAllByTeamIdAndAccessiblePosition(long teamId, Position position);

@Query("select d from Document d join d.timeBlock t where t.team.id = :teamId")
List<Document> findAllByTeamId(long teamId);

@Query("select d from Document d join fetch d.timeBlock where d.id = :documentId")
Document findByIdWithTimeBlock(long documentId);

void deleteAllByTimeBlockId(long timeBlockId);

List<Document> findAllByTeamIdAndFolderIdOrderByCreatedAtDesc(long teamId, Long folderId);

Optional<Document> findByIdAndTeamId(long id, long teamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.documenttimeblockmanager.adapter.DTBAdapter;
import com.tiki.server.external.util.S3Handler;
import com.tiki.server.folder.adapter.FolderFinder;
import com.tiki.server.folder.entity.Folder;
Expand All @@ -41,21 +42,15 @@ public class DocumentService {
private final MemberTeamManagerFinder memberTeamManagerFinder;
private final DeletedDocumentAdapter deletedDocumentAdapter;
private final TeamFinder teamFinder;
private final DTBAdapter dtbAdapter;
private final S3Handler s3Handler;

public DocumentsGetResponse getAllDocuments(final long memberId, final long teamId, final String type) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Position accessiblePosition = Position.getAccessiblePosition(type);
memberTeamManager.checkMemberAccessible(accessiblePosition);
return getAllDocumentsByType(teamId, accessiblePosition);
}

@Transactional
public void deleteDocument(final long memberId, final long teamId, final long documentId) {
MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
Document document = documentFinder.findByIdWithTimeBlock(documentId);
memberTeamManager.checkMemberAccessible(document.getTimeBlock().getAccessiblePosition());
documentDeleter.delete(document);
List<Document> documents = documentFinder.findAllByTeamId(teamId);
return DocumentsGetResponse.from(documents);
}

@Transactional
Expand All @@ -77,6 +72,7 @@ public DocumentsGetResponse get(final long memberId, final long teamId, final Lo
public void delete(final long memberId, final long teamId, final List<Long> documentIds) {
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<Document> documents = documentFinder.findAllByIdAndTeamId(documentIds, teamId);
dtbAdapter.deleteAllByDocuments(documentIds);
deletedDocumentAdapter.save(documents);
documentDeleter.deleteAll(documents);
}
Expand All @@ -86,7 +82,7 @@ public void deleteTrash(final long memberId, final long teamId, final List<Long>
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<DeletedDocument> deletedDocuments = deletedDocumentAdapter.get(documentIds, teamId);
restoreTeamUsage(teamId, deletedDocuments);
deletedDocuments.forEach(deletedDocument -> s3Handler.deleteFile(deletedDocument.getFileName()));
deletedDocuments.forEach(deletedDocument -> s3Handler.deleteFile(deletedDocument.getFileKey()));
deletedDocumentAdapter.deleteAll(deletedDocuments);
}

Expand All @@ -104,11 +100,6 @@ public DeletedDocumentsGetResponse getTrash(final long memberId, final long team
return DeletedDocumentsGetResponse.from(deletedDocuments);
}

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

private void validateFolder(final Long folderId, final long teamId) {
if (folderId == null) {
return;
Expand Down
Loading
Loading