forked from spring-petclinic/spring-petclinic-microservices
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing record class to only customer-service to start with (spri…
…ng-petclinic#253) Introducing record to the petclinic customer-service microservice
- Loading branch information
1 parent
81a1cc0
commit 39f6670
Showing
8 changed files
with
79 additions
and
60 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
...rvice/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerRequest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.springframework.samples.petclinic.customers.web; | ||
|
||
import jakarta.validation.constraints.Digits; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record OwnerRequest(@NotBlank String firstName, | ||
@NotBlank String lastName, | ||
@NotBlank String address, | ||
@NotBlank String city, | ||
@NotBlank | ||
@Digits(fraction = 0, integer = 12) | ||
String telephone | ||
) { | ||
} |
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
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
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
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
5 changes: 5 additions & 0 deletions
5
...vice/src/main/java/org/springframework/samples/petclinic/customers/web/mapper/Mapper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.springframework.samples.petclinic.customers.web.mapper; | ||
|
||
public interface Mapper<R, E> { | ||
E map(E response, R request); | ||
} |
19 changes: 19 additions & 0 deletions
19
...in/java/org/springframework/samples/petclinic/customers/web/mapper/OwnerEntityMapper.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.springframework.samples.petclinic.customers.web.mapper; | ||
|
||
import org.springframework.samples.petclinic.customers.model.Owner; | ||
import org.springframework.samples.petclinic.customers.web.OwnerRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OwnerEntityMapper implements Mapper<OwnerRequest, Owner> { | ||
// This is done by hand for simplicity purpose. In a real life use-case we should consider using MapStruct. | ||
@Override | ||
public Owner map(final Owner owner, final OwnerRequest request) { | ||
owner.setAddress(request.address()); | ||
owner.setCity(request.city()); | ||
owner.setTelephone(request.telephone()); | ||
owner.setFirstName(request.firstName()); | ||
owner.setLastName(request.lastName()); | ||
return owner; | ||
} | ||
} |