<commit_before>package ee.pardiralli.web;


import ee.pardiralli.domain.FeedbackType;
import ee.pardiralli.dto.InsertionDTO;
import ee.pardiralli.service.InsertionService;
import ee.pardiralli.util.ControllerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.validation.Valid;

@Controller
public class InsertionController {

    private final InsertionService insertionService;

    @Autowired
    public InsertionController(InsertionService insertionService) {
        this.insertionService = insertionService;
    }


    @GetMapping("/insert")
    public String getTemplate(Model model) {
        model.addAttribute("manualAdd", new InsertionDTO());
        return "insert";
    }

    @PostMapping("/owner")
    public String insertData(@Valid InsertionDTO insertionDTO,
                             BindingResult bindingResult,
                             Model model) {

        if (!insertionService.OpenedRaceExists()) {
            ControllerUtil.setFeedback(model, FeedbackType.ERROR, "Ükski võistlus ei ole avatud!");
            model.addAttribute("manualAdd", insertionDTO);
            return "insert";
        } else if (bindingResult.hasErrors()) {
            model.addAttribute("manualAdd", insertionDTO);
            return "insert";
        } else {
            Boolean success = insertionService.saveInsertion(insertionDTO);
            if (success) {
                ControllerUtil.setFeedback(model, FeedbackType.SUCCESS, "Andmed edukalt sisestatud");
            } else
                ControllerUtil.setFeedback(model, FeedbackType.ERROR, "Kinnitusmeili saatmine ebaõnnestus");
            model.addAttribute("manualAdd", new InsertionDTO());
        }
        return "insert";
    }
}
<commit_msg>InsertionController refactored & now displays success message also when mail confirmation fails<commit_after>package ee.pardiralli.web;


import ee.pardiralli.domain.FeedbackType;
import ee.pardiralli.dto.InsertionDTO;
import ee.pardiralli.service.InsertionService;
import ee.pardiralli.util.ControllerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.validation.Valid;

@Controller
public class InsertionController {

    private final InsertionService insertionService;

    @Autowired
    public InsertionController(InsertionService insertionService) {
        this.insertionService = insertionService;
    }


    @GetMapping("/insert")
    public String getTemplate(Model model) {
        model.addAttribute("manualAdd", new InsertionDTO());
        return "insert";
    }

    @PostMapping("/owner")
    public String insertData(@Valid InsertionDTO insertionDTO,
                             BindingResult bindingResult,
                             Model model) {

        if (!insertionService.OpenedRaceExists()) {
            ControllerUtil.setFeedback(model, FeedbackType.ERROR, "Ükski võistlus ei ole avatud!");
            model.addAttribute("manualAdd", insertionDTO);
            return "insert";
        } else if (bindingResult.hasErrors()) {
            model.addAttribute("manualAdd", insertionDTO);
            return "insert";
        } else {
            Boolean success = insertionService.saveInsertion(insertionDTO);
            ControllerUtil.setFeedback(model, FeedbackType.SUCCESS, "Andmed edukalt sisestatud");
            if (!success) {
                ControllerUtil.setFeedback(model, FeedbackType.ERROR, "Kinnitusmeili saatmine ebaõnnestus");
            }
            model.addAttribute("manualAdd", new InsertionDTO());
        }
        return "insert";
    }
}

{'fraction_non_alphanumeric': 0.09206039941548953, 'fraction_numerical': 0.0, 'mean_word_length': 3.195097037793667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7555307', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1078, 'n_words': 209}