diff --git a/BE/src/main/java/org/example/controllers/CategoryController.java b/BE/src/main/java/org/example/controllers/CategoryController.java new file mode 100644 index 0000000..28157f9 --- /dev/null +++ b/BE/src/main/java/org/example/controllers/CategoryController.java @@ -0,0 +1,25 @@ +package org.example.controllers; + + +import org.example.models.Category; +import org.example.services.CategoryService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/category") +public class CategoryController { + private final CategoryService categoryService; + + public CategoryController(CategoryService categoryService) { + this.categoryService = categoryService; + } + + @GetMapping("/getAllCategories") + public List getAllCategories(){ + return categoryService.getAllCategories(); + } +} diff --git a/BE/src/main/java/org/example/controllers/PostController.java b/BE/src/main/java/org/example/controllers/PostController.java index ac85610..2796dcf 100644 --- a/BE/src/main/java/org/example/controllers/PostController.java +++ b/BE/src/main/java/org/example/controllers/PostController.java @@ -1,15 +1,15 @@ package org.example.controllers; //import org.example.models.Author; -import org.example.models.Image; -import org.example.models.LikeRequest; -import org.example.models.Post; -import org.example.models.User; +import org.example.models.*; import org.example.objects.PostDTO; +import org.example.objects.PostWithMedia; +import org.example.repositories.CategoryRepository; import org.example.repositories.PostRepository; import org.example.services.PostService; import org.example.services.RecommendationService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.repository.query.Param; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -25,12 +25,14 @@ public class PostController { private final PostService postService; private final PostRepository postRepository; private final RecommendationService recommendationService; + private final CategoryRepository categoryRepository; @Autowired - public PostController(PostService postService, PostRepository postRepository, RecommendationService recommendationService) { + public PostController(PostService postService, PostRepository postRepository, RecommendationService recommendationService, CategoryRepository categoryRepository) { this.postService = postService; this.postRepository = postRepository; this.recommendationService = recommendationService; + this.categoryRepository = categoryRepository; } @GetMapping("/getAllPosts") @@ -45,17 +47,18 @@ public class PostController { @PostMapping("/edit/{id}") public Post updatePost(@PathVariable Long id,@RequestBody PostDTO postDTO) throws IOException { - return postService.editPost(id, postDTO.getTitle(), postDTO.getContent(), postDTO.getImageFile(), postDTO.getVideoFile()); + return postService.editPost(id, postDTO.getTitle(), postDTO.getContent(),postDTO.getCategory(), postDTO.getImageFile(), postDTO.getVideoFile()); } @PostMapping public Post createPost( @RequestParam("title") String title, @RequestParam("content") String content, + @RequestParam("category") Category category, @RequestParam(value = "imageFile", required = false) MultipartFile imageFile, @RequestParam(value = "videoFile", required = false) MultipartFile videoFile) throws IOException { - return postService.createPost(title, content, imageFile, videoFile); + return postService.createPost(title, content,category, imageFile, videoFile); } @GetMapping("/recommend/{username}") diff --git a/BE/src/main/java/org/example/controllers/UserController.java b/BE/src/main/java/org/example/controllers/UserController.java index 4044a11..64151ae 100644 --- a/BE/src/main/java/org/example/controllers/UserController.java +++ b/BE/src/main/java/org/example/controllers/UserController.java @@ -1,6 +1,7 @@ package org.example.controllers; import org.example.models.User; +import org.example.objects.FriendDTO; import org.example.objects.UserDTO; import org.example.repositories.UserRepository; import org.example.requests.CreateUserRequest; @@ -36,4 +37,10 @@ public class UserController { return new ResponseEntity<>(responseUser, HttpStatus.CREATED); } + @PostMapping("/addFriend") + public ResponseEntity addFriend(@RequestBody FriendDTO friendDTO){ + userService.addFriend(friendDTO.getUsername1(),friendDTO.getUsername2()); + System.out.println(friendDTO.getUsername1()); + return new ResponseEntity<>("Friend added", HttpStatus.CREATED); + } } diff --git a/BE/src/main/java/org/example/models/Category.java b/BE/src/main/java/org/example/models/Category.java index 5a6bbf9..1a3e721 100644 --- a/BE/src/main/java/org/example/models/Category.java +++ b/BE/src/main/java/org/example/models/Category.java @@ -7,6 +7,8 @@ import org.springframework.data.neo4j.core.schema.Relationship; import java.util.List; + + @Node public class Category { @Id @@ -14,9 +16,6 @@ public class Category { private Long id; private String name; - @Relationship(type = "HAS_POST") - private List posts; - public Long getId() { return id; } @@ -32,12 +31,4 @@ public class Category { public void setName(String name) { this.name = name; } - - public List getPosts() { - return posts; - } - - public void setPosts(List posts) { - this.posts = posts; - } } diff --git a/BE/src/main/java/org/example/models/Post.java b/BE/src/main/java/org/example/models/Post.java index 92904dc..5ce5ec6 100644 --- a/BE/src/main/java/org/example/models/Post.java +++ b/BE/src/main/java/org/example/models/Post.java @@ -27,39 +27,17 @@ public class Post { private String author; private String imgUrl; private int interactions; - @Relationship(type = "HAS_LIKE", direction = Relationship.Direction.INCOMING) - private List likedByUsers; - - @Relationship(type = "HAS_COMMENT", direction = Relationship.Direction.INCOMING) - private List comments; - - @Relationship(type = "HAS_SHARE", direction = Relationship.Direction.INCOMING) - private List sharedByUsers; - @Relationship(type = "HAS_POST", direction = Relationship.Direction.INCOMING) + @Relationship(type="HAS_CATEGORY", direction = Relationship.Direction.OUTGOING) private Category category; - - public List getLikedByUsers() { - return likedByUsers; - } - - public void setLikedByUsers(List likedByUsers) { - this.likedByUsers = likedByUsers; - } - - public void setComments(List comments) { - this.comments = comments; - } - - public List getSharedByUsers() { - return sharedByUsers; + public Category getCategory() { + return category; } - public void setSharedByUsers(List sharedByUsers) { - this.sharedByUsers = sharedByUsers; + public void setCategory(Category category) { + this.category = category; } - public int getInteractions() { return interactions; } @@ -68,22 +46,13 @@ public class Post { this.interactions = interactions; } - public Category getCategory() { - return category; - } - - public void setCategory(Category category) { - this.category = category; - } - - public String getImgUrl() { return imgUrl; } public void setImgUrl(String imgUrl) { - this.imgUrl = imgUrl; + this.imgUrl=imgUrl; } public String getAuthor() { diff --git a/BE/src/main/java/org/example/objects/FriendDTO.java b/BE/src/main/java/org/example/objects/FriendDTO.java new file mode 100644 index 0000000..ea4c8a9 --- /dev/null +++ b/BE/src/main/java/org/example/objects/FriendDTO.java @@ -0,0 +1,21 @@ +package org.example.objects; + +public class FriendDTO { + private String username1,username2; + + public String getUsername1() { + return username1; + } + + public void setUsername1(String username1) { + this.username1 = username1; + } + + public String getUsername2() { + return username2; + } + + public void setUsername2(String username2) { + this.username2 = username2; + } +} diff --git a/BE/src/main/java/org/example/objects/PostDTO.java b/BE/src/main/java/org/example/objects/PostDTO.java index 00e5e52..e728232 100644 --- a/BE/src/main/java/org/example/objects/PostDTO.java +++ b/BE/src/main/java/org/example/objects/PostDTO.java @@ -1,10 +1,22 @@ package org.example.objects; +import org.example.models.Category; import org.springframework.web.multipart.MultipartFile; public class PostDTO { String title,content; - MultipartFile imageFile,videoFile; + Category category; + MultipartFile imageFile; + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + + MultipartFile videoFile; public String getTitle() { return title; diff --git a/BE/src/main/java/org/example/objects/PostWithMedia.java b/BE/src/main/java/org/example/objects/PostWithMedia.java new file mode 100644 index 0000000..c2980da --- /dev/null +++ b/BE/src/main/java/org/example/objects/PostWithMedia.java @@ -0,0 +1,39 @@ +package org.example.objects; + +import org.example.models.Image; +import org.example.models.Post; +import org.example.models.Video; +import org.springframework.data.neo4j.core.schema.Node; +import java.util.List; + +public class PostWithMedia { + private Post post; + private List images; + private List