Skip to content

Commit

Permalink
Merge pull request #96 from potenday-project/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dongseoki authored Jan 8, 2024
2 parents fe16fbf + b17a8a3 commit 5b4cf2d
Show file tree
Hide file tree
Showing 33 changed files with 917 additions and 214 deletions.
2 changes: 1 addition & 1 deletion server/sql/231224_1450.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE alcohol_type
ADD `display_order` bigint DEFAULT NULL
ADD `display_order` int DEFAULT NULL
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.bside.bside_311.component;

import com.bside.bside_311.dto.AlcoholSearchCondition;
import com.bside.bside_311.entity.Alcohol;
import com.bside.bside_311.entity.AlcoholType;
import com.bside.bside_311.entity.Post;
import com.bside.bside_311.entity.PostAlcohol;
import com.bside.bside_311.entity.YesOrNo;
import com.bside.bside_311.repository.AlcoholRepository;
import com.bside.bside_311.repository.AlcoholTypeRepository;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class AlcoholManager {
private final AlcoholRepository alcoholRepository;
private final AlcoholTypeRepository alcoholTypeRepository;

public void connectAlcoholWithPost(Long alcoholNo, String alcoholFeature, Post post) {
Alcohol alcohol = alcoholRepository.findByIdAndDelYnIs(alcoholNo, YesOrNo.N).orElseThrow(
Expand All @@ -20,4 +27,22 @@ public void connectAlcoholWithPost(Long alcoholNo, String alcoholFeature, Post p
post.addPostAlcohol(postAlcohol);
alcohol.addPostAlcohol(postAlcohol);
}

public Page<Alcohol> searchAlcohol(Pageable pageable, String searchKeyword,
Long alcoholType) {
if (ObjectUtils.isNotEmpty(alcoholType)) {
AlcoholType alcoholType1 = alcoholTypeRepository.findByIdAndDelYnIs(alcoholType, YesOrNo.N)
.orElseThrow(
() -> new IllegalArgumentException(
"술 종류가 존재하지 않습니다."));
}
// 술 종류 fetch join
return alcoholRepository.searchAlcoholPage(AlcoholSearchCondition.builder()
.searchKeyword(
searchKeyword)
.alcoholType(
alcoholType)
.build(),
pageable);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bside.bside_311.component;

import com.bside.bside_311.dto.AttachDto;
import com.bside.bside_311.entity.Attach;
import com.bside.bside_311.entity.AttachType;
import com.bside.bside_311.entity.YesOrNo;
Expand All @@ -8,7 +9,10 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.bside.bside_311.util.ValidateUtil.resourceChangeableCheckByThisRequestToken;

Expand Down Expand Up @@ -50,4 +54,32 @@ public void deleteAttachesByRefNoAndAttachType(Long refNo, AttachType attachType
imageStorage.delete(attach.getPublicId());
}
}

public Map<Long, List<AttachDto>> getAttachInfoMapBykeysAndType(List<Long> keys,
AttachType attachType) {
List<Attach> attachList =
attachRepository.findByRefNoInAndAttachTypeIsAndDelYnIs(keys, attachType,
YesOrNo.N);
Map<Long, List<AttachDto>> kToAMap = new HashMap<>();
for (Attach attach : attachList) {
if (!kToAMap.containsKey(attach.getRefNo())) {
kToAMap.put(attach.getRefNo(), new ArrayList<>());
}
List<AttachDto> attachDtos = kToAMap.get(attach.getRefNo());
attachDtos.add(AttachDto.of(attach));
}
return kToAMap;
}

public List<AttachDto> getAttachListBykeyAndType(Long key,
AttachType attachType) {
List<Attach> attachList =
attachRepository.findByRefNoInAndAttachTypeIsAndDelYnIs(List.of(key), attachType,
YesOrNo.N);
List<AttachDto> attachDtos = new ArrayList<>();
for (Attach attach : attachList) {
attachDtos.add(AttachDto.of(attach));
}
return attachDtos;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.bside.bside_311.component;

import com.bside.bside_311.dto.GetPostsToOneMvo;
import com.bside.bside_311.dto.PostSearchCondition;
import com.bside.bside_311.entity.Post;
import com.bside.bside_311.entity.YesOrNo;
import com.bside.bside_311.repository.PostMybatisRepository;
import com.bside.bside_311.repository.PostRepository;
import com.bside.bside_311.util.AuthUtil;
import com.bside.bside_311.util.MessageUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@RequiredArgsConstructor
public class PostService {
private final PostRepository postRepository;
private final PostMybatisRepository postMybatisRepository;

public void savePost(Post post) {
postRepository.save(post);
}

public Post findPost(Long postNo) {
return postRepository.findByIdAndDelYnIs(postNo, YesOrNo.N).orElseThrow(
() -> new IllegalArgumentException(MessageUtil.POST_NOT_FOUND_MSG));
}

public void deletePost(Post post) {
post.setDelYn(YesOrNo.Y);
postRepository.save(post);
}

public Page<Post> getPostListCommon(Pageable pageable, String searchKeyword,
List<Long> searchUserNoList,
Boolean isLikedByMe, Boolean isCommentedByMe,
List<Long> searchAlcoholNoList) {
return postRepository.searchPageSimple(
PostSearchCondition.builder().searchKeyword(searchKeyword)
.searchUserNoList(searchUserNoList)
.isLikedByMe(isLikedByMe)
.isCommentedByMe(isCommentedByMe)
.myUserNo(
AuthUtil.getUserNoFromAuthentication())
.searchAlcoholNoList(searchAlcoholNoList)
.build(), pageable);
}

public Page<Post> getPostListPopular(Long page, Long size) {
return postRepository.searchPagePopular(page, size);
}

public Map<Long, GetPostsToOneMvo> getGetPostsToOneMvoMap(List<Long> postNos) {
List<GetPostsToOneMvo> postsToOneList =
CollectionUtils.isNotEmpty(postNos) ? postMybatisRepository.getPostsToOne(postNos) :
List.of();
Map<Long, GetPostsToOneMvo> postsToOneMap = new HashMap<>();
for (GetPostsToOneMvo getPostsToOneMvo : postsToOneList) {
postsToOneMap.put(getPostsToOneMvo.getPostNo(), getPostsToOneMvo);
}
return postsToOneMap;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bside.bside_311.component;

import com.bside.bside_311.entity.User;
import com.bside.bside_311.entity.YesOrNo;
import com.bside.bside_311.repository.UserRepository;
import com.bside.bside_311.util.MessageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

@Slf4j
@Component
@RequiredArgsConstructor
public class UserManager {
private final UserRepository userRepository;

public User getUser(Long userNo) {
if (ObjectUtils.isEmpty(userNo)) {
return null;
}
return userRepository.findByIdAndDelYnIs(userNo, YesOrNo.N).orElseThrow(
() -> new IllegalArgumentException(MessageUtil.USER_NOT_FOUND_MSG));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -102,9 +103,13 @@ public Page<AlcoholResponseDto> getAlcoholV2(
Pageable pageable,
@RequestParam(required = false, name = "searchKeyword")
@Schema(description = "키워드", example = "키워드")
String searchKeyword) {
String searchKeyword,
@RequestParam(required = false, name = "alcoholType")
@Schema(description = "술 타입(선택)", example = "1")
@Positive(message = "술 타입은 1이상의 숫자만 가능합니다.")
Long alcoholType) {
log.info(">>> AlcoholController.getAlcohol");
return alcoholService.getAlcoholV2(pageable, searchKeyword);
return alcoholService.getAlcoholV2(pageable, searchKeyword, alcoholType);
}

@Operation(summary = "[o]술 상세 조회", description = "술 상세 조회 API")
Expand Down
Loading

0 comments on commit 5b4cf2d

Please sign in to comment.