Skip to content
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

[review] f1-washpedia #144

Open
wants to merge 24 commits into
base: refactor/review
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ddd61fb
feature: 만약 버전은 어떻게 관리할 수 있을까 ?
YunNote Feb 17, 2024
c2a17d0
feature: 바로 return
YunNote Feb 17, 2024
f1d0672
feature: true만씀
YunNote Feb 17, 2024
07cb76d
feature: 사용하지 않음
YunNote Feb 17, 2024
c4e1569
feature: Objects 클래스 사용
YunNote Feb 17, 2024
19a24d0
feature: Objects 클래스 사용
YunNote Feb 17, 2024
c90f43c
feature: 오탈자
YunNote Feb 17, 2024
82db412
feature: 복수형으로 작성되어야 할듯
YunNote Feb 17, 2024
e0fcb63
feature: Pageable 에 대해서 직접 class 로 구현하여 사용해보시는건 어떨까요
YunNote Feb 17, 2024
1fc0f4e
feature: 미사용 메서드 제거
YunNote Feb 17, 2024
060196a
feature: Response 네이밍
YunNote Feb 17, 2024
5af31d2
feature: API url 복수형. 미사용 서비스 제거, mypage가 필요한지?
YunNote Feb 17, 2024
44918ee
feature: 고정된 response에 대해서 class로 반환하는건 어떨까요?
YunNote Feb 17, 2024
4d7d388
feature: 비밀번호에 대한 Validation 처리
YunNote Feb 17, 2024
789b0cb
feature: Mapper의 활용은 ?
YunNote Feb 17, 2024
927b0e7
feature: config설정은 따로 패키지에 분리
YunNote Feb 17, 2024
3afa661
feature: dto 명칭 대신 request, String 대신 Enum을 받아버림
YunNote Feb 17, 2024
dd9617a
feature: 정적 팩토리 메서드
YunNote Feb 17, 2024
e90ba9f
feature: 정적 팩토리 메서드
YunNote Feb 17, 2024
c4daa01
feature: null에 대한 여러가지 처리
YunNote Feb 17, 2024
d3cd247
feature: 전반적인 Validation 처리 필요
YunNote Feb 17, 2024
a4773a2
feature: 전체리스트 조회와, search를통한 조회 결과같이 항상 같은방향으로 개발이 되는지?
YunNote Feb 17, 2024
71676fa
feature: 컬럼
YunNote Feb 17, 2024
242c2f1
feature: 컬럼
YunNote Feb 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
public class CommonCodeController {

private final CommonCodeService commonCodeService;

//
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

만약 버저닝을 해야한다면 어떻게 관리할 수 있을까요?
URL로도 관리할 수 있지만 header를 통해서도 관리하는 방법에 대해 보시면 좋을것 같습니다!

@GetMapping("/{codeName}")
public ResponseEntity<ApiResponse<List<CommonCodeDto>>> getCommonCode (@PathVariable String codeName){

//
List<CommonCodeDto> codes = commonCodeService.getCodes(codeName);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반환타입을 저장하는 변수를 만드는것도 좋지만 사용처가 없다면 바로 return 문에 넣어주는것은 어떨까요 ?return
ApiResponse.toResponseEntity(GET_COMMON_CODE_SUCCESS, commonCodeService.getCodes(codeName));


return ApiResponse.toResponseEntity(GET_COMMON_CODE_SUCCESS, codes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public class CommonCodeService {

public List<CommonCodeDto> getCodes(String codeName) {

//
return commonCodeRepository.findAllByUpperNameAndIsUsed(codeName,true)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

항상 true만 반환하는데 spring data jpa 에서 제공하는 true를 그냥 써도 될것같습니다!

참고 사이트 전달드립니다

.stream()
.map(CommonCodeDto::from)
.toList();
}

//
public List<CommonCodeDto> getCodesMapper(String codeName) {

return commonCodeMapper.findAllByUpperNameAndIsUsed(codeName,true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
boolean result = true;
String requestToken = request.getHeader("Authorization");

//
if (requestToken == null || requestToken.isEmpty()) { throw new BusinessException(AcceptInterceptorErrorCode.DOSE_NOT_EXIST_REQUEST_TOKEN); }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects.isNull 을 활용하여 null에 대해 명시적으로 관리하면 좋을것 같습니다! 또한 2가지 조건에대해서도 처리 가능합니다!


if (!validRequestToken(requestToken)) { throw new BusinessException(AcceptInterceptorErrorCode.FAILED_VALID_REQUEST_TOKEN); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@
@RestController
@RequestMapping
@RequiredArgsConstructor

//
public class MainContoller {
chan99k marked this conversation as resolved.
Show resolved Hide resolved
private final ProductService productService;
private final MainService mainService;

//
@GetMapping("/banner")
ResponseEntity<ApiResponse<BannerDto>> getBanner() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API는 복수형으로 작성하시는걸 추천드립니다


return ApiResponse.toResponseEntity(BannerBusinessCode.GET_BANNER_DATA_SUCCESS, mainService.getBanner());
}


@GetMapping("/recommend-products")
//
ResponseEntity<ApiResponse<Page<RecommendProductsDto>>> getRecommendProducts(Pageable pageable) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pageable를 바로사용해도 좋지만 클래스로 만들어서 Custom하게 사용할 수 있도록 해보시는것도 좋아보입니다!

Page<RecommendProductsDto> recommendProductList = productService.getRecommendProductList(pageable);

Expand All @@ -37,6 +42,8 @@ ResponseEntity<ApiResponse<Page<RecommendProductsDto>>> getRecommendProducts(Pag
}

@GetMapping("/products/rank")

//
ResponseEntity<ApiResponse<Page<ProductDto>>> getProducts(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controller에서 반환하는 Response타입명을 DTO를 제거하고 Response를 붙여 보시는건 어떠세요?

@RequestParam(name = "sortType", defaultValue = "viewCnt-order") Sort sortType, Pageable pageable) {
Page<ProductDto> productDtos = sortType.sort(productService, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.domain.Pageable;


//
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort가 Enum인데 패키지의 위치가 controller에 있습니다. 패키지의 위치 조절이 필요해 보입니다 .

public enum Sort {

VIEW_COUNT_PRODUCT_ORDER("viewCnt-order") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.Optional;

//
@Configuration
public class AuditConfig implements AuditorAware<String> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
/**
* DTO for {@link com.kernel360.member.entity.Member}
*/


public record MemberDto(Long memberNo,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request용으로 사용하고 있다면 Dto라는 명 대신 Request로 변경하는것은 어떠세요?

String id,
String email,
String password,
//
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String 대신 Enum이 있다면 Enum으로 받는것도 추천드립니다.
Enum Value로 들어오면 매칭도 시켜주기 때문에 서비스 코드에서 존재하는지 확인할 필요가 없습니다.

참고 - https://www.baeldung.com/spring-enum-request-param

String gender,
String age,
LocalDate createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ static MemberInfo of(
return new MemberInfo(id, email, gender, age);
}


//
public Member toEntity() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entity를 만드는 책임을 Request 대신 Mapper와 같이 생성하는 클래스를 만들어보시면 어떨까요 ?

return Member.of(
this.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected Member getNewJoinMemberEntity(MemberDto requestDto) {
int ageOrdinal;

try {
// enum으로 받으면 다음과 같은 작업을 할 필요가 없음 .
genderOrdinal = Gender.valueOf(requestDto.gender()).ordinal();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum으로 Request를 받는다면 해당 부분은 자연스럽게 없어도 될것 같습니다!

ageOrdinal = Age.valueOf(requestDto.age()).ordinal();
} catch (Exception e) {
Expand Down Expand Up @@ -124,6 +125,8 @@ public boolean idDuplicationCheck(String id) {

@Transactional(readOnly = true)
public boolean emailDuplicationCheck(String email) {

//
Member member = memberRepository.findOneByEmail(email);

return member != null;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 null처리 하는 부분도 여러가지로 보면 좋을듯 합니다.

  • return Objects.nonNull(member);
  • return memberRepository.existMemberByEmail(email) 과 같이 메서드 레벨 반환

Expand Down Expand Up @@ -188,6 +191,7 @@ public Map<String, Object> getCarInfo(String token) {
Member member = memberRepository.findOneById(id);
CarInfoDto carInfoDto = CarInfoDto.from(member.getCarInfo());

//
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고정된 값들을 반환하는것 같은데 class로 분리해보심이 어떠실까요 ?

return Map.of(
"car_info", carInfoDto,
"segment_options", commonCodeService.getCodes("segment"),
Expand All @@ -200,6 +204,7 @@ public Map<String, Object> getCarInfo(String token) {

@Transactional
public void saveWashInfo(WashInfoDto washInfoDto, String token) {
//
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST 및 PUT에 대해서 전반적인 값에 대한 validation처리가 필요할듯합니다.
등록 및 수정에서 올바르지 않은 값들이 DB에 들어가면 원하지 않은 에러들을 마주할 확률이 높습니다.
따라서 등록 및 수정에서는 validation처리가 타이트하게 들어가는것이 좋을것 같습니다

String id = JWT.ownerId(token);
Member member = memberRepository.findOneById(id);
WashInfo washInfo = WashInfo.of(washInfoDto.washNo(), washInfoDto.washCount(), washInfoDto.monthlyExpense(), washInfoDto.interest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

@Slf4j
@RestController
//
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypage라는 URL을 표기해야 하는지 url에 대한 재정의도 해보면 좋을것 같습니다.
client 입장에서는 "내 정보" 가 되기때문에 /members를 통해서만 접근해보는건 어떻게 생각하시나요 ?

@RequestMapping("/mypage")
@RequiredArgsConstructor
public class MyPageController {
private final MemberService memberService;

//
private final ProductService productService;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미사용 서비스는 제거하면 좋을것 같습니다!


@GetMapping("/member")
Expand All @@ -45,6 +48,7 @@ ResponseEntity<ApiResponse<Void>> memberDelete(@RequestHeader("Authorization") S


@PostMapping("/member")
//
ResponseEntity<ApiResponse<String>> validatePassword(@RequestBody String password, @RequestHeader("Authorization") String authToken) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

비밀번호를 단건으로전달받더라도 class로 받아 validation처리를 축해주시면 좋을것 같습니다.
비밀번호 형식 및 길이등에 대해서 Request 레벨에서 validation처리가 가능합니다.

memberService.changePassword(password, authToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ProductController {

private final ProductService productService;

//
@GetMapping("/products")
ResponseEntity<ApiResponse<List<ProductDto>>> findProductList(){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProductDto를 2개 이상의 컨트롤러에서 같이 사용하고 있습니다.
해당 Response에서 고려해보면 좋을만한 내용은 다음과 같습니다.

  • API가 개발진행됨에 따라 2개의 API가 동일한 방향으로 Response가 개발되는지?

만약 조금이라도 다른방향으로 개발이 진행된다면 해당 API는 변경이 필요할것 같습니다!.

저는 개인적으로 API와 Request,Response는 한쌍으로 작업하는 편입니다! 참고부탁드립니다!

final List<ProductDto> productDtoList = productService.getProductList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Auth extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "auth_id_gen")
@SequenceGenerator(name = "auth_id_gen", sequenceName = "auth_auth_no_seq")

//
@Column(name = "auth_no", nullable = false)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JPA기본 설정시 underscore로 할지 camelcase로 컬럼명을 지정할지 정의할 수 있습니다
해당 옵션을 확인해보면 @column을 줄일 수 있을듯 합니다.

참고 - https://mycup.tistory.com/237

private Long authNo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@Getter
@MappedSuperclass
// 중복
@EntityListeners(AuditingEntityListener.class)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 설정이 중복되어 설정되어있는듯합니다.
spring application root에 설정 or configuration 파일에 단건 설정해주시는것도 좋을듯합니다.

public class BaseRawEntity {
// FIXME :: createdAt 자동 생성시, update 로직 진행중에 null or transient 문제가 발생. 임시방편으로 직접 지정하였으나 이후 수정 필요
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public static Member createJoinMember(String id, String email, String password,
/**
* joinMember Binding
**/
//
private Member(String id, String email, String password, int gender, int age) {
this.id = id;
this.email = email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
public interface ProductRepository extends JpaRepository<Product, Long> {
Page<Product> findByProductNameContaining(String keyword, Pageable pageable);

//
Page<Product> findAllByOrderByViewCountDesc(Pageable pageable);

Page<Product> findTop5ByOrderByProductNameDesc(Pageable pageable);

Page<Product> findAllBySafetyStatusEquals(SafetyStatus safetyStatus, Pageable pageable);

Page<Product> findAllByOrderByCreatedAtDesc(Pageable pageable);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미사용 메서드들은 제거해보시는거 어떨까요


@Query(value = "SELECT p FROM Product p WHERE p.productName = :productName "
Expand Down