Skip to content

Commit

Permalink
Added full meal registry implementation across different microservices
Browse files Browse the repository at this point in the history
  • Loading branch information
Goncalo Monteiro authored and Goncalo De Almeida Barreto Da Costa Monteiro committed Dec 8, 2020
1 parent a3ebe41 commit c8563dc
Show file tree
Hide file tree
Showing 134 changed files with 6,350 additions and 0 deletions.
37 changes: 37 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Directories #
build/
bin/
target/

.metadata
*.idea
.idea/*

# OS Files #
.DS_Store
desktop.ini
Thumbs.db

*.class
*.iml
*.ipr
*.iws
*~
*#
.*.swp
.*.swo
*.patch
.settings
._*

# Specific to the project
**/reports/

.classpath
.project
.idea
*/.idea
.idea
/.idea
.idea/
.DS_STORE
117 changes: 117 additions & 0 deletions backend/Meal/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>meal</groupId>
<artifactId>com.meal</artifactId>
<version>1.0-SNAPSHOT</version>

<name>com.meal</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.22.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions backend/Meal/script.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE `USERS` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`username` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
)
98 changes: 98 additions & 0 deletions backend/Meal/src/main/java/com/MealConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com;

import com.persistence.valueObjects.TypeOfFood;
import com.services.MealService;
import com.services.NutritionDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import com.dtos.AllergenDTO;
import com.dtos.DescriptorDTO;
import com.dtos.IngredientDTO;
import com.dtos.MealDTO;
import com.dtos.NutritionDataDTO;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Configuration
public class MealConfig {

private List<MealDTO> meals;
private List<IngredientDTO> ingredients;
private NutritionDataDTO nutritionData;

@Autowired
private MealService mealService;

@Autowired
private NutritionDataService nutritionDataService;

@PostConstruct
public void createDefaultMeals() {
createMealsList();
this.mealService.createMeal(this.meals.get(0));
}

private void createMealsList() {
createIngredientsList();
createNutritionData();
this.meals = new ArrayList<>();
MealDTO meal1 = new MealDTO(
this.nutritionData,
10,
TypeOfFood.SOUP,
"photo",
this.ingredients,
"Caldo Verde",
12,
new ArrayList<AllergenDTO>());

MealDTO meal2 = new MealDTO(
this.nutritionData,
4,
TypeOfFood.MAIN_DISH,
"photo",
this.ingredients,
"Francesinha",
1,
new ArrayList<AllergenDTO>());
MealDTO meal3 = new MealDTO(
this.nutritionData,
31,
TypeOfFood.DESERT,
"photo",
this.ingredients,
"Mousse de chocolate",
14,
new ArrayList<AllergenDTO>());
this.meals.add(meal1);
this.meals.add(meal2);
this.meals.add(meal3);
}

private void createIngredientsList() {
this.ingredients = new ArrayList<>();
IngredientDTO ingredient1 =
new IngredientDTO("batata");
IngredientDTO ingredient2 =
new IngredientDTO("agua");
IngredientDTO ingredient3 =
new IngredientDTO("queijo derretido");
this.ingredients.add(ingredient1);
this.ingredients.add(ingredient2);
this.ingredients.add(ingredient3);
}

private void createNutritionData() {
List<DescriptorDTO> descriptors = new ArrayList<>();
DescriptorDTO descriptor1 = new DescriptorDTO("caldo verde", 10, "boa sopa", 20);
DescriptorDTO descriptor2 = new DescriptorDTO("francesinha", 15, "bom molho", 30);
DescriptorDTO descriptor3 = new DescriptorDTO("mousse", 55, "chocolate", 66);
descriptors.add(descriptor1);
descriptors.add(descriptor2);
descriptors.add(descriptor3);
this.nutritionData = new NutritionDataDTO(descriptors);
this.nutritionDataService.createNutritionData(this.nutritionData);
}
}
11 changes: 11 additions & 0 deletions backend/Meal/src/main/java/com/MealsApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MealsApp {
public static void main(String[] args) {
SpringApplication.run(MealsApp.class, args);
}
}
23 changes: 23 additions & 0 deletions backend/Meal/src/main/java/com/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com;

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

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*").allowedHeaders("*").allowedOrigins("*");
}
};
}
}
75 changes: 75 additions & 0 deletions backend/Meal/src/main/java/com/controllers/MealController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.controllers;

import com.services.MealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dtos.MealDTO;
import com.dtos.MealsDTO;
import com.mappers.MealMapper;

@CrossOrigin(maxAge = 3600)
@Controller
@RequestMapping(
path = "/meal",
produces = MediaType.APPLICATION_JSON_VALUE)
public class MealController {

@Autowired
private MealService mealService;

@GetMapping(path = "/id/{mealId}")
public ResponseEntity<MealDTO> getSingleMeal(@PathVariable long mealId) {
return ResponseEntity.ok(this.mealService.getSingleMeal(mealId));
}

@GetMapping(path = "/designation/{designation}")
public ResponseEntity<MealDTO> getSingleMealByDesignation(@PathVariable String designation) {
return ResponseEntity.ok(this.mealService.getSingleMealByDesignation(designation));
}

@GetMapping(path = "")
public ResponseEntity<MealsDTO> getMeals() {
return new ResponseEntity<>(new MealsDTO(this.mealService.getMeals()), HttpStatus.OK);
}

@PostMapping(path = "/create")
public ResponseEntity<Object> createMeal(@RequestBody MealDTO mealDTO) {
this.mealService.createMeal(mealDTO);
return new ResponseEntity(HttpStatus.OK);
}

@PutMapping(path = "/update")
public ResponseEntity<Object> updateMeal(@RequestBody MealDTO mealDTO) {
this.mealService.updateMeal(MealMapper.mapMealDTOToMeal(mealDTO));
return new ResponseEntity(HttpStatus.OK);
}

@DeleteMapping(path = "/delete/{mealId}")
public ResponseEntity<Object> deleteMeal(@PathVariable long mealId) {
this.mealService.deleteMeal(mealId);
return new ResponseEntity(HttpStatus.OK);
}

@PutMapping(path = "/quantity/add/designation/{designation}")
public ResponseEntity<Object> increaseMealQuantityToSell(@PathVariable String designation){
this.mealService.decreaseMealQuantityToSell(designation);
return new ResponseEntity(HttpStatus.OK);
}

@PutMapping(path = "/quantity/remove/designation/{designation}")
public ResponseEntity<Object> decreaseMealQuantityToSell(@PathVariable String designation){
this.mealService.decreaseMealQuantityToSell(designation);
return new ResponseEntity(HttpStatus.OK);
}
}
Loading

0 comments on commit c8563dc

Please sign in to comment.