LeadController.java
package cz.vsb.crm.controller;
import cz.vsb.crm.dto.LeadLineResponse;
import cz.vsb.crm.dto.LeadRequest;
import cz.vsb.crm.dto.LeadResponse;
import cz.vsb.crm.service.LeadService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/leads")
@RequiredArgsConstructor
public class LeadController {
private final LeadService leadService;
@GetMapping
public List<LeadResponse> list() {
return leadService.findAll();
}
@GetMapping("/{id}")
public LeadResponse get(@PathVariable Long id) {
return leadService.findById(id);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public LeadResponse create(@Valid @RequestBody LeadRequest request) {
return leadService.create(request);
}
@PutMapping("/{id}")
public LeadResponse update(@PathVariable Long id, @Valid @RequestBody LeadRequest request) {
return leadService.update(id, request);
}
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void delete(@PathVariable Long id) {
leadService.delete(id);
}
@GetMapping("/{id}/products")
public List<LeadLineResponse> products(@PathVariable Long id) {
return leadService.getProducts(id);
}
}