-
Notifications
You must be signed in to change notification settings - Fork 1
Add Post service create/update/delete #2
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
Merged
Merged
Changes from all commits
Commits
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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/example/timecoder/gateway/controller/PostController.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,46 @@ | ||
| package com.example.timecoder.gateway.controller; | ||
|
|
||
| import com.example.timecoder.gateway.model.Post; | ||
| import com.example.timecoder.gateway.model.PostDto; | ||
| import com.example.timecoder.gateway.proxy.TimecoderServiceProxy; | ||
| import com.example.timecoder.gateway.service.PostService; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
| @RestController | ||
| public class PostController { | ||
|
|
||
| @Autowired | ||
| private TimecoderServiceProxy timecoderServiceProxy; | ||
|
|
||
| @Autowired | ||
| private PostService postService; | ||
|
|
||
| @RequestMapping(value = "/posts", method = RequestMethod.GET) | ||
| public List<Post> getAllPosts() { | ||
| return timecoderServiceProxy.getAllPosts(); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/posts/{id}", method = RequestMethod.GET) | ||
| public PostDto getPostById(@PathVariable("id") Long id) { | ||
| return postService.getPostById(id); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/posts", method = RequestMethod.POST) | ||
| public Object createPost(@RequestBody Post post) { | ||
| return timecoderServiceProxy.createPost(post); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/posts/{id}", method = RequestMethod.PUT) | ||
| public Object updatePost(@PathVariable("id") Long id, @RequestBody Post post) { | ||
| return timecoderServiceProxy.updatePost(id, post); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/posts/{id}", method = RequestMethod.DELETE) | ||
| public Object deletePost(@PathVariable("id") Long id) { | ||
| return timecoderServiceProxy.deletePost(id); | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
src/main/java/com/example/timecoder/gateway/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,81 @@ | ||
| package com.example.timecoder.gateway.model; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| public class Post { | ||
|
|
||
| private long id; | ||
| private long episodeId; | ||
| private Date createdAt = new Date(); | ||
| private String name; | ||
| private String shortDescription; | ||
| private String description; | ||
| private String link; | ||
| private Object guests; | ||
|
|
||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public long getEpisodeId() { | ||
| return episodeId; | ||
| } | ||
|
|
||
| public void setEpisodeId(long episodeId) { | ||
| this.episodeId = episodeId; | ||
| } | ||
|
|
||
| public Date getCreatedAt() { | ||
| return createdAt; | ||
| } | ||
|
|
||
| public void setCreatedAt(Date createdAt) { | ||
| this.createdAt = createdAt; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getShortDescription() { | ||
| return shortDescription; | ||
| } | ||
|
|
||
| public void setShortDescription(String shortDescription) { | ||
| this.shortDescription = shortDescription; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDescription(String description) { | ||
| this.description = description; | ||
| } | ||
|
|
||
| public String getLink() { | ||
| return link; | ||
| } | ||
|
|
||
| public void setLink(String link) { | ||
| this.link = link; | ||
| } | ||
|
|
||
| public Object getGuests() { | ||
| return guests; | ||
| } | ||
|
|
||
| public void setGuests(List<String> guests) { | ||
| this.guests = guests; | ||
| } | ||
|
|
||
| } | ||
42 changes: 42 additions & 0 deletions
42
src/main/java/com/example/timecoder/gateway/model/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,42 @@ | ||
| package com.example.timecoder.gateway.model; | ||
|
|
||
|
|
||
| public class PostDto { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lombok |
||
|
|
||
| private Object post; | ||
| private Object episode; | ||
| private Object patrons; | ||
|
|
||
| public PostDto() { | ||
| } | ||
|
|
||
| public PostDto(Object post, Object episode, Object patrons) { | ||
| this.post = post; | ||
| this.episode = episode; | ||
| this.patrons = patrons; | ||
| } | ||
|
|
||
| public Object getPost() { | ||
| return post; | ||
| } | ||
|
|
||
| public void setPost(Object post) { | ||
| this.post = post; | ||
| } | ||
|
|
||
| public Object getEpisode() { | ||
| return episode; | ||
| } | ||
|
|
||
| public void setEpisode(Object episode) { | ||
| this.episode = episode; | ||
| } | ||
|
|
||
| public Object getPatrons() { | ||
| return patrons; | ||
| } | ||
|
|
||
| public void setPatrons(Object patrons) { | ||
| this.patrons = patrons; | ||
| } | ||
| } | ||
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/timecoder/gateway/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,35 @@ | ||
| package com.example.timecoder.gateway.service; | ||
|
|
||
| import com.example.timecoder.gateway.model.Post; | ||
| import com.example.timecoder.gateway.model.PostDto; | ||
| import com.example.timecoder.gateway.proxy.PatronsServiceProxy; | ||
| import com.example.timecoder.gateway.proxy.TimecoderServiceProxy; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
|
|
||
| @Service | ||
| public class PostService { | ||
|
|
||
| @Autowired | ||
| private TimecoderServiceProxy timecoderServiceProxy; | ||
|
|
||
| @Autowired | ||
| private PatronsServiceProxy patronsServiceProxy; | ||
|
|
||
|
|
||
| public PostDto getPostById(Long id) { | ||
| Post post = null; | ||
| Object episode = null; | ||
| Object patronsList = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return post from proxy instead of object. And probably try catch needed only for patrons service |
||
| try { | ||
| post = timecoderServiceProxy.getPostById(id); | ||
| episode = timecoderServiceProxy.getEpisodeById(post.getEpisodeId()); | ||
| patronsList = patronsServiceProxy.getAllActivePatrons(); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| return new PostDto(post, episode, patronsList); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lombok