MediaController.java
1,041 bytes
| 1 | package com.tasteprint.media; |
|---|---|
| 2 | |
| 3 | import org.springframework.http.HttpStatus; |
| 4 | import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 5 | import org.springframework.web.bind.annotation.PostMapping; |
| 6 | import org.springframework.web.bind.annotation.RequestMapping; |
| 7 | import org.springframework.web.bind.annotation.RequestPart; |
| 8 | import org.springframework.web.bind.annotation.ResponseStatus; |
| 9 | import org.springframework.web.bind.annotation.RestController; |
| 10 | import org.springframework.web.multipart.MultipartFile; |
| 11 | |
| 12 | import com.tasteprint.account.AuthenticatedUser; |
| 13 | |
| 14 | @RestController |
| 15 | @RequestMapping("/api/v1/media") |
| 16 | class MediaController { |
| 17 | |
| 18 | private final MediaStorage mediaStorage; |
| 19 | |
| 20 | MediaController(MediaStorage mediaStorage) { |
| 21 | this.mediaStorage = mediaStorage; |
| 22 | } |
| 23 | |
| 24 | @PostMapping |
| 25 | @ResponseStatus(HttpStatus.CREATED) |
| 26 | MediaUpload upload(@AuthenticationPrincipal AuthenticatedUser user, |
| 27 | @RequestPart("file") MultipartFile file) { |
| 28 | return mediaStorage.store(user.id(), file); |
| 29 | } |
| 30 | } |
| 31 | |