Skip to content

Commit

Permalink
added new routes for UserSkills, UserRoutes, and StudioUsers PR (#6)
Browse files Browse the repository at this point in the history
* added new routes for UserSkills, UserRoutes, and StudioUsers

* added new routes for UserSkills, UserRoutes, and StudioUsers

* avoiding single statement if clauses by adding {}
  • Loading branch information
picksitquick authored Dec 17, 2023
1 parent 665b1f2 commit 3c52b0c
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.gamedoora.backend.proxy.aggregation.api;

import com.gamedoora.backend.proxy.aggregation.assembler.StudioDataAggregatorAssembler;
import com.gamedoora.model.dto.GdUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/aggregate/studios")
public class StudioDataAggregationService {
private StudioDataAggregatorAssembler studioDataAggregatorAssembler;

@RequestMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
public GdUser getStudiosByUser(@RequestParam("email") String email){
return getStudioDataAggregatorAssembler().getStudiosByUser(email);
}

public StudioDataAggregatorAssembler getStudioDataAggregatorAssembler() {
return studioDataAggregatorAssembler;
}

@Autowired
public void setStudioDataAggregatorAssembler(StudioDataAggregatorAssembler studioDataAggregatorAssembler) {
this.studioDataAggregatorAssembler = studioDataAggregatorAssembler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gamedoora.model.dto.GdUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,6 +18,21 @@ public class UserDataAggregationService {
public GdUser getUserProfileByEmail(@RequestParam("emailId") String email){
return getAggregatorAssembler().getUserByEmail(email);
}

@PostMapping(value = "/roles",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public void getUserProfileByRoles(@RequestParam("user") GdUser user){
getAggregatorAssembler().addRoles(user);
}

@PostMapping(value = "/skills",
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public void getUserProfileBySkills(@RequestParam("user") GdUser user){
getAggregatorAssembler().addSkills(user);
}

public UserDataAggregatorAssembler getAggregatorAssembler() {
return aggregatorAssembler;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.gamedoora.backend.proxy.aggregation.assembler;

import com.gamedoora.backend.proxy.aggregation.routes.StudioProfileRoute;
import com.gamedoora.model.dto.GdUser;
import com.gamedoora.model.dto.StudiosDTO;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class StudioDataAggregatorAssembler {
private ProducerTemplate producerTemplate;

@Autowired
private CamelContext camelContext;
private StudioProfileRoute studioProfileRoute;

public GdUser getStudiosByUser(String email){
List<StudiosDTO> studioDTOList = getProducerTemplate().requestBody("direct:studioUserQuery" , email, ArrayList.class);
return GdUser
.builder()
.studios(studioDTOList)
.build();
}

public ProducerTemplate getProducerTemplate() {
return producerTemplate;
}

public void setProducerTemplate(ProducerTemplate producerTemplate) {
this.producerTemplate = producerTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.gamedoora.backend.proxy.aggregation.assembler;

import com.gamedoora.backend.proxy.aggregation.exceptions.ClientResponseException;
import com.gamedoora.backend.proxy.aggregation.routes.UserProfileRoute;
import com.gamedoora.model.dto.GdUser;
import com.gamedoora.model.dto.RoleDTO;
import com.gamedoora.model.dto.SkillsDTO;
import com.gamedoora.model.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.support.DefaultExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -37,6 +36,24 @@ public GdUser getUserByEmail(String email){
.build();
}

public void addRoles(GdUser user) throws ClientResponseException{
List<RoleDTO> roleDTOList = user.getRoles();
if(roleDTOList.isEmpty() || user.getUser().getEmail().isEmpty()){
throw new ClientResponseException("No Roles found", 400);
}

getProducerTemplate().requestBody("direct:addUserRoleQuery", roleDTOList, ArrayList.class);
}

public void addSkills(GdUser user)throws ClientResponseException{
List<SkillsDTO> skillsDTOList = user.getSkills();
if(skillsDTOList.isEmpty() || user.getUser().getEmail().isEmpty()){
throw new ClientResponseException("No Roles found", 400);
}

getProducerTemplate().requestBody("direct:addUserSkillQuery", skillsDTOList, ArrayList.class);
}

public ProducerTemplate getProducerTemplate() {
return producerTemplate;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.gamedoora.backend.proxy.aggregation.enrichment.apis;

import com.gamedoora.model.dto.StudiosDTO;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@RefreshScope
@FeignClient(value = "studiosClient", url = "{services.studios.url}")
public interface StudioServicesApi {

@GetMapping(
value = "/users/{email}",
produces = {MediaType.APPLICATION_JSON_VALUE})
ResponseEntity <List<StudiosDTO>> getStudiosByUser(@PathVariable String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,22 @@ ResponseEntity<UserDTO> updateUsers(
@GetMapping(
value = "/roles/{name}",
produces = {MediaType.APPLICATION_JSON_VALUE})
ResponseEntity<List<UserDTO>> getAllUsersByRoles(@PathVariable String name)//confirm mapping
;
ResponseEntity<List<UserDTO>> getAllUsersByRoles(@PathVariable String name);//confirm mapping

@GetMapping(
value = "/email",
produces = {MediaType.APPLICATION_JSON_VALUE})
ResponseEntity<UserDTO> getUserByEmail(@RequestParam(required = true) String email);

@PostMapping(
value = "/roles",
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
ResponseEntity<UserDTO> addRoles(@RequestBody UserDTO usersDto); // email part will be in userDto

@PostMapping(
value = "/skills",
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
ResponseEntity<UserDTO> addSkills(@RequestBody UserDTO usersDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.gamedoora.backend.proxy.aggregation.enrichment.clients;

import com.gamedoora.model.dto.StudiosDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RetriableStudiosServicesClient {

private StudioServicesClient studioServicesClient;

private RetryTemplate retryTemplate;

public List<StudiosDTO> getStudiosForUserByEmail(String email){
return getRetryTemplate().execute(retryContext -> getStudioServicesClient().getStudiosByUser(email));
}

public StudioServicesClient getStudioServicesClient() {
return studioServicesClient;
}

@Autowired
public void setStudioServicesClient(StudioServicesClient studioServicesClient) {
this.studioServicesClient = studioServicesClient;
}

public RetryTemplate getRetryTemplate() {
return retryTemplate;
}

@Autowired
public void setRetryTemplate(RetryTemplate retryTemplate) {
this.retryTemplate = retryTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.gamedoora.backend.proxy.aggregation.enrichment.clients;

import com.gamedoora.model.dto.SkillsDTO;
import com.gamedoora.model.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RetriableUsersServicesClient {
private UserServicesClient userServicesClient;
Expand All @@ -18,6 +15,13 @@ public UserDTO getRolesForUserByEmail(String email){
});
}

public void addRolesForUser(UserDTO userDTO){
getRetryTemplate().execute(retryContext -> getUserServicesClient().addRoleToUser(userDTO));
}

public void addSkillsForUser(UserDTO userDTO){
getRetryTemplate().execute(retryContext -> getUserServicesClient().addSkillToUser(userDTO));
}

public RetryTemplate getRetryTemplate() {
return retryTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gamedoora.backend.proxy.aggregation.enrichment.clients;

import com.gamedoora.backend.proxy.aggregation.enrichment.apis.StudioServicesApi;
import com.gamedoora.model.dto.StudiosDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class StudioServicesClient {

private StudioServicesApi studioServicesApi;

public StudioServicesApi getStudioServicesApi() {
return studioServicesApi;
}

@Autowired
public void setStudioServicesApi(StudioServicesApi studioServicesApi) {
this.studioServicesApi = studioServicesApi;
}

public List<StudiosDTO> getStudiosByUser(String email) {
return getStudioServicesApi().getStudiosByUser(email).getBody();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public void setUserServicesApi(UserServicesApi userServicesApi) {
UserDTO getUserByEmail(@NonNull String email){
return getUserServicesApi().getUserByEmail(email).getBody();
}

UserDTO addRoleToUser(UserDTO userDTO){return getUserServicesApi().addRoles(userDTO).getBody();}

UserDTO addSkillToUser(UserDTO userDTO){return getUserServicesApi().addSkills(userDTO).getBody();}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gamedoora.backend.proxy.aggregation.routes;

import com.gamedoora.backend.proxy.aggregation.enrichment.clients.RetriableStudiosServicesClient;
import feign.FeignException;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class StudioProfileRoute extends RouteBuilder {

private RetriableStudiosServicesClient studiosServicesClient;

@Override
public void configure() throws Exception{
onException(FeignException.class)
.maximumRedeliveries(3)
.logStackTrace(true)
.handled(false);

from("direct:studioQuery")
.to("bean:retriableStudiosServicesClient?method=getStudioForUserByEmail")
.end();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import com.gamedoora.backend.proxy.aggregation.enrichment.clients.RetriableRolesServicesClient;
import com.gamedoora.backend.proxy.aggregation.enrichment.clients.RetriableSkillsServicesClient;
import com.gamedoora.backend.proxy.aggregation.enrichment.clients.RetriableUsersServicesClient;
import com.gamedoora.backend.proxy.aggregation.exceptions.ClientResponseException;
import feign.FeignException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy;
import org.apache.camel.processor.aggregate.GroupedMessageAggregationStrategy;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -32,6 +29,12 @@ public void configure() throws Exception {
from("direct:userSkillsQuery")
.to("bean:retriableSkillsServicesClient?method=getSkillsForUserByEmail")
.end();
from("direct:addUserRoleQuery")
.to("bean:retriableUsersServicesClient?method=addRolesForUser")
.end();
from("direct:addUserSkillQuery")
.to("bean:retriableUsersServicesClient?method=addSkillsForUser")
.end();
}


Expand Down

0 comments on commit 3c52b0c

Please sign in to comment.