Compare commits

...

21 Commits

Author SHA1 Message Date
Vincent Guillet
58a10fd4b8 Refactor Hibernate configuration to use a static local environment variable and simplify controller instantiation 2025-05-23 16:39:02 +02:00
Vincent Guillet
180e1e1622 Refactor Hibernate configuration and update data factory methods for clarity 2025-05-23 16:15:59 +02:00
Vincent Guillet
8bfc801b26 Add RestClient and DataFactory for HTTP requests and test data generation 2025-05-23 15:44:24 +02:00
Vincent Guillet
dc73603cda Refactor services and controllers to use ID for updates and standardize DAO method names 2025-05-23 14:50:27 +02:00
Vincent Guillet
c1617cbd38 Add server initialization in main application class 2025-05-23 11:26:30 +02:00
Vincent Guillet
a803a9ef22 Add dependency-reduced POM file for project configuration 2025-05-23 11:26:16 +02:00
Vincent Guillet
ed83c35f3c Add ApiApplication class to configure Jersey and register Jackson feature 2025-05-23 11:26:07 +02:00
Vincent Guillet
b63f1ef054 Add UserController class for user management endpoints 2025-05-23 11:25:56 +02:00
Vincent Guillet
8b8fae6e24 Update User class to use EAGER fetching for articles relationship 2025-05-23 11:25:44 +02:00
Vincent Guillet
adbdf0d619 Add ServerConfig class to initialize and start the server 2025-05-23 11:23:35 +02:00
Vincent Guillet
0887925477 Add Jackson JSR310 module dependency for Java 8 date/time support 2025-05-23 11:23:07 +02:00
Vincent Guillet
153380f541 update 2025-05-23 10:38:13 +02:00
Vincent Guillet
4cc46d7ac3 Add 'target/' to .gitignore to exclude build artifacts 2025-05-20 13:46:53 +02:00
Vincent Guillet
7fcdee6e2b remove target output 2025-05-20 13:46:29 +02:00
Vincent Guillet
3c330e9800 Refactor Publication class to use JOINED inheritance strategy and IDENTITY generation type 2025-05-20 13:44:51 +02:00
Vincent Guillet
47ee6f7ef1 Add Jakarta Validation API dependency and update Reflections dependency 2025-05-20 13:44:41 +02:00
Vincent Guillet
eaba56b92d Add Hibernate configuration file for database setup 2025-05-20 13:44:30 +02:00
Vincent Guillet
7f3157b7a2 Add Pair annotation for custom validation of even numbers 2025-05-20 13:44:10 +02:00
Vincent Guillet
5de8594095 Add PairValidator class for custom validation of even integers 2025-05-20 13:43:20 +02:00
Vincent Guillet
3da2712bdf Add HibernateConfig class for database configuration and refactor App to use BigDecimal for Ad prices 2025-05-20 13:43:09 +02:00
Vincent Guillet
24eab5f2cc Update Ad model to use BigDecimal for price and add email validation 2025-05-20 13:42:54 +02:00
23 changed files with 585 additions and 55 deletions

1
.gitignore vendored
View File

@@ -27,6 +27,7 @@ dist/
build/
coverage/
out/
target/
# Environment and secrets
.env

View 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>

View File

@@ -30,6 +30,13 @@
<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>
@@ -57,16 +64,73 @@
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>9.3.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<!-- JAX-RS (Jersey) -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<!-- H2 Database (pour tests, sinon MySQL/PostgreSQL) -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>runtime</scope>
</dependency>
<!-- Servlet API -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.25</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>11.0.25</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
</dependencies>

View File

