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;
|
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;
|
private Long id;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "cart")
|
@OneToMany(mappedBy = "cart")
|
||||||
@JoinColumn(nullable = false)
|
@Column(nullable = false)
|
||||||
private List<CartEntry> cartEntries;
|
private List<CartEntry> cartEntries;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,5 @@ public class Category {
|
||||||
private Event event;
|
private Event event;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "category")
|
@OneToMany(mappedBy = "category")
|
||||||
@JoinColumn
|
|
||||||
private List<CartEntry> cartEntries;
|
private List<CartEntry> cartEntries;
|
||||||
}
|
}
|
||||||
|
|
@ -42,6 +42,5 @@ public class User {
|
||||||
private Role role;
|
private Role role;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "user")
|
@OneToMany(mappedBy = "user")
|
||||||
@JoinColumn(nullable = false)
|
|
||||||
private List<Cart> carts;
|
private List<Cart> carts;
|
||||||
}
|
}
|
||||||
|
|
@ -4,5 +4,6 @@ import me.jweissen.aeticket.model.User;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Integer> {
|
public interface UserRepository extends JpaRepository<User, Integer> {
|
||||||
|
User findByToken(String token);
|
||||||
User findByEmail(String email);
|
User findByEmail(String email);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package me.jweissen.aeticket.service;
|
package me.jweissen.aeticket.service;
|
||||||
|
|
||||||
import me.jweissen.aeticket.dto.response.LoginResponseDto;
|
import me.jweissen.aeticket.dto.response.LoginResponseDto;
|
||||||
|
import me.jweissen.aeticket.model.Role;
|
||||||
import me.jweissen.aeticket.model.User;
|
import me.jweissen.aeticket.model.User;
|
||||||
import me.jweissen.aeticket.repository.UserRepository;
|
import me.jweissen.aeticket.repository.UserRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -10,12 +11,10 @@ import java.util.Optional;
|
||||||
@Service
|
@Service
|
||||||
public class AuthService {
|
public class AuthService {
|
||||||
private final JwtService jwtService;
|
private final JwtService jwtService;
|
||||||
private final UserService userService;
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
public AuthService(JwtService jwtService, UserService userService, UserRepository userRepository) {
|
public AuthService(JwtService jwtService, UserRepository userRepository) {
|
||||||
this.jwtService = jwtService;
|
this.jwtService = jwtService;
|
||||||
this.userService = userService;
|
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,5 +30,13 @@ public class AuthService {
|
||||||
return Optional.of(new LoginResponseDto(username));
|
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
|
@Service
|
||||||
public class JwtService {
|
public class JwtService {
|
||||||
@Value("${token.secret}")
|
|
||||||
private String secret;
|
|
||||||
@Value("${token.validForHours}")
|
|
||||||
private Long tokenValidForHours;
|
|
||||||
|
|
||||||
private final JWTVerifier jwtVerifier;
|
private final JWTVerifier jwtVerifier;
|
||||||
private final Algorithm algorithm;
|
private final Algorithm algorithm;
|
||||||
private final String userIdClaimKey = "userId";
|
private final String userIdClaimKey = "userId";
|
||||||
private final Long tokenValidForMillis;
|
private final Long tokenValidForMillis;
|
||||||
|
|
||||||
public JwtService() {
|
public JwtService(@Value("${token.secret}") String secret, @Value("${token.validForHours}") Long tokenValidForHours) {
|
||||||
tokenValidForMillis = 1000L * 3600 * tokenValidForHours;
|
tokenValidForMillis = 1000L * 3600 * tokenValidForHours;
|
||||||
algorithm = Algorithm.HMAC256(secret);
|
algorithm = Algorithm.HMAC256(secret);
|
||||||
jwtVerifier = JWT.require(algorithm).build();
|
jwtVerifier = JWT.require(algorithm).build();
|
||||||
|
|
|
||||||
Reference in a new issue