|
9 | 9 | import io.swagger.v3.oas.annotations.security.SecurityRequirement; |
10 | 10 | import io.swagger.v3.oas.annotations.tags.Tag; |
11 | 11 | import kattsyn.dev.rentplace.entities.Image; |
12 | | -import kattsyn.dev.rentplace.enums.ImageType; |
13 | 12 | import kattsyn.dev.rentplace.services.ImageService; |
14 | 13 | import lombok.extern.slf4j.Slf4j; |
15 | 14 | import org.springframework.beans.factory.annotation.Value; |
|
20 | 19 | import org.springframework.http.ResponseEntity; |
21 | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
22 | 21 | import org.springframework.web.bind.annotation.*; |
23 | | -import org.springframework.web.multipart.MultipartFile; |
24 | 22 |
|
25 | 23 | import java.io.IOException; |
26 | 24 | import java.nio.file.Files; |
27 | 25 | import java.nio.file.Path; |
28 | 26 | import java.nio.file.Paths; |
29 | | -import java.util.ArrayList; |
30 | | -import java.util.List; |
31 | 27 |
|
32 | 28 | @RestController |
33 | 29 | @RequestMapping("${api.path}/images") |
@@ -70,59 +66,6 @@ public ResponseEntity<Resource> getImage( |
70 | 66 | } |
71 | 67 | } |
72 | 68 |
|
73 | | - @Operation( |
74 | | - summary = "Загрузка фотографии", |
75 | | - description = "Загрузка фотографии" |
76 | | - ) |
77 | | - @ApiResponses(value = { |
78 | | - @ApiResponse(responseCode = "200", description = "Успешно", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Image.class))), |
79 | | - @ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content) |
80 | | - }) |
81 | | - @SecurityRequirement(name = "JWT") |
82 | | - @PreAuthorize("hasAuthority('ROLE_ADMIN')") |
83 | | - @PostMapping(path = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
84 | | - public ResponseEntity<Image> uploadImage( |
85 | | - @Parameter( |
86 | | - description = "Файл фотографии", |
87 | | - required = true, |
88 | | - content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE) |
89 | | - ) @RequestParam("file") MultipartFile file, |
90 | | - @Parameter( |
91 | | - description = "Тип изображения", |
92 | | - required = true, |
93 | | - schema = @Schema( |
94 | | - implementation = ImageType.class) |
95 | | - ) @RequestParam ImageType imageType) { //todo: delete method |
96 | | - return ResponseEntity.ok(imageService.uploadImage(file, imageType)); |
97 | | - } |
98 | | - |
99 | | - |
100 | | - |
101 | | - @PostMapping(value = "/multiple/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
102 | | - @Operation( |
103 | | - summary = "Массовая загрузка фотографий", |
104 | | - description = "Загружает несколько фотографий за один запрос. Максимальное количество файлов - 10. Максимальный размер каждого файла - 10MB.") |
105 | | - @ApiResponses(value = { |
106 | | - @ApiResponse(responseCode = "200", description = "Фотографии успешно загружены", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Image[].class))), |
107 | | - @ApiResponse(responseCode = "400", description = "Некорректный запрос (превышено кол-во файлов, неверный формат и т.д.)", content = @Content), |
108 | | - @ApiResponse(responseCode = "413", description = "Превышен максимальный размер запроса"), |
109 | | - @ApiResponse(responseCode = "500", description = "Внутренняя ошибка сервера") |
110 | | - }) |
111 | | - @SecurityRequirement(name = "JWT") |
112 | | - @PreAuthorize("hasAuthority('ROLE_ADMIN')") |
113 | | - public ResponseEntity<List<Image>> uploadMultipleImages(@Parameter( |
114 | | - description = "Массив файлов фотографий", |
115 | | - required = true, |
116 | | - content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE, schema = @Schema(type = "string", format = "binary")) |
117 | | - ) @RequestPart("files") MultipartFile[] files) { |
118 | | - List<Image> savedImages = new ArrayList<>(); |
119 | | - |
120 | | - for (MultipartFile file : files) { |
121 | | - savedImages.add(imageService.uploadImage(file)); |
122 | | - } |
123 | | - |
124 | | - return ResponseEntity.ok(savedImages); |
125 | | - } |
126 | 69 |
|
127 | 70 | @Operation( |
128 | 71 | summary = "Получить фотографию", |
|
0 commit comments