4.3Kпросмотров
10 марта 2026 г.
Score: 4.7K
WB 1. Сделать ревью 2. Что будет если упадет сеть в строке "//упала сеть" (и что делать) import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.transaction.support.TransactionTemplate; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import java.util.List; import java.util.Map; @Component public class InterviewService { private final ScoreRepository scoreRepository; private final TransactionTemplate transactionTemplate; private final InterviewScoreMLService interviewScoreMLService; private final ObjectMapper objectMapper = new ObjectMapper(); public InterviewService(ScoreRepository scoreRepository, TransactionTemplate transactionTemplate, InterviewScoreMLService interviewScoreMLService) { this.scoreRepository = scoreRepository; this.transactionTemplate = transactionTemplate; this.interviewScoreMLService = interviewScoreMLService; } &nbsp; &nbsp; /** &nbsp;&nbsp; &nbsp; Метод считает сколько очков заработал кандидат, &nbsp;&nbsp; &nbsp; сохраняет результат в базу и кидает callback об этом во внешний сервис &nbsp;&nbsp; &nbsp; */ public void process(Candidate c) { transactionTemplate.executeWithoutResult(status -> { Score s = interviewScoreMLService.compute(c); String body = objectMapper.writeValueAsString(Map.of(c.getName(), s)); Mono<ResponseEntity<Void>> request = WebClient.create() .post() .body(BodyInserters.fromValue(body)) .retrieve() .toBodilessEntity(); scoreRepository.saveScore(s); }); //упала сеть } } class Candidate { private final String name; private final List<Integer> tasksSolvedId; public Candidate(String name, List<Integer> tasksSolvedId) { this.name = name; this.tasksSolvedId = tasksSolvedId; } public String getName() { return name; } public List<Integer> getTasksSolvedId() { return tasksSolvedId; } } class Score { private final String name; private final int score; public Score(String name, int score) { this.name = name; this.score = score; } public String getName() { return name; } public int getScore() { return score; } } #wilberries Прислать задачу | Подписаться
4.3K
просмотров
2673
символов
Нет
эмодзи
Нет
медиа

Другие посты @java_interviews

Все посты канала →