package com.robocubs4205.cubscout.rest.v1;

import com.robocubs4205.cubscout.model.scorecard.Scorecard;
import com.robocubs4205.cubscout.model.scorecard.ScorecardRepository;
import com.robocubs4205.cubscout.rest.JsonArrayContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/scorecards",produces = "application/vnd.robocubs-v1+json")
public class ScorecardController {

    private final ScorecardRepository scorecardRepository;

    @Autowired
    public ScorecardController(ScorecardRepository scorecardRepository){

        this.scorecardRepository = scorecardRepository;
    }

    @RequestMapping(method = RequestMethod.GET)
    public JsonArrayContainer<ScorecardResource> getAllScorecards(){
        return new JsonArrayContainer<>(new ScorecardResourceAssembler().toResources(scorecardRepository.findAll()));
    }

    @RequestMapping(value = "/{scorecard:[0-9]+}")
    public ScorecardResource getScorecard(@PathVariable Scorecard scorecard){
        if(scorecard==null)throw new ResourceNotFoundException("scorecard does not exist");
        return new ScorecardResourceAssembler().toResource(scorecard);
    }

    @RequestMapping(value = "/{scorecard:[0-9]+}/results")
    public JsonArrayContainer<ResultResource> getResults(@PathVariable Scorecard scorecard) {
        if(scorecard==null)throw new ResourceNotFoundException("scorecard does not exist");
        return new JsonArrayContainer<>(new ResultResourceAssembler().toResources(scorecard.getResults()));
    }
}

@@ -390,165 +390,23 @@
 ork.
-web.bind.annotation.PathVariable;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod
+http.HttpStatus
 ;%0Aim
@@ -454,46 +454,9 @@
 ion.
-RestController;%0A%0Aimport java.util.List
+*
 ;%0A%0A@
@@ -1094,16 +1094,41 @@
 %5B0-9%5D+%7D%22
+,method=RequestMethod.GET
 )%0A    pu
@@ -1426,16 +1426,41 @@
 results%22
+,method=RequestMethod.GET
 )%0A    pu
@@ -1631,32 +1631,32 @@
 es not exist%22);%0A
-
         return n
@@ -1752,11 +1752,384 @@
 );%0A    %7D
+%0A%0A    @ResponseStatus(HttpStatus.NO_CONTENT)%0A    @RequestMapping(value = %22/%7Bscorecard:%5B0-9%5D+%7D%22,method=RequestMethod.DELETE)%0A    public void deleteScorecard(@PathVariable Scorecard scorecard)%7B%0A        if(scorecard==null)throw new ResourceNotFoundException(%22scorecard does not exist%22);%0A        scorecardRepository.delete(scorecard);%0A        scorecardRepository.flush();%0A    %7D
 %0A%7D%0A

add method annotation to Scorecard Controller add scorecard deletion method