-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImageController.java
40 lines (34 loc) · 1.42 KB
/
ImageController.java
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
package com.wypl.wyplimage.controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.wypl.applicationcommon.WyplResponseEntity;
import com.wypl.wyplimage.data.DeleteImageRequest;
import com.wypl.wyplimage.data.UploadImageResponse;
import com.wypl.wyplimage.service.ImageService;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@RequestMapping("/file")
@RestController
public class ImageController {
private final ImageService imageService;
@PostMapping("/v1/images")
public WyplResponseEntity<UploadImageResponse> uploadImage(
@RequestPart("image") final MultipartFile file
) {
String savedImageUrl = imageService.saveImage(file);
return WyplResponseEntity.created(new UploadImageResponse(savedImageUrl),
"이미지 업로드가 정상적으로 처리되었습니다.");
}
@DeleteMapping("/v1/images")
public WyplResponseEntity<Void> deleteImage(
@RequestBody DeleteImageRequest request
) {
imageService.removeImages(request);
return WyplResponseEntity.ok("사진 삭제가 정상적으로 처리되었습니다.");
}
}