Why this change is needed?
When someone need to prototype a project, sometimes it needs a rest
endpoint to perform some actions. This pr intent to create a
template for the developer to use.
How this commit address this issue?
It create a new generator inside macchiato. To run yo macchiato:rest.
It will create a similar Rest Controller:
@RestController
public class UserRestController {
@GetMapping
@ResponseStatus(OK)
public User get(@RequestParam("id") String id) {
//TODO: fetch the data from service layer.
return User.from(id);
}
@PostMapping(consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(CREATED)
public User create(@RequestBody User resource) {
//TODO: goes to service layer to create the entity.
return User.createSelfLink(resource);
}
@DeleteMapping
@ResponseStatus(NO_CONTENT)
public void delete(@RequestParam("id") String id) {
//TODO: Goes to service layer and delete the entity.
}
@AllArgsConstructor
@Getter
private static class User extends ResourceSupport {
private final UUID resourceId;
private static User from(String id) {
User resource = new User(UUID.fromString(id));
resource.add(linkTo(methodOn(UserRestController.class)
.get(id))
.withSelfRel());
return resource;
}
private static User createSelfLink(User resource) {
return from(resource.getResourceId().toString());
}
}
}
Why this change is needed? When someone need to prototype a project, sometimes it needs a rest endpoint to perform some actions. This pr intent to create a template for the developer to use.
How this commit address this issue? It create a new generator inside macchiato. To run
yo macchiato:rest
.It will create a similar Rest Controller: