77.1. Add new user (#9 Section 11: User Resource)

This commit is contained in:
Art
2021-09-09 20:23:05 +03:00
parent bff1992842
commit 6c4b06233d
2 changed files with 78 additions and 1 deletions

View File

@ -1,9 +1,11 @@
package net.shyshkin.study.fullstack.supportportal.backend.controller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.shyshkin.study.fullstack.supportportal.backend.constant.SecurityConstants;
import net.shyshkin.study.fullstack.supportportal.backend.domain.HttpResponse;
import net.shyshkin.study.fullstack.supportportal.backend.domain.User;
import net.shyshkin.study.fullstack.supportportal.backend.domain.dto.UserDto;
import net.shyshkin.study.fullstack.supportportal.backend.service.UserService;
import net.shyshkin.study.fullstack.supportportal.backend.utility.JwtTokenProvider;
import org.springframework.http.ResponseEntity;
@ -15,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
import static org.springframework.http.HttpStatus.OK;
@Slf4j
@RestController
@RequestMapping("user")
@RequiredArgsConstructor
@ -53,6 +55,12 @@ public class UserResource {
.body(httpResponse);
}
@PostMapping("add")
public User addNewUser(UserDto userDto) {
log.debug("User DTO: {}", userDto);
return userService.addNewUser(userDto);
}
private void authenticate(String username, String password) {
Authentication auth = new UsernamePasswordAuthenticationToken(username, password);
authenticationManager.authenticate(auth);