Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/OurMenu/OurMenu-BE into fix…
Browse files Browse the repository at this point in the history
…/develop
  • Loading branch information
You-Hyuk committed Aug 19, 2024
2 parents ccb247c + 26ca308 commit ab5f3a1
Show file tree
Hide file tree
Showing 20 changed files with 492 additions and 59 deletions.
12 changes: 9 additions & 3 deletions mysql/init/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ create table article (
title varchar(255),
status enum ('CREATED','DELETED','UPDATED'),
primary key (article_id)
) engine=InnoDB
) engine=InnoDB;

create table article_menu (
place_latitude float(53) not null,
place_longitude float(53) not null,
price integer not null,
article_id bigint,
article_menu_id bigint not null auto_increment,
group_id bigint,
address varchar(255),
img_url varchar(255),
menu_icon_type varchar(255),
menu_memo_title varchar(255),
place_memo varchar(255),
place_title varchar(255),
title varchar(255),
shared_count bigint,
primary key (article_menu_id)
) engine=InnoDB;

Expand All @@ -46,7 +52,7 @@ create table menu (
title varchar(255),
status enum ('CREATED','DELETED','UPDATED'),
primary key (menu_id)
) engine=InnoDB
) engine=InnoDB;

create table menu_image (
menu_id bigint,
Expand Down Expand Up @@ -91,7 +97,7 @@ create table place (
place_id bigint not null auto_increment,
user_id bigint,
address varchar(255),
info varchar(255),
info varchar(500),
title varchar(255),
status enum ('CREATED','DELETED','UPDATED'),
primary key (place_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.ourMenu.backend.domain.article.api;

import com.ourMenu.backend.domain.article.api.request.DownloadArticleMenu;
import com.ourMenu.backend.domain.article.api.request.PostArticleRequest;
import com.ourMenu.backend.domain.article.api.request.PutArticleRequest;
import com.ourMenu.backend.domain.article.api.response.ArticleMenuResponse;
import com.ourMenu.backend.domain.article.api.response.ArticleResponse;
import com.ourMenu.backend.domain.article.api.response.CommunityArticle;
import com.ourMenu.backend.domain.article.api.response.DownloadArticleMenuResponse;
import com.ourMenu.backend.domain.article.application.ArticleService;
import com.ourMenu.backend.domain.article.domain.Article;
import com.ourMenu.backend.domain.article.domain.ArticleMenu;
import com.ourMenu.backend.domain.article.domain.ORDER_CRITERIA;
import com.ourMenu.backend.global.argument_resolver.UserId;
import com.ourMenu.backend.global.common.ApiResponse;
Expand All @@ -25,31 +29,72 @@ public class ArticleController {
@PostMapping("/article")
public ApiResponse<ArticleResponse> postArticle(@RequestBody PostArticleRequest postArticleRequest, @UserId Long userId) {
Article article = PostArticleRequest.toEntity(postArticleRequest);
Article saveArticle = articleService.saveArticleWithMenu(article,userId);
return ApiUtils.success(ArticleResponse.toDto(saveArticle));
Article saveArticle = articleService.saveArticleWithMenu(article, userId);
if (saveArticle.getUser().getImgUrl() == null) {
return ApiUtils.success(ArticleResponse.toDto(article));
}
String userImgUrl = articleService.getUserImgUrl(article.getUser().getImgUrl());
return ApiUtils.success(ArticleResponse.toDto(saveArticle, userImgUrl));
}

@GetMapping("/article/{articleId}")
public ApiResponse<ArticleResponse> getArticle(@PathVariable Long articleId) {
Article article = articleService.visitArticleById(articleId);
return ApiUtils.success(ArticleResponse.toDto(article));
if (article.getUser().getImgUrl() == null) {
return ApiUtils.success(ArticleResponse.toDto(article));
}
String userImgUrl = articleService.getUserImgUrl(article.getUser().getImgUrl());
return ApiUtils.success(ArticleResponse.toDto(article, userImgUrl));
}

@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);
return ApiUtils.success(ArticleResponse.toDto(saveArticle));
if (saveArticle.getUser().getImgUrl() == null) {
return ApiUtils.success(ArticleResponse.toDto(saveArticle));
}
String userImgUrl = articleService.getUserImgUrl(saveArticle.getUser().getImgUrl());
return ApiUtils.success(ArticleResponse.toDto(saveArticle, userImgUrl));
}

@GetMapping("/community")
@DeleteMapping("/article/{articleId}")
public ApiResponse<String> deleteArticle(@PathVariable Long articleId, @UserId Long userId){
articleService.hardDeleteByUserId(articleId, userId);
return ApiUtils.success("OK");
}

@GetMapping("")
public ApiResponse<List<CommunityArticle>> getArticleList(@RequestParam(required = false) String title,//검색어
@RequestParam(defaultValue = "0") int page, // 페이지 번호, 기본값은 0
@RequestParam(defaultValue = "5") int size, // 페이지 크기, 기본값은 5
@RequestParam(value = "orderCriteria", defaultValue = "CREATED_AT_DESC") ORDER_CRITERIA orderCriteria){
List<Article> articleList = articleService.findArticleByUserIdAndOrderAndPage(title, page, size, orderCriteria);
List<CommunityArticle> communityArticleList = articleList.stream().map(CommunityArticle::toDto).toList();
@RequestParam(defaultValue = "0") int page, // 페이지 번호, 기본값은 0
@RequestParam(defaultValue = "5") int size, // 페이지 크기, 기본값은 5
@RequestParam(value = "orderCriteria", defaultValue = "CREATED_AT_DESC") ORDER_CRITERIA orderCriteria,
@RequestParam(defaultValue = "false") Boolean isMyArticle,
@UserId Long userId) {
List<Article> articleList = articleService.findArticleByUserIdAndOrderAndPage(title, page, size, orderCriteria, isMyArticle, userId);
List<CommunityArticle> communityArticleList = articleList.stream().map(article -> {
if (article.getUser().getImgUrl() == null) {
return CommunityArticle.toDto(article);
}
String userImgUrl = articleService.getUserImgUrl(article.getUser().getImgUrl());
return CommunityArticle.toDto(article, userImgUrl);
}).toList();
return ApiUtils.success(communityArticleList);
}

@GetMapping("/article/menu/{articleMenuId}")
public ApiResponse<ArticleMenuResponse> getSharedArticleMenu(@PathVariable Long articleMenuId){
ArticleMenu articleMenu = articleService.addSharedCount(articleMenuId);

return ApiUtils.success(ArticleMenuResponse.toDto(articleMenu));
}

@PostMapping("/article/menu/{articleMenuId}")
public ApiResponse<DownloadArticleMenuResponse> downloadArticleMenu(@PathVariable Long articleMenuId,
@RequestBody DownloadArticleMenu downloadArticleMenu,
@UserId Long userId){
Long groupId = articleService.downloadMenus(articleMenuId, downloadArticleMenu, userId);

return ApiUtils.success(DownloadArticleMenuResponse.toDto(groupId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class ArticleMenuRequest {
private String menuImgUrl;
private String menuAddress;

private String menuMemoTitle;
private String menuIconType;
private String placeMemo;
private double placeLatitude;
private double placeLongitude;


public static ArticleMenu toEntity(ArticleMenuRequest articleMenuRequest){
return ArticleMenu.builder()
Expand All @@ -27,6 +33,11 @@ public static ArticleMenu toEntity(ArticleMenuRequest articleMenuRequest){
.price(articleMenuRequest.getMenuPrice())
.imgUrl(articleMenuRequest.getMenuImgUrl())
.address(articleMenuRequest.getMenuAddress())
.menuMemoTitle(articleMenuRequest.getMenuMemoTitle())
.menuIconType(articleMenuRequest.getMenuIconType())
.placeMemo(articleMenuRequest.getPlaceMemo())
.placeLatitude(articleMenuRequest.getPlaceLatitude())
.placeLongitude(articleMenuRequest.getPlaceLongitude())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ourMenu.backend.domain.article.api.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
public class DownloadArticleMenu {

private List<Long> articleMenuIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,33 @@
@AllArgsConstructor
public class ArticleMenuResponse {

private Long articleMenuId;
private String placeTitle;
private String menuTitle;
private int menuPrice;
private String menuImgUrl;
private String menuAddress;
private int sharedCount;

private String menuMemoTitle;
private String menuIconType;
private String placeMemo;
private double placeLatitude;
private double placeLongitude;
public static ArticleMenuResponse toDto(ArticleMenu articleMenu){
return ArticleMenuResponse.builder()
.articleMenuId(articleMenu.getId())
.placeTitle(articleMenu.getPlaceTitle())
.menuTitle(articleMenu.getTitle())
.menuPrice(articleMenu.getPrice())
.menuImgUrl(articleMenu.getImgUrl())
.menuAddress(articleMenu.getAddress())
.sharedCount(articleMenu.getSharedCount())
.menuMemoTitle(articleMenu.getMenuMemoTitle())
.menuIconType(articleMenu.getMenuIconType())
.placeMemo(articleMenu.getPlaceMemo())
.placeLatitude(articleMenu.getPlaceLatitude())
.placeLongitude(articleMenu.getPlaceLongitude())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ArticleResponse {

private Long articleId;
private String articleTitle;
private String userEmail;
private String userNickname;
private String userImgUrl;
private LocalDateTime createdBy;
Expand All @@ -26,6 +27,28 @@ public class ArticleResponse {
private int articleViews;
List<ArticleMenuResponse> articleMenus;

public static ArticleResponse toDto(Article article, String userImgUrl) {
String menuImg = null;
for (ArticleMenu articleMenu : article.getArticleMenuList()) {
if (articleMenu.getImgUrl() != null) {
menuImg = articleMenu.getImgUrl();
break;
}
}
return ArticleResponse.builder()
.articleId(article.getId())
.articleTitle(article.getTitle())
.userEmail(article.getUser().getEmail())
.userNickname(article.getUser().getNickname())
.userImgUrl(userImgUrl)
.createdBy(article.getCreatedAt())
.articleContent(article.getContent())
.articleThumbnail(menuImg)
.articleViews(article.getViews())
.articleMenus(article.getArticleMenuList().stream().map(ArticleMenuResponse::toDto).toList())
.build();
}

public static ArticleResponse toDto(Article article) {
String menuImg = null;
for (ArticleMenu articleMenu : article.getArticleMenuList()) {
Expand All @@ -37,8 +60,8 @@ public static ArticleResponse toDto(Article article) {
return ArticleResponse.builder()
.articleId(article.getId())
.articleTitle(article.getTitle())
.userEmail(article.getUser().getEmail())
.userNickname(article.getUser().getNickname())
.userImgUrl(article.getUser().getImgUrl())
.createdBy(article.getCreatedAt())
.articleContent(article.getContent())
.articleThumbnail(menuImg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ public class CommunityArticle {
private int articleViews;
private String articleThumbnail;

public static CommunityArticle toDto(Article article, String userImgUrl){
String menuImg = null;
for (ArticleMenu articleMenu : article.getArticleMenuList()) {
if (articleMenu.getImgUrl() != null) {
menuImg = articleMenu.getImgUrl();
break;
}
}
return CommunityArticle.builder()
.articleId(article.getId())
.articleTitle(article.getTitle())
.articleContent(article.getContent())
.userNickname(article.getUser().getNickname())
.userImgUrl(userImgUrl)
.createdBy(article.getCreatedAt())
.menusCount(article.getMenuCount())
.articleViews(article.getViews())
.articleThumbnail(menuImg)
.build();
}

public static CommunityArticle toDto(Article article){
String menuImg = null;
for (ArticleMenu articleMenu : article.getArticleMenuList()) {
Expand All @@ -38,7 +59,6 @@ public static CommunityArticle toDto(Article article){
.articleTitle(article.getTitle())
.articleContent(article.getContent())
.userNickname(article.getUser().getNickname())
.userImgUrl(article.getUser().getImgUrl())
.createdBy(article.getCreatedAt())
.menusCount(article.getMenuCount())
.articleViews(article.getViews())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ourMenu.backend.domain.article.api.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@AllArgsConstructor
@Builder
public class DownloadArticleMenuResponse {

public Long menuGroupId;

public static DownloadArticleMenuResponse toDto(Long groupId) {
return DownloadArticleMenuResponse.builder()
.menuGroupId(groupId)
.build();
}
}
Loading

0 comments on commit ab5f3a1

Please sign in to comment.