@@ -1,8 +1,12 @@
package com.humanbooster;
import com.humanbooster.client.RestClient;
import com.humanbooster.config.HibernateConfig;
import com.humanbooster.config.ServerConfig;
import com.humanbooster.dao.AdDao;
import com.humanbooster.dao.ArticleDao;
import com.humanbooster.dao.UserDao;
import com.humanbooster.factory.DataFactory;
import com.humanbooster.model.Ad;
import com.humanbooster.model.Article;
import com.humanbooster.model.User;
@@ -10,51 +14,38 @@ import com.humanbooster.service.AdService;
import com.humanbooster.service.ArticleService;
import com.humanbooster.service.UserService;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import java.time.Duration;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
public class App {
public static final boolean LOCAL_ENVIRONMENT = true;
public static void main(String[] args) {
System.out.println("Démarrage de l'application");
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure()
.build();
RestClient client = new RestClient();
Metadata metadata = new MetadataSources(registry).buildMetadata();
SessionFactory sessionFactory = metadata.buildSessionFactory();
System.out.println("Connexion réussie !");
try {
ServerConfig serverConfig = new ServerConfig();
serverConfig.startServer();
} catch (Exception e) {
System.out.println("Erreur lors du démarrage du serveur : " + e.getMessage());
}
User user = new User("Bob", "bob@example.com", null);
user.setArticles(List.of(
new Article("Article 1", "Contenu de l'article 1", LocalDate.now(), user, 0),
new Article("Article 2", "Contenu de l'article 2", LocalDate.now(), user, 0)
));
Ad ad = new Ad("Ad 1", "Contenu de l'annonce 1", LocalDate.now(), LocalDate.now().plusDays(7), "contact@example.com", 12);
SessionFactory sessionFactory = new HibernateConfig().getSessionFactory();
UserService userService = new UserService(new UserDao(sessionFactory));
ArticleService articleService = new ArticleService(new ArticleDao(sessionFactory));
AdService adService = new AdService(new AdDao(sessionFactory));
DataFactory dataFactory = new DataFactory();
cleanDatabase(userService, articleService, adService);
userService.createUser(user);
articleService.findArticlesByCriteria("test", 3L, 1, 1).forEach(article -> {
System.out.println("\nArticle trouvé :" + article.toString());
}
);
adService.createAd(ad);
userService.createUser(dataFactory.createUser("Michel", "michel@test.fr"));
dataFactory.createAds().forEach(adService::createAd);
sessionFactory.close();
System.out.print("Fin du programme");

View File

@@ -0,0 +1,63 @@
package com.humanbooster.client;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class RestClient {
private final HttpClient httpClient = HttpClient.newHttpClient();
public String sendGetRequest(String url, String method, String body) {
HttpRequest.Builder builder = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json");
switch (method.toUpperCase()) {
case "GET":
builder.GET();
break;
case "POST":
builder.POST(HttpRequest.BodyPublishers.ofString(body));
break;
case "PUT":
builder.PUT(HttpRequest.BodyPublishers.ofString(body));
break;
case "DELETE":
builder.DELETE();
break;
default:
throw new IllegalArgumentException("Invalid HTTP method: " + method);
}
HttpRequest request = builder.build();
HttpResponse<String> response;
try {
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
return parseResponse(response.body());
} catch (Exception e) {
System.err.println("Error occurred while sending the request: " + e.getMessage());
}
return null;
}
private String parseResponse(String response) {
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode jsonNode = mapper.readTree(response);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
} catch (Exception e) {
System.err.println("Error occurred while parsing the response: " + e.getMessage());
}
return null;
}
}

View File

@@ -0,0 +1,48 @@
package com.humanbooster.config;
import com.humanbooster.App;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.reflections.Reflections;
import jakarta.persistence.Entity;
public class HibernateConfig {
public SessionFactory getSessionFactory() {
SessionFactory sessionFactory;
if (App.LOCAL_ENVIRONMENT) {
Configuration config = new Configuration()
.setProperty("hibernate.connection.url", "jdbc:mysql://127.0.0.1:3306/testdb")
.setProperty("hibernate.connection.username", "admin")
.setProperty("hibernate.connection.password", "admin")
.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver")
.setProperty("hibernate.hbm2ddl.auto", "update")
.setProperty("hibernate.show_sql", "false")
.setProperty("hibernate.format_sql", "true");
Reflections reflections = new Reflections("com.humanbooster.model");
for (Class<?> clazz : reflections.getTypesAnnotatedWith(Entity.class)) {
config.addAnnotatedClass(clazz);
}
return sessionFactory = config.buildSessionFactory();
} else {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure()
.build();
Metadata metadata = new MetadataSources(registry).buildMetadata();
return sessionFactory = metadata.buildSessionFactory();
}
}
}

View File

@@ -0,0 +1,37 @@
package com.humanbooster.config;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
public class ServerConfig extends ResourceConfig {
public ServerConfig() {
packages("com.humanbooster");
register(JacksonFeature.class);
}
public void startServer() throws Exception {
System.out.println("Lancement du serveur...");
ResourceConfig config = this;
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("Serveur démarré sur le port 80");
server.join();
} catch (Exception e) {
System.out.println("Echec lors du lancement du serveur: " + e.getMessage());
}
}
}

