-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageController.java
More file actions
45 lines (38 loc) · 2 KB
/
ImageController.java
File metadata and controls
45 lines (38 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.stackbytes.controllers;
import com.stackbytes.models.dto.InsertImageResponseDto;
import com.stackbytes.services.ImageService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@RestController
public class ImageController {
private final ImageService imageService;
public ImageController(ImageService imageService) {
this.imageService = imageService;
}
@PostMapping("/insert")
public ResponseEntity<InsertImageResponseDto> insertImage(@RequestParam("file")MultipartFile file, @RequestParam("name") String name, @RequestParam("isProfilePicture") boolean isProfilePicture){
InsertImageResponseDto response = imageService.insertImage(file, name, isProfilePicture);
if(response.isSuccess()){
return ResponseEntity.ok(response);
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
@PostMapping("/insert-reduced")
public ResponseEntity<InsertImageResponseDto> insertReducedImage(@RequestParam("file")MultipartFile file, @RequestParam("name") String name, @RequestParam("isProfilePicture") boolean isProfilePicture) {
InsertImageResponseDto response = imageService.insertReducedImage(file, name, isProfilePicture);
if(response.isSuccess()){
return ResponseEntity.ok(response);
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
@PostMapping("/insert-avatar")
public ResponseEntity<InsertImageResponseDto> insertAvatarImage(@RequestParam("file")MultipartFile file, @RequestParam("name") String name, @RequestParam("reduced") boolean reduced) {
InsertImageResponseDto response = imageService.insertAvatarImage(file, name, reduced);
if(response.isSuccess()){
return ResponseEntity.ok(response);
}
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
}
}