-
Notifications
You must be signed in to change notification settings - Fork 0
addPost API to create a Post #15
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
Open
tailorsmit
wants to merge
12
commits into
main
Choose a base branch
from
smit/post
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
772e406
addPost API to create a Post
tailorsmit 630ccb0
added public apis for view.
tailorsmit 14a8d1b
Posts frontend.
tailorsmit 7f5a1ad
all post endpoints added
tailorsmit 513d512
merged main branch
tailorsmit 92785a5
api for viewing profile
tailorsmit e8d4386
profile page
tailorsmit 8432116
Post UI
tailorsmit 030e830
Added material UI.
tailorsmit 16d8e96
Merge branch 'main' of https://github.com/webtutsplus/social-network …
tailorsmit 7eabf8d
add post ui
tailorsmit e9f71a8
post feature patched with backend
tailorsmit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
springbackend/src/main/java/com/simplecoding/social/dtos/PostDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.simplecoding.social.dtos; | ||
|
|
||
| public class PostDto { | ||
| Integer id; | ||
| String content; | ||
|
|
||
| public Integer getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Integer id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getContent() { | ||
| return content; | ||
| } | ||
|
|
||
| public void setContent(String content) { | ||
| this.content = content; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
springbackend/src/main/java/com/simplecoding/social/model/Post.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.simplecoding.social.model; | ||
|
|
||
| import javax.persistence.*; | ||
|
|
||
| @Entity | ||
| @Table(name = "posts") | ||
| public class Post { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Integer id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.EAGER) | ||
| @JoinColumn(name = "user_id",referencedColumnName = "id") | ||
| private User user; | ||
|
|
||
| private String content; | ||
|
|
||
| public Post() { | ||
| } | ||
|
|
||
| public Integer getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Integer id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public User getUser() { | ||
| return user; | ||
| } | ||
|
|
||
| public void setUser(User user) { | ||
| this.user = user; | ||
| } | ||
|
|
||
| public String getContent() { | ||
| return content; | ||
| } | ||
|
|
||
| public void setContent(String content) { | ||
| this.content = content; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
springbackend/src/main/java/com/simplecoding/social/repo/PostRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.simplecoding.social.repo; | ||
|
|
||
| import com.simplecoding.social.model.Post; | ||
| import com.simplecoding.social.model.User; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface PostRepository extends JpaRepository<Post,Integer> { | ||
|
|
||
| List<Post> findPostByUser(User user); | ||
| } |
53 changes: 53 additions & 0 deletions
53
springbackend/src/main/java/com/simplecoding/social/service/PostService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.simplecoding.social.service; | ||
|
|
||
| import com.simplecoding.social.auth.SecurityService; | ||
| import com.simplecoding.social.auth.models.UserDto; | ||
| import com.simplecoding.social.dtos.PostDto; | ||
| import com.simplecoding.social.model.Post; | ||
| import com.simplecoding.social.model.User; | ||
| import com.simplecoding.social.repo.PostRepository; | ||
| import com.simplecoding.social.repo.UserRepository; | ||
| import org.modelmapper.ModelMapper; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| public class PostService { | ||
|
|
||
| @Autowired | ||
| PostRepository postRepository; | ||
|
|
||
| @Autowired | ||
| UserRepository userRepository; | ||
|
|
||
| @Autowired | ||
| ModelMapper modelMapper; | ||
|
|
||
| @Autowired | ||
| SecurityService securityService; | ||
|
|
||
| public Post savePost(UserDto userDto, String content){ | ||
| Post post = new Post(); | ||
| User user = userRepository.findUserByEmail(userDto.getEmail()); | ||
| post.setUser(user); | ||
| post.setContent(content); | ||
| return postRepository.save(post); | ||
| } | ||
|
|
||
| public List<PostDto> getPostsOfUser(Integer userId){ | ||
| List<Post> postList= postRepository.findPostByUser(userRepository.findUserById(userId)); | ||
| List<PostDto> postDtoList= new ArrayList<>(); | ||
| for (Post post :postList) { | ||
| postDtoList.add(modelMapper.map(post,PostDto.class)); | ||
| } | ||
| return postDtoList; | ||
| } | ||
|
|
||
| public List<Post> getAllPost(){ | ||
| return postRepository.findAll(); | ||
| } | ||
|
|
||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.