Skip to content

Commit

Permalink
Merge pull request #291 from HyunJunSon/feature/admin/member
Browse files Browse the repository at this point in the history
Feature:: Admin 회원관리 api 추가
  • Loading branch information
HyunJunSon authored Mar 14, 2024
2 parents 312e271 + 6989428 commit 5f18490
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kernel360.member.code;

import com.kernel360.code.BusinessCode;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

@RequiredArgsConstructor
public enum MemberBusinessCode implements BusinessCode {

SUCCESS_REQUEST_ALL_MEMBER_LIST(HttpStatus.OK.value(), "BMC001", "전체회원목록 조회 성공");

private final int status;
private final String code;
private final String message;

@Override
public int getStatus() {
return status;
}

@Override
public String getCode() {
return code;
}

@Override
public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.kernel360.member.controller;

import com.kernel360.member.code.MemberBusinessCode;
import com.kernel360.member.dto.MemberResponse;
import com.kernel360.member.service.MemberService;
import com.kernel360.response.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin")
public class MemberController {

private final MemberService memberService;

@GetMapping("members")
public ResponseEntity<ApiResponse<Page<MemberResponse>>> getMemberList(Pageable pageable) {
Page<MemberResponse> members = memberService.getAllMembers(pageable);

return ApiResponse.toResponseEntity(MemberBusinessCode.SUCCESS_REQUEST_ALL_MEMBER_LIST, members);
}
}
46 changes: 46 additions & 0 deletions module-admin/src/main/java/com/kernel360/member/dto/MemberDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.kernel360.member.dto;


import java.time.LocalDateTime;


public record MemberDto(Long memberNo,
String id,
String email,
String password,
String gender,
String age,
LocalDateTime createdAt,
String createdBy,
LocalDateTime modifiedAt,
String modifiedBy
) {

public static MemberDto of(
Long memberNo,
String id,
String email,
String password,
String gender,
String age,
LocalDateTime createdAt,
String createdBy,
LocalDateTime modifiedAt,
String modifiedBy
) {
return new MemberDto(
memberNo,
id,
email,
password,
gender,
age,
createdAt,
createdBy,
modifiedAt,
modifiedBy
);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.kernel360.member.dto;


import com.kernel360.carinfo.entity.CarInfo;
import com.kernel360.washinfo.entity.WashInfo;
import com.querydsl.core.annotations.QueryProjection;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class MemberResponse {
private Long memberNo;
private String id;
private String email;
private int gender;
private int age;
private LocalDateTime registerDate;
private String accountType;
private WashInfo washInfo;
private CarInfo carInfo;
@QueryProjection
public MemberResponse(Long memberNo, String id, String email, int gender, int age, LocalDateTime registerDate,
String accountType, WashInfo washInfo, CarInfo carInfo) {
this.memberNo = memberNo;
this.id = id;
this.email = email;
this.gender = gender;
this.age = age;
this.registerDate = registerDate;
this.accountType = accountType;
this.washInfo = washInfo;
this.carInfo = carInfo;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.kernel360.member.dto;

import com.kernel360.carinfo.entity.CarInfo;
import com.kernel360.washinfo.entity.WashInfo;
import lombok.Builder;

import java.time.LocalDateTime;

@Builder
public record MemberSearchDto(
String id,
String name,
String email,
String age,
LocalDateTime registerDate,
WashInfo washInfo,
CarInfo carInfo
) {
}
16 changes: 16 additions & 0 deletions module-admin/src/main/java/com/kernel360/member/enumset/Age.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kernel360.member.enumset;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum Age {
AGE_20(20),
AGE_30(30),
AGE_40(40),
AGE_50(50),
AGE_60(60),
AGE_99(99);

private final int value;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kernel360.member.enumset;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum Gender {
MALE(0),
FEMALE(1),
OTHERS(99);

private final int value;

}
23 changes: 23 additions & 0 deletions module-admin/src/main/java/com/kernel360/member/enumset/Sort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.kernel360.member.enumset;

public enum Sort {
ID_ORDER("id-order"),
GENDER_ORDER("gender-order"),
AGE_ORDER("age-order"),
REGISTER_ORDER("register-order"),
RECENT_PRODUCT_ORDER("recent-order");


private final String orderType;

Sort(String orderType) {
this.orderType = orderType;
}

public String getOrderType() {
return orderType;
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.kernel360.member.repository;


public interface MemberRepository extends MemberRepositoryJpa, MemberRepositoryDsl {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kernel360.member.repository;

import com.kernel360.member.dto.MemberResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface MemberRepositoryDsl {
Page<MemberResponse> findAllMember(Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.kernel360.member.repository;


import com.kernel360.member.dto.MemberResponse;
import com.kernel360.member.dto.QMemberResponse;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;

import java.util.List;

import static com.kernel360.carinfo.entity.QCarInfo.*;
import static com.kernel360.member.entity.QMember.*;
import static com.kernel360.washinfo.entity.QWashInfo.*;


@RequiredArgsConstructor
public class MemberRepositoryImpl implements MemberRepositoryDsl {

private final JPAQueryFactory query;

@Override
public Page<MemberResponse> findAllMember(Pageable pageable) {
List<MemberResponse> members = query.select(new QMemberResponse(
member.memberNo,
member.id,
member.email,
member.gender,
member.age,
member.createdAt,
member.accountType,
washInfo,
carInfo
))
.from(member)
.leftJoin(member.washInfo, washInfo).on(isWashInfoNotNull())
.leftJoin(member.carInfo, carInfo).on(isCarInfoNotNull())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(member.memberNo.desc())
.fetch();

return PageableExecutionUtils.getPage(members, pageable, members::size);
}

private static BooleanExpression isCarInfoNotNull() {
return member.carInfo.carNo.isNotNull();
}

private static BooleanExpression isWashInfoNotNull() {
return member.washInfo.washNo.isNotNull();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.kernel360.member.service;

import com.kernel360.member.dto.MemberResponse;
import com.kernel360.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


@Slf4j
@Service
@RequiredArgsConstructor
public class MemberService {

private final MemberRepository memberRepository;

public Page<MemberResponse> getAllMembers(Pageable pageable) {

return memberRepository.findAllMember(pageable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.kernel360.review.repository;

public interface ReviewRepository extends ReviewRepositoryJpa, ReviewRepositoryDsl{
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kernel360.review.respository;
package com.kernel360.review.repository;

import com.kernel360.review.dto.ReviewSearchDto;
import com.kernel360.review.entity.Review;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kernel360.review.respository;
package com.kernel360.review.repository;

import static com.kernel360.review.entity.QReview.review;

Expand All @@ -9,7 +9,6 @@
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.function.LongSupplier;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.kernel360.review.code.ReviewErrorCode;
import com.kernel360.review.dto.AdminReviewDto;
import com.kernel360.review.dto.ReviewSearchDto;
import com.kernel360.review.respository.ReviewRepository;
import com.kernel360.review.repository.ReviewRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ public KakaoUserDto getKakaoUserByToken(String accessToken) {
}
Map<String, Object> kakaoAccount = mapper.convertValue(kakaoResponse.get("kakao_account"), HashMap.class);

KakaoUserDto dto = KakaoUserDto.of(kakaoResponse.get("id").toString(),kakaoAccount.get("email").toString());
return KakaoUserDto.of(kakaoResponse.get("id").toString(),kakaoAccount.get("email").toString());

return dto;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kernel360.member.entity;
package com.kernel360.admin.entity;


import com.kernel360.base.BaseEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kernel360.admin.repository;

import com.kernel360.admin.entity.Admin;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AdminRepository extends JpaRepository<Admin,Long> {
}
Loading

0 comments on commit 5f18490

Please sign in to comment.