feat: add a batch creation api for photos (#1564)

* feat: add an api of batch creation photos

* feat: add an api verification
pull/1568/head
guqing 2021-12-04 15:58:10 +08:00 committed by GitHub
parent 9801bc7a20
commit a802572128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -4,12 +4,14 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Valid;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.SortDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -32,6 +34,7 @@ import run.halo.app.service.PhotoService;
* @author ryanwang
* @date 2019-03-21
*/
@Validated
@RestController
@RequestMapping("/api/admin/photos")
public class PhotoController {
@ -75,6 +78,18 @@ public class PhotoController {
return new PhotoDTO().convertFrom(photoService.createBy(photoParam));
}
@PostMapping("/batch")
@ApiOperation("Batch creation photos")
public List<PhotoDTO> createBatchBy(@RequestBody List<@Valid PhotoParam> photoParams) {
return photoParams.stream()
.map(photoParam -> {
PhotoDTO photoDto = new PhotoDTO();
photoDto.convertFrom(photoService.createBy(photoParam));
return photoDto;
})
.collect(Collectors.toList());
}
@PutMapping("{photoId:\\d+}")
@ApiOperation("Updates a photo")
public PhotoDTO updateBy(@PathVariable("photoId") Integer photoId,