package be.mentoringsystems.merke.presentation.rest; import be.mentoringsystems.merke.model.QueryParams; import be.mentoringsystems.merke.model.db.Vendor; import be.mentoringsystems.merke.model.dto.ApiDTO; import be.mentoringsystems.merke.model.dto.PagedListDTO; import be.mentoringsystems.merke.model.dto.VendorDTO; import be.mentoringsystems.merke.model.dto.View; import be.mentoringsystems.merke.service.VendorService; import com.fasterxml.jackson.annotation.JsonView; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; /** * * @author anthonyarents */ @RestController @RequestMapping("/vendors") public class VendorController { @Autowired private transient VendorService vendorService; @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) public ApiDTO deleteById(@PathVariable UUID id) { vendorService.delete(id); return new ApiDTO(); } @JsonView(View.Vendor.class) @RequestMapping(value = "/{id}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) public ApiDTO updateById(@PathVariable UUID id, @RequestBody VendorDTO dto) { dto.setId(id); final Vendor result = vendorService.save(dto); return new ApiDTO(result); } @JsonView(View.Vendor.class) @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public ApiDTO createNew(@RequestBody VendorDTO dto) { final Vendor result = vendorService.save(dto); return new ApiDTO(result); } @JsonView(View.Vendor.class) @RequestMapping(value = "/{id}", method = RequestMethod.GET) public ApiDTO getById(@PathVariable UUID id) { final Vendor result = vendorService.getById(id); return new ApiDTO(result); } @JsonView(View.Vendor.class) @RequestMapping(value = "", method = RequestMethod.GET) public PagedListDTO getAll(QueryParams queryParams) { return vendorService.getAllDTO(queryParams); } }