-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11bc10e
commit 2246a32
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/com/prgrms/board/user/controller/UserController.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,45 @@ | ||
package com.prgrms.board.user.controller; | ||
|
||
import com.prgrms.board.user.controller.dto.UserControllerConverter; | ||
import com.prgrms.board.user.controller.dto.UserDetailedRequest; | ||
import com.prgrms.board.user.controller.dto.UserShortResponse; | ||
import com.prgrms.board.user.service.UserService; | ||
import com.prgrms.board.user.service.dto.UserDetailedParam; | ||
import com.prgrms.board.user.service.dto.UserShortResult; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.prgrms.board.user.controller.UserController.USER_REST_URI; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
@RestController | ||
@RequestMapping(value = USER_REST_URI, | ||
consumes = APPLICATION_JSON_VALUE, | ||
produces = APPLICATION_JSON_VALUE) | ||
public class UserController { | ||
|
||
public static final String USER_REST_URI = "api/users"; | ||
|
||
private final UserService service; | ||
private final UserControllerConverter converter; | ||
|
||
public UserController(UserService service, UserControllerConverter converter) { | ||
this.service = service; | ||
this.converter = converter; | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<UserShortResponse> create(@RequestBody @Validated UserDetailedRequest request) { | ||
UserDetailedParam param = converter.toUserDetailedParam(request); | ||
UserShortResult result = service.save(param); | ||
UserShortResponse response = converter.toUserResponse(result); | ||
return ResponseEntity | ||
.status(HttpStatus.CREATED) | ||
.body(response); | ||
} | ||
} |