package ru.ulstu.commit.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.PageableItems;
import ru.ulstu.commit.model.CommitListDto;
import ru.ulstu.commit.service.CommitService;
import ru.ulstu.core.model.response.Response;
import ru.ulstu.odin.controller.OdinController;
import ru.ulstu.odin.model.OdinVoid;

import static ru.ulstu.commit.controller.CommitController.URL;

@RestController
@RequestMapping(URL)
public class CommitController extends OdinController<CommitListDto, OdinVoid> {
    public static final String URL = Constants.API_1_0 + "commits";
    private final CommitService commitService;

    public CommitController(CommitService commitService) {
        super(CommitListDto.class);
        this.commitService = commitService;
    }

    @GetMapping("")
    public Response<PageableItems<CommitListDto>> getCommits(@RequestParam(value = "offset", defaultValue = "0") int offset,
                                                             @RequestParam(value = "count", defaultValue = "10") int count) {
        return new Response<>(commitService.getCommits(offset, count));
    }
}
