-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #96
Develop #96
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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( | ||
|
@@ -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); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위의 코드 패치를 간단히 검토해 드리겠습니다.
개선 제안:
수정된 public Page<Alcohol> searchAlcohol(Pageable pageable, String searchKeyword, Long alcoholType) {
if (ObjectUtils.isNotEmpty(alcoholType)) {
AlcoholType alcoholTypeEntity = alcoholTypeRepository.findByIdAndDelYnIs(alcoholType, YesOrNo.N)
.orElseThrow(() -> new IllegalArgumentException("술 종류가 존재하지 않습니다."));
// 알코올 유형이 유효한 경우 해당 유형에 따라 검색결과 반환
return alcoholRepository.searchAlcoholPage(AlcoholSearchCondition.builder()
.searchKeyword(searchKeyword)
.alcoholType(alcoholTypeEntity)
.build(),
pageable);
} else {
// 알코올 유형이 주어지지 않은 경우 모든 알코올 검색결과 반환
return alcoholRepository.searchAlcoholPage(AlcoholSearchCondition.builder()
.searchKeyword(searchKeyword)
.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; | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음은 코드 패치입니다. 버그 위험이나 개선 제안 사항을 알려주세요: @@ -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;
@@ -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;
@@ -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; | ||
} | ||
|
||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치는 PostService 클래스에 대한 변경 사항입니다. 아래는 코드 리뷰입니다:
개선 제안:
잠재적인 버그 위험 요소나 이외의 개선 사항은 제시된 코드에서 확인하기 어렵습니다. 전체 애플리케이션의 아키텍처와 다른 모듈들과의 상호 작용을 고려하여 추가적인 코드 리뷰가 필요할 것입니다. |
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)); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 리뷰를 진행하겠습니다:
개선 제안:
위 내용은 단순한 코드 리뷰입니다. 실제 애플리케이션에 적합한지는 전제 조건과 요구사항에 따라 다를 수 있습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드 패치는 다음과 같은 변경 사항을 포함하고 있습니다:
개선 및 버그 위험 사항에 대한 제안:
위의 사항들을 고려하여 코드를 개선할 수 있습니다. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드 패치는
alcohol_type
테이블에display_order
라는 열을 추가하는 ALTER TABLE 문입니다. 변경된 부분은 데이터 형식입니다. bigint 대신 int로 변경되었습니다.이러한 코드 리뷰에서 주의해야 할 사항은 다음과 같습니다:
개선 제안:
위의 정보를 참고하여 코드 패치를 검토해보세요.