#539 Code Review of Interview and Candidate Service

Companies:
Wildberries
Themes:
SpringTransactionsCode Review

Perform a code review:

@Component
class InterviewService(
    private val scoreRepository: ScoreRepository,
    private val transactionTemplate: TransactionTemplate,
    private val interviewScoreMLService: InterviewScoreMLService,
) {
    private val objectMapper = ObjectMapper()

    /**
    * The method calculates how many points the candidate earned,
    * saves the result to the database, and sends a callback to an external service
    */
    fun process(c: Candidate) {
        transactionTemplate.executeWithoutResult {
            val s: Score = interviewScoreMLService.compute(c)

            val request: Mono<ResponseEntity<Void>> = WebClient.create()
                .post()

                .body(BodyInserts.fromValue(objectMapper.writeValueAsString(c.name to s)))
                .retrieve()
                .toBodilessEntity()

            scoreRepository.saveScore(s)
        }
    }
}

data class Candidate(
    val name: String,
    val exercisesSolvedId: List<Int>,
)

data class Score(
    val name: String,
    val score: Int,
)

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in