package hdm.mi.growbros.controllers;

import hdm.mi.growbros.models.Plant;
import hdm.mi.growbros.service.PlantsService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@CrossOrigin
public class PlantsController {
    private final PlantsService plantsService;

    public PlantsController(PlantsService plantsService) {
        this.plantsService = plantsService;
    }

    @GetMapping("/api/v1/plants")
    public Collection<Plant> getAllPlants() {
        return plantsService.getPlants();
    }

    @PostMapping("/api/v1/plants")
    public void createPlant(@RequestBody @Valid Plant plant) {
        plantsService.create(plant);
    }
}