refactor code structure
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2024-08-07 00:46:27 +02:00
parent 36c9f4f188
commit c7003c1d02
8 changed files with 22 additions and 17 deletions

View File

@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<version>5.6.15.Final</version> <version>6.6.0.CR1</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -6,6 +6,8 @@ import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import wtf.beatrice.releasehive.db.HibernateManager;
import wtf.beatrice.releasehive.model.User;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package wtf.beatrice.releasehive; package wtf.beatrice.releasehive.db;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;

View File

@ -1,10 +1,8 @@
package wtf.beatrice.releasehive; package wtf.beatrice.releasehive.model;
import javax.persistence.Column; import jakarta.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@ -13,7 +11,7 @@ public class User
{ {
@Id @Id
@Column @GeneratedValue(strategy = GenerationType.UUID)
private UUID uuid; private UUID uuid;
@Column @Column

View File

@ -1,8 +1,9 @@
package wtf.beatrice.releasehive; package wtf.beatrice.releasehive.resource;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import wtf.beatrice.releasehive.util.JsonUtil;
import wtf.beatrice.releasehive.model.User;
import wtf.beatrice.releasehive.service.AccountService;
import java.util.UUID; import java.util.UUID;
@ -18,10 +19,7 @@ public class AccountResource {
produces="application/json") produces="application/json")
public String register(@RequestBody User user) public String register(@RequestBody User user)
{ {
UUID id = UUID.randomUUID();
user.setUuid(id);
accountService.registerUser(user); accountService.registerUser(user);
return JsonUtil.convertToJson(user); return JsonUtil.convertToJson(user);
} }
} }

View File

@ -1,7 +1,9 @@
package wtf.beatrice.releasehive; package wtf.beatrice.releasehive.service;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import wtf.beatrice.releasehive.db.HibernateManager;
import wtf.beatrice.releasehive.model.User;
public class AccountService public class AccountService
{ {

View File

@ -1,4 +1,4 @@
package wtf.beatrice.releasehive; package wtf.beatrice.releasehive.util;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -7,6 +7,11 @@ import org.apache.logging.log4j.Logger;
public class JsonUtil public class JsonUtil
{ {
private JsonUtil() {
throw new AssertionError("Utility class");
}
private static final Logger LOGGER = LogManager.getLogger(JsonUtil.class); private static final Logger LOGGER = LogManager.getLogger(JsonUtil.class);
private static final ObjectMapper MAPPER = new ObjectMapper(); private static final ObjectMapper MAPPER = new ObjectMapper();

View File

@ -22,7 +22,7 @@
<property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.hbm2ddl.auto">update</property>
<!-- Annotated entity classes --> <!-- Annotated entity classes -->
<mapping class="wtf.beatrice.releasehive.User"/> <mapping class="wtf.beatrice.releasehive.model.User"/>
</session-factory> </session-factory>
</hibernate-configuration> </hibernate-configuration>