Compare commits
7 Commits
153380f541
...
c1617cbd38
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1617cbd38 | ||
|
|
a803a9ef22 | ||
|
|
ed83c35f3c | ||
|
|
b63f1ef054 | ||
|
|
8b8fae6e24 | ||
|
|
adbdf0d619 | ||
|
|
0887925477 |
148
hibernate-project/dependency-reduced-pom.xml
Normal file
148
hibernate-project/dependency-reduced-pom.xml
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.humanbooster</groupId>
|
||||||
|
<artifactId>hibernate-project</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<mainClass>com.humanbooster.App</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.12.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer>
|
||||||
|
<mainClass>com.humanbooster.App</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>opentest4j</artifactId>
|
||||||
|
<groupId>org.opentest4j</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>junit-platform-commons</artifactId>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>apiguardian-api</artifactId>
|
||||||
|
<groupId>org.apiguardian</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>apiguardian-api</artifactId>
|
||||||
|
<groupId>org.apiguardian</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.servlet</groupId>
|
||||||
|
<artifactId>jakarta.servlet-api</artifactId>
|
||||||
|
<version>6.0.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-platform</artifactId>
|
||||||
|
<version>6.6.13.Final</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey</groupId>
|
||||||
|
<artifactId>jersey-bom</artifactId>
|
||||||
|
<version>3.1.5</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
@@ -128,6 +128,11 @@
|
|||||||
<artifactId>jetty-servlet</artifactId>
|
<artifactId>jetty-servlet</artifactId>
|
||||||
<version>11.0.25</version>
|
<version>11.0.25</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>2.17.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<artifactId>jersey-container-servlet</artifactId>
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.humanbooster;
|
package com.humanbooster;
|
||||||
|
|
||||||
import com.humanbooster.config.HibernateConfig;
|
import com.humanbooster.config.HibernateConfig;
|
||||||
|
import com.humanbooster.config.ServerConfig;
|
||||||
import com.humanbooster.dao.AdDao;
|
import com.humanbooster.dao.AdDao;
|
||||||
import com.humanbooster.dao.ArticleDao;
|
import com.humanbooster.dao.ArticleDao;
|
||||||
import com.humanbooster.dao.UserDao;
|
import com.humanbooster.dao.UserDao;
|
||||||
@@ -17,15 +18,20 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
|
|||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Démarrage de l'application");
|
System.out.println("Démarrage de l'application");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ServerConfig serverConfig = new ServerConfig();
|
||||||
|
serverConfig.startServer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Erreur lors du démarrage du serveur : " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
SessionFactory sessionFactory;
|
SessionFactory sessionFactory;
|
||||||
|
|
||||||
if (HibernateConfig.isLocalEnvironment()) sessionFactory = HibernateConfig.getSessionFactory();
|
if (HibernateConfig.isLocalEnvironment()) sessionFactory = HibernateConfig.getSessionFactory();
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.humanbooster.api;
|
||||||
|
|
||||||
|
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||||
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
|
||||||
|
public class ApiApplication extends ResourceConfig {
|
||||||
|
public ApiApplication() {
|
||||||
|
packages("com.humanbooster");
|
||||||
|
register(JacksonFeature.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.humanbooster.config;
|
||||||
|
|
||||||
|
import com.humanbooster.api.ApiApplication;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
import org.glassfish.jersey.servlet.ServletContainer;
|
||||||
|
|
||||||
|
public class ServerConfig {
|
||||||
|
|
||||||
|
public void startServer() throws Exception {
|
||||||
|
System.out.println("Starting server...");
|
||||||
|
|
||||||
|
ResourceConfig config = new ApiApplication();
|
||||||
|
|
||||||
|
ServletHolder servlet = new ServletHolder(new ServletContainer(config));
|
||||||
|
Server server = new Server(80);
|
||||||
|
|
||||||
|
ServletContextHandler context = new ServletContextHandler(server, "/");
|
||||||
|
context.setServer(server);
|
||||||
|
context.addServlet(servlet, "/*");
|
||||||
|
|
||||||
|
try {
|
||||||
|
server.start();
|
||||||
|
System.out.println("Server started on port 80");
|
||||||
|
server.join();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Failed to start server: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.humanbooster.controller;
|
||||||
|
|
||||||
|
import com.humanbooster.config.HibernateConfig;
|
||||||
|
import com.humanbooster.dao.UserDao;
|
||||||
|
import com.humanbooster.model.User;
|
||||||
|
import jakarta.ws.rs.*;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Path("/users")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
SessionFactory sessionFactory = HibernateConfig.getSessionFactory();
|
||||||
|
|
||||||
|
private final UserDao dao = new UserDao(sessionFactory);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public List<User> getAll() {
|
||||||
|
return dao.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{id}")
|
||||||
|
public User getById(@PathParam("id") Long id) {
|
||||||
|
return dao.read(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public void create(User person) {
|
||||||
|
dao.create(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/{id}")
|
||||||
|
public void update(@PathParam("id") Long id, User user) {
|
||||||
|
user.setId(id);
|
||||||
|
dao.update(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/{id}")
|
||||||
|
public void delete(@PathParam("id") Long id) {
|
||||||
|
System.out.println();
|
||||||
|
dao.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ public class User {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@OneToMany(mappedBy="author", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy="author", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||||
private List<Article> articles;
|
private List<Article> articles;
|
||||||
|
|
||||||
public User() {}
|
public User() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user