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 @@ -3,13 +3,12 @@
import com.cuoco.adapter.in.controller.model.IngredientRequest;
import com.cuoco.adapter.in.controller.model.IngredientResponse;
import com.cuoco.adapter.in.controller.model.ParametricResponse;
import com.cuoco.adapter.in.controller.model.QuickRecipeRequest;
import com.cuoco.adapter.in.controller.model.RecipeConfiguration;
import com.cuoco.adapter.in.controller.model.RecipeFilterRequest;
import com.cuoco.adapter.in.controller.model.RecipeRequest;
import com.cuoco.adapter.in.controller.model.RecipeResponse;
import com.cuoco.adapter.in.controller.model.StepResponse;
import com.cuoco.adapter.in.utils.Utils;
import com.cuoco.adapter.in.utils.UtilsAdapter;
import com.cuoco.application.port.in.FindOrCreateRecipeCommand;
import com.cuoco.application.port.in.FindRecipesCommand;
import com.cuoco.application.port.in.GetRecipeByIdQuery;
Expand All @@ -18,7 +17,6 @@
import com.cuoco.application.usecase.model.Recipe;
import com.cuoco.shared.GlobalExceptionHandler;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -257,10 +255,10 @@ private RecipeResponse buildResponse(Recipe recipe) {
.image(recipe.getImage())
.preparationTime(ParametricResponse.fromDomain(recipe.getPreparationTime()))
.cookLevel(ParametricResponse.fromDomain(recipe.getCookLevel()))
.diet(Utils.mapNull(recipe.getDiet()))
.diet(UtilsAdapter.mapNull(recipe.getDiet()))
.mealTypes(recipe.getMealTypes().stream().map(ParametricResponse::fromDomain).toList())
.allergies(Utils.mapNullOrEmpty(recipe.getAllergies()))
.dietaryNeeds(Utils.mapNullOrEmpty(recipe.getDietaryNeeds()))
.allergies(UtilsAdapter.mapNullOrEmpty(recipe.getAllergies()))
.dietaryNeeds(UtilsAdapter.mapNullOrEmpty(recipe.getDietaryNeeds()))
.ingredients(recipe.getIngredients().stream().map(IngredientResponse::fromDomain).toList())
.build();
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;
import java.util.Optional;

public class Utils {
public class UtilsAdapter {

public static ParametricResponse mapNull(Parametric source) {
return source != null ? ParametricResponse.fromDomain(source) : null;
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/cuoco/adapter/out/email/EmailService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

@Slf4j
@Repository
public class CreateAllMealPrepsDatabaseRepository implements CreateAllMealPrepsRepository {
public class CreateAllMealPrepsDatabaseRepositoryAdapter implements CreateAllMealPrepsRepository {

private final CreateAllMealPrepsHibernateRepositoryAdapter createAllMealPrepsHibernateRepositoryAdapter;

private final GetIngredientByNameHibernateRepositoryAdapter getIngredientByNameHibernateRepositoryAdapter;
private final CreateIngredientHibernateRepositoryAdapter createIngredientHibernateRepositoryAdapter;

public CreateAllMealPrepsDatabaseRepository(
public CreateAllMealPrepsDatabaseRepositoryAdapter(
CreateAllMealPrepsHibernateRepositoryAdapter createAllMealPrepsHibernateRepositoryAdapter,
GetIngredientByNameHibernateRepositoryAdapter getIngredientByNameHibernateRepositoryAdapter,
CreateIngredientHibernateRepositoryAdapter createIngredientHibernateRepositoryAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<MealPrep> execute(MealPrep mealPrep) {
try {
return objectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
throw new NotAvailableException(ErrorDescription.NOT_AVAILABLE.getValue());
}
}).toList();

Expand Down Expand Up @@ -100,7 +100,7 @@ public List<MealPrep> execute(MealPrep mealPrep) {
throw new NotAvailableException("Failed to generate meal preps");
} catch (Exception e) {
log.error("Error generating meal preps from Gemini", e);
throw new RuntimeException("Failed to generate meal preps");
throw new UnprocessableException("Failed to generate meal preps");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.cuoco.application.exception;

public class ConflictException extends BusinessException {
public ConflictException(String description) {
super(description, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface CreateUserRecipeCommand {

void execute(CreateUserRecipeCommand.Command command);
void execute(Command command);

@Data
@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cuoco.application.usecase;

import com.cuoco.adapter.exception.ConflictException;
import com.cuoco.application.exception.ConflictException;
import com.cuoco.application.port.in.CreateUserMealPrepCommand;
import com.cuoco.application.port.out.CreateUserMealPrepRepository;
import com.cuoco.application.port.out.ExistsUserMealPrepRepository;
Expand All @@ -11,7 +11,6 @@
import com.cuoco.application.usecase.model.UserMealPrep;
import com.cuoco.shared.model.ErrorDescription;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.cuoco.application.usecase;


import com.cuoco.adapter.exception.ConflictException;
import com.cuoco.application.exception.ConflictException;
import com.cuoco.application.port.in.CreateUserRecipeCommand;
import com.cuoco.application.port.out.CreateUserRecipeRepository;
import com.cuoco.application.port.out.GetRecipeByIdRepository;
import com.cuoco.application.port.out.ExistsUserRecipeByUserIdAndRecipeIdRepository;
import com.cuoco.application.port.out.GetRecipeByIdRepository;
import com.cuoco.application.usecase.domainservice.UserDomainService;
import com.cuoco.application.usecase.model.Recipe;
import com.cuoco.application.usecase.model.User;
import com.cuoco.application.usecase.model.UserRecipe;
import com.cuoco.shared.model.ErrorDescription;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Slf4j
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/cuoco/shared/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public ResponseEntity<ApiErrorResponse> handle(ConflictException ex) {
return buildResponseError(HttpStatus.CONFLICT, ex);
}

@ExceptionHandler(com.cuoco.application.exception.ConflictException.class)
public ResponseEntity<ApiErrorResponse> handle(com.cuoco.application.exception.ConflictException ex) {
log.warn(HttpStatus.CONFLICT.getReasonPhrase());
return buildResponseError(HttpStatus.CONFLICT, ex);
}

@ExceptionHandler(BadRequestException.class)
public ResponseEntity<ApiErrorResponse> handle(BadRequestException ex) {
log.warn(HttpStatus.BAD_REQUEST.getReasonPhrase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.cuoco.application.port.in.AuthenticateUserCommand;
import com.cuoco.application.port.in.GetAllAllergiesQuery;
import com.cuoco.application.usecase.model.Allergy;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import java.util.List;

Expand All @@ -18,20 +20,26 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(AllergyControllerAdapter.class)
@ExtendWith(MockitoExtension.class)
class AllergyControllerAdapterTest {

@Autowired
private MockMvc mockMvc;

@MockitoBean
@Mock
private GetAllAllergiesQuery getAllAllergiesQuery;

@MockitoBean
@Mock
private AuthenticateUserCommand authenticateUserCommand;

@InjectMocks
private AllergyControllerAdapter allergyControllerAdapter;

@BeforeEach
void setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(allergyControllerAdapter).build();
}

@Test
@WithMockUser
void GIVEN_existing_allergies_WHEN_getAll_THEN_return_list_of_parametric_response() throws Exception {
List<Allergy> allergies = List.of(
Allergy.builder().id(1).description("Mani").build(),
Expand Down
Loading