/
java56
/
FindMaxNumber
Обзор
Документация
Войти
/
java56
/
FindMaxNumber
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/mikhail/digit/controller/NumberController.java
50 строк
3 KB
Mikhail Gorbatenkov
11 - add a rest controller
23 фев 2025, 16:12
23 фев 2025, 16:12
cec1682
Код
Авторство
О чём код?
package com.mikhail.digit.controller; import com.mikhail.digit.service.FindMaxService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; @Tag(name = "Обработка файла XLSX-файла") @RestController @RequestMapping(value = "/api/v1/numbers") public class NumberController { private FindMaxService findMaxService; public NumberController(FindMaxService findMaxService) { this.findMaxService = findMaxService; } @Operation(summary = "Получение максимального числа", description = "Получить N-е максимальное число из файла.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Максимальное число успешно получено", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = Integer.class))), @ApiResponse(responseCode = "400", description = "Произошла ошибка в поиске максимального числа", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value = "{\"error\": \"Произошла ошибка: описание_ошибки\"}"))) }) @PostMapping(value = "/find-max") public ResponseEntity<Integer> findMaxNumber(@Parameter(description = "Путь к локальному файлу") @RequestParam(name = "path") String filePath, @Parameter(description = "Число N") @RequestParam(name = "n") int n ) throws IOException { return ResponseEntity.ok(findMaxService.findNthMaxNumber(filePath, n)); } }