feat(ReadRecipe): implementado servicio para leer recetas básico

parent d746f599
package com.example.apprecetas.recipe.application;
import com.example.apprecetas.recipe.infrastructure.controller.dto.RecipeOutputDto;
import java.util.List;
public interface ReadRecipeUseCase {
RecipeOutputDto readById(Long id);
List<RecipeOutputDto> readAll();
}
package com.example.apprecetas.recipe.application.impl;
import com.example.apprecetas.exceptions.EntityNotFoundException;
import com.example.apprecetas.recipe.application.ReadRecipeUseCase;
import com.example.apprecetas.recipe.domain.repository.ReadRecipeRepository;
import com.example.apprecetas.recipe.infrastructure.controller.dto.RecipeOutputDto;
import com.example.apprecetas.recipe.infrastructure.mapper.RecipeMapper;
import com.example.apprecetas.recipe.infrastructure.repository.jpa.RecipeJpa;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ReadRecipeUseCaseImpl implements ReadRecipeUseCase {
@Autowired
private ReadRecipeRepository repository;
private final RecipeMapper mapper = Mappers.getMapper(RecipeMapper.class);
@Override
public RecipeOutputDto readById(Long id) {
RecipeJpa recipeJpa = repository.readById(id)
.orElseThrow(() -> new EntityNotFoundException("La receta con id " + id + " no existe"));
return mapper.map(mapper.mapJpa(recipeJpa));
}
@Override
public List<RecipeOutputDto> readAll() {
return repository.readAll().stream()
.map(mapper::mapJpa)
.map(mapper::map)
.toList();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment