structure update
This commit is contained in:
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -36,7 +37,7 @@ public class JacksonCustomizations {
|
||||
if (value == null) {
|
||||
gen.writeNull();
|
||||
} else {
|
||||
gen.writeString(value.toString());
|
||||
gen.writeString(ISODateTimeFormat.dateTime().withZoneUTC().print(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package io.spring.api;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import io.spring.api.exception.NoAuthorizationException;
|
||||
import io.spring.api.exception.ResourceNotFoundException;
|
||||
import io.spring.application.AuthorizationService;
|
||||
import io.spring.application.article.ArticleData;
|
||||
import io.spring.application.article.ArticleQueryService;
|
||||
import io.spring.core.service.AuthorizationService;
|
||||
import io.spring.application.data.ArticleData;
|
||||
import io.spring.application.ArticleQueryService;
|
||||
import io.spring.core.article.ArticleRepository;
|
||||
import io.spring.core.user.User;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.spring.api;
|
||||
|
||||
import io.spring.api.exception.ResourceNotFoundException;
|
||||
import io.spring.application.article.ArticleData;
|
||||
import io.spring.application.article.ArticleQueryService;
|
||||
import io.spring.application.data.ArticleData;
|
||||
import io.spring.application.ArticleQueryService;
|
||||
import io.spring.core.article.Article;
|
||||
import io.spring.core.article.ArticleRepository;
|
||||
import io.spring.core.favorite.ArticleFavorite;
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.spring.api;
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import io.spring.api.exception.InvalidRequestException;
|
||||
import io.spring.application.Page;
|
||||
import io.spring.application.article.ArticleQueryService;
|
||||
import io.spring.application.ArticleQueryService;
|
||||
import io.spring.core.article.Article;
|
||||
import io.spring.core.article.ArticleRepository;
|
||||
import io.spring.core.user.User;
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import io.spring.api.exception.InvalidRequestException;
|
||||
import io.spring.api.exception.NoAuthorizationException;
|
||||
import io.spring.api.exception.ResourceNotFoundException;
|
||||
import io.spring.application.AuthorizationService;
|
||||
import io.spring.application.comment.CommentData;
|
||||
import io.spring.application.comment.CommentQueryService;
|
||||
import io.spring.core.service.AuthorizationService;
|
||||
import io.spring.application.data.CommentData;
|
||||
import io.spring.application.CommentQueryService;
|
||||
import io.spring.core.article.Article;
|
||||
import io.spring.core.article.ArticleRepository;
|
||||
import io.spring.core.comment.Comment;
|
||||
|
||||
@@ -2,8 +2,9 @@ package io.spring.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import io.spring.api.exception.InvalidRequestException;
|
||||
import io.spring.application.user.UserQueryService;
|
||||
import io.spring.application.user.UserWithToken;
|
||||
import io.spring.application.UserQueryService;
|
||||
import io.spring.application.UserWithToken;
|
||||
import io.spring.application.data.UserData;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.core.user.UserRepository;
|
||||
import lombok.Getter;
|
||||
@@ -40,11 +41,15 @@ public class CurrentUserApi {
|
||||
@GetMapping
|
||||
public ResponseEntity currentUser(@AuthenticationPrincipal User currentUser,
|
||||
@RequestHeader(value = "Authorization") String authorization) {
|
||||
return ResponseEntity.ok(userResponse(userQueryService.fetchCurrentUser(currentUser.getUsername(), authorization.split(" ")[1])));
|
||||
UserData userData = userQueryService.findById(currentUser.getId()).get();
|
||||
return ResponseEntity.ok(userResponse(
|
||||
new UserWithToken(userData, authorization.split(" ")[1])
|
||||
));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public ResponseEntity updateProfile(@AuthenticationPrincipal User currentUser,
|
||||
@RequestHeader("Authorization") String token,
|
||||
@Valid @RequestBody UpdateUserParam updateUserParam,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
@@ -59,7 +64,10 @@ public class CurrentUserApi {
|
||||
updateUserParam.getBio(),
|
||||
updateUserParam.getImage());
|
||||
userRepository.save(currentUser);
|
||||
return ResponseEntity.ok(userResponse(userQueryService.fetchNewAuthenticatedUser(currentUser.getUsername())));
|
||||
UserData userData = userQueryService.findById(currentUser.getId()).get();
|
||||
return ResponseEntity.ok(userResponse(
|
||||
new UserWithToken(userData, token.split(" ")[1])
|
||||
));
|
||||
}
|
||||
|
||||
private void checkUniquenessOfUsernameAndEmail(User currentUser, UpdateUserParam updateUserParam, BindingResult bindingResult) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.spring.api;
|
||||
|
||||
import io.spring.api.exception.ResourceNotFoundException;
|
||||
import io.spring.application.profile.ProfileData;
|
||||
import io.spring.application.profile.ProfileQueryService;
|
||||
import io.spring.application.data.ProfileData;
|
||||
import io.spring.application.ProfileQueryService;
|
||||
import io.spring.core.user.FollowRelation;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.core.user.UserRepository;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.spring.api;
|
||||
|
||||
import io.spring.application.tag.TagsQueryService;
|
||||
import io.spring.application.TagsQueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@@ -2,8 +2,10 @@ package io.spring.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonRootName;
|
||||
import io.spring.api.exception.InvalidRequestException;
|
||||
import io.spring.application.user.UserQueryService;
|
||||
import io.spring.application.user.UserWithToken;
|
||||
import io.spring.application.UserQueryService;
|
||||
import io.spring.application.UserWithToken;
|
||||
import io.spring.application.data.UserData;
|
||||
import io.spring.core.service.JwtService;
|
||||
import io.spring.core.user.EncryptService;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.core.user.UserRepository;
|
||||
@@ -32,32 +34,25 @@ public class UsersApi {
|
||||
private UserQueryService userQueryService;
|
||||
private String defaultImage;
|
||||
private EncryptService encryptService;
|
||||
private JwtService jwtService;
|
||||
|
||||
@Autowired
|
||||
public UsersApi(UserRepository userRepository,
|
||||
UserQueryService userQueryService,
|
||||
EncryptService encryptService,
|
||||
@Value("${image.default}") String defaultImage) {
|
||||
@Value("${image.default}") String defaultImage,
|
||||
JwtService jwtService) {
|
||||
this.userRepository = userRepository;
|
||||
this.userQueryService = userQueryService;
|
||||
this.encryptService = encryptService;
|
||||
this.defaultImage = defaultImage;
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/users", method = POST)
|
||||
public ResponseEntity createUser(@Valid @RequestBody RegisterParam registerParam, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
throw new InvalidRequestException(bindingResult);
|
||||
}
|
||||
if (userRepository.findByUsername(registerParam.getUsername()).isPresent()) {
|
||||
bindingResult.rejectValue("username", "DUPLICATED", "duplicated username");
|
||||
throw new InvalidRequestException(bindingResult);
|
||||
}
|
||||
checkInput(registerParam, bindingResult);
|
||||
|
||||
if (userRepository.findByEmail(registerParam.getEmail()).isPresent()) {
|
||||
bindingResult.rejectValue("email", "DUPLICATED", "duplicated email");
|
||||
throw new InvalidRequestException(bindingResult);
|
||||
}
|
||||
User user = new User(
|
||||
registerParam.getEmail(),
|
||||
registerParam.getUsername(),
|
||||
@@ -65,14 +60,33 @@ public class UsersApi {
|
||||
"",
|
||||
defaultImage);
|
||||
userRepository.save(user);
|
||||
return ResponseEntity.status(201).body(userResponse(userQueryService.fetchNewAuthenticatedUser(user.getUsername())));
|
||||
UserData userData = userQueryService.findById(user.getId()).get();
|
||||
return ResponseEntity.status(201).body(userResponse(new UserWithToken(userData, jwtService.toToken(user))));
|
||||
}
|
||||
|
||||
private void checkInput(@Valid @RequestBody RegisterParam registerParam, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
throw new InvalidRequestException(bindingResult);
|
||||
}
|
||||
if (userRepository.findByUsername(registerParam.getUsername()).isPresent()) {
|
||||
bindingResult.rejectValue("username", "DUPLICATED", "duplicated username");
|
||||
}
|
||||
|
||||
if (userRepository.findByEmail(registerParam.getEmail()).isPresent()) {
|
||||
bindingResult.rejectValue("email", "DUPLICATED", "duplicated email");
|
||||
}
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
throw new InvalidRequestException(bindingResult);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/users/login", method = POST)
|
||||
public ResponseEntity userLogin(@Valid @RequestBody LoginParam loginParam, BindingResult bindingResult) {
|
||||
Optional<User> optional = userRepository.findByEmail(loginParam.getEmail());
|
||||
if (optional.isPresent() && encryptService.check(loginParam.getPassword(), optional.get().getPassword())) {
|
||||
return ResponseEntity.ok(userResponse(userQueryService.fetchNewAuthenticatedUser(optional.get().getUsername())));
|
||||
UserData userData = userQueryService.findById(optional.get().getId()).get();
|
||||
return ResponseEntity.ok(userResponse(new UserWithToken(userData, jwtService.toToken(optional.get()))));
|
||||
} else {
|
||||
bindingResult.rejectValue("password", "INVALID", "invalid email or password");
|
||||
throw new InvalidRequestException(bindingResult);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.spring.api.security;
|
||||
|
||||
import io.spring.application.JwtService;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.core.service.JwtService;
|
||||
import io.spring.core.user.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application.article;
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.core.user.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.spring.application.article;
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.application.Page;
|
||||
import io.spring.application.profile.UserRelationshipQueryService;
|
||||
import io.spring.application.data.ArticleData;
|
||||
import io.spring.application.data.ArticleDataList;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.infrastructure.mybatis.readservice.ArticleReadService;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.spring.application.comment;
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.application.profile.UserRelationshipQueryService;
|
||||
import io.spring.application.data.CommentData;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.infrastructure.mybatis.readservice.CommentReadService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -1,8 +1,10 @@
|
||||
package io.spring.application.profile;
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.application.user.UserData;
|
||||
import io.spring.application.user.UserReadService;
|
||||
import io.spring.application.data.ProfileData;
|
||||
import io.spring.application.data.UserData;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserReadService;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserRelationshipQueryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.spring.application.tag;
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.infrastructure.mybatis.readservice.TagReadService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
24
src/main/java/io/spring/application/UserQueryService.java
Normal file
24
src/main/java/io/spring/application/UserQueryService.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.application.data.UserData;
|
||||
import io.spring.core.service.JwtService;
|
||||
import io.spring.infrastructure.mybatis.readservice.UserReadService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class UserQueryService {
|
||||
private UserReadService userReadService;
|
||||
private JwtService jwtService;
|
||||
|
||||
public UserQueryService(UserReadService userReadService, JwtService jwtService) {
|
||||
this.userReadService = userReadService;
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
public Optional<UserData> findById(String id) {
|
||||
return Optional.ofNullable(userReadService.findById(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.spring.application.user;
|
||||
package io.spring.application;
|
||||
|
||||
import io.spring.application.data.UserData;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.spring.application.article;
|
||||
package io.spring.application.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.spring.application.profile.ProfileData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application.article;
|
||||
package io.spring.application.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
@@ -1,8 +1,7 @@
|
||||
package io.spring.application.comment;
|
||||
package io.spring.application.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.spring.application.profile.ProfileData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application.profile;
|
||||
package io.spring.application.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application.user;
|
||||
package io.spring.application.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.spring.application.user;
|
||||
|
||||
import io.spring.application.JwtService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserQueryService {
|
||||
private UserReadService userReadService;
|
||||
private JwtService jwtService;
|
||||
|
||||
public UserQueryService(UserReadService userReadService, JwtService jwtService) {
|
||||
this.userReadService = userReadService;
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
public UserWithToken fetchNewAuthenticatedUser(String username) {
|
||||
UserData userData = userReadService.findByUsername(username);
|
||||
return new UserWithToken(userData, jwtService.toToken(userData));
|
||||
}
|
||||
|
||||
public UserWithToken fetchCurrentUser(String username, String token) {
|
||||
return new UserWithToken(userReadService.findByUsername(username), token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application;
|
||||
package io.spring.core.service;
|
||||
|
||||
import io.spring.core.article.Article;
|
||||
import io.spring.core.comment.Comment;
|
||||
@@ -1,13 +1,13 @@
|
||||
package io.spring.application;
|
||||
package io.spring.core.service;
|
||||
|
||||
import io.spring.application.user.UserData;
|
||||
import io.spring.core.user.User;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public interface JwtService {
|
||||
String toToken(UserData userData);
|
||||
String toToken(User user);
|
||||
|
||||
Optional<String> getSubFromToken(String token);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.infrastructure.favorite;
|
||||
package io.spring.infrastructure.mybatis.mapper;
|
||||
|
||||
import io.spring.core.favorite.ArticleFavorite;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.infrastructure.article;
|
||||
package io.spring.infrastructure.mybatis.mapper;
|
||||
|
||||
import io.spring.core.article.Article;
|
||||
import io.spring.core.article.Tag;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.infrastructure.comment;
|
||||
package io.spring.infrastructure.mybatis.mapper;
|
||||
|
||||
import io.spring.core.comment.Comment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.infrastructure.user;
|
||||
package io.spring.infrastructure.mybatis.mapper;
|
||||
|
||||
import io.spring.core.user.FollowRelation;
|
||||
import io.spring.core.user.User;
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.spring.application.article;
|
||||
package io.spring.infrastructure.mybatis.readservice;
|
||||
|
||||
import io.spring.application.Page;
|
||||
import io.spring.application.data.ArticleData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.spring.application.comment;
|
||||
package io.spring.infrastructure.mybatis.readservice;
|
||||
|
||||
import io.spring.application.data.CommentData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application.tag;
|
||||
package io.spring.infrastructure.mybatis.readservice;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.spring.application.user;
|
||||
package io.spring.infrastructure.mybatis.readservice;
|
||||
|
||||
import io.spring.application.data.UserData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -9,5 +10,7 @@ import org.springframework.stereotype.Component;
|
||||
public interface UserReadService {
|
||||
|
||||
UserData findByUsername(@Param("username") String username);
|
||||
|
||||
UserData findById(@Param("id") String id);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.spring.application.profile;
|
||||
package io.spring.infrastructure.mybatis.readservice;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -1,7 +1,8 @@
|
||||
package io.spring.infrastructure.favorite;
|
||||
package io.spring.infrastructure.repository;
|
||||
|
||||
import io.spring.core.favorite.ArticleFavorite;
|
||||
import io.spring.core.favorite.ArticleFavoriteRepository;
|
||||
import io.spring.infrastructure.mybatis.mapper.ArticleFavoriteMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package io.spring.infrastructure.article;
|
||||
package io.spring.infrastructure.repository;
|
||||
|
||||
import io.spring.core.article.Article;
|
||||
import io.spring.core.article.ArticleRepository;
|
||||
import io.spring.core.article.Tag;
|
||||
import io.spring.infrastructure.mybatis.mapper.ArticleMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -1,7 +1,8 @@
|
||||
package io.spring.infrastructure.comment;
|
||||
package io.spring.infrastructure.repository;
|
||||
|
||||
import io.spring.core.comment.Comment;
|
||||
import io.spring.core.comment.CommentRepository;
|
||||
import io.spring.infrastructure.mybatis.mapper.CommentMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package io.spring.infrastructure.user;
|
||||
package io.spring.infrastructure.repository;
|
||||
|
||||
import io.spring.core.user.FollowRelation;
|
||||
import io.spring.core.user.User;
|
||||
import io.spring.core.user.UserRepository;
|
||||
import io.spring.infrastructure.mybatis.mapper.UserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -4,8 +4,8 @@ import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jws;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.spring.application.JwtService;
|
||||
import io.spring.application.user.UserData;
|
||||
import io.spring.core.service.JwtService;
|
||||
import io.spring.core.user.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -26,9 +26,9 @@ public class DefaultJwtService implements JwtService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toToken(UserData userData) {
|
||||
public String toToken(User user) {
|
||||
return Jwts.builder()
|
||||
.setSubject(userData.getId())
|
||||
.setSubject(user.getId())
|
||||
.setExpiration(expireTimeFromNow())
|
||||
.signWith(SignatureAlgorithm.HS512, secret)
|
||||
.compact();
|
||||
|
||||
Reference in New Issue
Block a user