/
Sturon
/
Diplom
Обзор
Документация
Войти
/
Sturon
/
Diplom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/src/main/java/ru/diplom/vision/api/ReferenceImageController.java
62 строки
2 KB
Sturon
Initial
03 июн 2026, 15:01
03 июн 2026, 15:01
17b44a2
Код
Авторство
О чём код?
package ru.diplom.vision.api; import jakarta.validation.Valid; import java.util.List; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import ru.diplom.vision.api.dto.ReferenceImageResponse; import ru.diplom.vision.api.dto.RoiRequest; import ru.diplom.vision.service.ReferenceImageService; @RestController @RequestMapping("/api/reference-images") public class ReferenceImageController { private final ReferenceImageService referenceImageService; private final ApiMapper apiMapper; public ReferenceImageController(ReferenceImageService referenceImageService, ApiMapper apiMapper) { this.referenceImageService = referenceImageService; this.apiMapper = apiMapper; } @GetMapping public List<ReferenceImageResponse> findAll() { return referenceImageService.findAll().stream() .map(apiMapper::toReferenceImageResponse) .toList(); } @GetMapping("/{id}") public ReferenceImageResponse findById(@PathVariable Long id) { return apiMapper.toReferenceImageResponse(referenceImageService.getRequired(id)); } @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ReferenceImageResponse create( @RequestPart("file") MultipartFile file, @RequestParam(value = "name", required = false) String name ) { return apiMapper.toReferenceImageResponse(referenceImageService.create(name, file)); } @PutMapping("/{id}/roi") public ReferenceImageResponse updateRoi(@PathVariable Long id, @Valid @RequestBody RoiRequest request) { return apiMapper.toReferenceImageResponse(referenceImageService.updateRoi(id, request)); } @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { referenceImageService.delete(id); } }