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
@@ -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<Folder> 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));
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.callv2.drive.application.folder.update.name;

import com.callv2.drive.application.UnitUseCase;

public abstract class UpdateFolderNameUseCase extends UnitUseCase<UpdateFolderNameInput> {

}
2 changes: 1 addition & 1 deletion infrastructure/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,67 +26,55 @@
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;

@Tag(name = "Files")
@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<CreateFileResponse> 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<CreateFileResponse> 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<Void> 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<Void> 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<GetFileResponse> 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<GetFileResponse> 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<Resource> 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<Resource> 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<Page<FileListResponse>> 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<String> 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<Page<FileListResponse>> 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<String> filters);

}
Loading