Skip to content

Commit

Permalink
Merge pull request #248 from trebol-ecommerce/feature/put-and-patch-api
Browse files Browse the repository at this point in the history
Feature/put and patch api
  • Loading branch information
bglamadrid committed May 27, 2023
2 parents 931c11e + 8816396 commit 68cce0e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 7 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for partial update
- Meant to be, but not yet mapped as PATCH methods
- Support for partial updates using `PATCH` request in these endpoints
- `/data/products`
- `/data/sales`
- `/data/users`
- `/data/images`
- `/data/product_categories`
- `/data/shippers`
- `/data/product_lists`

### Changed

Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@

## Current Status 📓

This project's artifact, group and version have changed recently, as I decided that the conditions it must meet to reach a proper `v1.0` have changed.
Implementing [Trébol API v1.7.2](https://github.com/trebol-ecommerce/api/blob/v1.7.2/src/trebol-api.json).

Please take a look at the `CHANGELOG.md` file to review this and other recent changes and additions.

Currently bound to and implementing [Trébol API v1.5.0](https://github.com/trebol-ecommerce/api/blob/v1.5.0/trebol-api.json).
Please take a look at the `CHANGELOG.md` file to review the most recent changes and additions to the codebase.

## Features 🚀

* Exposes a [RESTful API](https://github.com/trebol-ecommerce/trebol-api) and supports all of the operations described by the document, such as
* Exposes a [RESTful API](https://github.com/trebol-ecommerce/trebol-api) and supports all the operations described by the document, such as
* CRUD operations on all declared data types
* Can filter, sort and paginate through query params
* Some endpoints support partial updates using `PATCH` requests
* Login, registration and optionally, guest customer accounts
* Checking out as a registered user or a guest (when enabled)
* Uses [Project Lombok](https://projectlombok.org) in all of its API models and JPA entities
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/trebol/api/controllers/DataImagesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -86,6 +87,16 @@ public void update(@RequestBody ImagePojo input, @RequestParam Map<String, Strin
super.update(input, requestParams);
}

@Override
@PatchMapping({"", "/"})
@PreAuthorize("hasAuthority('images:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
@RequestParam Map<String, String> requestParams
) throws BadInputException, EntityNotFoundException {
super.partialUpdate(input, requestParams);
}

@Override
@DeleteMapping({"", "/"})
@PreAuthorize("hasAuthority('images:delete')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -87,6 +88,16 @@ public void update(@Valid @RequestBody ProductCategoryPojo input, @RequestParam
super.update(input, requestParams);
}

@Override
@PatchMapping({"", "/"})
@PreAuthorize("hasAuthority('product_categories:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
@RequestParam Map<String, String> requestParams
) throws BadInputException, EntityNotFoundException {
super.partialUpdate(input, requestParams);
}

@Override
@DeleteMapping({"", "/"})
@PreAuthorize("hasAuthority('product_categories:delete')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -84,6 +85,16 @@ public void update(@RequestBody ProductListPojo input, @RequestParam Map<String,
super.update(input, requestParams);
}

@Override
@PatchMapping({"", "/"})
@PreAuthorize("hasAuthority('product_lists:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
@RequestParam Map<String, String> requestParams
) throws BadInputException, EntityNotFoundException {
super.partialUpdate(input, requestParams);
}

@Override
@DeleteMapping({"", "/"})
@PreAuthorize("hasAuthority('product_lists:delete')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -84,6 +85,16 @@ public void update(@RequestBody ProductPojo input, @RequestParam Map<String, Str
super.update(input, requestParams);
}

@Override
@PatchMapping({"", "/"})
@PreAuthorize("hasAuthority('products:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
@RequestParam Map<String, String> requestParams
) throws BadInputException, EntityNotFoundException {
super.partialUpdate(input, requestParams);
}

@Override
@DeleteMapping({"", "/"})
@PreAuthorize("hasAuthority('products:delete')")
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/trebol/api/controllers/DataSalesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -116,6 +117,16 @@ public void update(@RequestBody SellPojo input, @RequestParam Map<String, String
super.update(input, requestParams);
}

@Override
@PatchMapping({"", "/"})
@PreAuthorize("hasAuthority('sales:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
@RequestParam Map<String, String> requestParams
) throws BadInputException, EntityNotFoundException {
super.partialUpdate(input, requestParams);
}

@Override
@DeleteMapping({"", "/"})
@PreAuthorize("hasAuthority('sales:delete')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -84,6 +85,16 @@ public void update(@RequestBody ShipperPojo input, @RequestParam Map<String, Str
super.update(input, requestParams);
}

@Override
@PatchMapping({"", "/"})
@PreAuthorize("hasAuthority('shippers:update')")
public void partialUpdate(
@RequestBody Map<String, Object> input,
@RequestParam Map<String, String> requestParams
) throws BadInputException, EntityNotFoundException {
super.partialUpdate(input, requestParams);
}

@Override
@DeleteMapping({"", "/"})
@PreAuthorize("hasAuthority('shippers:delete')")
Expand Down

0 comments on commit 68cce0e

Please sign in to comment.