Skip to content

Commit

Permalink
Merge pull request #120 from OurMenu/fix/onboarding
Browse files Browse the repository at this point in the history
fix: PUT/article
  • Loading branch information
david-parkk authored Aug 20, 2024
2 parents 58324df + 99fb4ab commit cb61d99
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
Expand Down Expand Up @@ -50,7 +49,7 @@ public ApiResponse<ArticleResponse> getArticle(@PathVariable Long articleId) {
@PutMapping("/article/{articleId}")
public ApiResponse<ArticleResponse> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ public class PutArticleRequest {

private String articleContent;

private List<ArticleMenuRequest> articleMenus;
private List<Long> groupIds;

public static Article toEntity(PutArticleRequest putArticleRequest){
List<ArticleMenu> articleMenuList = putArticleRequest.getArticleMenus().stream().map(ArticleMenuRequest::toEntity).toList();
return Article.builder()
.title(putArticleRequest.articleTitle)
.content(putArticleRequest.articleContent)
.articleMenuList(articleMenuList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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<Long> groupIds) {

Article findArticle = findOne(articleId);
User user = findArticle.getUser();
Expand All @@ -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<Menu> 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;
Expand Down Expand Up @@ -277,4 +284,5 @@ public Article getArticleByGroupId(PostArticleRequest postArticleRequest, Long u
return saveArticle;
}


}

0 comments on commit cb61d99

Please sign in to comment.