From c07cc6911c3c7fc61105c44b7a94a20b8025c72f Mon Sep 17 00:00:00 2001 From: minuk926 Date: Mon, 21 Mar 2022 14:34:21 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/ctgy/controller/BoardController.java | 51 +++++++++++++++ .../ctgy/controller/MinUserController.java | 64 +++++++++++++++++++ .../ctgy/repository/IMinUserRepository.java | 23 +++++++ .../xit/biz/ctgy/service/IBoardService.java | 11 ++++ .../xit/biz/ctgy/service/IMinUserService.java | 15 +++++ .../biz/ctgy/service/impl/MinUserService.java | 48 ++++++++++++++ 6 files changed, 212 insertions(+) create mode 100644 src/main/java/com/xit/biz/ctgy/controller/BoardController.java create mode 100644 src/main/java/com/xit/biz/ctgy/controller/MinUserController.java create mode 100644 src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java create mode 100644 src/main/java/com/xit/biz/ctgy/service/IBoardService.java create mode 100644 src/main/java/com/xit/biz/ctgy/service/IMinUserService.java create mode 100644 src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java diff --git a/src/main/java/com/xit/biz/ctgy/controller/BoardController.java b/src/main/java/com/xit/biz/ctgy/controller/BoardController.java new file mode 100644 index 0000000..421c384 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/controller/BoardController.java @@ -0,0 +1,51 @@ +package com.xit.biz.ctgy.controller; + +import com.xit.biz.ctgy.dto.MinCivBoard680Dto; +import com.xit.biz.ctgy.dto.struct.MinCivBoard680Mapstruct; +import com.xit.biz.ctgy.service.IBoardService; +import com.xit.core.api.IRestResponse; +import com.xit.core.api.RestResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.mapstruct.factory.Mappers; +import org.springframework.data.domain.Pageable; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "MinCivBoard680Controller", description = "게시글 관리") +@RestController +@RequestMapping("/api/v1/ctgy/board") +@Validated +@RequiredArgsConstructor +public class BoardController { + + private final IBoardService service; + + private final MinCivBoard680Mapstruct mapstruct = Mappers.getMapper(MinCivBoard680Mapstruct.class); + + // TODO :: 파라메터 정의 필요 + @Operation(summary = "게시글 목록 조회" , description = "게시글 목록 조회") + @Parameters({ + @Parameter(in = ParameterIn.QUERY, name = "ciTitle", description = "제목", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "ciName", description = "이름", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), + @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") + }) + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findMinCivBoard680s( + @Parameter(hidden = true) + final MinCivBoard680Dto dto, + @Parameter(hidden = true) + final Pageable pageable) { + return RestResponse.of(service.findAll(mapstruct.toEntity(dto), pageable)); + } + +} diff --git a/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java b/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java new file mode 100644 index 0000000..8fa1767 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/controller/MinUserController.java @@ -0,0 +1,64 @@ +package com.xit.biz.ctgy.controller; + +import com.xit.biz.ctgy.dto.MinUserinfoDto; +import com.xit.biz.ctgy.dto.struct.MinUserinfoMapstruct; +import com.xit.biz.ctgy.service.IMinUserService; +import com.xit.core.annotation.Secured; +import com.xit.core.annotation.SecurityPolicy; +import com.xit.core.api.IRestResponse; +import com.xit.core.api.RestResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.mapstruct.factory.Mappers; +import org.springframework.data.domain.Pageable; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "MinUserinfoController", description = "사용자 관리") +@RestController +@RequestMapping("/api/v1/ctgy/user") +@Validated +@RequiredArgsConstructor +public class MinUserController { + + private final IMinUserService service; + + private final MinUserinfoMapstruct mapstruct = Mappers.getMapper(MinUserinfoMapstruct.class); + + // TODO :: 파라메터 정의 필요 + @Operation(summary = "사용자 목록 조회" , description = "사용자 목록 조회") + @Parameters({ + @Parameter(in = ParameterIn.QUERY, name = "userid", description = "사용자ID", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "name", description = "이름", required = false, example = " "), + @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), + @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") + }) + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity findMinUserinfos( + @Parameter(hidden = true) + @ModelAttribute("minUserinfoDto") + final MinUserinfoDto minUserinfoDto, + @Parameter(hidden = true) + final Pageable pageable) { + return RestResponse.of(service.findMinUsers(mapstruct.toEntity(minUserinfoDto), pageable)); + } + + @Operation(summary = "사용자 정보 조회" , description = "사용자 정보 조회") + @GetMapping("/info") + @Secured(policy = SecurityPolicy.TOKEN) + @Transactional(readOnly = true) + public ResponseEntity getUserInfo() { + return RestResponse.of(service.findMyUserWithoutAuthorities()); + } + +} diff --git a/src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java b/src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java new file mode 100644 index 0000000..839f8a9 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/repository/IMinUserRepository.java @@ -0,0 +1,23 @@ +package com.xit.biz.ctgy.repository; + +import com.xit.biz.ctgy.entity.MinUserinfo; +import com.xit.core.oauth2.utils.SecurityUtil; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +public interface IMinUserRepository extends JpaRepository { + Optional findByUserid(String userid); + + @Query(value = "SELECT TRAFFIC.ECL_ENCRYPT(?1) AS passwd FROM DUAL C", nativeQuery = true) + //@Query(value = "SELECT ECL_ENCRYPT(?1) AS passwd", nativeQuery = true) + String queryGetPasswdEncode(@Param("passwd") String passwd); + + @Query(value = "SELECT ECL_DECRYPT(MU.passwd) AS passwd FROM min_userinfo MU WHERE MU.userid = ?1", nativeQuery = true) + String queryGetPasswd(@Param("userid") String userid); + + MinUserinfo findMinUserinfoByUserid(String userid); +} \ No newline at end of file diff --git a/src/main/java/com/xit/biz/ctgy/service/IBoardService.java b/src/main/java/com/xit/biz/ctgy/service/IBoardService.java new file mode 100644 index 0000000..17bac65 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/service/IBoardService.java @@ -0,0 +1,11 @@ +package com.xit.biz.ctgy.service; + +import com.xit.biz.ctgy.entity.MinCivBoard680; +import com.xit.core.support.jpa.IJpaOperation; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface IBoardService { + + Page findAll(MinCivBoard680 minCivBoard680, Pageable pageable); +} diff --git a/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java b/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java new file mode 100644 index 0000000..8c24f56 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/service/IMinUserService.java @@ -0,0 +1,15 @@ +package com.xit.biz.ctgy.service; + +import com.xit.biz.cmm.entity.CmmUser; +import com.xit.biz.ctgy.entity.MinUserinfo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.Optional; + +public interface IMinUserService { + + Page findMinUsers(MinUserinfo minUserinfo, Pageable pageable); + + MinUserinfo findMyUserWithoutAuthorities(); +} diff --git a/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java b/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java new file mode 100644 index 0000000..e7a31d6 --- /dev/null +++ b/src/main/java/com/xit/biz/ctgy/service/impl/MinUserService.java @@ -0,0 +1,48 @@ +package com.xit.biz.ctgy.service.impl; + +import com.xit.biz.ctgy.entity.MinUserinfo; +import com.xit.biz.ctgy.repository.IMinUserRepository; +import com.xit.biz.ctgy.service.IMinUserService; +import com.xit.core.oauth2.utils.HeaderUtil; +import com.xit.core.support.jpa.JpaUtil; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains; + +@Service +public class MinUserService implements IMinUserService { + + private final IMinUserRepository repository; + + public MinUserService(IMinUserRepository repository) { + this.repository = repository; + } + + @Transactional//(readOnly = true) + public Page findMinUsers(MinUserinfo minUserinfo, Pageable pageable) { + //Sort sort = Sort.by(Sort.Direction.ASC, "codeOrdr"); + pageable = JpaUtil.getPagingInfo(pageable); + ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll() + .withMatcher("userid", contains()) + .withMatcher("name", contains()); + Example example = Example.of(minUserinfo, exampleMatcher); + Page page = repository.findAll(example, pageable); + // List userList = page.getContent(); + return page; + } + + @Override + @Transactional(readOnly = true) + public MinUserinfo findMyUserWithoutAuthorities() { + //cmmUserRepos + //return Optional.empty(); //cmmUserRepository.findOneWithAuthorities(SecurityUtil.getCurrentMemberId()); + return repository.findMinUserinfoByUserid(HeaderUtil.getUserId()); + } +}