Skip to content

Commit

Permalink
chore(api-v3): update status codes for several /data endpoints
Browse files Browse the repository at this point in the history
all POST requests return 201 (excepting `/data/orders/*`)
all PUT,PATCH,DELETE,OPTIONS requests return 204
  • Loading branch information
bglamadrid committed Sep 29, 2024
1 parent 2d1a52b commit f3382bb
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- And all other constant and variable names that reference them
- remove `CustomerPojo` and `SalespersonPojo` classes
- the `OrderPojo` class now relates to two instances of `PersonPojo` instead
- Change status codes for most `/data` endpoints
- All POST requests return 201, except for three specific paths
- `/data/orders/confirmation`
- `/data/orders/rejection`
- `/data/orders/completion`
- All PUT,PATCH,DELETE,OPTIONS requests return 204

## [v0.2.4] - 2024-28-08

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@
import com.querydsl.core.types.OrderSpecifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.trebol.api.DataCrudGenericController;
import org.trebol.api.models.DataPagePojo;
import org.trebol.api.models.PersonPojo;
Expand All @@ -47,6 +40,9 @@
import jakarta.validation.Valid;
import java.util.Map;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/customers")
@PreAuthorize("isAuthenticated()")
Expand All @@ -73,13 +69,15 @@ public DataPagePojo<PersonPojo> readMany(@RequestParam Map<String, String> allRe
@Override
@PostMapping({"", "/"})
@PreAuthorize("hasAuthority('customers:create')")
@ResponseStatus(CREATED)
public void create(@Valid @RequestBody PersonPojo input)
throws BadInputException, EntityExistsException {
crudService.create(input);
}

@Override
@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('customers:update')")
public void update(@Valid @RequestBody PersonPojo input, @RequestParam Map<String, String> requestParams)
throws EntityNotFoundException, BadInputException {
Expand All @@ -88,6 +86,7 @@ public void update(@Valid @RequestBody PersonPojo input, @RequestParam Map<Strin

@Override
@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('customers:delete')")
public void delete(Map<String, String> requestParams)
throws EntityNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.trebol.api.DataCrudGenericController;
import org.trebol.api.models.DataPagePojo;
Expand All @@ -48,6 +49,9 @@
import jakarta.validation.Valid;
import java.util.Map;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/images")
@PreAuthorize("isAuthenticated()")
Expand All @@ -73,6 +77,7 @@ public DataPagePojo<ImagePojo> readMany(@RequestParam Map<String, String> allReq

@Override
@PostMapping({"", "/"})
@ResponseStatus(CREATED)
@PreAuthorize("hasAuthority('images:create')")
public void create(@Valid @RequestBody ImagePojo input)
throws BadInputException, EntityExistsException {
Expand All @@ -81,6 +86,7 @@ public void create(@Valid @RequestBody ImagePojo input)

@Override
@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('images:update')")
public void update(@Valid @RequestBody ImagePojo input, @RequestParam Map<String, String> requestParams)
throws EntityNotFoundException, BadInputException {
Expand All @@ -89,6 +95,7 @@ public void update(@Valid @RequestBody ImagePojo input, @RequestParam Map<String

@Override
@PatchMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('images:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
Expand All @@ -99,6 +106,7 @@ public void partialUpdate(

@Override
@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('images:delete')")
public void delete(@RequestParam Map<String, String> requestParams)
throws EntityNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.trebol.api.DataCrudGenericController;
import org.trebol.api.models.DataPagePojo;
Expand All @@ -55,6 +56,9 @@
import java.util.List;
import java.util.Map;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/orders")
@PreAuthorize("isAuthenticated()")
Expand Down Expand Up @@ -103,6 +107,7 @@ public DataPagePojo<OrderPojo> readMany(@RequestParam Map<String, String> allReq

@Override
@PostMapping({"", "/"})
@ResponseStatus(CREATED)
@PreAuthorize("hasAuthority('orders:create')")
public void create(@Valid @RequestBody OrderPojo input)
throws BadInputException, EntityExistsException {
Expand All @@ -111,6 +116,7 @@ public void create(@Valid @RequestBody OrderPojo input)

@Override
@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('orders:update')")
public void update(@Valid @RequestBody OrderPojo input, @RequestParam Map<String, String> requestParams)
throws BadInputException, EntityNotFoundException {
Expand All @@ -119,6 +125,7 @@ public void update(@Valid @RequestBody OrderPojo input, @RequestParam Map<String

@Override
@PatchMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('orders:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
Expand All @@ -129,13 +136,15 @@ public void partialUpdate(

@Override
@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('orders:delete')")
public void delete(@RequestParam Map<String, String> requestParams)
throws EntityNotFoundException {
super.delete(requestParams);
}

@PostMapping({"/confirmation", "/confirmation/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('orders:update')")
public void confirmSell(@RequestBody OrderPojo sell)
throws BadInputException, MailingServiceException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.trebol.api.DataCrudGenericController;
import org.trebol.api.models.DataPagePojo;
Expand All @@ -48,6 +49,9 @@
import jakarta.validation.Valid;
import java.util.Map;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/product_categories")
public class DataProductCategoriesController
Expand All @@ -74,6 +78,7 @@ public DataPagePojo<ProductCategoryPojo> readMany(@RequestParam Map<String, Stri

@Override
@PostMapping({"", "/"})
@ResponseStatus(CREATED)
@PreAuthorize("hasAuthority('product_categories:create')")
public void create(@Valid @RequestBody ProductCategoryPojo input)
throws BadInputException, EntityExistsException {
Expand All @@ -82,6 +87,7 @@ public void create(@Valid @RequestBody ProductCategoryPojo input)

@Override
@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_categories:update')")
public void update(@Valid @RequestBody ProductCategoryPojo input, @RequestParam Map<String, String> requestParams)
throws BadInputException, EntityNotFoundException {
Expand All @@ -90,6 +96,7 @@ public void update(@Valid @RequestBody ProductCategoryPojo input, @RequestParam

@Override
@PatchMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_categories:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
Expand All @@ -100,6 +107,7 @@ public void partialUpdate(

@Override
@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_categories:delete')")
public void delete(@RequestParam Map<String, String> requestParams)
throws EntityNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.trebol.api.models.DataPagePojo;
import org.trebol.api.models.ProductPojo;
Expand All @@ -62,6 +63,9 @@
import java.util.Map;
import java.util.Optional;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/product_list_contents")
public class DataProductListContentsController {
Expand Down Expand Up @@ -125,6 +129,7 @@ public DataPagePojo<ProductPojo> readContents(@RequestParam Map<String, String>
}

@PostMapping({"", "/"})
@ResponseStatus(CREATED)
@PreAuthorize("hasAuthority('product_lists:contents')")
public void addToContents(@Valid @RequestBody ProductPojo input,
@RequestParam Map<String, String> requestParams)
Expand All @@ -147,6 +152,7 @@ public void addToContents(@Valid @RequestBody ProductPojo input,
}

@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_lists:contents')")
public void updateContents(@RequestBody Collection<ProductPojo> input,
@RequestParam Map<String, String> requestParams)
Expand All @@ -172,6 +178,7 @@ public void updateContents(@RequestBody Collection<ProductPojo> input,
}

@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_lists:contents')")
public void deleteFromContents(@RequestParam Map<String, String> requestParams)
throws BadInputException, EntityNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.trebol.api.DataCrudGenericController;
import org.trebol.api.models.DataPagePojo;
Expand All @@ -48,6 +49,9 @@
import jakarta.validation.Valid;
import java.util.Map;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/product_lists")
public class DataProductListsController
Expand All @@ -71,6 +75,7 @@ public DataPagePojo<ProductListPojo> readMany(@RequestParam Map<String, String>

@Override
@PostMapping({"", "/"})
@ResponseStatus(CREATED)
@PreAuthorize("hasAuthority('product_lists:create')")
public void create(@Valid @RequestBody ProductListPojo input)
throws BadInputException, EntityExistsException {
Expand All @@ -79,6 +84,7 @@ public void create(@Valid @RequestBody ProductListPojo input)

@Override
@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_lists:update')")
public void update(@Valid @RequestBody ProductListPojo input, @RequestParam Map<String, String> requestParams)
throws BadInputException, EntityNotFoundException {
Expand All @@ -87,6 +93,7 @@ public void update(@Valid @RequestBody ProductListPojo input, @RequestParam Map<

@Override
@PatchMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_lists:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
Expand All @@ -97,6 +104,7 @@ public void partialUpdate(

@Override
@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('product_lists:delete')")
public void delete(@RequestParam Map<String, String> requestParams)
throws EntityNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.trebol.api.DataCrudGenericController;
import org.trebol.api.models.DataPagePojo;
Expand All @@ -48,6 +49,9 @@
import jakarta.validation.Valid;
import java.util.Map;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NO_CONTENT;

@RestController
@RequestMapping("/data/products")
public class DataProductsController
Expand All @@ -71,6 +75,7 @@ public DataPagePojo<ProductPojo> readMany(@RequestParam Map<String, String> allR

@Override
@PostMapping({"", "/"})
@ResponseStatus(CREATED)
@PreAuthorize("hasAuthority('products:create')")
public void create(@Valid @RequestBody ProductPojo input)
throws BadInputException, EntityExistsException {
Expand All @@ -79,6 +84,7 @@ public void create(@Valid @RequestBody ProductPojo input)

@Override
@PutMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('products:update')")
public void update(@Valid @RequestBody ProductPojo input, @RequestParam Map<String, String> requestParams)
throws BadInputException, EntityNotFoundException {
Expand All @@ -87,6 +93,7 @@ public void update(@Valid @RequestBody ProductPojo input, @RequestParam Map<Stri

@Override
@PatchMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('products:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
Expand All @@ -97,6 +104,7 @@ public void partialUpdate(

@Override
@DeleteMapping({"", "/"})
@ResponseStatus(NO_CONTENT)
@PreAuthorize("hasAuthority('products:delete')")
public void delete(@RequestParam Map<String, String> requestParams)
throws EntityNotFoundException {
Expand Down
Loading

0 comments on commit f3382bb

Please sign in to comment.