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

This commit is contained in:
Bea 2024-08-07 10:21:35 +02:00
parent f142912471
commit b88a9f75bf
4 changed files with 16 additions and 9 deletions

@ -9,6 +9,7 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<dependencies> <dependencies>
<!-- Logging Dependencies -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
@ -19,6 +20,8 @@
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.23.1</version> <version>2.23.1</version>
</dependency> </dependency>
<!-- Web Dependencies -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
@ -30,12 +33,12 @@
<version>3.3.2</version> <version>3.3.2</version>
</dependency> </dependency>
<!-- Database Dependencies -->
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<version>6.6.0.CR1</version> <version>6.6.0.CR1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>

@ -18,22 +18,25 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
LOGGER.info("Hello world!"); LOGGER.info("Hello world!");
LOGGER.info("Registering shutdown hooks");
Runtime.getRuntime().addShutdownHook(shutdownHook); Runtime.getRuntime().addShutdownHook(shutdownHook);
LOGGER.info("Initializing database backend");
HibernateManager.initialize();
LOGGER.info("Initializing Spring Boot"); LOGGER.info("Initializing Spring Boot");
SpringApplication.run(Main.class, args); SpringApplication.run(Main.class, args);
LOGGER.info("Spring Boot initialized!");
HibernateManager.initialize(); LOGGER.info("Spring Boot & DB initialized!");
Session session = HibernateManager.getSession(); Session session = HibernateManager.getSession();
Transaction transaction = session.beginTransaction(); Transaction transaction = session.beginTransaction();
List<User> users = session.createQuery("FROM User", User.class).getResultList(); List<User> users = session.createQuery("FROM User", User.class).getResultList();
for (User user : users) {
LOGGER.info("ID: {}, Name: {}", user.getUuid(), user.getUsername());
}
transaction.commit(); transaction.commit();
users.forEach(user -> LOGGER.info("ID: {}, Name: {}", user.getUuid(), user.getUsername()));
} }
private static final Thread shutdownHook = new Thread(() -> { private static final Thread shutdownHook = new Thread(() -> {

@ -1,8 +1,10 @@
package wtf.beatrice.releasehive.resource; package wtf.beatrice.releasehive.resource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import wtf.beatrice.releasehive.util.JsonUtil; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wtf.beatrice.releasehive.model.User; import wtf.beatrice.releasehive.model.User;
import wtf.beatrice.releasehive.service.AccountService; import wtf.beatrice.releasehive.service.AccountService;

@ -17,7 +17,6 @@ public class AccountServiceImpl implements AccountService {
return JsonUtil.spawnJsonError("Cannot register user without username"); return JsonUtil.spawnJsonError("Cannot register user without username");
} }
if(null == user.getPassword() || user.getPassword().isEmpty()) { if(null == user.getPassword() || user.getPassword().isEmpty()) {
return JsonUtil.spawnJsonError("Cannot register user without password"); return JsonUtil.spawnJsonError("Cannot register user without password");
} }