Receipe full
This commit is contained in:
parent
deb36f05e3
commit
627d461e27
|
@ -0,0 +1,34 @@
|
|||
package net.meutel.recettes.api.entity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class QuantityEntity {
|
||||
|
||||
private BigDecimal value;
|
||||
|
||||
private String unit;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "QuantityEntity [value=" + value + ", unit=" + unit + "]";
|
||||
}
|
||||
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(BigDecimal value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -13,10 +13,12 @@ public class ReceipeEntity {
|
|||
private String cookTime;
|
||||
private String prepTime;
|
||||
private String author;
|
||||
private ReceipeYieldEntity receipeYield;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReceipeEntity [id=" + id + ", name=" + name + ", description=" + description + ", cookTime=" + cookTime
|
||||
+ ", prepTime=" + prepTime + ", author=" + author + "]";
|
||||
+ ", prepTime=" + prepTime + ", author=" + author + ", receipeYield=" + receipeYield + "]";
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -54,7 +56,11 @@ public class ReceipeEntity {
|
|||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
|
||||
public ReceipeYieldEntity getReceipeYield() {
|
||||
return receipeYield;
|
||||
}
|
||||
public void setReceipeYield(ReceipeYieldEntity receipeYield) {
|
||||
this.receipeYield = receipeYield;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package net.meutel.recettes.api.entity;
|
||||
|
||||
public class ReceipeYieldEntity {
|
||||
|
||||
private QuantityEntity quantity;
|
||||
|
||||
private String of;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReceipeYieldEntity [quantity=" + quantity + ", of=" + of + "]";
|
||||
}
|
||||
|
||||
public QuantityEntity getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(QuantityEntity quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getOf() {
|
||||
return of;
|
||||
}
|
||||
|
||||
public void setOf(String of) {
|
||||
this.of = of;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import net.meutel.recettes.api.exception.ItemNotFoundException;
|
||||
import net.meutel.recettes.api.mapper.ReceipeFullMapper;
|
||||
import net.meutel.recettes.api.mapper.ReceipeSimplifiedMapper;
|
||||
import net.meutel.recettes.api.model.Receipe;
|
||||
import net.meutel.recettes.api.repository.ReceipeRepository;
|
||||
|
@ -15,10 +16,12 @@ public class ReceipeServiceImpl implements ReceipeService {
|
|||
|
||||
private final ReceipeRepository repo;
|
||||
private final ReceipeSimplifiedMapper mapper;
|
||||
private final ReceipeFullMapper fullMapper;
|
||||
|
||||
public ReceipeServiceImpl(ReceipeRepository repo, ReceipeSimplifiedMapper mapper) {
|
||||
public ReceipeServiceImpl(ReceipeRepository repo, ReceipeSimplifiedMapper mapper, ReceipeFullMapper fullMapper) {
|
||||
this.repo = repo;
|
||||
this.mapper = mapper;
|
||||
this.fullMapper = fullMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +35,7 @@ public class ReceipeServiceImpl implements ReceipeService {
|
|||
@Override
|
||||
public Receipe getReceipeById(String id) {
|
||||
return repo.findById(id)
|
||||
.map(mapper::fromEntity)
|
||||
.map(fullMapper::fromEntity)
|
||||
.orElseThrow(() -> new ItemNotFoundException("Receipe", id));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.meutel.recettes.api.service;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -12,9 +13,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import net.meutel.recettes.api.entity.QuantityEntity;
|
||||
import net.meutel.recettes.api.entity.ReceipeEntity;
|
||||
import net.meutel.recettes.api.entity.ReceipeYieldEntity;
|
||||
import net.meutel.recettes.api.exception.ItemNotFoundException;
|
||||
import net.meutel.recettes.api.model.Receipe;
|
||||
import net.meutel.recettes.api.model.ReceipeReceipeYield;
|
||||
import net.meutel.recettes.api.repository.ReceipeRepository;
|
||||
|
||||
@SpringBootTest
|
||||
|
@ -33,8 +37,14 @@ public class ReceipeServiceImplTest {
|
|||
|
||||
@Test
|
||||
void getReceipeById_exists_receipe() {
|
||||
ReceipeEntity r1 = new ReceipeEntity();
|
||||
var r1 = new ReceipeEntity();
|
||||
r1.setName("pates carbo");
|
||||
var yield = new ReceipeYieldEntity();
|
||||
yield.setOf("personne");
|
||||
var qty = new QuantityEntity();
|
||||
qty.setValue(new BigDecimal(1));
|
||||
yield.setQuantity(qty);
|
||||
r1.setReceipeYield(yield);
|
||||
when(repo.findById("TEST"))
|
||||
.thenReturn(Optional.of(r1));
|
||||
|
||||
|
@ -44,6 +54,16 @@ public class ReceipeServiceImplTest {
|
|||
.isNotNull()
|
||||
.extracting(Receipe::getName)
|
||||
.isEqualTo("pates carbo");
|
||||
assertThat(result)
|
||||
.extracting(Receipe::getReceipeYield)
|
||||
.isNotNull()
|
||||
.extracting(ReceipeReceipeYield::getQuantity)
|
||||
.isNotNull();
|
||||
assertThat(result)
|
||||
.extracting(Receipe::getReceipeYield)
|
||||
.extracting(ReceipeReceipeYield::getOf)
|
||||
.isEqualTo("personne");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -136,11 +136,11 @@ components:
|
|||
type: object
|
||||
required:
|
||||
- quantity
|
||||
- what
|
||||
- of
|
||||
properties:
|
||||
quantity:
|
||||
$ref: '#/components/schemas/Quantity'
|
||||
what:
|
||||
of:
|
||||
description: Production target
|
||||
type: string
|
||||
Quantity:
|
||||
|
|
Loading…
Reference in New Issue