This file contains 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
public final class Person { | |
private final String firstName; | |
private final String lastName; | |
private final Integer age; | |
Person(String firstName, String lastName, Integer age) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.age = age; |
This file contains 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
public class Person { | |
String firstName; | |
String lastName; | |
Integer age; | |
} |
This file contains 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 | |
@RequiredArgsConstructor | |
public class CustomArgumentResolverController { | |
private final PersonRepository personRepository; | |
@Fetch | |
public Person fetchPerson(@PathVariable String id) { | |
return personRepository.findBy(id); | |
} |
This file contains 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
@Test | |
public void should_patch_the_person_name() throws Exception { | |
when(personRepository.findBy(id)).thenReturn(personOldVersion()); | |
mockMvc.perform(patchPersonName()) | |
.andExpect(status().isOk()); | |
verify(personRepository).save(personNewVersion()); | |
} |
This file contains 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 | |
@RequiredArgsConstructor | |
public class PatchUsingModelAttributeController { | |
private final PersonRepository personRepository; | |
@ModelAttribute | |
public Person populatePerson(@PathVariable String id) { | |
return personRepository.findBy(id); | |
} |
This file contains 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
@Data | |
@Wither | |
@Builder | |
@AllArgsConstructor | |
public class PersonDto { | |
private String id; | |
private String name; | |
private Integer age; | |
} |
This file contains 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
@Data | |
@Wither | |
@Builder | |
@AllArgsConstructor | |
public class Person { | |
private String id; | |
private String name; | |
private Integer age; | |
} |
This file contains 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
import {Order} from './order'; | |
import {OrderDiscount} from './order-discount'; | |
export class Customer { | |
constructor(public orders: Order[]) {} | |
orderDiscount(): OrderDiscount { | |
return new OrderDiscount(this.orders.length); | |
} |
This file contains 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
import {OrderDiscount} from './order-discount'; | |
export class Order { | |
constructor(public amount: number, public discount: OrderDiscount) {} | |
discountedAmount() { | |
return (100 - this.discount.discount()) * this.amount; | |
} | |
} |
This file contains 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
export class OrderDiscount { | |
constructor(private ordersNumber: number) {} | |
discount() { | |
if (this.ordersNumber > 5) { | |
return 10; | |
} else { | |
return 3; | |
} |