View File

@@ -0,0 +1,20 @@
package com.humanbooster.controller;
import com.humanbooster.config.HibernateConfig;
import com.humanbooster.dao.ArticleDao;
import com.humanbooster.dao.GenericDao;
import com.humanbooster.model.Article;
import jakarta.ws.rs.Path;
import org.hibernate.SessionFactory;
@Path("/articles")
public class ArticleController extends GenericControllerImpl<Article, Long> {
public ArticleController() {
this(new HibernateConfig().getSessionFactory(), new ArticleDao(new HibernateConfig().getSessionFactory()));
}
public ArticleController(SessionFactory sessionFactory, GenericDao<Article, Long> dao) {
super(sessionFactory, dao);
}
}

View File

@@ -0,0 +1,11 @@
package com.humanbooster.controller;
import java.util.List;
public interface GenericController<T, ID> {
void create(T entity);
T read(ID id);
void update(ID id);
void delete(ID id);
List<T> getAll();
}

View File

@@ -0,0 +1,55 @@
package com.humanbooster.controller;
import com.humanbooster.config.HibernateConfig;
import com.humanbooster.dao.GenericDao;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.hibernate.SessionFactory;
import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public abstract class GenericControllerImpl<T, ID> implements GenericController<T, ID>, GenericDao<T, ID> {
protected final SessionFactory sessionFactory;
private final GenericDao<T, ID> dao;
public GenericControllerImpl(SessionFactory sessionFactory, GenericDao<T, ID> dao) {
this.sessionFactory = sessionFactory;
this.dao = dao;
}
@POST
@Override
public void create(T entity) {
dao.create(entity);
}
@GET
@Path("/{id}")
@Override
public T read(@PathParam("id") ID id) {
return dao.read(id);
}
@PUT
@Path("/{id}")
@Override
public void update(@PathParam("id") ID id) {
dao.update(id);
}
@DELETE
@Path("/{id}")
@Override
public void delete(@PathParam("id") ID id) {
dao.delete(id);
}
@GET
@Override
public List<T> getAll() {
return dao.getAll();
}
}

View File

@@ -0,0 +1,23 @@
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;
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UserController extends GenericControllerImpl<User, Long> {
public UserController() {
this(new HibernateConfig().getSessionFactory(), new UserDao(new HibernateConfig().getSessionFactory()));
}
public UserController(SessionFactory sessionFactory, UserDao userDao) {
super(sessionFactory, userDao);
}
}

View File

@@ -5,7 +5,7 @@ import java.util.List;
public interface GenericDao<T, ID> {
void create(T entity);
T read(ID id);
void update(T entity);
void update(ID id);
void delete(ID id);
List<T> findAll();
List<T> getAll();
}

View File

