diff --git a/application/src/main/java/com/callv2/drive/application/folder/update/name/DefaultUpdateFolderNameUseCase.java b/application/src/main/java/com/callv2/drive/application/folder/update/name/DefaultUpdateFolderNameUseCase.java new file mode 100644 index 00000000..d3267a16 --- /dev/null +++ b/application/src/main/java/com/callv2/drive/application/folder/update/name/DefaultUpdateFolderNameUseCase.java @@ -0,0 +1,44 @@ +package com.callv2.drive.application.folder.update.name; + +import java.util.Set; + +import com.callv2.drive.domain.exception.NotFoundException; +import com.callv2.drive.domain.exception.ValidationException; +import com.callv2.drive.domain.folder.Folder; +import com.callv2.drive.domain.folder.FolderGateway; +import com.callv2.drive.domain.folder.FolderID; +import com.callv2.drive.domain.folder.FolderName; +import com.callv2.drive.domain.validation.ValidationError; +import com.callv2.drive.domain.validation.handler.Notification; + +public class DefaultUpdateFolderNameUseCase extends UpdateFolderNameUseCase { + + private final FolderGateway folderGateway; + + public DefaultUpdateFolderNameUseCase(final FolderGateway folderGateway) { + this.folderGateway = folderGateway; + } + + @Override + public void execute(final UpdateFolderNameInput input) { + + final Folder folder = this.folderGateway + .findById(FolderID.of(input.folderId())) + .orElseThrow(() -> NotFoundException.with(Folder.class, input.folderId().toString())); + + final FolderName folderName = FolderName.of(input.name()); + + final Notification notification = Notification.create(); + + final Set subFolders = folderGateway.findByParentFolderId(folder.getParentFolder()); + + if (subFolders.stream().anyMatch(subFolder -> subFolder.getName().equals(folderName))) + notification.append(ValidationError.with("Folder with the same name already exists")); + + if (notification.hasError()) + throw ValidationException.with("Could not update folder name", notification); + + this.folderGateway.update(folder.changeName(folderName)); + } + +} \ No newline at end of file diff --git a/application/src/main/java/com/callv2/drive/application/folder/update/name/UpdateFolderNameInput.java b/application/src/main/java/com/callv2/drive/application/folder/update/name/UpdateFolderNameInput.java new file mode 100644 index 00000000..f590bf3b --- /dev/null +++ b/application/src/main/java/com/callv2/drive/application/folder/update/name/UpdateFolderNameInput.java @@ -0,0 +1,13 @@ +package com.callv2.drive.application.folder.update.name; + +import java.util.UUID; + +public record UpdateFolderNameInput( + UUID folderId, + String name) { + + public static UpdateFolderNameInput of(final UUID folderId, final String name) { + return new UpdateFolderNameInput(folderId, name); + } + +} diff --git a/application/src/main/java/com/callv2/drive/application/folder/update/name/UpdateFolderNameUseCase.java b/application/src/main/java/com/callv2/drive/application/folder/update/name/UpdateFolderNameUseCase.java new file mode 100644 index 00000000..5b588846 --- /dev/null +++ b/application/src/main/java/com/callv2/drive/application/folder/update/name/UpdateFolderNameUseCase.java @@ -0,0 +1,7 @@ +package com.callv2.drive.application.folder.update.name; + +import com.callv2.drive.application.UnitUseCase; + +public abstract class UpdateFolderNameUseCase extends UnitUseCase { + +} diff --git a/infrastructure/build.gradle b/infrastructure/build.gradle index c5ab35fc..ebd9c95d 100644 --- a/infrastructure/build.gradle +++ b/infrastructure/build.gradle @@ -1,7 +1,7 @@ plugins { id 'java' id 'application' - id 'org.springframework.boot' version '3.4.6' + id 'org.springframework.boot' version '3.5.5' id 'io.spring.dependency-management' version '1.1.7' } diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FileAPI.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FileAPI.java index 6b8799fa..9f61d40f 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FileAPI.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FileAPI.java @@ -12,7 +12,6 @@ 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.RequestPart; import org.springframework.web.multipart.MultipartFile; import com.callv2.drive.domain.pagination.Filter; @@ -27,7 +26,6 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; @@ -35,59 +33,48 @@ @RequestMapping("files") public interface FileAPI { - @PostMapping(value = "/folders/{folderId}/upload", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { - MediaType.APPLICATION_JSON_VALUE }) - @Operation(summary = "Upload a file to a specific folder", description = "This method uploads a file", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "201", description = "File uploaded successfully", content = @Content(schema = @Schema(implementation = CreateFileResponse.class))), - @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "413", description = "File is too large", content = @Content(schema = @Schema(implementation = ApiError.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) - ResponseEntity create( - @PathVariable(required = true, name = "folderId") UUID folderId, - @RequestPart("file") MultipartFile file); + @Operation(summary = "Upload a file to a specific folder", description = "This method uploads a file", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponse(responseCode = "201", description = "File uploaded successfully", content = @Content(schema = @Schema(implementation = CreateFileResponse.class))) + @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "413", description = "File is too large", content = @Content(schema = @Schema(implementation = ApiError.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + ResponseEntity create( + @RequestParam("folderId") UUID folderId, + @RequestParam("file") MultipartFile file); - @DeleteMapping(value = "{id}", produces = { MediaType.APPLICATION_JSON_VALUE }) - @Operation(summary = "Delete a file", description = "This method deletes a file", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "204", description = "File deleted successfully"), - @ApiResponse(responseCode = "404", description = "File not found", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) - ResponseEntity delete(@PathVariable(required = true) UUID id); + @Operation(summary = "Delete a file", description = "This method deletes a file", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponse(responseCode = "204", description = "File deleted successfully") + @ApiResponse(responseCode = "404", description = "File not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @DeleteMapping("{id}") + ResponseEntity delete(@PathVariable UUID id); - @GetMapping(value = "{id}", produces = { MediaType.APPLICATION_JSON_VALUE }) - @Operation(summary = "Retrive a file", description = "This method retrive a file", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "File retrieved successfully", content = @Content(schema = @Schema(implementation = GetFileResponse.class))), - @ApiResponse(responseCode = "404", description = "File not found", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) - ResponseEntity getById(@PathVariable(required = true) UUID id); + @Operation(summary = "Retrive a file", description = "This method retrive a file", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponse(responseCode = "200", description = "File retrieved successfully", content = @Content(schema = @Schema(implementation = GetFileResponse.class))) + @ApiResponse(responseCode = "404", description = "File not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping("{id}") + ResponseEntity getById(@PathVariable UUID id); - @GetMapping(value = "{id}/download", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE }) - @Operation(summary = "Download a file", description = "This method downloads a file", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "File downloaded successfully", content = @Content(schema = @Schema(implementation = Resource.class))), - @ApiResponse(responseCode = "404", description = "File not found", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ApiError.class))) - }) - ResponseEntity download(@PathVariable(required = true) UUID id); + @Operation(summary = "Download a file", description = "This method downloads a file", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponse(responseCode = "200", description = "File downloaded successfully", content = @Content(schema = @Schema(implementation = Resource.class))) + @ApiResponse(responseCode = "404", description = "File not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping("{id}/content") + ResponseEntity download(@PathVariable UUID id); - @GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE }) - @Operation(summary = "List files", description = "This method list files", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Files listed successfully", content = @Content(schema = @Schema(implementation = Page.class, subTypes = { - FileListResponse.class }))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) - ResponseEntity> list( - @RequestParam(name = "page", required = false, defaultValue = "0") final int page, - @RequestParam(name = "perPage", required = false, defaultValue = "10") final int perPage, - @RequestParam(name = "orderField", required = false, defaultValue = "createdAt") String orderField, - @RequestParam(name = "orderDirection", required = false, defaultValue = "DESC") Pagination.Order.Direction orderDirection, - @RequestParam(name = "filterOperator", required = false, defaultValue = "AND") Filter.Operator filterOperator, - @RequestParam(name = "filters", required = false) List filters); + @Operation(summary = "List files", description = "This method list files", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponse(responseCode = "200", description = "Files listed successfully", content = @Content(schema = @Schema(implementation = Page.class, subTypes = { + FileListResponse.class }))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping + ResponseEntity> list( + @RequestParam(name = "page", required = false, defaultValue = "0") final int page, + @RequestParam(name = "perPage", required = false, defaultValue = "10") final int perPage, + @RequestParam(name = "orderField", required = false, defaultValue = "createdAt") String orderField, + @RequestParam(name = "orderDirection", required = false, defaultValue = "DESC") Pagination.Order.Direction orderDirection, + @RequestParam(name = "filterOperator", required = false, defaultValue = "AND") Filter.Operator filterOperator, + @RequestParam(name = "filters", required = false) List filters); } diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FolderAPI.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FolderAPI.java index a3031648..0c5a9817 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FolderAPI.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/FolderAPI.java @@ -3,7 +3,6 @@ import java.util.List; import java.util.UUID; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -27,7 +26,6 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; @@ -35,51 +33,39 @@ @RequestMapping("folders") public interface FolderAPI { - @GetMapping(value = "root", produces = { MediaType.APPLICATION_JSON_VALUE }) @Operation(summary = "Retrive a folder", description = "This method retrive a root folder", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Root folder retrieved successfully", content = @Content(schema = @Schema(implementation = GetFolderResponse.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) + @ApiResponse(responseCode = "200", description = "Root folder retrieved successfully", content = @Content(schema = @Schema(implementation = GetFolderResponse.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping("root") ResponseEntity getRoot(); - @PostMapping(consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { - MediaType.APPLICATION_JSON_VALUE }) @Operation(summary = "Create a folder", description = "This method creates a folder", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "201", description = "Folder created successfully", content = @Content(schema = @Schema(implementation = CreateFolderResponse.class))), - @ApiResponse(responseCode = "422", description = "A validation error was thrown", content = @Content(schema = @Schema(implementation = ApiError.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) + @ApiResponse(responseCode = "201", description = "Folder created successfully", content = @Content(schema = @Schema(implementation = CreateFolderResponse.class))) + @ApiResponse(responseCode = "422", description = "A validation error was thrown", content = @Content(schema = @Schema(implementation = ApiError.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @PostMapping ResponseEntity create(@RequestBody CreateFolderRequest request); - @GetMapping(value = "{id}", produces = { MediaType.APPLICATION_JSON_VALUE }) @Operation(summary = "Retrive a folder", description = "This method retrive a folder", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Folder retrieved successfully", content = @Content(schema = @Schema(implementation = GetFolderResponse.class))), - @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) + @ApiResponse(responseCode = "200", description = "Folder retrieved successfully", content = @Content(schema = @Schema(implementation = GetFolderResponse.class))) + @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping("{id}") ResponseEntity getById(@PathVariable(required = true) UUID id); - @PatchMapping(value = "{id}/move", consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { - MediaType.APPLICATION_JSON_VALUE }) @Operation(summary = "Move a folder", description = "This method moves a folder to a new location", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "204", description = "Folder moved successfully", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))), - @ApiResponse(responseCode = "422", description = "A validation error was thrown", content = @Content(schema = @Schema(implementation = ApiError.class))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) + @ApiResponse(responseCode = "204", description = "Folder moved successfully", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "422", description = "A validation error was thrown", content = @Content(schema = @Schema(implementation = ApiError.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @PatchMapping("{id}/parent") ResponseEntity move(@PathVariable(required = true) UUID id, @RequestBody MoveFolderRequest request); - @GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE }) @Operation(summary = "List folders", description = "This method list folders", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Folders listed successfully", content = @Content(schema = @Schema(implementation = Page.class, subTypes = { - FolderListResponse.class }))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) + @ApiResponse(responseCode = "200", description = "Folders listed successfully", content = @Content(schema = @Schema(implementation = Page.class, subTypes = { + FolderListResponse.class }))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping ResponseEntity> list( @RequestParam(name = "page", required = false, defaultValue = "0") final int page, @RequestParam(name = "perPage", required = false, defaultValue = "10") final int perPage, @@ -88,4 +74,12 @@ ResponseEntity> list( @RequestParam(name = "filterOperator", required = false, defaultValue = "AND") Filter.Operator filterOperator, @RequestParam(name = "filters", required = false) List filters); + @Operation(summary = "Change folder name", description = "This method changes the name of a folder", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponse(responseCode = "204", description = "Folder name changed successfully", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "404", description = "Folder not found", content = @Content(schema = @Schema(implementation = Void.class))) + @ApiResponse(responseCode = "422", description = "A validation error was thrown", content = @Content(schema = @Schema(implementation = ApiError.class))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @PatchMapping("{id}/name") + ResponseEntity changeName(@PathVariable(required = true) UUID id, @RequestBody String request); + } diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAPI.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAPI.java index c7e48c99..da733ae1 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAPI.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAPI.java @@ -14,7 +14,6 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; @@ -22,22 +21,18 @@ @RequestMapping("members") public interface MemberAPI { - @PostMapping("quotas/requests/{amount}") @Operation(summary = "Request drive quota", description = "This method request a drive ammount quota", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "204", description = "Requested successfuly"), - @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) - }) + @ApiResponse(responseCode = "204", description = "Requested successfuly") + @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) + @PostMapping("quotas/requests/{amount}") ResponseEntity requestQuota( @PathVariable(value = "amount", required = true) long amount, @RequestParam(value = "unit", defaultValue = "GIGABYTE") QuotaUnit unit); - @GetMapping("quotas") @Operation(summary = "Retrieve actual drive quota", description = "This method retrieve a drive ammount quota", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Retrieve successfuly"), - @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) - }) + @ApiResponse(responseCode = "200", description = "Retrieve successfuly") + @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) + @GetMapping("quotas") ResponseEntity getQuota(); } \ No newline at end of file diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAdminAPI.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAdminAPI.java index 544dd3ec..f3ea018a 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAdminAPI.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/MemberAdminAPI.java @@ -1,10 +1,9 @@ package com.callv2.drive.infrastructure.api; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -18,7 +17,6 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; @@ -26,31 +24,25 @@ @RequestMapping("admin/members") public interface MemberAdminAPI { - @GetMapping("{id}/quotas") @Operation(summary = "Request drive quota", description = "This method request a drive ammount quota", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Retrieve successfuly"), - @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) - }) + @ApiResponse(responseCode = "200", description = "Retrieve successfuly") + @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) + @GetMapping("{id}/quotas") ResponseEntity getQuota(@PathVariable(value = "id", required = true) String id); - @PostMapping("{id}/quotas/requests/approve") @Operation(summary = "Approve drive quota request", description = "This method approve a drive ammount quota request", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "204", description = "Approved successfuly"), - @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) - }) + @ApiResponse(responseCode = "204", description = "Approved successfuly") + @ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class))) + @PatchMapping("{id}/quotas/requests") ResponseEntity approveQuotaRequest( @PathVariable(value = "id", required = true) String id, @RequestParam(value = "approved", defaultValue = "true") boolean approved); - @GetMapping(value = "quotas/requests", produces = { MediaType.APPLICATION_JSON_VALUE }) @Operation(summary = "List quotas requests", description = "This method list quotas requests", security = @SecurityRequirement(name = "bearerAuth")) - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Quotas requests listed successfully", content = @Content(schema = @Schema(implementation = Page.class, subTypes = { - QuotaRequestListResponse.class }))), - @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) - }) + @ApiResponse(responseCode = "200", description = "Quotas requests listed successfully", content = @Content(schema = @Schema(implementation = Page.class, subTypes = { + QuotaRequestListResponse.class }))) + @ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class))) + @GetMapping("quotas/requests") ResponseEntity> listQuotaRequests( @RequestParam(name = "page", required = false, defaultValue = "0") final int page, @RequestParam(name = "perPage", required = false, defaultValue = "10") final int perPage, diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/controller/FolderController.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/controller/FolderController.java index e8d83a9f..9854733f 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/controller/FolderController.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/api/controller/FolderController.java @@ -14,6 +14,8 @@ import com.callv2.drive.application.folder.retrieve.get.root.GetRootFolderInput; import com.callv2.drive.application.folder.retrieve.get.root.GetRootFolderUseCase; import com.callv2.drive.application.folder.retrieve.list.ListFoldersUseCase; +import com.callv2.drive.application.folder.update.name.UpdateFolderNameInput; +import com.callv2.drive.application.folder.update.name.UpdateFolderNameUseCase; import com.callv2.drive.domain.pagination.Filter; import com.callv2.drive.domain.pagination.Page; import com.callv2.drive.domain.pagination.Pagination; @@ -37,18 +39,21 @@ public class FolderController implements FolderAPI { private final GetFolderUseCase getFolderUseCase; private final MoveFolderUseCase moveFolderUseCase; private final ListFoldersUseCase listFoldersUseCase; + private final UpdateFolderNameUseCase updateFolderNameUseCase; public FolderController( final GetRootFolderUseCase getRootFolderUseCase, final CreateFolderUseCase createFolderUseCase, final GetFolderUseCase getFolderUseCase, final MoveFolderUseCase moveFolderUseCase, - final ListFoldersUseCase listFoldersUseCase) { + final ListFoldersUseCase listFoldersUseCase, + final UpdateFolderNameUseCase updateFolderNameUseCase) { this.getRootFolderUseCase = getRootFolderUseCase; this.createFolderUseCase = createFolderUseCase; this.getFolderUseCase = getFolderUseCase; this.moveFolderUseCase = moveFolderUseCase; this.listFoldersUseCase = listFoldersUseCase; + this.updateFolderNameUseCase = updateFolderNameUseCase; } @Override @@ -103,4 +108,12 @@ public ResponseEntity> list( return ResponseEntity.ok(listFoldersUseCase.execute(query).map(FolderPresenter::present)); } + @Override + public ResponseEntity changeName(UUID id, String newName) { + + this.updateFolderNameUseCase.execute(new UpdateFolderNameInput(id, newName)); + + return ResponseEntity.noContent().build(); + } + } diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/configuration/usecase/FolderUseCaseConfig.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/configuration/usecase/FolderUseCaseConfig.java index 960229c1..7312bf5d 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/configuration/usecase/FolderUseCaseConfig.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/configuration/usecase/FolderUseCaseConfig.java @@ -13,6 +13,8 @@ import com.callv2.drive.application.folder.retrieve.get.root.GetRootFolderUseCase; import com.callv2.drive.application.folder.retrieve.list.DefaultListFoldersUseCase; import com.callv2.drive.application.folder.retrieve.list.ListFoldersUseCase; +import com.callv2.drive.application.folder.update.name.DefaultUpdateFolderNameUseCase; +import com.callv2.drive.application.folder.update.name.UpdateFolderNameUseCase; import com.callv2.drive.domain.file.FileGateway; import com.callv2.drive.domain.folder.FolderGateway; import com.callv2.drive.domain.member.MemberGateway; @@ -58,4 +60,9 @@ ListFoldersUseCase listFoldersUseCase() { return new DefaultListFoldersUseCase(folderGateway); } + @Bean + UpdateFolderNameUseCase updateFolderNameUseCase() { + return new DefaultUpdateFolderNameUseCase(folderGateway); + } + } diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/file/FileJPAGateway.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/file/FileJPAGateway.java index 59bda478..825302a8 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/file/FileJPAGateway.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/file/FileJPAGateway.java @@ -61,7 +61,7 @@ public Page findAll(final SearchQuery searchQuery) { searchQuery.filters()); final org.springframework.data.domain.Page pageResult = this.fileRepository - .findAll(Specification.where(specification), page); + .findAll(specification, page); return new Page<>( pageResult.getNumber(), diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/filter/FilterService.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/filter/FilterService.java index c95c8fd7..5e58773f 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/filter/FilterService.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/filter/FilterService.java @@ -23,12 +23,12 @@ public Specification buildSpecification( final List filters) { if (filterMethod.equals(Filter.Operator.AND)) - return Specification.where(andSpecifications(buildSpecifications(entityClass, filters))); + return andSpecifications(buildSpecifications(entityClass, filters)); if (filterMethod.equals(Filter.Operator.OR)) - return Specification.where(orSpecifications(buildSpecifications(entityClass, filters))); + return orSpecifications(buildSpecifications(entityClass, filters)); - return Specification.where(andSpecifications(buildSpecifications(entityClass, filters))); + return andSpecifications(buildSpecifications(entityClass, filters)); } private List> buildSpecifications(Class entityClass, diff --git a/infrastructure/src/main/java/com/callv2/drive/infrastructure/folder/FolderJpaGateway.java b/infrastructure/src/main/java/com/callv2/drive/infrastructure/folder/FolderJpaGateway.java index 59365ad8..bd2f6843 100644 --- a/infrastructure/src/main/java/com/callv2/drive/infrastructure/folder/FolderJpaGateway.java +++ b/infrastructure/src/main/java/com/callv2/drive/infrastructure/folder/FolderJpaGateway.java @@ -81,7 +81,7 @@ public Page findAll(SearchQuery searchQuery) { searchQuery.filters()); final org.springframework.data.domain.Page pageResult = this.folderRepository.findAll( - Specification.where(specification), + specification, page); return new Page<>(