Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/posts #19

Open
wants to merge 42 commits into
base: temp/main1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6438955
added frontend
ovindumandith Apr 29, 2024
1d74fe4
added ReplyModel for frontend
ovindumandith Apr 29, 2024
911570d
made changes to replymodel
ovindumandith Apr 29, 2024
8921b63
changes to frontend
ovindumandith Apr 29, 2024
20c6f4f
made changes to frontend
ovindumandith Apr 30, 2024
3338728
changes made to frontend of posts
ovindumandith Apr 30, 2024
72d0883
made xhanges to frontend
ovindumandith May 1, 2024
047e32e
frontend changes to user profile
ovindumandith May 1, 2024
dad8ca8
added DTO for comments and posts
ovindumandith May 1, 2024
4dd2d53
frontend changes made
ovindumandith May 1, 2024
0282712
added post shre class
ovindumandith May 2, 2024
86134b9
added post shre DTO class
ovindumandith May 2, 2024
7ed3e28
few refinements
ovindumandith May 2, 2024
fe246e2
frontend changes for posts
ovindumandith May 3, 2024
ae70466
Frontend link changes
ovindumandith May 3, 2024
f01a84f
Update README.md
IT21063596 May 7, 2024
5ff8efc
updated backend for posts,like and comments
ovindumandith May 7, 2024
a9545ec
updated backend for posts,like and comments with redux
ovindumandith May 7, 2024
f79e840
updated backend for posts,like and comments with redux and axios
ovindumandith May 8, 2024
b26615b
updated backend for posts,like and comments with redux and clodinary
ovindumandith May 8, 2024
f047549
Merge branch 'feature/posts' of https://github.com/PAF-IT3030/paf-ass…
ovindumandith May 8, 2024
c3f52aa
updated backend for edit posts
ovindumandith May 8, 2024
bffaed4
updated backend for edit posts and adding comments
ovindumandith May 9, 2024
a66c4e1
updated backend for post to pass the image URL to the DB
ovindumandith May 10, 2024
275baa7
updated frontend to send the image to S3 bucket
ovindumandith May 10, 2024
7aea21c
updated frontend to send the image to S3 bucket through .env
ovindumandith May 10, 2024
1ae3c9b
updated backend to modify the post entity
ovindumandith May 10, 2024
be59344
updated backend to modify the post entity
ovindumandith May 10, 2024
11e183d
updated fronted o handle edit of posts
ovindumandith May 10, 2024
4fceba0
updated fronted o handle edit of posts
ovindumandith May 10, 2024
9a0b21b
updated fronted to address the non sterlized values
ovindumandith May 10, 2024
009e5a8
updated fronted to address the non sterlized values
ovindumandith May 10, 2024
d16a42d
updated frontend for error correction in rendering of posts
ovindumandith May 10, 2024
3d7fbce
made api corrections for delete function
ovindumandith May 11, 2024
018cab3
added toaastify for alert functios
ovindumandith May 11, 2024
6156692
mapped backend and frontened to handle update posts
ovindumandith May 11, 2024
822d645
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
895aaac
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
dfb7b3a
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
a9dcc7f
updated gitignore to avoid pushing secret keys
ovindumandith May 11, 2024
52944f5
mapped backend and frontened to handle update posts
ovindumandith May 11, 2024
dfe561c
made cahanges for user profile to display the posts
ovindumandith May 11, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Please go under edit and edit this file as needed for your project

#### Brief Description of your Solution -

