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 org.mapstruct.factory.Mappers;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
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.*;
import javax.validation.Valid;
@Tag(name = "MinUserController", description = "사용자 관리")
@RestController
@RequestMapping("/api/v1/ctgy/user")
@ -37,13 +40,13 @@ public class MinUserController {
@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 = "team", description = "팀", required = false, example = "001"),
@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<? extends IRestResponse> findMinUsers(
@Parameter(hidden = true)
@ModelAttribute("minUserinfoDto")
final MinUserinfoDto minUserinfoDto,
@Parameter(hidden = true)
final Pageable pageable) {
@ -64,4 +67,22 @@ public class MinUserController {
public ResponseEntity<? extends IRestResponse> getMinUser(@PathVariable final String 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;
import com.xit.biz.ctgy.entity.MinSimsaUser680;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
@Schema(name = "MinUserinfoDto", description = "사용자 DTO")
@Getter
@ -51,6 +47,10 @@ public class MinUserinfoDto implements Serializable {
@Schema(required = false, title = "구청코드", example = " ", description = "Input Description...")
private String gu;
@Schema(required = true, title = "신규유저여부", example = "true", description = "신규유저여부: 'Y'인경우 id duplication check")
private String newYn;
@Override
public boolean equals(Object o) {
if (this == o) return true;

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

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

@ -1,34 +1,35 @@
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.repository.IMinUserRepository;
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.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 lombok.AllArgsConstructor;
import org.mapstruct.factory.Mappers;
import org.springframework.data.domain.*;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
@AllArgsConstructor
@Service
public class MinUserService implements IMinUserService {
private final PasswordEncoder passwordEncoder;
private final IMinUserRepository repository;
public MinUserService(IMinUserRepository repository) {
this.repository = repository;
}
private final MinUserinfoMapstruct mapstruct = Mappers.getMapper(MinUserinfoMapstruct.class);
@Transactional//(readOnly = true)
public Page<MinUserinfo> findMinUsers(final MinUserinfo minUserinfo, Pageable pageable) {
//Sort sort = Sort.by(Sort.Direction.ASC, "codeOrdr");
pageable = JpaUtil.getPagingInfo(pageable);
Sort sort = Sort.by(Sort.Direction.ASC, "team", "name");
pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAll()
.withMatcher("userid", contains())
.withMatcher("name", contains());
@ -47,7 +48,24 @@ public class MinUserService implements IMinUserService {
}
@Override
@Transactional(readOnly = true)
public MinUserinfo findMinUserByUserid(final String 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