추가정보를 전송하기 위한 hateoas 적용
This commit is contained in:
@@ -31,7 +31,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-hateoas</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Date;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonFilter("UserInfo")
|
||||
//@JsonFilter("UserInfo")
|
||||
public class User {
|
||||
private Integer id;
|
||||
@Size(min = 2, message = "Name은 2글자 이상 입력해 주세요.")
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.example.restfulwebservice.user;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
@@ -11,6 +13,9 @@ import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
private final UserDaoService userDaoService;
|
||||
@@ -27,14 +32,18 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/users/{id}")
|
||||
public User retrieveUser(@PathVariable int id) {
|
||||
public EntityModel<User> retrieveUser(@PathVariable int id) {
|
||||
User user = userDaoService.findOne(id);
|
||||
|
||||
if (user == null) {
|
||||
throw new UserNotFoundException(String.format("ID[%s] not found", id));
|
||||
}
|
||||
|
||||
return user;
|
||||
EntityModel<User> entityModel = new EntityModel<>(user);
|
||||
WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());
|
||||
entityModel.add(linkTo.withRel("all-users"));
|
||||
|
||||
return entityModel;
|
||||
}
|
||||
|
||||
@PostMapping("/users")
|
||||
|
||||
Reference in New Issue
Block a user