/
Sturon
/
Diplom
Обзор
Документация
Войти
/
Sturon
/
Diplom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/src/main/java/ru/diplom/vision/api/ProfileController.java
92 строки
4 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.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.RestController; import ru.diplom.vision.api.dto.InspectionItemSummaryResponse; import ru.diplom.vision.api.dto.ProfileDetailsResponse; import ru.diplom.vision.api.dto.ProfileRequest; import ru.diplom.vision.api.dto.ProfileStatsResponse; import ru.diplom.vision.api.dto.ProfileSummaryResponse; import ru.diplom.vision.service.InspectionProfileService; import ru.diplom.vision.service.InspectionQueryService; @RestController @RequestMapping("/api/profiles") public class ProfileController { private final InspectionProfileService inspectionProfileService; private final InspectionQueryService inspectionQueryService; private final ApiMapper apiMapper; public ProfileController( InspectionProfileService inspectionProfileService, InspectionQueryService inspectionQueryService, ApiMapper apiMapper ) { this.inspectionProfileService = inspectionProfileService; this.inspectionQueryService = inspectionQueryService; this.apiMapper = apiMapper; } @GetMapping public List<ProfileSummaryResponse> findAll() { return inspectionProfileService.getSummaries(); } @GetMapping("/{id}") public ProfileDetailsResponse findById(@PathVariable Long id) { return apiMapper.toProfileDetailsResponse( inspectionProfileService.getRequired(id), inspectionProfileService.getStats(id) ); } @PostMapping public ProfileDetailsResponse create(@Valid @RequestBody ProfileRequest request) { var profile = inspectionProfileService.create(request); return apiMapper.toProfileDetailsResponse(profile, inspectionProfileService.getStats(profile.getId())); } @PutMapping("/{id}") public ProfileDetailsResponse update(@PathVariable Long id, @Valid @RequestBody ProfileRequest request) { var profile = inspectionProfileService.update(id, request); return apiMapper.toProfileDetailsResponse(profile, inspectionProfileService.getStats(profile.getId())); } @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { inspectionProfileService.delete(id); } @PostMapping("/{id}/run") public ProfileDetailsResponse run(@PathVariable Long id) { var profile = inspectionProfileService.startAnalysis(id); return apiMapper.toProfileDetailsResponse(profile, inspectionProfileService.getStats(profile.getId())); } @PostMapping("/{id}/stop") public ProfileDetailsResponse stop(@PathVariable Long id) { var profile = inspectionProfileService.stopAnalysis(id); return apiMapper.toProfileDetailsResponse(profile, inspectionProfileService.getStats(profile.getId())); } @GetMapping("/{id}/items") public List<InspectionItemSummaryResponse> getItems(@PathVariable Long id) { return inspectionQueryService.getRecentItems(id, 24).stream() .map(apiMapper::toInspectionItemSummaryResponse) .toList(); } @GetMapping("/{id}/stats") public ProfileStatsResponse getStats(@PathVariable Long id) { return inspectionProfileService.getStats(id); } }