@@ -35,9 +35,10 @@ public abstract class GenericDaoImpl<T, ID> implements GenericDao<T, ID> {
}
@Override
public void update(T entity) {
public void update(ID id) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
T entity = session.get(entityClass, id);
session.merge(entity);
session.getTransaction().commit();
}
@@ -47,14 +48,14 @@ public abstract class GenericDaoImpl<T, ID> implements GenericDao<T, ID> {
public void delete(ID id) {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
T entity = session.get(entityClass, id);
T entity = session.find(entityClass, id);
if (entity != null) session.remove(entity);
session.getTransaction().commit();
}
}
@Override
public List<T> findAll() {
public List<T> getAll() {
try (Session session = sessionFactory.openSession()) {
session.beginTransaction();
List<T> entities = session.createQuery("from " + entityClass.getName(), entityClass).list();

View File

@@ -0,0 +1,43 @@
package com.humanbooster.factory;
import com.humanbooster.model.Ad;
import com.humanbooster.model.Article;
import com.humanbooster.model.User;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
public class DataFactory {
public User createUser(String name, String email) {
User user = new User(name, email, null);
user.setArticles(List.of(
new Article("Article 1", "Contenu de l'article 1", LocalDate.now(), user, 0),
new Article("Article 2", "Contenu de l'article 2", LocalDate.now(), user, 0)
));
return user;
}
public List<Ad> createAds() {
return List.of(
(new Ad(
"Ad 1",
"Contenu de l'annonce 1",
LocalDate.now(),
LocalDate.now().plusDays(7),
"contact@example.com",
BigDecimal.valueOf(12))),
(new Ad(
"Ad 2",
"Contenu de l'annonce 2",
LocalDate.now(),
LocalDate.now().plusDays(10),
"contact@example.com",
BigDecimal.valueOf(6.7)))
);
}
}

View File

@@ -2,7 +2,9 @@ package com.humanbooster.model;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.Email;
import java.math.BigDecimal;
import java.time.LocalDate;
@Entity
@@ -12,14 +14,15 @@ public class Ad extends Publication {
private LocalDate expirationDate;
@Column(nullable = false)
@Email
private String contactEmail;
private int price;
private BigDecimal price;
public Ad() {
}
public Ad(String title, String content, LocalDate publishDate, LocalDate expirationDate, String contactEmail, int price) {
public Ad(String title, String content, LocalDate publishDate, LocalDate expirationDate, String contactEmail, BigDecimal price) {
super(title, content, publishDate);
this.expirationDate = expirationDate;
this.contactEmail = contactEmail;
@@ -42,11 +45,11 @@ public class Ad extends Publication {
this.contactEmail = contactEmail;
}
public int getPrice() {
public BigDecimal getPrice() {
return price;
}
public void setPrice(int price) {
public void setPrice(BigDecimal price) {
this.price = price;
}
}

View File

@@ -1,5 +1,6 @@
package com.humanbooster.model;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import java.time.LocalDate;
@@ -9,6 +10,7 @@ public class Article extends Publication {
@ManyToOne
@JoinColumn(name="author_id", nullable = false)
@JsonBackReference
private User author;
private int views = 0;

View File

@@ -5,12 +5,12 @@ import jakarta.persistence.*;
import java.time.LocalDate;
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn
public abstract class Publication {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 200)

View File

@@ -1,6 +1,8 @@
package com.humanbooster.model;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.List;
@@ -11,10 +13,14 @@ public class User {
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String name;
@NotNull
private String email;
@OneToMany(mappedBy="author", cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(mappedBy="author", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonManagedReference
private List<Article> articles;
public User() {}

View File

@@ -15,8 +15,8 @@ public record AdService (AdDao adDao) {
return adDao.read(id);
}
public void updateAd(Ad ad) {
adDao.update(ad);
public void updateAd(Long id) {
adDao.update(id);
}
public void deleteAd(Long id) {
@@ -24,6 +24,6 @@ public record AdService (AdDao adDao) {
}
public List<Ad> getAllAds() {
return adDao.findAll();
return adDao.getAll();
}
}

View File

@@ -15,8 +15,8 @@ public record ArticleService(ArticleDao articleDao) {
articleDao.read(id);
}
public void updateArticle(Article article) {
articleDao.update(article);
public void updateArticle(Long id) {
articleDao.update(id);
}
public void deleteArticle(Long id) {
@@ -24,7 +24,7 @@ public record ArticleService(ArticleDao articleDao) {
}
public List<Article> getAllArticles() {
return articleDao.findAll();
return articleDao.getAll();
}
public Article findArticleByAuthor(String author) {

View File

@@ -15,8 +15,8 @@ public record UserService (UserDao userDao) {
userDao.read(id);
}
public void updateUser(User user) {
userDao.update(user);
public void updateUser(Long id) {
userDao.update(id);
}
public void deleteUser(Long id) {
@@ -24,7 +24,7 @@ public record UserService (UserDao userDao) {
}
public List<User> getAllUsers() {
return userDao.findAll();
return userDao.getAll();
}
public User findUserByEmail(String email) {

View File

@@ -12,9 +12,9 @@
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">true</property>
<mapping class="com.humanbooster.model.User"/>
<mapping class="com.humanbooster.model.Article"/>
<mapping class="com.humanbooster.model.Ad"/>

View File

@@ -0,0 +1,14 @@
### GET request to example server
GET http://localhost/users
###
POST http://localhost/users/
Content-Type: application/json
{
"name": "John Doe",
"email": "john.doe@example.com"
}
###
DELETE http://localhost/articles/13