-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(backend): Reorganize entities and separate user-related opera…
…tions
- Loading branch information
1 parent
25ea707
commit c5fc075
Showing
19 changed files
with
236 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
server/src/main/java/dev/shiperist/entity/VerificationTokenEntity.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
server/src/main/java/dev/shiperist/repository/SessionRepository.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
server/src/main/java/dev/shiperist/user/entity/AccountEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dev.shiperist.user.entity; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheEntity; | ||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@Entity | ||
@Table(name = "account") | ||
public class AccountEntity extends PanacheEntity { | ||
|
||
@Column(name = "user_id") | ||
private String userId; | ||
|
||
@Column(name = "type") | ||
private String type; | ||
|
||
@Column(name = "provider") | ||
private String provider; | ||
|
||
@Column(name = "provider_account_id") | ||
private String providerAccountId; | ||
|
||
@Column(name = "refresh_token") | ||
private String refreshToken; | ||
|
||
@Column(name = "refresh_token_expires_in") | ||
private Integer refreshTokenExpiresIn; | ||
|
||
@Column(name = "access_token") | ||
private String accessToken; | ||
|
||
@Column(name = "expires_at") | ||
private Integer expiresAt; | ||
|
||
@Column(name = "token_type") | ||
private String tokenType; | ||
|
||
@Column(name = "scope") | ||
private String scope; | ||
|
||
@Column(name = "id_token") | ||
private String idToken; | ||
|
||
@Column(name = "session_state") | ||
private String sessionState; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", insertable = false, updatable = false) | ||
private UserEntity user; | ||
|
||
public AccountEntity() { | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
server/src/main/java/dev/shiperist/user/entity/SessionEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.shiperist.user.entity; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheEntity; | ||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
@Entity | ||
@Table(name = "session") | ||
public class SessionEntity extends PanacheEntity { | ||
|
||
@Column(name = "session_token", unique = true) | ||
private String sessionToken; | ||
|
||
@Column(name = "user_id") | ||
private String userId; | ||
|
||
@Column(name = "expires") | ||
private LocalDateTime expires; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", insertable = false, updatable = false) | ||
private UserEntity user; | ||
|
||
public SessionEntity() { | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
server/src/main/java/dev/shiperist/user/entity/UserEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.shiperist.user.entity; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Set; | ||
|
||
@Getter | ||
@Builder | ||
@Entity | ||
@Table(name = "user") | ||
public class UserEntity extends PanacheEntity { | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
@Column(name = "email", unique = true) | ||
private String email; | ||
|
||
@Column(name = "email_verified") | ||
private LocalDateTime emailVerified; | ||
|
||
@Column(name = "image") | ||
private String image; | ||
|
||
@OneToMany(mappedBy = "user") | ||
private Set<AccountEntity> accounts; | ||
|
||
@OneToMany(mappedBy = "user") | ||
private Set<SessionEntity> sessions; | ||
|
||
public UserEntity() { | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/dev/shiperist/user/mapper/AccountMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.shiperist.user.mapper; | ||
|
||
public interface AccountMapper { | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/dev/shiperist/user/mapper/SessionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.shiperist.user.mapper; | ||
|
||
public interface SessionMapper { | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/dev/shiperist/user/mapper/UserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.shiperist.user.mapper; | ||
|
||
public interface UserMapper { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.shiperist.user.model; | ||
|
||
public class User { | ||
} |
13 changes: 13 additions & 0 deletions
13
server/src/main/java/dev/shiperist/user/model/request/CreateUserRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.shiperist.user.model.request; | ||
|
||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class CreateUserRequest { | ||
private String name; | ||
private String email; | ||
private LocalDateTime isEmailVerified; | ||
private String image; | ||
} |
7 changes: 7 additions & 0 deletions
7
server/src/main/java/dev/shiperist/user/repository/AccountRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.shiperist.user.repository; | ||
|
||
import dev.shiperist.user.entity.AccountEntity; | ||
import io.quarkus.hibernate.reactive.panache.PanacheRepository; | ||
|
||
public class AccountRepository implements PanacheRepository<AccountEntity> { | ||
} |
7 changes: 7 additions & 0 deletions
7
server/src/main/java/dev/shiperist/user/repository/SessionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.shiperist.user.repository; | ||
|
||
import dev.shiperist.user.entity.SessionEntity; | ||
import io.quarkus.hibernate.reactive.panache.PanacheRepository; | ||
|
||
public class SessionRepository implements PanacheRepository<SessionEntity> { | ||
} |
7 changes: 7 additions & 0 deletions
7
server/src/main/java/dev/shiperist/user/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.shiperist.user.repository; | ||
|
||
import dev.shiperist.user.entity.UserEntity; | ||
import io.quarkus.hibernate.reactive.panache.PanacheRepository; | ||
|
||
public class UserRepository implements PanacheRepository<UserEntity> { | ||
} |
28 changes: 28 additions & 0 deletions
28
server/src/main/java/dev/shiperist/user/resource/UserResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.shiperist.user.resource; | ||
|
||
import dev.shiperist.user.entity.UserEntity; | ||
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.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
@Path("/user") | ||
public class UserResource { | ||
|
||
@Inject | ||
UserRepository userRepository; | ||
|
||
@GET | ||
public Uni<User> createUser(CreateUserRequest request) { | ||
UserEntity.UserEntityBuilder builder = UserEntity.builder(); | ||
builder.name(request.getName()); | ||
builder.email(request.getEmail()); | ||
builder.emailVerified(request.getIsEmailVerified()); | ||
builder.image(request.getImage()); | ||
|
||
return userRepository.persist(builder.build()).map(User::new); | ||
} | ||
} |