Skip to content
Extraits de code Groupes Projets
Valider 263d765f rédigé par youssef.achkir's avatar youssef.achkir
Parcourir les fichiers

Favorite documents feature implementations

parent c8916eea
Branches
Étiquettes
2 requêtes de fusion!34feature/VSN-1115 - "Favorite documents feature implementations",!33feature/VSN-1118 - Share Many Documents at once With user / share On S3
Pipeline #18659 en échec avec les étapes
in 1 minute
Affichage de avec 69 ajouts et 1 suppression
......@@ -13,6 +13,7 @@
- Folder Download bug fix
- Share Document With user / share On S3
- Share Many Documents at once With user / share On S3
- Favorite documents feature implementations
## [0.0.9]
-
## [0.0.8]
......
......@@ -18,7 +18,7 @@
<dependency>
<groupId>com.marketingconfort</groupId>
<artifactId>vsn-common</artifactId>
<version>0.0.61-RELEASE</version>
<version>0.0.65-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
......
......@@ -50,4 +50,7 @@ public class Paths {
public static final String GET_DOWNLOAD_URL = "/get-download-url";
public static final String DOCUMENT_SHARE = "/share";
public static final String BULK_SHARE_DOCUMENTS = "/bulk-share";
public static final String MARK_DOC_AS_FAVORITE = "/favorite/{documentId}";
public static final String UNMARK_DOC_AS_FAVORITE = "/cancel-favorite/{documentId}";
public static final String FAVORITE_DOCS = "/favorites";
}
......@@ -152,5 +152,26 @@ public class DocumentController {
}
}
@PostMapping(Paths.MARK_DOC_AS_FAVORITE)
public ResponseEntity<Void> markAsFavorite(
@PathVariable Long documentId,
@RequestParam Long ownerId) throws FunctionalException {
documentService.markAsFavorite(documentId, ownerId);
return ResponseEntity.ok().build();
}
@DeleteMapping(Paths.UNMARK_DOC_AS_FAVORITE)
public ResponseEntity<Void> unmarkAsFavorite(
@PathVariable Long documentId,
@RequestParam Long ownerId) throws FunctionalException {
documentService.unmarkAsFavorite(documentId, ownerId);
return ResponseEntity.ok().build();
}
@GetMapping(Paths.FAVORITE_DOCS)
public ResponseEntity<List<DocumentDTO>> getFavoriteDocuments(
@RequestParam Long ownerId) {
return ResponseEntity.ok(documentService.getFavoriteDocuments(ownerId));
}
}
......@@ -19,4 +19,5 @@ public class DocumentDTO extends BaseEntityDTO{
private Long ownerId; // ID of user who owns the document
private DocumentType documentType;
private FolderDTO folder; // Reference to parent folder
private boolean favorite;
}
......@@ -28,6 +28,7 @@ public class DocumentMapper {
dto.setS3Key(document.getS3Key());
dto.setOwnerId(document.getOwnerId());
dto.setDocumentType(document.getDocumentType());
dto.setFavorite(document.isFavorite());
try {
String presignedUrl = documentStorageService.getFileSharableLink(bucketName, document.getS3Key());
......@@ -51,6 +52,7 @@ public class DocumentMapper {
document.setS3Key(dto.getS3Key());
document.setOwnerId(dto.getOwnerId());
document.setDocumentType(dto.getDocumentType());
document.setFavorite(dto.isFavorite());
document.setFolder(folder); // assumed preloaded
return document;
......
......@@ -33,5 +33,6 @@ public interface DocumentRepository extends JpaRepository<Document, Long> , JpaS
@Param("keyword") String keyword,
Sort sort
);
List<Document> findByOwnerIdAndFavoriteTrue(Long ownerId);
}
......@@ -41,4 +41,7 @@ public interface DocumentService {
void bulkDeleteDocuments(List<Long> documentIds, Long ownerId) throws FunctionalException;
void shareDocument(Long documentId, Long targetUserId) throws FunctionalException, S3FunctionalException;
void bulkShareDocuments(List<Long> documentIds, Long targetUserId) throws FunctionalException, S3FunctionalException;
void markAsFavorite(Long documentId, Long ownerId) throws FunctionalException;
void unmarkAsFavorite(Long documentId, Long ownerId) throws FunctionalException;
List<DocumentDTO> getFavoriteDocuments(Long ownerId);
}
......@@ -353,6 +353,42 @@ public class DocumentServiceImpl implements DocumentService {
documentRepository.save(sharedDoc);
}
@Override
@Transactional
public void markAsFavorite(Long documentId, Long ownerId) throws FunctionalException {
Document doc = documentRepository.findById(documentId)
.orElseThrow(() -> new FunctionalException(MessageConstants.DOCUMENT_NOT_FOUND));
if (!(doc.getOwnerId() == ownerId)) {
throw new FunctionalException(MessageConstants.UNAUTHORIZED_ACCESS);
}
doc.setFavorite(true);
documentRepository.save(doc);
}
@Override
@Transactional
public void unmarkAsFavorite(Long documentId, Long ownerId) throws FunctionalException {
Document doc = documentRepository.findById(documentId)
.orElseThrow(() -> new FunctionalException(MessageConstants.DOCUMENT_NOT_FOUND));
if (!(doc.getOwnerId() == ownerId)) {
throw new FunctionalException(MessageConstants.UNAUTHORIZED_ACCESS);
}
doc.setFavorite(false);
documentRepository.save(doc);
}
@Override
@Transactional(readOnly = true)
public List<DocumentDTO> getFavoriteDocuments(Long ownerId) {
List<Document> docs = documentRepository.findByOwnerIdAndFavoriteTrue(ownerId);
return docs.stream().map(documentMapper::toDto).collect(Collectors.toList());
}
private Folder getOrCreateSharedWithMe(Long targetUserId) {
return folderRepository.findByOwnerIdAndName(targetUserId, "sharedWithMe")
.orElseGet(() -> {
......
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