fixed to runnable state
This commit is contained in:
parent
f33d798663
commit
baa24b4b86
7 changed files with 14 additions and 13 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package me.jweissen.aeticket.dto.response;
|
||||
|
||||
public record UserResponseDto(int id, String firstname, String lastname, String email) {
|
||||
public record UserResponseDto(Long id, String firstname, String lastname, String email) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class Cart {
|
|||
private Long id;
|
||||
|
||||
@OneToMany(mappedBy = "cart")
|
||||
@JoinColumn(nullable = false)
|
||||
@Column(nullable = false)
|
||||
private List<CartEntry> cartEntries;
|
||||
|
||||
@ManyToOne
|
||||
|
|
|
|||
|
|
@ -33,6 +33,5 @@ public class Category {
|
|||
private Event event;
|
||||
|
||||
@OneToMany(mappedBy = "category")
|
||||
@JoinColumn
|
||||
private List<CartEntry> cartEntries;
|
||||
}
|
||||
|
|
@ -42,6 +42,5 @@ public class User {
|
|||
private Role role;
|
||||
|
||||
@OneToMany(mappedBy = "user")
|
||||
@JoinColumn(nullable = false)
|
||||
private List<Cart> carts;
|
||||
}
|
||||
|
|
@ -4,5 +4,6 @@ import me.jweissen.aeticket.model.User;
|
|||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Integer> {
|
||||
User findByToken(String token);
|
||||
User findByEmail(String email);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package me.jweissen.aeticket.service;
|
||||
|
||||
import me.jweissen.aeticket.dto.response.LoginResponseDto;
|
||||
import me.jweissen.aeticket.model.Role;
|
||||
import me.jweissen.aeticket.model.User;
|
||||
import me.jweissen.aeticket.repository.UserRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -10,12 +11,10 @@ import java.util.Optional;
|
|||
@Service
|
||||
public class AuthService {
|
||||
private final JwtService jwtService;
|
||||
private final UserService userService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public AuthService(JwtService jwtService, UserService userService, UserRepository userRepository) {
|
||||
public AuthService(JwtService jwtService, UserRepository userRepository) {
|
||||
this.jwtService = jwtService;
|
||||
this.userService = userService;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
|
|
@ -31,5 +30,13 @@ public class AuthService {
|
|||
return Optional.of(new LoginResponseDto(username));
|
||||
}
|
||||
|
||||
public Optional<Role> getRole(String token) {
|
||||
User user = userRepository.findByToken(token);
|
||||
if (user == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(user.getRole());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,17 +14,12 @@ import java.util.Optional;
|
|||
|
||||
@Service
|
||||
public class JwtService {
|
||||
@Value("${token.secret}")
|
||||
private String secret;
|
||||
@Value("${token.validForHours}")
|
||||
private Long tokenValidForHours;
|
||||
|
||||
private final JWTVerifier jwtVerifier;
|
||||
private final Algorithm algorithm;
|
||||
private final String userIdClaimKey = "userId";
|
||||
private final Long tokenValidForMillis;
|
||||
|
||||
public JwtService() {
|
||||
public JwtService(@Value("${token.secret}") String secret, @Value("${token.validForHours}") Long tokenValidForHours) {
|
||||
tokenValidForMillis = 1000L * 3600 * tokenValidForHours;
|
||||
algorithm = Algorithm.HMAC256(secret);
|
||||
jwtVerifier = JWT.require(algorithm).build();
|
||||
|
|
|
|||
Reference in a new issue