diff --git a/server/pom.xml b/server/pom.xml index b518097..93a4f5d 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -31,6 +31,7 @@ + io.quarkus quarkus-resteasy-reactive-jackson @@ -39,10 +40,6 @@ io.quarkus quarkus-resteasy-reactive-jsonb - - io.quarkus - quarkus-mutiny - io.quarkus quarkus-resteasy-reactive @@ -72,6 +69,8 @@ io.quarkus quarkus-security + + org.eclipse.microprofile.jwt microprofile-jwt-auth-api @@ -99,6 +98,8 @@ 0.11.2 runtime + + org.projectlombok lombok @@ -110,6 +111,8 @@ mapstruct ${mapstruct.version} + + io.quarkus quarkus-junit5 diff --git a/server/src/main/java/dev/shiperist/repository/AccountRepository.java b/server/src/main/java/dev/shiperist/repository/AccountRepository.java index 060f507..cb11fca 100644 --- a/server/src/main/java/dev/shiperist/repository/AccountRepository.java +++ b/server/src/main/java/dev/shiperist/repository/AccountRepository.java @@ -1,10 +1,11 @@ package dev.shiperist.repository; import dev.shiperist.entity.AccountEntity; -import io.quarkus.hibernate.reactive.panache.PanacheRepository; import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase; +import io.quarkus.hibernate.reactive.panache.common.WithSession; import jakarta.enterprise.context.ApplicationScoped; +@WithSession @ApplicationScoped public class AccountRepository implements PanacheRepositoryBase { } diff --git a/server/src/main/java/dev/shiperist/repository/SessionRepository.java b/server/src/main/java/dev/shiperist/repository/SessionRepository.java index 9c3ea6c..7c3e262 100644 --- a/server/src/main/java/dev/shiperist/repository/SessionRepository.java +++ b/server/src/main/java/dev/shiperist/repository/SessionRepository.java @@ -1,11 +1,12 @@ package dev.shiperist.repository; import dev.shiperist.entity.SessionEntity; -import io.quarkus.hibernate.reactive.panache.PanacheRepository; import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase; +import io.quarkus.hibernate.reactive.panache.common.WithSession; import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; +@WithSession @ApplicationScoped public class SessionRepository implements PanacheRepositoryBase { diff --git a/server/src/main/java/dev/shiperist/repository/UserRepository.java b/server/src/main/java/dev/shiperist/repository/UserRepository.java index da17417..ff75953 100644 --- a/server/src/main/java/dev/shiperist/repository/UserRepository.java +++ b/server/src/main/java/dev/shiperist/repository/UserRepository.java @@ -1,11 +1,12 @@ package dev.shiperist.repository; import dev.shiperist.entity.UserEntity; -import io.quarkus.hibernate.reactive.panache.PanacheRepository; import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase; +import io.quarkus.hibernate.reactive.panache.common.WithSession; import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; +@WithSession @ApplicationScoped public class UserRepository implements PanacheRepositoryBase { diff --git a/server/src/main/java/dev/shiperist/resource/AuthService.java b/server/src/main/java/dev/shiperist/resource/AuthService.java index 94debb0..f52a8a7 100644 --- a/server/src/main/java/dev/shiperist/resource/AuthService.java +++ b/server/src/main/java/dev/shiperist/resource/AuthService.java @@ -76,11 +76,9 @@ public Uni getToken(@FormParam("grant_type") String grantType, .entity("Invalid email or password.").build()); } - System.out.println("password: " + password); User validUser = user.get(); if (userService.checkPassword(password, validUser.getPassword())) { - System.out.println("validUser: " + validUser); return sessionService.createSession(validUser) .map(session -> Response.ok(session).build()); } else { diff --git a/server/src/main/java/dev/shiperist/service/AccountService.java b/server/src/main/java/dev/shiperist/service/AccountService.java index eae6280..84f81ac 100644 --- a/server/src/main/java/dev/shiperist/service/AccountService.java +++ b/server/src/main/java/dev/shiperist/service/AccountService.java @@ -4,15 +4,13 @@ import dev.shiperist.mapper.AccountMapper; import dev.shiperist.model.Account; import dev.shiperist.repository.AccountRepository; -import io.quarkus.hibernate.reactive.panache.common.WithSession; +import io.quarkus.hibernate.reactive.panache.common.WithTransaction; import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.transaction.Transactional; import java.util.Optional; -@WithSession @ApplicationScoped public class AccountService { @@ -22,13 +20,12 @@ public class AccountService { @Inject AccountMapper accountMapper; - @Transactional + @WithTransaction public Uni createAccount(Account account) { AccountEntity accountEntity = accountMapper.toEntity(account); return accountRepository.persist(accountEntity).map(accountMapper::toDomain); } - @Transactional public Uni> getAccount(Long id) { return accountRepository.findById(id) .map(accountMapper::toDomain) @@ -36,13 +33,13 @@ public Uni> getAccount(Long id) { .onItem().ifNull().continueWith(Optional.empty()); } - @Transactional + @WithTransaction public Uni updateAccount(Account account) { AccountEntity accountEntity = accountMapper.toEntity(account); return accountRepository.persist(accountEntity).map(accountMapper::toDomain); } - @Transactional + @WithTransaction public Uni deleteAccount(Long accountId) { return accountRepository.deleteById(accountId); } diff --git a/server/src/main/java/dev/shiperist/service/SessionService.java b/server/src/main/java/dev/shiperist/service/SessionService.java index 7b042fc..813201a 100644 --- a/server/src/main/java/dev/shiperist/service/SessionService.java +++ b/server/src/main/java/dev/shiperist/service/SessionService.java @@ -8,11 +8,10 @@ import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.security.Keys; -import io.quarkus.hibernate.reactive.panache.common.WithSession; +import io.quarkus.hibernate.reactive.panache.common.WithTransaction; import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.transaction.Transactional; import java.security.Key; import java.time.Instant; @@ -21,7 +20,6 @@ import java.util.Date; import java.util.Optional; -@WithSession @ApplicationScoped public class SessionService { @@ -31,7 +29,7 @@ public class SessionService { @Inject SessionMapper sessionMapper; - @Transactional + @WithTransaction public Uni createSession(User user) { SessionEntity session = new SessionEntity(); Date expires = Date.from(Instant.now().plus(1, ChronoUnit.HOURS)); @@ -43,7 +41,6 @@ public Uni createSession(User user) { return sessionRepository.persist(session).map(sessionMapper::toDomain); } - @Transactional public Uni> getSession(Long id) { return sessionRepository.findById(id) .map(sessionMapper::toDomain) @@ -51,7 +48,6 @@ public Uni> getSession(Long id) { .onItem().ifNull().continueWith(Optional.empty()); } - @Transactional public Uni> getSessionByToken(String token) { return sessionRepository.findByToken(token) .map(sessionMapper::toDomain) @@ -59,13 +55,13 @@ public Uni> getSessionByToken(String token) { .onItem().ifNull().continueWith(Optional.empty()); } - @Transactional + @WithTransaction public Uni updateSession(Session session) { SessionEntity sessionEntity = sessionMapper.toEntity(session); return sessionRepository.persist(sessionEntity).map(sessionMapper::toDomain); } - @Transactional + @WithTransaction public Uni deleteSession(Long sessionId) { return sessionRepository.deleteById(sessionId); } diff --git a/server/src/main/java/dev/shiperist/service/UserService.java b/server/src/main/java/dev/shiperist/service/UserService.java index 7da0f5b..169ff22 100644 --- a/server/src/main/java/dev/shiperist/service/UserService.java +++ b/server/src/main/java/dev/shiperist/service/UserService.java @@ -5,15 +5,13 @@ import dev.shiperist.mapper.UserMapper; import dev.shiperist.model.User; import dev.shiperist.repository.UserRepository; -import io.quarkus.hibernate.reactive.panache.common.WithSession; +import io.quarkus.hibernate.reactive.panache.common.WithTransaction; import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.transaction.Transactional; import java.util.Optional; -@WithSession @ApplicationScoped public class UserService { @@ -23,33 +21,32 @@ public class UserService { @Inject UserMapper userMapper; - @Transactional + @WithTransaction public Uni createUser(String name, String email, String image, String password) { UserEntity user = new UserEntity(); user.setName(name); user.setEmail(email); user.setImage(image); user.setPassword(hashPassword(password)); - return userRepository.persist(user).map(userMapper::toDomain); + return userRepository.persist(user) + .map(userMapper::toDomain); } - @Transactional public Uni> getUser(Long id) { return userRepository.findById(id).map(user -> Optional.ofNullable(userMapper.toDomain(user))); } - @Transactional public Uni> getUserByEmail(String email) { return userRepository.findByEmail(email).map(user -> Optional.ofNullable(userMapper.toDomain(user))); } - @Transactional + @WithTransaction public Uni updateUser(User user) { UserEntity userEntity = userMapper.toEntity(user); return userRepository.persist(userEntity).map(userMapper::toDomain); } - @Transactional + @WithTransaction public Uni deleteUser(Long userId) { return userRepository.deleteById(userId); } diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index 5bb98d2..c41b8ba 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -1,5 +1,7 @@ -quarkus.datasource.db-kind=postgresql +%prod.quarkus.datasource.db-kind=postgresql quarkus.datasource.username=quarkus_test quarkus.datasource.password=quarkus_test + quarkus.datasource.devservices.port=5432 -quarkus.hibernate-orm.database.generation.create-schemas=true +quarkus.hibernate-orm.database.generation=drop-and-create +quarkus.hibernate-orm.log.sql=true