package de.oaa.xxx.aufgaben.controller;

import de.oaa.xxx.aufgaben.DefaultFiller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RestController;

@RestController
@RequestMapping("/filler")
public class FillerController {

    private static final Logger LOGGER = LoggerFactory.getLogger(FillerController.class);

    private final DefaultFiller defaultFiller;

    public FillerController(DefaultFiller defaultFiller) {
        this.defaultFiller = defaultFiller;
    }

    @PostMapping
    public ResponseEntity<Void> fill() {
        try {
            defaultFiller.fill();
            return ResponseEntity.ok().build();
        } catch (Exception exception) {
            LOGGER.error(exception.getMessage(), exception);
            return ResponseEntity.internalServerError().build();
        }
    }
}
