diff --git a/src/main/java/com/ourMenu/backend/domain/article/api/ArticleController.java b/src/main/java/com/ourMenu/backend/domain/article/api/ArticleController.java index f35b386..ac708cf 100644 --- a/src/main/java/com/ourMenu/backend/domain/article/api/ArticleController.java +++ b/src/main/java/com/ourMenu/backend/domain/article/api/ArticleController.java @@ -17,7 +17,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; @RestController @@ -50,7 +49,7 @@ public ApiResponse getArticle(@PathVariable Long articleId) { @PutMapping("/article/{articleId}") public ApiResponse putArticle(@PathVariable Long articleId, @RequestBody PutArticleRequest putArticleRequest, @UserId Long userId) { Article article = PutArticleRequest.toEntity(putArticleRequest); - Article saveArticle = articleService.updateArticleWithMenu(articleId, article, userId); + Article saveArticle = articleService.updateArticleWithMenu(articleId, article, userId, putArticleRequest.getGroupIds()); if (saveArticle.getUser().getImgUrl() == null) { return ApiUtils.success(ArticleResponse.toDto(saveArticle)); } diff --git a/src/main/java/com/ourMenu/backend/domain/article/api/request/PutArticleRequest.java b/src/main/java/com/ourMenu/backend/domain/article/api/request/PutArticleRequest.java index 8690e37..1a04183 100644 --- a/src/main/java/com/ourMenu/backend/domain/article/api/request/PutArticleRequest.java +++ b/src/main/java/com/ourMenu/backend/domain/article/api/request/PutArticleRequest.java @@ -19,14 +19,12 @@ public class PutArticleRequest { private String articleContent; - private List articleMenus; + private List groupIds; public static Article toEntity(PutArticleRequest putArticleRequest){ - List articleMenuList = putArticleRequest.getArticleMenus().stream().map(ArticleMenuRequest::toEntity).toList(); return Article.builder() .title(putArticleRequest.articleTitle) .content(putArticleRequest.articleContent) - .articleMenuList(articleMenuList) .build(); } } diff --git a/src/main/java/com/ourMenu/backend/domain/article/application/ArticleService.java b/src/main/java/com/ourMenu/backend/domain/article/application/ArticleService.java index c62be4e..1188c46 100644 --- a/src/main/java/com/ourMenu/backend/domain/article/application/ArticleService.java +++ b/src/main/java/com/ourMenu/backend/domain/article/application/ArticleService.java @@ -13,15 +13,10 @@ import com.ourMenu.backend.domain.menu.domain.Menu; import com.ourMenu.backend.domain.menu.dto.request.PostMenuRequest; import com.ourMenu.backend.domain.menu.dto.request.StoreRequestDTO; -import com.ourMenu.backend.domain.menu.dto.response.MenuDetailDto; -import com.ourMenu.backend.domain.menu.dto.response.PostMenuResponse; import com.ourMenu.backend.domain.menulist.application.MenuListService; -import com.ourMenu.backend.domain.menulist.domain.MenuList; import com.ourMenu.backend.domain.user.application.UserService; import com.ourMenu.backend.domain.user.domain.User; -import com.ourMenu.backend.global.argument_resolver.UserId; import com.ourMenu.backend.global.common.Status; -import jakarta.persistence.EntityManager; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; @@ -30,8 +25,6 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; import software.amazon.awssdk.services.s3.S3Client; import java.util.*; @@ -151,7 +144,7 @@ public Article saveArticleWithMenu(Article article, Long userId) { } @Transactional - public Article updateArticleWithMenu(Long articleId, Article article, Long userId) { + public Article updateArticleWithMenu(Long articleId, Article article, Long userId, List groupIds) { Article findArticle = findOne(articleId); User user = findArticle.getUser(); @@ -166,10 +159,24 @@ public Article updateArticleWithMenu(Long articleId, Article article, Long userI findArticle.deleteAllArticleMenus(); - for (ArticleMenu articleMenu : article.getArticleMenuList()) { - findArticle.addArticleMenu(articleMenu); - articleMenu.confirmArticle(findArticle); - articleMenuService.save(articleMenu); + List menuList = menuService.getMenuByGroupId(groupIds, userId); + for (Menu menu : menuList) { + ArticleMenu articleMenu = ArticleMenu.builder() + .article(findArticle) + .title(menu.getTitle()) + .price(menu.getPrice()) + .placeTitle(menu.getPlace().getTitle()) + .address(menu.getPlace().getAddress()) + .imgUrl(menu.getImages().size() == 0 ? null : menu.getImages().get(0).getUrl()) + .groupId(menu.getGroupId()) + .menuMemoTitle(menu.getMemoTitle()) + .menuIconType(menu.getMenuIconType()) + .placeMemo(menu.getPlace().getInfo()) + .placeLatitude(menu.getPlace().getLatitude()) + .placeLongitude(menu.getPlace().getLongitude()) + .build(); + ArticleMenu saveArticleMenu = articleMenuService.save(articleMenu); + findArticle.addArticleMenu(saveArticleMenu); } findArticle.update(article); return findArticle; @@ -277,4 +284,5 @@ public Article getArticleByGroupId(PostArticleRequest postArticleRequest, Long u return saveArticle; } + }