Skip to content
Extraits de code Groupes Projets
Valider 59531b6b rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'feature/VSN-1122' into 'develop'

feature/VSN-1122 - Document listing implementations

Closes VSN-1122

See merge request !25
parents 5e9e4242 1ce8def0
Branches
Étiquettes v0.0.15
1 requête de fusion!25feature/VSN-1122 - Document listing implementations
Pipeline #18315 réussi avec l'étape
in 24 secondes
Affichage de
avec 71 ajouts et 14 suppressions
......@@ -14,6 +14,7 @@
- Add bulk operations : delete, share, move on folders
- Create document/Upload new Document/s3 docs upload: implementations
- Add root documents to storage quota counting
- Document listing implementations
## [0.0.9]
-
## [0.0.8]
......
......@@ -21,4 +21,5 @@ public class MessageConstants {
public static final String EXCEL_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
public static final String SUCCESSFUL_UPLOAD = "Document uploaded successfully.";
public static final String DUPLICATE_NAME = "A document with the same name already exists in the target folder.";
public static final String DOCUMENT_NOT_FOUND = "Document Not Found";
}
......@@ -40,5 +40,8 @@ public class Paths {
//document management urls
public static final String DOCUMENT_BASE = BASE_URL + "/docs";
public static final String DOCUMENT_UPLOAD = "/upload";
public static final String USER_DOCUMENTS = "/all";
public static final String DOCUMENT_DETAILS = "/details";
public static final String ROOT_DOCUMENTS = "/root";
}
......@@ -2,6 +2,7 @@ package com.marketingconfort.adanev.vsn.document.controller;
import com.marketingconfort.adanev.vsn.document.constants.MessageConstants;
import com.marketingconfort.adanev.vsn.document.constants.paths.Paths;
import com.marketingconfort.adanev.vsn.document.dtos.DocumentDTO;
import com.marketingconfort.adanev.vsn.document.dtos.requests.AddDocumentRequest;
import com.marketingconfort.adanev.vsn.document.services.DocumentService;
import com.marketingconfort.starter.core.exceptions.FunctionalException;
......@@ -10,13 +11,11 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping(Paths.DOCUMENT_BASE)
......@@ -44,4 +43,19 @@ public class DocumentController {
throw new RuntimeException(e);
}
}
@GetMapping(Paths.USER_DOCUMENTS)
public ResponseEntity<List<DocumentDTO>> getDocumentsByUser(@RequestParam Long ownerId) throws FunctionalException {
return ResponseEntity.ok(documentService.getDocumentsByOwnerId(ownerId));
}
@GetMapping(Paths.DOCUMENT_DETAILS)
public ResponseEntity<DocumentDTO> getDocumentDetails(@RequestParam Long documentId, @RequestParam Long ownerId) throws FunctionalException {
return ResponseEntity.ok(documentService.getDocumentByIdAndOwner(documentId, ownerId));
}
@GetMapping(Paths.ROOT_DOCUMENTS)
public ResponseEntity<List<DocumentDTO>> getRootDocuments(@RequestParam Long ownerId) {
return ResponseEntity.ok(documentService.getRootDocumentsByOwnerId(ownerId));
}
}
......@@ -7,7 +7,7 @@ import com.marketingconfort.adanev.vsn.document.models.Folder;
public class DocumentMapper {
// Map document to DTO
public static DocumentDTO toDto(Document document, boolean includeFolder) {
public static DocumentDTO toDto(Document document) {
if (document == null) return null;
DocumentDTO dto = new DocumentDTO();
......@@ -19,11 +19,6 @@ public class DocumentMapper {
dto.setS3Key(document.getS3Key());
dto.setOwnerId(document.getOwnerId());
dto.setDocumentType(document.getDocumentType());
if (includeFolder && document.getFolder() != null) {
dto.setFolder(FolderMapper.toDto(document.getFolder())); // avoid deep nesting
}
return dto;
}
......
......@@ -38,7 +38,7 @@ public class FolderMapper {
// Conditionally map documents
if (folder.getDocuments() != null && !folder.getDocuments().isEmpty()) {
List<DocumentDTO> documentDtos = folder.getDocuments().stream()
.map(doc -> DocumentMapper.toDto(doc, false)) // prevent infinite nesting
.map(DocumentMapper::toDto) // prevent infinite nesting
.collect(Collectors.toList());
dto.setDocuments(documentDtos);
}
......
......@@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface DocumentRepository extends JpaRepository<Document, Long> {
......@@ -16,4 +17,8 @@ public interface DocumentRepository extends JpaRepository<Document, Long> {
boolean existsByNameAndFolderIdAndOwnerId(String name, Long folderId, Long ownerId);
List<Document> findByOwnerIdAndFolderIsNull(Long ownerId);
List<Document> findByOwnerId(Long ownerId);
Optional<Document> findByIdAndOwnerId(Long documentId, Long ownerId);
}
package com.marketingconfort.adanev.vsn.document.services;
import com.marketingconfort.adanev.vsn.document.dtos.DocumentDTO;
import com.marketingconfort.adanev.vsn.document.dtos.requests.AddDocumentRequest;
import com.marketingconfort.adanev.vsn.document.dtos.response.DocumentUploadResponseDTO;
import com.marketingconfort.starter.core.exceptions.FunctionalException;
......@@ -8,10 +9,15 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface DocumentService {
@Transactional
void importDocument(MultipartFile file, AddDocumentRequest request) throws FunctionalException, IOException, S3FunctionalException;
void importDocumentToRoot(MultipartFile file,AddDocumentRequest request) throws FunctionalException, IOException, S3FunctionalException;
List<DocumentDTO> getDocumentsByOwnerId(Long ownerId) throws FunctionalException;
DocumentDTO getDocumentByIdAndOwner(Long documentId, Long ownerId) throws FunctionalException;
List<DocumentDTO> getRootDocumentsByOwnerId(Long ownerId);
}
package com.marketingconfort.adanev.vsn.document.services.Implementations;
import com.marketingconfort.adanev.vsn.document.config.AWSConfig;
import com.marketingconfort.adanev.vsn.document.config.EnvConfigLoader;
import com.marketingconfort.adanev.vsn.document.constants.MessageConstants;
import com.marketingconfort.adanev.vsn.document.dtos.DocumentDTO;
import com.marketingconfort.adanev.vsn.document.dtos.requests.AddDocumentRequest;
import com.marketingconfort.adanev.vsn.document.mappers.DocumentMapper;
import com.marketingconfort.adanev.vsn.document.models.Document;
import com.marketingconfort.adanev.vsn.document.enums.ContentType;
import com.marketingconfort.adanev.vsn.document.enums.DocumentType;
import com.marketingconfort.adanev.vsn.document.models.Folder;
import com.marketingconfort.adanev.vsn.document.repositories.DocumentRepository;
import com.marketingconfort.adanev.vsn.document.repositories.FolderRepository;
......@@ -22,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
......@@ -66,6 +68,10 @@ public class DocumentServiceImpl implements DocumentService {
document.setFolder(folder);
document.setOwnerId(request.getOwnerId());
document.setDocumentType(request.getDocumentType());
if (folder != null) {
folder.getDocuments().add(document);
folderRepository.save(folder);
}
documentRepository.save(document);
}
......@@ -76,6 +82,27 @@ public class DocumentServiceImpl implements DocumentService {
importDocument(file, request);
}
@Override
@Transactional
public List<DocumentDTO> getDocumentsByOwnerId(Long ownerId) {
List<Document> documents = documentRepository.findByOwnerId(ownerId);
return documents.stream().map(DocumentMapper::toDto).collect(Collectors.toList());
}
@Transactional
@Override
public DocumentDTO getDocumentByIdAndOwner(Long documentId, Long ownerId) throws FunctionalException {
Document document = documentRepository.findByIdAndOwnerId(documentId, ownerId)
.orElseThrow(() -> new FunctionalException(MessageConstants.DOCUMENT_NOT_FOUND));
return DocumentMapper.toDto(document);
}
@Override
public List<DocumentDTO> getRootDocumentsByOwnerId(Long ownerId) {
List<Document> documents = documentRepository.findByOwnerIdAndFolderIsNull(ownerId);
return documents.stream().map(DocumentMapper::toDto).collect(Collectors.toList());
}
public boolean isDocumentNameUnique(String name, Long folderId, Long ownerId) {
if (folderId == null) {
// Root space: check documents for this user with no folder
......
......@@ -123,7 +123,7 @@ public class FolderServiceImpl implements FolderService {
@Transactional(readOnly = true)
public List<DocumentDTO> listDocumentsInFolder(Long folderId, Long ownerId) {
List<Document> docs = documentRepository.findByFolderIdAndOwnerId(folderId, ownerId);
return docs.stream().map(doc -> DocumentMapper.toDto(doc, false)).toList();
return docs.stream().map(DocumentMapper::toDto).toList();
}
@Override
......
......@@ -6,9 +6,14 @@ spring:
name: vsn-document-service
profiles:
active: ${SPRING_PROFILES_ACTIVE:local}
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
main:
allow-bean-definition-overriding: true
management:
endpoint:
health:
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter