Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3ad264f
initial commit forum
VitalysRDT May 29, 2024
dbb23fe
ajout des commentaires
VitalysRDT May 29, 2024
15e3c46
added post category
Genoxis12 May 29, 2024
9614db2
le forum minimal
VitalysRDT May 30, 2024
4326f83
LONGTEXT
VitalysRDT May 30, 2024
1ef13df
fix view courses
Genoxis12 May 30, 2024
f2130e8
remove definer
Genoxis12 May 30, 2024
d8bf0ab
fix view courses
Genoxis12 May 30, 2024
c99e55c
Merge pull request #4 from AlphaOrOmega/fix/view_courses
Genoxis12 May 30, 2024
ec69d4e
search knowledge
AlphaOrOmega Jun 24, 2024
cfabe6d
Merge pull request #5 from AlphaOrOmega/feat/endpoint-cours
AlphaOrOmega Jun 24, 2024
d978dcc
Plusieurs forums possibles
VitalysRDT Jun 24, 2024
ef2d3aa
Plusieurs forums possibles
VitalysRDT Jun 24, 2024
25a8049
Merge branch 'refs/heads/master' into feat/forum
VitalysRDT Jun 24, 2024
a6755af
cors
AlphaOrOmega Jun 24, 2024
6cde54d
Merge pull request #6 from AlphaOrOmega/feat/endpoint-cours
AlphaOrOmega Jun 24, 2024
d4e0370
Optimise import
VitalysRDT Jun 24, 2024
a0976a1
resolve conflicts
VitalysRDT Jun 24, 2024
5aed39d
resolve conflicts
VitalysRDT Jun 24, 2024
9f2aae4
Merge branch 'refs/heads/master' into feat/forum
VitalysRDT Jun 24, 2024
f11ac86
Merge pull request #7 from AlphaOrOmega/feat/forum
VitalysRDT Jun 25, 2024
f08f144
get course + fix db naming
AlphaOrOmega Jun 25, 2024
8f0586e
get course + fix db naming
AlphaOrOmega Jun 25, 2024
b6da122
petit commit (révisions)
AlphaOrOmega Jun 26, 2024
73a754f
Merge remote-tracking branch 'origin/feat/endpoint-cours' into feat/e…
AlphaOrOmega Jun 27, 2024
eeab2f2
Merge pull request #8 from AlphaOrOmega/feat/endpoint-cours
AlphaOrOmega Jun 27, 2024
b40c654
added post category
Genoxis12 May 29, 2024
ffa7781
added post category
Genoxis12 May 29, 2024
15d02dc
Merge remote-tracking branch 'origin/fix/add_categories_post' into fi…
AlphaOrOmega Jun 27, 2024
e3a0d21
partial triggers
AlphaOrOmega Jun 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<database.password>secret</database.password>
</properties>
<dependencies>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
Expand Down Expand Up @@ -67,6 +72,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootApplication
public class KnowledgeCentreBackendApplication {

public static void main(String[] args) {
SpringApplication.run(KnowledgeCentreBackendApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(KnowledgeCentreBackendApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Optional;

@NoRepositoryBean
public interface ReadOnlyRepository <T, ID> extends Repository<T, ID> {
public interface ReadOnlyRepository<T, ID> extends Repository<T, ID> {

List<T> findAll();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.autol.knowledgecentrebackend.comment;

import jakarta.persistence.*;
import lombok.Data;
import org.autol.knowledgecentrebackend.post.Post;


@Data
@Entity
public class Comment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String content;

@ManyToOne
@JoinColumn(name = "post_id")
private Post post;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.autol.knowledgecentrebackend.comment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/posts/{postId}/comments")
public class CommentController {

@Autowired
private CommentService commentService;

@GetMapping
public List<Comment> getAllCommentsByPostId(@PathVariable Long postId) {
return commentService.getAllCommentsByPostId(postId);
}

@PostMapping
public Comment createComment(@PathVariable Long postId, @RequestBody Comment comment) {
return commentService.saveComment(postId, comment);
}

@DeleteMapping("/{commentId}")
public void deleteComment(@PathVariable Long commentId) {
commentService.deleteComment(commentId);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.autol.knowledgecentrebackend.comment;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findByPostId(Long postId);
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.autol.knowledgecentrebackend.comment;

import org.autol.knowledgecentrebackend.post.Post;
import org.autol.knowledgecentrebackend.post.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CommentService {

@Autowired
private CommentRepository commentRepository;

@Autowired
private PostRepository postRepository;

@Transactional(readOnly = true)
public List<Comment> getAllCommentsByPostId(Long postId) {
return commentRepository.findByPostId(postId);
}

@Transactional
public Comment saveComment(Long postId, Comment comment) {
Post post = postRepository.findById(postId)
.orElseThrow(() -> new IllegalArgumentException("Post not found"));
comment.setPost(post);
return commentRepository.save(comment);
}

@Transactional
public void deleteComment(Long commentId) {
commentRepository.deleteById(commentId);
}
}


Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.autol.knowledgecentrebackend.config;

import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("org.autol.knowledgecentrebackend")
public class ApplicationConfig {
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.autol.knowledgecentrebackend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
}
37 changes: 37 additions & 0 deletions src/main/java/org/autol/knowledgecentrebackend/cours/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.autol.knowledgecentrebackend.cours;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "course_view")
@Data
@NoArgsConstructor
public class Course {

@Id
@Column(name = "id")
private Long id;

@Column(name = "description")
private String description;

@Column(name = "title")
private String title;

@Column(name = "courses")
private String courses;

@Column(name = "pages")
private String pages;

public Course(String titre, String description) {
this.description = description;
this.title = titre;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.autol.knowledgecentrebackend.cours;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value="/course")
public class CourseController {

private final CourseService courseService;

@Autowired
public CourseController(CourseService courseService) {
this.courseService = courseService;
}

@GetMapping("/details/{pageId}")
public Course getDetails(@PathVariable(value="pageId") Long pageId) {
return courseService.getPageDetails(pageId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.autol.knowledgecentrebackend.cours;

import org.autol.knowledgecentrebackend.ReadOnlyRepository;


public interface CourseRepository extends ReadOnlyRepository<Course, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.autol.knowledgecentrebackend.cours;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseService {

private final CourseRepository courseRepository;

@Autowired
public CourseService(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}

public Course getPageDetails(Long pageId) {
return courseRepository.findById(pageId).orElseThrow();
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/autol/knowledgecentrebackend/forum/Forum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.autol.knowledgecentrebackend.forum;


import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import org.autol.knowledgecentrebackend.post.Post;

import java.util.List;

@Entity
@Data
public class Forum {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;

@OneToMany(mappedBy = "forum", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonIgnore
private List<Post> posts;


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.autol.knowledgecentrebackend.forum;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/forums")
public class ForumController {

@Autowired
private ForumService forumService;

@GetMapping
public List<Forum> getAllForums() {
return forumService.getAllForums();
}

@GetMapping("/{id}")
public Forum getOrCreateForum(@PathVariable Long id) {
return forumService.getOrCreateForum(id);
}

@DeleteMapping("/{id}")
public void deleteForum(@PathVariable Long id) {
forumService.deleteForum(id);
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.autol.knowledgecentrebackend.forum;

import org.springframework.data.jpa.repository.JpaRepository;

public interface ForumRepository extends JpaRepository<Forum, Long> {
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.autol.knowledgecentrebackend.forum;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ForumService {

@Autowired
private ForumRepository forumRepository;

public List<Forum> getAllForums() {
return forumRepository.findAll();
}

public Forum getOrCreateForum(Long id) {
return forumRepository.findById(id).orElseGet(() -> {
Forum forum = new Forum();
forum.setId(id);
forum.setName("Forum " + id); // You can set a default name or use any logic here
return forumRepository.save(forum);
});
}

public void deleteForum(Long id) {
forumRepository.deleteById(id);
}
}


Loading