Note - The student's github account should be given in brackets e.g. (asiriRepos), this ideally should be your student id
The goal of this project is to develop a user-friendly social media platform tailored for fitness enthusiasts to share their fitness journey, workouts, and healthy lifestyle tips. This platform will facilitate users in uploading media content, sharing workout statuses, exchanging workout and meal plans, and interacting with other users. The goal is to foster a supportive community where individuals can inspire and motivate each other to achieve their fitness goals.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.paf.socailfitnessapplication.config;

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

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
Expand All @@ -29,11 +29,16 @@ public ResponseEntity<Comment> getCommentById(@PathVariable String id) {
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

@PutMapping("/{id}")
public ResponseEntity<Comment> updateComment(@PathVariable String id, @RequestBody Comment comment) {
Optional<Comment> updatedComment = commentService.updateComment(id, comment);
return updatedComment.map(value -> new ResponseEntity<>(value, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
@GetMapping("/user/{userId}")
public ResponseEntity<List<Comment>> getAllCommentsByUserId(@PathVariable String userId) {
List<Comment> comments = commentService.getAllCommentsByUserId(userId);
return new ResponseEntity<>(comments, HttpStatus.OK);
}

@GetMapping("/post/{postId}")
public ResponseEntity<List<Comment>> getAllCommentsByPostId(@PathVariable String postId) {
List<Comment> comments = commentService.getAllCommentsByPostId(postId);
return new ResponseEntity<>(comments, HttpStatus.OK);
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.paf.socailfitnessapplication.controller;

import com.paf.socailfitnessapplication.entity.Like;
import com.paf.socailfitnessapplication.service.LikeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/likes")
@RequiredArgsConstructor
public class LikeController {

private final LikeService likeService;

@PostMapping
public ResponseEntity<Like> createLike(@RequestBody Like like) {
Like createdLike = likeService.createLike(like);
return new ResponseEntity<>(createdLike, HttpStatus.CREATED);
}

@GetMapping("/{id}")
public ResponseEntity<Like> getLikeById(@PathVariable String id) {
Optional<Like> like = likeService.getLikeById(id);
return like.map(value -> new ResponseEntity<>(value, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

@GetMapping("/user/{userId}")
public ResponseEntity<List<Like>> getAllLikesByUserId(@PathVariable String userId) {
List<Like> likes = likeService.getAllLikesByUserId(userId);
return new ResponseEntity<>(likes, HttpStatus.OK);
}

@GetMapping("/post/{postId}")
public ResponseEntity<List<Like>> getAllLikesByPostId(@PathVariable String postId) {
List<Like> likes = likeService.getAllLikesByPostId(postId);
return new ResponseEntity<>(likes, HttpStatus.OK);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteLike(@PathVariable String id) {
boolean deleted = likeService.deleteLike(id);
return deleted ? new ResponseEntity<>(HttpStatus.NO_CONTENT) : new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

Expand All @@ -29,13 +28,38 @@ public ResponseEntity<Post> getPostById(@PathVariable String id) {
return post.map(value -> new ResponseEntity<>(value, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

@GetMapping
public ResponseEntity<List<Post>> getAllPosts() {
List<Post> posts = postService.getAllPosts();
return new ResponseEntity<>(posts, HttpStatus.OK);
}


@GetMapping("/user/{userId}")
public ResponseEntity<List<Post>> getAllPostsByUserId(@PathVariable String userId) {
List<Post> posts = postService.getAllPostsByUserId(userId);
return new ResponseEntity<>(posts, HttpStatus.OK);
}

@GetMapping("/search")
public ResponseEntity<List<Post>> searchPostsByKeyword(@RequestParam String keyword) {
List<Post> posts = postService.searchPostsByKeyword(keyword);
return new ResponseEntity<>(posts, HttpStatus.OK);
}

@GetMapping("/likedby/{userId}")
public ResponseEntity<List<Post>> getPostsLikedByUser(@PathVariable String userId) {
List<Post> posts = postService.getPostsLikedByUser(userId);
return new ResponseEntity<>(posts, HttpStatus.OK);
}

@GetMapping("/commentedby/{userId}")
public ResponseEntity<List<Post>> getPostsCommentedByUser(@PathVariable String userId) {
List<Post> posts = postService.getPostsCommentedByUser(userId);
return new ResponseEntity<>(posts, HttpStatus.OK);
}

@PutMapping("/{id}")
public ResponseEntity<Post> updatePost(@PathVariable String id, @RequestBody Post post) {
Optional<Post> updatedPost = postService.updatePost(id, post);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.paf.socailfitnessapplication.controller;

import com.paf.socailfitnessapplication.entity.PostShare;
import com.paf.socailfitnessapplication.service.PostShareService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/postshares")
@RequiredArgsConstructor
public class PostShareController {

private final PostShareService postShareService;

@PostMapping
public ResponseEntity<PostShare> createPostShare(@RequestBody PostShare postShare) {
PostShare createdPostShare = postShareService.createPostShare(postShare);
return new ResponseEntity<>(createdPostShare, HttpStatus.CREATED);
}

@GetMapping("/{id}")
public ResponseEntity<PostShare> getPostShareById(@PathVariable String id) {
Optional<PostShare> postShare = postShareService.getPostShareById(id);
return postShare.map(value -> new ResponseEntity<>(value, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

@GetMapping
public ResponseEntity<List<PostShare>> getAllPostShares() {
List<PostShare> postShares = postShareService.getAllPostShares();
return new ResponseEntity<>(postShares, HttpStatus.OK);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deletePostShare(@PathVariable String id) {
postShareService.deletePostShare(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.paf.socailfitnessapplication.entity.User;
import com.paf.socailfitnessapplication.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import lombok.RequiredArgsConstructor;import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.paf.socailfitnessapplication.dto;

import lombok.Data;

import java.util.Date;

@Data
public class CommentDTO {
private String id;
private String text;
private String userId;
private String postId;
private Date createdAt;
private Date updatedAt;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.paf.socailfitnessapplication.dto;

import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.List;

@Getter
@Setter
public class PostDTO {
private String id;
private String userId;
private String imageUrl;
private String caption;
private List<String> likedby;
private Date createdAt;
private Date updatedAt;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.paf.socailfitnessapplication.dto;

import com.paf.socailfitnessapplication.entity.Post;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PostShareDTO {
private String id;
private String caption;
private String userId;
private Post post;
private Date createdAt;
private Date updatedAt;

// Optional: You can add static methods to convert between entities and DTOs if needed
// For example:
// public static PostShareDTO fromEntity(PostShare postShare) {
// return new PostShareDTO(postShare.getId(), postShare.getCaption(), postShare.getUserId(), postShare.getPost(), postShare.getCreatedAt(), postShare.getUpdatedAt());
// }
//
// public PostShare toEntity() {
// PostShare postShare = new PostShare();
// postShare.setId(this.getId());
// postShare.setCaption(this.getCaption());
// postShare.setUserId(this.getUserId());
// postShare.setPost(this.getPost());
// postShare.setCreatedAt(this.getCreatedAt());
// postShare.setUpdatedAt(this.getUpdatedAt());
// return postShare;
// }
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package com.paf.socailfitnessapplication.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;

@Data
@NoArgsConstructor
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "comments")

public class Comment {
@Id
private String id;
private String text;
private String userId;
private String postId;
private String text;
private Date createdAt;
private Date updatedAt;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.paf.socailfitnessapplication.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.Date;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "likes")
public class Like {
@Id
private String id;
private String userId;
private String postId;
private Date createdAt;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.paf.socailfitnessapplication.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.List;

Expand All @@ -14,14 +14,14 @@
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "posts")

public class Post {
@Id
private String id;
private String userId;
private List<String> imgLink;
private String imageUrl;
private String caption;
private List<String> likedby;
private List<Like> likes;
private List<Comment> comments;
private Date createdAt;
private Date updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.paf.socailfitnessapplication.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "postshare")
public class PostShare {
@Id
private String id;
private String caption;
private String userId;
@DBRef
private Post post;
private Date createdAt;
private Date updatedAt;
}

Loading