Skip to content

Commit

Permalink
feat: add transactional on recipe service
Browse files Browse the repository at this point in the history
  • Loading branch information
geoje committed Sep 23, 2024
1 parent 4fce6ec commit b74658b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class RecipeService {

Expand All @@ -49,6 +48,7 @@ public class RecipeService {
private final CommentService commentService;
private final RecipeLikeService recipeLikeService;

@Transactional(readOnly = true)
public List<RecipeHomeWithMineResponse> readRecipes(UserInfo userInfo, PageRecipeRequest pageRecipeRequest) {
Pageable pageable = pageRecipeRequest.getPageable();
List<Long> recipeIds = recipeRepository.findRecipeIdsByCategoryAndKeyword(
Expand All @@ -66,6 +66,7 @@ public List<RecipeHomeWithMineResponse> readRecipes(UserInfo userInfo, PageRecip
.toList();
}

@Transactional(readOnly = true)
public List<RecipeHomeWithMineResponse> readLikeRecipes(UserInfo userInfo) {
List<Long> likeRecipeIds = likeRepository.findRecipeIdsByUserId(userInfo.getId());
List<RecipeHomeResponse> recipeHomeResponses = recipeRepository.findRecipeData(likeRecipeIds);
Expand All @@ -76,6 +77,7 @@ public List<RecipeHomeWithMineResponse> readLikeRecipes(UserInfo userInfo) {
.toList();
}

@Transactional
public RecipeResponse createRecipe(UserInfo userInfo, RecipeRequest recipeRequest) {
User author = userRepository.findById(userInfo.getId()).orElseThrow();
String thumbnailUrl = s3ClientService.getImageUrl(recipeRequest.thumbnail()).url();
Expand All @@ -96,6 +98,7 @@ public RecipeResponse createRecipe(UserInfo userInfo, RecipeRequest recipeReques
return new RecipeResponse(savedRecipe);
}

@Transactional(readOnly = true)
public RecipeDescriptionResponse readRecipeDescription(UserInfo userInfo, long recipeId) {
List<RecipeDataResponse> recipeDataResponses = recipeRepository.findRecipeData(recipeId);

Expand All @@ -107,6 +110,7 @@ public RecipeDescriptionResponse readRecipeDescription(UserInfo userInfo, long r
);
}

@Transactional
public void deleteRecipe(UserInfo userInfo, long recipeId) {
Optional<Recipe> targetRecipe = recipeRepository.findById(recipeId);

Expand Down

0 comments on commit b74658b

Please sign in to comment.