This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "id": 1, | |
| "firstName": "Henrick", | |
| "lastName": "Kakutalua", | |
| "birthday": "2020-06-02T22:10:16.016+01:00", | |
| "bio": "Lorem ipsum", | |
| "imageUrl": "https://image/profile_photo.jpg" | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person person = personOptional.get(); | |
| if (personUpdateDto.getFirstName() != null) { | |
| person.setFirstName(personUpdateDto.getFirstName()); | |
| } | |
| if (personUpdateDto.getLastName() != null) { | |
| person.setLastName(personUpdateDto.getLastName()); | |
| } | |
| if (personUpdateDto.getBirthday() != null) { | |
| person.setBirthday(personUpdateDto.getBirthday()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.partialupdates.config; | |
| import com.fasterxml.jackson.databind.ObjectMapper; | |
| import org.openapitools.jackson.nullable.JsonNullableModule; | |
| import org.springframework.context.annotation.Configuration; | |
| import javax.annotation.PostConstruct; | |
| @Configuration | |
| public class JacksonConfiguration { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.partialupdates.controllers.dtos; | |
| import org.openapitools.jackson.nullable.JsonNullable; | |
| import javax.validation.constraints.NotNull; | |
| import java.time.OffsetDateTime; | |
| @SuppressWarnings("FieldMayBeFinal") | |
| public class PersonUpdateDto { | |
| @NotNull |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| @RequestMapping("/api/people") | |
| public class PeopleController { | |
| ... | |
| @PatchMapping("{id}") | |
| public ResponseEntity<Void> updatePerson(@PathVariable("id") long id, | |
| @Valid @RequestBody PersonUpdateDto personUpdateDto) { | |
| Optional<Person> personOptional = peopleRepository.getById(id); | |
| if (!personOptional.isPresent()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.partialupdates.utils; | |
| import org.openapitools.jackson.nullable.JsonNullable; | |
| import java.util.function.Consumer; | |
| public final class JsonNullableUtils { | |
| private JsonNullableUtils() {} | |
| public static <T> void changeIfPresent(JsonNullable<T> nullable, Consumer<T> consumer) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| @RequestMapping("/api/people") | |
| public class PeopleController { | |
| ... | |
| @PatchMapping("{id}") | |
| public ResponseEntity<Void> updatePerson(@PathVariable("id") long id, | |
| @Valid @RequestBody PersonUpdateDto personUpdateDto) { | |
| Optional<Person> personOptional = peopleRepository.getById(id); | |
| if (!personOptional.isPresent()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val product = productsRepository.findByIdOrNull(cartItem.productId) | |
| if (product == null) { | |
| return ResponseEntity.notFound().build() | |
| } | |
| val cart = cartsRepository.findByIdOrNull(cartId) | |
| if (cart == null) { | |
| return ResponseEntity.notFound().build() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| @RequestMapping("carts/{cart_id}/items") | |
| class CartItemsController( | |
| private val cartsRepository: CartsRepository, | |
| private val productsRepository: ProductsRepository) { | |
| @PostMapping | |
| fun addItemToCart( | |
| @PathVariable("cart_id") cartId: UUID, | |
| @RequestBody cartItem: CartItemInputModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SpringBootTest | |
| @ExtendWith(PostgresDbCleanerExtension::class) | |
| internal class CartsControllerTests { | |
| @Autowired | |
| lateinit var cartsRepository: CartsRepository | |
| @Autowired | |
| lateinit var webApplicationContext: WebApplicationContext | |
| ... |