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 | |
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE) | |
@AllArgsConstructor | |
public class ApiRest { | |
private final UserUseCase userUseCase; | |
@GetMapping(path = "/{id}") | |
public ResponseEntity<User> getUser(@PathVariable("id") String id) { | |
return ResponseEntity.ok(userUseCase.getUser(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
@Repository | |
public class JPARepositoryAdapter extends AdapterOperations<User, UserEntity, String, JPARepository> | |
implements UserRepository | |
{ | |
public JPARepositoryAdapter(JPARepository repository, ObjectMapper mapper) { | |
/** | |
* Could be use mapper.mapBuilder if your domain model implement builder pattern | |
* super(repository, mapper, d -> mapper.mapBuilder(d,ObjectModel.ObjectModelBuilder.class).build()); | |
* Or using mapper.map with the class of the object model |
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
@Entity | |
@Table(name = "`user`") | |
@Data | |
public class UserEntity { | |
@Id | |
private String id; | |
private String firstName; | |
private String lastName; | |
private String userName; | |
private String email; |
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
@RequiredArgsConstructor | |
public class UserUseCase { | |
private final UserRepository userRepository; | |
public User saveUser(User user) { | |
return userRepository.saveUser(user); | |
} | |
public User updateUser(User user) { | |
return userRepository.updateUser(user); |