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 @@ -15,14 +15,16 @@ public record DocumentResponse(
DocumentType type,
String title,
LocalDate lastModifiedDate,
int latestVersion,
List<ApplicationFormSimpleResponse> applicationForms
) {
public static DocumentResponse of(final Document document, final List<ApplicationFormSimpleResponse> applicationForms) {
public static DocumentResponse of(final Document document, final int latestVersion, final List<ApplicationFormSimpleResponse> applicationForms) {
return DocumentResponse.builder()
.id(document.getId())
.type(document.getType())
.title(document.getTitle())
.lastModifiedDate(document.getModifiedDate().toLocalDate())
.latestVersion(latestVersion)
.applicationForms(applicationForms)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface DocumentVersionRepository extends JpaRepository<DocumentVersion, Long> {
@Query("select v from DocumentVersion v join fetch v.document d join d.user u where u.id = :userId and d.id = :documentId order by v.version desc")
Page<DocumentVersion> findAllByUserIdAndDocumentId(final Long userId, final Long documentId, final Pageable pageable);

/* 해당 문서의 최신 버전 조회 */
@Query("select MAX(v.version) from DocumentVersion v where v.document.id = :documentId")
Optional<Integer> findLatestVersionByDocumentId(final Long documentId);
int findLatestVersionByDocumentId(final Long documentId);

/* 해당 유저의 문서 총 이용 용량 조회 */
@Query("select COALESCE(SUM(v.fileSize), 0) from DocumentVersion v join v.document d where d.user.id = :userId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Long uploadNewVersionDocument(final Long userId, final Long documentId, f
Document document = getByIdOrThrow(documentId);
document.validateOwner(userId);

int version = documentVersionRepository.findLatestVersionByDocumentId(documentId).orElse(0) + 1;
int version = documentVersionRepository.findLatestVersionByDocumentId(documentId) + 1;

return saveDocumentVersion(userId, document, request, version);
}
Expand All @@ -55,6 +55,7 @@ public Page<DocumentResponse> getAll(final Long userId, final Pageable pageable)
.map(document ->
DocumentResponse.of(
document,
documentVersionRepository.findLatestVersionByDocumentId(document.getId()),
applicationFormDocumentService.getSimpleResponsesByDocumentId(userId, document.getId())
));
}
Expand Down
Loading