사용자 관리 추가
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.kamco.cd.kamcoback.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||
import com.kamco.cd.kamcoback.auth.service.AuthService;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
@@ -11,12 +13,15 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "사용자 관리", description = "사용자 관리 API")
|
||||
@Tag(name = "관리자 관리", description = "관리자 관리 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/auth")
|
||||
@@ -24,12 +29,12 @@ public class AuthApiController {
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
@Operation(summary = "사용자 등록", description = "사용자를 등록 합니다.")
|
||||
@Operation(summary = "관리자 등록", description = "관리자 를 등록 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "사용자 등록 성공",
|
||||
description = "관리자 등록 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
@@ -41,7 +46,7 @@ public class AuthApiController {
|
||||
@PostMapping("/signup")
|
||||
public ApiResponseDto<Long> signup(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "사용자 정보",
|
||||
description = "관리자 정보",
|
||||
required = true,
|
||||
content =
|
||||
@Content(
|
||||
@@ -52,4 +57,57 @@ public class AuthApiController {
|
||||
AuthDto.Signup signup) {
|
||||
return ApiResponseDto.createOK(authService.signup(signup));
|
||||
}
|
||||
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = AuthDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@Operation(summary = "관리자 상세조회", description = "관리자 정보를 조회 합니다.")
|
||||
@GetMapping("/detail")
|
||||
public ApiResponseDto<AuthDto.Basic> getDetail(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "관리자 목록 id",
|
||||
required = true)
|
||||
@RequestParam
|
||||
Long id) {
|
||||
return ApiResponseDto.ok(authService.getFindUserById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "관리자 목록", description = "관리자 목록 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "검색 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Page.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 검색 조건", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/list")
|
||||
public ApiResponseDto<Page<Basic>> getUserList(
|
||||
@Parameter(description = "관리자 이름")
|
||||
@RequestParam(required = false) String userNm,
|
||||
@Parameter(description = "페이지 번호 (0부터 시작)", example = "0")
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@Parameter(description = "페이지 크기", example = "20")
|
||||
@RequestParam(defaultValue = "20") int size,
|
||||
@Parameter(description = "정렬 조건 (형식: 필드명,방향)", example = "name,asc")
|
||||
@RequestParam(required = false) String sort
|
||||
) {
|
||||
AuthDto.SearchReq searchReq = new AuthDto.SearchReq(userNm, page, size, sort);
|
||||
Page<AuthDto.Basic> userList = authService.getUserList(searchReq);
|
||||
return ApiResponseDto.ok(userList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package com.kamco.cd.kamcoback.auth.dto;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import java.time.ZonedDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class AuthDto {
|
||||
@@ -13,18 +20,23 @@ public class AuthDto {
|
||||
@Setter
|
||||
public static class Basic {
|
||||
|
||||
private Long id;
|
||||
private String userAuth;
|
||||
private String userNm;
|
||||
private String userId;
|
||||
private String empId;
|
||||
private String userEmail;
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime createdDttm;
|
||||
|
||||
public Basic(String userAuth, String userNm, String userId, String empId, String userEmail) {
|
||||
public Basic(Long id, String userAuth, String userNm, String userId, String empId, String userEmail, ZonedDateTime createdDttm) {
|
||||
this.id = id;
|
||||
this.userAuth = userAuth;
|
||||
this.userNm = userNm;
|
||||
this.userId = userId;
|
||||
this.empId = empId;
|
||||
this.userEmail = userEmail;
|
||||
this.createdDttm = createdDttm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +90,31 @@ public class AuthDto {
|
||||
String userId;
|
||||
String userPw;
|
||||
}
|
||||
|
||||
@Schema(name = "UserSearchReq", description = "관리자 목록 요청 정보")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class SearchReq {
|
||||
|
||||
// 검색 조건
|
||||
private String userNm;
|
||||
|
||||
// 페이징 파라미터
|
||||
private int page = 0;
|
||||
private int size = 20;
|
||||
private String sort;
|
||||
|
||||
public Pageable toPageable() {
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
String[] sortParams = sort.split(",");
|
||||
String property = sortParams[0];
|
||||
Sort.Direction direction =
|
||||
sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC;
|
||||
return PageRequest.of(page, size, Sort.by(direction, property));
|
||||
}
|
||||
return PageRequest.of(page, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.kamco.cd.kamcoback.auth.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.core.AuthCoreService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -15,7 +17,7 @@ public class AuthService {
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
/**
|
||||
* 사용자 등록
|
||||
* 관리자 등록
|
||||
*
|
||||
* @param signup
|
||||
* @return
|
||||
@@ -25,4 +27,22 @@ public class AuthService {
|
||||
signup.setUserPw(passwordEncoder.encode(signup.getUserPw()));
|
||||
return authCoreService.signup(signup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 시퀀스 id로 관리자 조회
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public AuthDto.Basic getFindUserById(Long id){
|
||||
return authCoreService.findUserById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 목록 조회
|
||||
* @param searchReq
|
||||
* @return
|
||||
*/
|
||||
public Page<Basic> getUserList(AuthDto.SearchReq searchReq) {
|
||||
return authCoreService.getUserList(searchReq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.auth.AuthRepository;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -12,7 +14,7 @@ public class AuthCoreService {
|
||||
private final AuthRepository authRepository;
|
||||
|
||||
/**
|
||||
* 사용자 등록
|
||||
* 관리자 등록
|
||||
*
|
||||
* @param signup
|
||||
* @return
|
||||
@@ -23,4 +25,23 @@ public class AuthCoreService {
|
||||
}
|
||||
return authRepository.signup(signup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 시퀀스 id로 관리자 조회
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public AuthDto.Basic findUserById(Long id){
|
||||
UserEntity entity = authRepository.findUserById(id).orElseThrow(() -> new EntityNotFoundException("관리자를 찾을 수 없습니다. " + id));
|
||||
return entity.toDto();
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 목록 조회
|
||||
* @param searchReq
|
||||
* @return
|
||||
*/
|
||||
public Page<AuthDto.Basic> getUserList(AuthDto.SearchReq searchReq) {
|
||||
return authRepository.getUserList(searchReq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class MapSheetAnalDataEntity {
|
||||
@Column(name = "anal_uid")
|
||||
private Long analUid;
|
||||
|
||||
@Column(name = "map_sheep_num")
|
||||
@Column(name = "map_sheet_num")
|
||||
private Long mapSheepNum;
|
||||
|
||||
@Column(name = "detecting_cnt")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -83,4 +84,17 @@ public class UserEntity {
|
||||
@NotNull
|
||||
@Column(name = "emp_id", nullable = false)
|
||||
private String empId;
|
||||
|
||||
public AuthDto.Basic toDto() {
|
||||
return new AuthDto.Basic(
|
||||
this.id,
|
||||
this.userAuth,
|
||||
this.userNm,
|
||||
this.userId,
|
||||
this.empId,
|
||||
this.userEmail,
|
||||
this.createdDttm
|
||||
) ;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface AuthRepositoryCustom {
|
||||
Long signup(AuthDto.Signup signup);
|
||||
|
||||
Optional<UserEntity> findByUserId(String userId);
|
||||
|
||||
Optional<UserEntity> findUserById(Long id);
|
||||
|
||||
Page<Basic> getUserList(AuthDto.SearchReq searchReq);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.auth;
|
||||
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto;
|
||||
import com.kamco.cd.kamcoback.auth.dto.AuthDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QUserEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.UserEntity;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@@ -15,7 +23,7 @@ public class AuthRepositoryImpl implements AuthRepositoryCustom {
|
||||
private final QUserEntity userEntity = QUserEntity.userEntity;
|
||||
|
||||
/**
|
||||
* 사용자 등록
|
||||
* 관리자 등록
|
||||
*
|
||||
* @param signup
|
||||
* @return
|
||||
@@ -42,7 +50,7 @@ public class AuthRepositoryImpl implements AuthRepositoryCustom {
|
||||
}
|
||||
|
||||
/**
|
||||
* 유저 아이디 조회
|
||||
* 유저 아이디로 조회
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
@@ -52,4 +60,59 @@ public class AuthRepositoryImpl implements AuthRepositoryCustom {
|
||||
return Optional.ofNullable(
|
||||
queryFactory.selectFrom(userEntity).where(userEntity.userId.eq(userId)).fetchOne());
|
||||
}
|
||||
|
||||
/**
|
||||
* 유저 시퀀스 id로 조회
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Optional<UserEntity> findUserById(Long id) {
|
||||
return Optional.ofNullable(
|
||||
queryFactory.selectFrom(userEntity).where(userEntity.id.eq(id)).fetchOne());
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 목록 조회
|
||||
* @param searchReq
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<Basic> getUserList(AuthDto.SearchReq searchReq) {
|
||||
Pageable pageable = searchReq.toPageable();
|
||||
BooleanBuilder builder = new BooleanBuilder();
|
||||
if (searchReq.getUserNm() != null && !searchReq.getUserNm().isEmpty()) {
|
||||
builder.and(likeName(userEntity, searchReq.getUserNm()));
|
||||
}
|
||||
|
||||
List<Basic> content =
|
||||
queryFactory
|
||||
.select(Projections.constructor(AuthDto.Basic.class,
|
||||
userEntity.id,
|
||||
userEntity.userAuth,
|
||||
userEntity.userNm,
|
||||
userEntity.userId,
|
||||
userEntity.empId,
|
||||
userEntity.userEmail,
|
||||
userEntity.createdDttm
|
||||
))
|
||||
.from(userEntity)
|
||||
.where(
|
||||
builder
|
||||
)
|
||||
.orderBy(userEntity.userId.asc())
|
||||
.fetch();
|
||||
|
||||
long total =
|
||||
queryFactory.select(userEntity.id).from(userEntity).where(builder).fetchCount();
|
||||
return new PageImpl<>(content, pageable, total);
|
||||
}
|
||||
|
||||
private BooleanExpression likeName(QUserEntity entity, String nameStr) {
|
||||
if (nameStr == null || nameStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// ex) WHERE LOWER(name) LIKE LOWER('%입력값%')
|
||||
return entity.userNm.containsIgnoreCase(nameStr.trim());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user