Skip to content

Commit

Permalink
feature(backend): Reorganize entities and separate user-related opera…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
zZHorizonZz committed Jul 16, 2023
1 parent 25ea707 commit c5fc075
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 24 deletions.
31 changes: 31 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
Expand All @@ -53,6 +65,12 @@
<artifactId>quarkus-minio</artifactId>
<version>3.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down Expand Up @@ -88,6 +106,19 @@
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<!-- Your existing annotation processor(s)... -->
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-common</artifactId>
<version>${quarkus.platform.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
4 changes: 0 additions & 4 deletions server/src/main/java/dev/shiperist/entity/AccountEntity.java

This file was deleted.

4 changes: 0 additions & 4 deletions server/src/main/java/dev/shiperist/entity/AppEntity.java

This file was deleted.

4 changes: 0 additions & 4 deletions server/src/main/java/dev/shiperist/entity/SessionEntity.java

This file was deleted.

4 changes: 0 additions & 4 deletions server/src/main/java/dev/shiperist/entity/UserEntity.java

This file was deleted.

This file was deleted.

This file was deleted.

56 changes: 56 additions & 0 deletions server/src/main/java/dev/shiperist/user/entity/AccountEntity.java
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 server/src/main/java/dev/shiperist/user/entity/SessionEntity.java
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 server/src/main/java/dev/shiperist/user/entity/UserEntity.java
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() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.shiperist.user.mapper;

public interface AccountMapper {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.shiperist.user.mapper;

public interface SessionMapper {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.shiperist.user.mapper;

public interface UserMapper {
}
4 changes: 4 additions & 0 deletions server/src/main/java/dev/shiperist/user/model/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dev.shiperist.user.model;

public class User {
}
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;
}
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> {
}
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> {
}
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 server/src/main/java/dev/shiperist/user/resource/UserResource.java
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);
}
}

0 comments on commit c5fc075

Please sign in to comment.