diff --git a/server/pom.xml b/server/pom.xml
index 5c36879..614b071 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -13,6 +13,7 @@
quarkus-bom
io.quarkus.platform
3.2.0.Final
+ 1.4.2.Final
true
3.0.0
@@ -71,6 +72,11 @@
1.18.28
provided
+
+ org.mapstruct
+ mapstruct
+ ${mapstruct.version}
+
io.quarkus
quarkus-junit5
@@ -118,6 +124,11 @@
lombok
1.18.28
+
+ org.mapstruct
+ mapstruct-processor
+ ${mapstruct.version}
+
diff --git a/server/src/main/java/dev/shiperist/ExampleResource.java b/server/src/main/java/dev/shiperist/ExampleResource.java
deleted file mode 100644
index ad9cf87..0000000
--- a/server/src/main/java/dev/shiperist/ExampleResource.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package dev.shiperist;
-
-import jakarta.ws.rs.GET;
-import jakarta.ws.rs.Path;
-import jakarta.ws.rs.Produces;
-import jakarta.ws.rs.core.MediaType;
-
-@Path("/hello")
-public class ExampleResource {
-
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public String hello() {
- return "Hello from RESTEasy Reactive";
- }
-}
diff --git a/server/src/main/java/dev/shiperist/user/mapper/AccountMapper.java b/server/src/main/java/dev/shiperist/user/mapper/AccountMapper.java
index 6f14cab..0d5a1ae 100644
--- a/server/src/main/java/dev/shiperist/user/mapper/AccountMapper.java
+++ b/server/src/main/java/dev/shiperist/user/mapper/AccountMapper.java
@@ -1,4 +1,13 @@
package dev.shiperist.user.mapper;
+import dev.shiperist.user.entity.AccountEntity;
+import dev.shiperist.user.model.Account;
+import org.mapstruct.Mapper;
+
+@Mapper(componentModel = "jakarta")
public interface AccountMapper {
+
+ AccountEntity toEntity(Account domain);
+
+ Account toDomain(AccountEntity entity);
}
diff --git a/server/src/main/java/dev/shiperist/user/mapper/SessionMapper.java b/server/src/main/java/dev/shiperist/user/mapper/SessionMapper.java
index aa7a6f6..9665288 100644
--- a/server/src/main/java/dev/shiperist/user/mapper/SessionMapper.java
+++ b/server/src/main/java/dev/shiperist/user/mapper/SessionMapper.java
@@ -1,4 +1,13 @@
package dev.shiperist.user.mapper;
+import dev.shiperist.user.entity.SessionEntity;
+import dev.shiperist.user.model.Session;
+import org.mapstruct.Mapper;
+
+@Mapper(componentModel = "jakarta")
public interface SessionMapper {
+
+ SessionEntity toEntity(Session domain);
+
+ Session toDomain(SessionEntity entity);
}
diff --git a/server/src/main/java/dev/shiperist/user/mapper/UserMapper.java b/server/src/main/java/dev/shiperist/user/mapper/UserMapper.java
index 4845430..703961e 100644
--- a/server/src/main/java/dev/shiperist/user/mapper/UserMapper.java
+++ b/server/src/main/java/dev/shiperist/user/mapper/UserMapper.java
@@ -1,4 +1,13 @@
package dev.shiperist.user.mapper;
+import dev.shiperist.user.entity.UserEntity;
+import dev.shiperist.user.model.User;
+import org.mapstruct.Mapper;
+
+@Mapper(componentModel = "jakarta")
public interface UserMapper {
+
+ UserEntity toEntity(User domain);
+
+ User toDomain(UserEntity entity);
}
diff --git a/server/src/main/java/dev/shiperist/user/model/Account.java b/server/src/main/java/dev/shiperist/user/model/Account.java
new file mode 100644
index 0000000..9c058ba
--- /dev/null
+++ b/server/src/main/java/dev/shiperist/user/model/Account.java
@@ -0,0 +1,21 @@
+package dev.shiperist.user.model;
+
+import dev.shiperist.user.entity.UserEntity;
+import lombok.Getter;
+
+@Getter
+public class Account {
+ private String userId;
+ private String type;
+ private String provider;
+ private String providerAccountId;
+ private String refreshToken;
+ private Integer refreshTokenExpiresIn;
+ private String accessToken;
+ private Integer expiresAt;
+ private String tokenType;
+ private String scope;
+ private String idToken;
+ private String sessionState;
+ private UserEntity user;
+}
diff --git a/server/src/main/java/dev/shiperist/user/model/Session.java b/server/src/main/java/dev/shiperist/user/model/Session.java
new file mode 100644
index 0000000..acb5bda
--- /dev/null
+++ b/server/src/main/java/dev/shiperist/user/model/Session.java
@@ -0,0 +1,14 @@
+package dev.shiperist.user.model;
+
+import dev.shiperist.user.entity.UserEntity;
+import lombok.Getter;
+
+import java.time.LocalDateTime;
+
+@Getter
+public class Session {
+ private String sessionToken;
+ private String userId;
+ private LocalDateTime expires;
+ private UserEntity user;
+}
diff --git a/server/src/main/java/dev/shiperist/user/model/User.java b/server/src/main/java/dev/shiperist/user/model/User.java
index 36f6498..666fe6a 100644
--- a/server/src/main/java/dev/shiperist/user/model/User.java
+++ b/server/src/main/java/dev/shiperist/user/model/User.java
@@ -1,4 +1,18 @@
package dev.shiperist.user.model;
+import dev.shiperist.user.entity.AccountEntity;
+import dev.shiperist.user.entity.SessionEntity;
+import lombok.Getter;
+
+import java.time.LocalDateTime;
+import java.util.Set;
+
+@Getter
public class User {
+ private String name;
+ private String email;
+ private LocalDateTime emailVerified;
+ private String image;
+ private Set accounts;
+ private Set sessions;
}
diff --git a/server/src/main/java/dev/shiperist/user/resource/UserResource.java b/server/src/main/java/dev/shiperist/user/resource/UserResource.java
index 74d2bc8..06b8b9e 100644
--- a/server/src/main/java/dev/shiperist/user/resource/UserResource.java
+++ b/server/src/main/java/dev/shiperist/user/resource/UserResource.java
@@ -1,21 +1,29 @@
package dev.shiperist.user.resource;
import dev.shiperist.user.entity.UserEntity;
+import dev.shiperist.user.mapper.UserMapper;
import dev.shiperist.user.model.User;
import dev.shiperist.user.model.request.CreateUserRequest;
import dev.shiperist.user.repository.UserRepository;
import io.smallrye.mutiny.Uni;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
@Path("/user")
+@RequestScoped
public class UserResource {
@Inject
UserRepository userRepository;
+ @Inject
+ UserMapper userMapper;
+
@GET
+ @Path("/create")
public Uni createUser(CreateUserRequest request) {
UserEntity.UserEntityBuilder builder = UserEntity.builder();
builder.name(request.getName());
@@ -23,6 +31,7 @@ public Uni createUser(CreateUserRequest request) {
builder.emailVerified(request.getIsEmailVerified());
builder.image(request.getImage());
- return userRepository.persist(builder.build()).map(User::new);
+ return userRepository.persist(builder.build())
+ .map(userMapper::toDomain);
}
}
diff --git a/server/src/test/java/dev/shiperist/user/resource/UserResourceTest.java b/server/src/test/java/dev/shiperist/user/resource/UserResourceTest.java
new file mode 100644
index 0000000..f1a91ca
--- /dev/null
+++ b/server/src/test/java/dev/shiperist/user/resource/UserResourceTest.java
@@ -0,0 +1,29 @@
+package dev.shiperist.user.resource;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+
+@QuarkusTest
+public class UserResourceTest {
+
+ @Test
+ void createUser() {
+ String userCreateRequest = """
+ {
+ "name": "test",
+ "email": "test@test.com",
+ "isEmailVerified": true,
+ "image": "test"
+ }
+ """;
+
+ given()
+ .when()
+ .body(userCreateRequest)
+ .post("/user/create")
+ .then()
+ .statusCode(200);
+ }
+}