fix: 사용자 관리 반영

dev
minuk926 3 years ago
parent 81320104c9
commit f5894c88df

@ -15,12 +15,15 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@Tag(name = "MinUserController", description = "사용자 관리") @Tag(name = "MinUserController", description = "사용자 관리")
@RestController @RestController
@RequestMapping("/api/v1/ctgy/user") @RequestMapping("/api/v1/ctgy/user")
@ -37,13 +40,13 @@ public class MinUserController {
@Parameters({ @Parameters({
@Parameter(in = ParameterIn.QUERY, name = "userid", description = "사용자ID", required = false, example = " "), @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 = "name", description = "이름", required = false, example = " "),
@Parameter(in = ParameterIn.QUERY, name = "team", description = "팀", required = false, example = "001"),
@Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"), @Parameter(in = ParameterIn.QUERY, name = "page", description = "페이지", required = true, example = "0"),
@Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10") @Parameter(in = ParameterIn.QUERY, name = "size", description = "페이지당갯수", required = true, example = "10")
}) })
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<? extends IRestResponse> findMinUsers( public ResponseEntity<? extends IRestResponse> findMinUsers(
@Parameter(hidden = true) @Parameter(hidden = true)
@ModelAttribute("minUserinfoDto")
final MinUserinfoDto minUserinfoDto, final MinUserinfoDto minUserinfoDto,
@Parameter(hidden = true) @Parameter(hidden = true)
final Pageable pageable) { final Pageable pageable) {
@ -64,4 +67,22 @@ public class MinUserController {
public ResponseEntity<? extends IRestResponse> getMinUser(@PathVariable final String userid) { public ResponseEntity<? extends IRestResponse> getMinUser(@PathVariable final String userid) {
return RestResponse.of(service.findMinUserByUserid(userid)); return RestResponse.of(service.findMinUserByUserid(userid));
} }
@Operation(summary = "사용자 정보 저장" , description = "사용자 정보 저장")
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<? extends IRestResponse> saveMinUser(
@Valid
final MinUserinfoDto minUserinfoDto) {
service.saveMinUser(minUserinfoDto);
return RestResponse.of(HttpStatus.OK);
}
@Operation(summary = "사용자 삭제" , description = "사용자 삭제")
@PutMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<? extends IRestResponse> removeMinUser(
@Valid
final MinUserinfoDto minUserinfoDto) {
service.removeMinUser(minUserinfoDto);
return RestResponse.of(HttpStatus.OK);
}
} }

@ -1,14 +1,10 @@
package com.xit.biz.ctgy.dto; package com.xit.biz.ctgy.dto;
import com.xit.biz.ctgy.entity.MinSimsaUser680;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
@Schema(name = "MinUserinfoDto", description = "사용자 DTO") @Schema(name = "MinUserinfoDto", description = "사용자 DTO")
@Getter @Getter
@ -51,6 +47,10 @@ public class MinUserinfoDto implements Serializable {
@Schema(required = false, title = "구청코드", example = " ", description = "Input Description...") @Schema(required = false, title = "구청코드", example = " ", description = "Input Description...")
private String gu; private String gu;
@Schema(required = true, title = "신규유저여부", example = "true", description = "신규유저여부: 'Y'인경우 id duplication check")
private String newYn;
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

@ -1,6 +1,5 @@
package com.xit.biz.ctgy.entity; package com.xit.biz.ctgy.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
@ -8,10 +7,10 @@ import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.domain.Persistable; import org.springframework.data.domain.Persistable;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.time.LocalDate;
import java.util.HashSet; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
@Schema(name = "MinUserinfo", description = "null") @Schema(name = "MinUserinfo", description = "null")
@Table(name = "min_userinfo", schema = "", catalog = "") @Table(name = "min_userinfo", schema = "", catalog = "")
@ -59,10 +58,11 @@ public class MinUserinfo implements Persistable<String> {
@Schema(required = false, title = "등록일시", example = " ", description = "Input Description...") @Schema(required = false, title = "등록일시", example = " ", description = "Input Description...")
@Column(name = "regdate", nullable = true) @Column(name = "regdate", nullable = true)
private java.sql.Date regdate; private LocalDate regdate;
@Schema(required = false, title = "사용여부", example = " ", description = "Input Description...") @Schema(required = false, title = "사용여부", example = " ", description = "Input Description...")
@Column(name = "isenable", nullable = true, length = 1) @Column(name = "isenable", nullable = true, length = 1)
@Setter
private String isenable; private String isenable;
@Schema(required = false, title = "구청코드", example = " ", description = "Input Description...") @Schema(required = false, title = "구청코드", example = " ", description = "Input Description...")
@ -81,20 +81,22 @@ public class MinUserinfo implements Persistable<String> {
} }
//@Transient @PrePersist
//@JsonIgnore public void onPrePersist(){
//@OneToMany(targetEntity = MinSimsaUser680.class, mappedBy = "minUserinfo") //, fetch = FetchType.EAGER)//, cascade = CascadeType.ALL, orphanRemoval = true) LocalDateTime localDateTime = LocalDateTime.now();
//private final Set<MinSimsaUser680> minSimsaUser680s = new HashSet<>(); this.regdate = LocalDate.parse(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
this.isenable = "1";
// public void addMinSimsaUser680(final MinSimsaUser680 minSimsaUser680){ this.gu = "680";
// minSimsaUser680s.add(minSimsaUser680); }
// minSimsaUser680.setMinUserinfo(this);
// } @PreUpdate
// public void onPreUpdate(){
// public void removeSimsaUser680(final MinSimsaUser680 minSimsaUser680){ // LocalDateTime localDateTime = LocalDateTime.now();
// minSimsaUser680s.remove(minSimsaUser680); // this.inNalja = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// minSimsaUser680.setMinUserinfo(null); // this.inTime = localDateTime.format(DateTimeFormatter.ofPattern("HH:mm"));
// } // this.inName = HeaderUtil.getUserName();
// this.inHit = this.inHit + 1;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {

@ -1,6 +1,7 @@
package com.xit.biz.ctgy.service; package com.xit.biz.ctgy.service;
import com.xit.biz.cmm.entity.CmmUser; import com.xit.biz.cmm.entity.CmmUser;
import com.xit.biz.ctgy.dto.MinUserinfoDto;
import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.biz.ctgy.entity.MinUserinfo;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -14,4 +15,8 @@ public interface IMinUserService {
MinUserinfo findMinUser(); MinUserinfo findMinUser();
MinUserinfo findMinUserByUserid(final String userId); MinUserinfo findMinUserByUserid(final String userId);
void saveMinUser(MinUserinfoDto dto);
void removeMinUser(MinUserinfoDto dto);
} }

@ -1,34 +1,35 @@
package com.xit.biz.ctgy.service.impl; package com.xit.biz.ctgy.service.impl;
import com.xit.biz.ctgy.dto.MinUserinfoDto;
import com.xit.biz.ctgy.dto.struct.MinUserinfoMapstruct;
import com.xit.biz.ctgy.entity.MinUserinfo; import com.xit.biz.ctgy.entity.MinUserinfo;
import com.xit.biz.ctgy.repository.IMinUserRepository; import com.xit.biz.ctgy.repository.IMinUserRepository;
import com.xit.biz.ctgy.service.IMinUserService; import com.xit.biz.ctgy.service.IMinUserService;
import com.xit.core.constant.ErrorCode;
import com.xit.core.exception.CustomBaseException;
import com.xit.core.oauth2.utils.HeaderUtil; import com.xit.core.oauth2.utils.HeaderUtil;
import com.xit.core.support.jpa.JpaUtil; import lombok.AllArgsConstructor;
import org.springframework.data.domain.Example; import org.mapstruct.factory.Mappers;
import org.springframework.data.domain.ExampleMatcher; import org.springframework.data.domain.*;
import org.springframework.data.domain.Page; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains; import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
@AllArgsConstructor
@Service @Service
public class MinUserService implements IMinUserService { public class MinUserService implements IMinUserService {
private final PasswordEncoder passwordEncoder;
private final IMinUserRepository repository; private final IMinUserRepository repository;
public MinUserService(IMinUserRepository repository) { private final MinUserinfoMapstruct mapstruct = Mappers.getMapper(MinUserinfoMapstruct.class);
this.repository = repository;
}
@Transactional//(readOnly = true) @Transactional//(readOnly = true)
public Page<MinUserinfo> findMinUsers(final MinUserinfo minUserinfo, Pageable pageable) { public Page<MinUserinfo> findMinUsers(final MinUserinfo minUserinfo, Pageable pageable) {
//Sort sort = Sort.by(Sort.Direction.ASC, "codeOrdr"); Sort sort = Sort.by(Sort.Direction.ASC, "team", "name");
pageable = JpaUtil.getPagingInfo(pageable); pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll() ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll()
.withMatcher("userid", contains()) .withMatcher("userid", contains())
.withMatcher("name", contains()); .withMatcher("name", contains());
@ -47,7 +48,24 @@ public class MinUserService implements IMinUserService {
} }
@Override @Override
@Transactional(readOnly = true)
public MinUserinfo findMinUserByUserid(final String userid) { public MinUserinfo findMinUserByUserid(final String userid) {
return repository.findMinUserinfoByUserid(userid); return repository.findMinUserinfoByUserid(userid);
} }
@Override
@Transactional
public void saveMinUser(MinUserinfoDto dto) {
if("Y".equals(dto.getNewYn()) && repository.findByUserid(dto.getUserid()).isPresent()) throw new CustomBaseException(ErrorCode.MEMBER_EXISTS);
dto.setPasswd(passwordEncoder.encode(dto.getPasswd()));
repository.save(mapstruct.toEntity(dto));
}
@Override
@Transactional
public void removeMinUser(MinUserinfoDto dto) {
MinUserinfo entity = repository.findByUserid(dto.getUserid()).orElseThrow(()-> new CustomBaseException(ErrorCode.USER_NOT_FOUND));
entity.setIsenable("0");
repository.save(entity);
}
} }

Loading…
Cancel
Save