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
@@ -1,6 +1,7 @@
package com.tiki.server.document.adapter;

import static com.tiki.server.document.message.ErrorCode.INVALID_DOCUMENT;
import static com.tiki.server.folder.constant.Constant.ROOT_PATH;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -47,4 +48,8 @@ public List<Document> findAllByTeamId(long teamId) {
public boolean existsById(Long timeBlockId) {
return documentRepository.existsById(timeBlockId);
}

public List<Document> findByTeamIdAndFolderId(final long teamId, final Long folderId) {
return documentRepository.findAllByTeamIdAndFolderIdOrderByCreatedAtDesc(teamId, folderId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1/documents")
@RequestMapping("api/v1")
public class DocumentController implements DocumentControllerDocs {

private final DocumentService documentService;

@Override
@GetMapping("/team/{teamId}/timeline")
@GetMapping("/documents/team/{teamId}/timeline")
public ResponseEntity<SuccessResponse<DocumentsGetResponse>> getAllDocuments(
Principal principal,
@PathVariable long teamId,
Expand All @@ -46,7 +46,7 @@ public ResponseEntity<SuccessResponse<DocumentsGetResponse>> getAllDocuments(
}

@Override
@DeleteMapping("/team/{teamId}/document/{documentId}")
@DeleteMapping("/documents/team/{teamId}/document/{documentId}")
public ResponseEntity<?> deleteDocument(
Principal principal,
@PathVariable long teamId,
Expand All @@ -57,7 +57,7 @@ public ResponseEntity<?> deleteDocument(
return ResponseEntity.noContent().build();
}

@PostMapping
@PostMapping("/documents")
public ResponseEntity<SuccessResponse<DocumentsCreateResponse>> createDocuments(
Principal principal,
@RequestHeader("team-id") long teamId,
Expand All @@ -68,4 +68,15 @@ public ResponseEntity<SuccessResponse<DocumentsCreateResponse>> createDocuments(
return ResponseEntity.created(UriGenerator.getUri("api/v1/documents"))
.body(SuccessResponse.success(SUCCESS_CREATE_DOCUMENTS.getMessage(), response));
}

@GetMapping("/teams/{teamId}/documents")
public ResponseEntity<SuccessResponse<DocumentsGetResponse>> getDocuments(
final Principal principal,
@PathVariable long teamId,
@RequestParam(required = false) Long folderId
) {
long memberId = Long.parseLong(principal.getName());
DocumentsGetResponse response = documentService.get(memberId, teamId, folderId);
return ResponseEntity.ok(SuccessResponse.success(SUCCESS_GET_DOCUMENTS.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static lombok.AccessLevel.PRIVATE;

import java.time.LocalDateTime;
import java.util.List;

import com.tiki.server.document.entity.Document;
Expand All @@ -14,29 +15,29 @@ public record DocumentsGetResponse(
List<DocumentGetResponse> documents
) {

public static DocumentsGetResponse from(List<Document> documents) {
public static DocumentsGetResponse from(final List<Document> documents) {
return DocumentsGetResponse.builder()
.documents(documents.stream().map(DocumentGetResponse::from).toList())
.build();
.documents(documents.stream().map(DocumentGetResponse::from).toList())
.build();
}

@Builder(access = PRIVATE)
private record DocumentGetResponse(
long documentId,
@NonNull String fileName,
@NonNull String fileUrl,
@NonNull String blockName,
@NonNull String color
@NonNull String name,
@NonNull String url,
double capacity,
@NonNull LocalDateTime createdTime
) {

public static DocumentGetResponse from(Document document) {
public static DocumentGetResponse from(final Document document) {
return DocumentGetResponse.builder()
.documentId(document.getId())
.fileName(document.getFileName())
.fileUrl(document.getFileUrl())
.blockName(document.getTimeBlock().getName())
.color(document.getTimeBlock().getColor())
.build();
.documentId(document.getId())
.name(document.getFileName())
.url(document.getFileUrl())
.capacity(document.getCapacity())
.createdTime(document.getCreatedAt())
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface DocumentRepository extends JpaRepository<Document, Long> {
Document findByIdWithTimeBlock(long documentId);

void deleteAllByTimeBlockId(long timeBlockId);

List<Document> findAllByTeamIdAndFolderIdOrderByCreatedAtDesc(long teamId, Long folderId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public DocumentsCreateResponse createDocuments(long memberId, long teamId, Docum
return DocumentsCreateResponse.from(documentIds);
}

public DocumentsGetResponse get(final long memberId, final long teamId, final Long folderId) {
memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);
List<Document> documents = documentFinder.findByTeamIdAndFolderId(teamId, folderId);
return DocumentsGetResponse.from(documents);
}

private DocumentsGetResponse getAllDocumentsByType(long teamId, Position accessiblePosition) {
List<Document> documents = documentFinder.findAllByTeamIdAndAccessiblePosition(teamId, accessiblePosition);
return DocumentsGetResponse.from(documents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public Folder findById(long id) {

public List<Folder> findByTeamIdAndPath(final long teamId, final String path) {
if (path.equals(ROOT_PATH)) {
return folderRepository.findAllByTeamIdAndPath(teamId, path);
return folderRepository.findAllByTeamIdAndPathOrderByCreatedAtDesc(teamId, path);
}
return folderRepository.findAllByPath(path);
return folderRepository.findAllByPathOrderByCreatedAtDesc(path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
import com.tiki.server.folder.entity.Folder;

public interface FolderRepository extends JpaRepository<Folder, Long> {
List<Folder> findAllByTeamIdAndPath(long teamId, String path);
List<Folder> findAllByPath(String path);
List<Folder> findAllByTeamIdAndPathOrderByCreatedAtDesc(long teamId, String path);
List<Folder> findAllByPathOrderByCreatedAtDesc(String path);
}
Loading