first commit with existing project files
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
FROM maven:3.9.6-eclipse-temurin-17 AS build
|
||||
FROM maven:3.9.6-eclipse-temurin-21 AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY pom.xml .
|
||||
|
||||
RUN mvn dependency:go-offline -B
|
||||
COPY src ./src
|
||||
RUN mvn package -DskipTests
|
||||
|
||||
FROM eclipse-temurin:17-jre-alpine
|
||||
RUN mvn clean package -DskipTests
|
||||
|
||||
|
||||
FROM eclipse-temurin:21-jre-alpine
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/target/hibernate-projet-1.0-SNAPSHOT.jar app.jar
|
||||
ENTRYPOINT [ "java", "-jar", "app.jar" ]
|
||||
|
||||
# java -jar app.jar
|
||||
COPY --from=build /app/target/hibernate-project-1.0-SNAPSHOT.jar app.jar
|
||||
|
||||
ENTRYPOINT [ "java", "-jar", "app.jar" ]
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>com.exemple.App</mainClass>
|
||||
<mainClass>com.humanbooster.App</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
@@ -122,7 +122,7 @@
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>com.exemple.App</mainClass>
|
||||
<mainClass>com.humanbooster.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
||||
@@ -24,9 +24,11 @@ public class App {
|
||||
SessionFactory sessionFactory = metadata.buildSessionFactory();
|
||||
System.out.println("Connexion réussie !");
|
||||
|
||||
User user = new User("Bob", "bob@example.com", List.of(
|
||||
new Article("Article 1", "Contenu de l'article 1", null),
|
||||
new Article("Article 2", "Contenu de l'article 2", null)
|
||||
User user = new User("Bob", "bob@example.com", null);
|
||||
|
||||
user.setArticles(List.of(
|
||||
new Article("Article 1", "Contenu de l'article 1", user),
|
||||
new Article("Article 2", "Contenu de l'article 2", user)
|
||||
));
|
||||
|
||||
UserService userService = new UserService(new UserDao(sessionFactory));
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.humanbooster.model.Article;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
public class ArticleDto extends GenericDaoImpl<Article,Long> {
|
||||
public class ArticleDao extends GenericDaoImpl<Article,Long> {
|
||||
|
||||
public ArticleDto(SessionFactory sessionFactory, Class<Article> entityClass) {
|
||||
super(sessionFactory, entityClass);
|
||||
public ArticleDao(SessionFactory sessionFactory) {
|
||||
super(sessionFactory, Article.class);
|
||||
}
|
||||
|
||||
public Article findByAuthor(String author) {
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
public abstract class GenericDaoImpl<T, ID> implements GenericDao<T, ID> {
|
||||
|
||||
private final Class<T> entityClass;
|
||||
protected final Class<T> entityClass;
|
||||
protected SessionFactory sessionFactory;
|
||||
|
||||
public GenericDaoImpl(SessionFactory sessionFactory, Class<T> entityClass) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.hibernate.SessionFactory;
|
||||
public class UserDao extends GenericDaoImpl<User,Long> {
|
||||
|
||||
public UserDao(SessionFactory sessionFactory) {
|
||||
super(sessionFactory, entityClass);
|
||||
super(sessionFactory, User.class);
|
||||
}
|
||||
|
||||
public User findByEmail(String email) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.humanbooster.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Entity
|
||||
public class Article {
|
||||
@@ -19,7 +20,9 @@ public class Article {
|
||||
@JoinColumn(name="author_id", nullable=false)
|
||||
private User author;
|
||||
|
||||
public Article (String titre, String content, User author){
|
||||
public Article() {}
|
||||
|
||||
public Article (String title, String content, User author){
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.author = author;
|
||||
|
||||
@@ -17,6 +17,8 @@ public class User {
|
||||
@OneToMany(mappedBy="author", cascade= CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private List<Article> articles;
|
||||
|
||||
public User() {}
|
||||
|
||||
public User(String name, String email, List<Article> articles) {
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
package com.humanbooster.service;
|
||||
|
||||
import com.humanbooster.dao.ArticleDto;
|
||||
import com.humanbooster.dao.ArticleDao;
|
||||
import com.humanbooster.model.Article;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ArticleService {
|
||||
|
||||
public final ArticleDto articleDto;
|
||||
public final ArticleDao articleDao;
|
||||
|
||||
public ArticleService(ArticleDto articleDto) {
|
||||
this.articleDto = articleDto;
|
||||
public ArticleService(ArticleDao articleDao) {
|
||||
this.articleDao = articleDao;
|
||||
}
|
||||
|
||||
public void createArticle(Article article) {
|
||||
articleDto.create(article);
|
||||
articleDao.create(article);
|
||||
}
|
||||
|
||||
public void getArticleById(Long id) {
|
||||
articleDto.read(id);
|
||||
articleDao.read(id);
|
||||
}
|
||||
|
||||
public void updateArticle(Article article) {
|
||||
articleDto.update(article);
|
||||
articleDao.update(article);
|
||||
}
|
||||
|
||||
public void deleteArticle(Long id) {
|
||||
articleDto.delete(id);
|
||||
articleDao.delete(id);
|
||||
}
|
||||
|
||||
public List<Article> getAllArticles() {
|
||||
return articleDto.findAll();
|
||||
return articleDao.findAll();
|
||||
}
|
||||
|
||||
public Article findArticleByAuthor(String author) {
|
||||
return articleDto.findByAuthor(author);
|
||||
return articleDao.findByAuthor(author);
|
||||
}
|
||||
|
||||
public Article findArticleByTitle(String title) {
|
||||
return articleDto.findByTitle(title);
|
||||
return articleDao.findByTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user