Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/gateway/auth/**", "/stream")
.permitAll()
.antMatchers("/free-theme").permitAll()
.antMatchers(HttpMethod.GET, "/posts/**").permitAll()
.antMatchers("/api/user/checkUsernameAvailability", "/api/user/checkEmailAvailability")
.permitAll()
.antMatchers(HttpMethod.GET, "/api/users/**")
Expand Down
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 src/main/java/com/example/timecoder/gateway/model/Post.java
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lombok


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 src/main/java/com/example/timecoder/gateway/model/PostDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.timecoder.gateway.model;


public class PostDto {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.timecoder.gateway.proxy;

import com.example.timecoder.gateway.model.Post;
import com.example.timecoder.gateway.payload.timecoder.EpisodePayload;
import com.example.timecoder.gateway.payload.timecoder.ThemePayload;
import org.springframework.cloud.openfeign.FeignClient;
Expand Down Expand Up @@ -47,4 +48,19 @@ public interface TimecoderServiceProxy {

@RequestMapping(value = "/theme/{id}/delete", method = RequestMethod.DELETE)
Object deleteTheme(@RequestParam Long id);

@RequestMapping(value = "/posts", method = RequestMethod.GET)
List<Post> getAllPosts();

@RequestMapping(value = "/posts/{id}", method = RequestMethod.GET)
Post getPostById(@RequestParam Long id);

@RequestMapping(value = "/posts", method = RequestMethod.POST)
Object createPost(Post post);

@RequestMapping(value = "/posts/{id}", method = RequestMethod.DELETE)
Object deletePost(@RequestParam Long id);

@RequestMapping(value = "/posts/{id}", method = RequestMethod.PUT)
Object updatePost(@RequestParam Long id, Post post);
}
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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
}