From bab4b8439e9f9f1b0b4c07fcecd3073c567e03bf Mon Sep 17 00:00:00 2001 From: oU-Ua Date: Sun, 11 Feb 2024 22:16:30 +0900 Subject: [PATCH] =?UTF-8?q?chore=20:=20UserRole=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/asset/dto/AssetRes.java | 6 ++--- .../contract/service/ContractService.java | 1 + .../user/controller/UserController.java | 6 ++--- .../domain/user/dto/MainRes.java | 4 ---- .../domain/user/dto/UserInfoRes.java | 22 +++++++++++++++++++ .../domain/user/entity/User.java | 2 +- .../domain/user/entity/UserRole.java | 4 ++++ .../user/repository/UserRepository.java | 14 ++++++++++++ .../domain/user/service/UserService.java | 3 +++ .../domain/user/service/UserServiceImpl.java | 16 +++++++++++--- .../global/config/WebConfig.java | 7 ++++++ .../KbdsItamServerAdminApplicationTests.java | 16 ++++++++++++-- 12 files changed, 85 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/com/kbds/itamserveradmin/domain/user/dto/MainRes.java create mode 100644 src/main/java/com/kbds/itamserveradmin/domain/user/dto/UserInfoRes.java diff --git a/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java index 4e98222..063d6a2 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/asset/dto/AssetRes.java @@ -27,9 +27,9 @@ public static AssetRes assetInfo (Asset asset){ return AssetRes.builder() .astId(asset.getAstId()) .astName(asset.getAstName()) - .astTag(asset.getAstTag()) //자산태그 - .astDpd(asset.getAstDpd()) //상세설명 - .astSpd(asset.getAstSpd()) //간략설명 + .astTag(asset.getAstTag()) + .astDpd(asset.getAstDpd()) + .astSpd(asset.getAstSpd()) .astVer(asset.getAstVer()) .astPrice(asset.getAstPrice()) .build(); diff --git a/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java b/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java index 12edc87..3dc2c14 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/contract/service/ContractService.java @@ -1,5 +1,6 @@ package com.kbds.itamserveradmin.domain.contract.service; +import com.kbds.itamserveradmin.domain.asset.entity.Asset; import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; import com.kbds.itamserveradmin.domain.assetRequest.entity.UserAssetRequestInfo; import com.kbds.itamserveradmin.domain.assetRequest.repository.AssetRequestRepository; diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java b/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java index 077f32e..f11a6b4 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/controller/UserController.java @@ -1,6 +1,6 @@ package com.kbds.itamserveradmin.domain.user.controller; -import com.kbds.itamserveradmin.domain.user.dto.MainRes; +import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; import com.kbds.itamserveradmin.domain.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -15,8 +15,8 @@ public class UserController { private final UserService userService; @PostMapping("/") - public ResponseEntityGetUserInfo(@RequestBody String userId){ + public ResponseEntityGetUserInfo(@RequestBody String userId){ - return ResponseEntity.ok(null); + return ResponseEntity.ok(userService.GetUserInfo(userId)); } } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/dto/MainRes.java b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/MainRes.java deleted file mode 100644 index 8c451a2..0000000 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/dto/MainRes.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.kbds.itamserveradmin.domain.user.dto; - -public class MainRes { -} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/dto/UserInfoRes.java b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/UserInfoRes.java new file mode 100644 index 0000000..cd2f6bf --- /dev/null +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/dto/UserInfoRes.java @@ -0,0 +1,22 @@ +package com.kbds.itamserveradmin.domain.user.dto; + + +import com.kbds.itamserveradmin.domain.user.entity.UserRole; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UserInfoRes { + private String userId; + private String userName; + private String userPhoto; + private UserRole userRole; + private String DeptName; + private String CorpName; + +} diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java b/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java index b4a28e6..36ab604 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/entity/User.java @@ -1,6 +1,7 @@ package com.kbds.itamserveradmin.domain.user.entity; +import com.fasterxml.jackson.annotation.JsonFormat; import com.kbds.itamserveradmin.domain.asset.entity.AssetNotice; import com.kbds.itamserveradmin.domain.assetRequest.entity.AssetRequest; import com.kbds.itamserveradmin.domain.contract.entity.ContractRecord; @@ -23,7 +24,6 @@ @Builder public class User extends BaseEntity { @Id - @Column(name = "user_id") private String userId; @Column(name = "user_name") diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/entity/UserRole.java b/src/main/java/com/kbds/itamserveradmin/domain/user/entity/UserRole.java index 0c75c16..81b9ef8 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/entity/UserRole.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/entity/UserRole.java @@ -1,10 +1,13 @@ package com.kbds.itamserveradmin.domain.user.entity; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonValue; import lombok.AllArgsConstructor; import lombok.Getter; @AllArgsConstructor @Getter +@JsonFormat(shape = JsonFormat.Shape.OBJECT) public enum UserRole { L0("L0","주임"), L1("L1","대리"), @@ -12,5 +15,6 @@ public enum UserRole { L3_1("L3","수석 차장"),L3_2("L3","팀장"), L4_1("L4","부장"),L4_2("L4","본부장"); private final String code; + @JsonValue private final String value; } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java b/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java index 7d8305c..68b25a5 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/repository/UserRepository.java @@ -1,7 +1,21 @@ package com.kbds.itamserveradmin.domain.user.repository; +import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; import com.kbds.itamserveradmin.domain.user.entity.User; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; public interface UserRepository extends JpaRepository { + +// @Query("SELECT u FROM User u WHERE u.userId =:user_id") +// User findByUserId(@Param("user_id") String userId); + + + @Query("SELECT NEW com.kbds.itamserveradmin.domain.user.dto.UserInfoRes(u.userId, u.userName, u.userPhoto, u.userRole, d.deptName, c.corpName) " + + "FROM User u JOIN u.department d JOIN u.corporation c " + + "WHERE u.userId = :userId") + UserInfoRes findUserInfoWithCooperationAndDepartmentByUserId(@Param("userId") String userId); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java index 635f4c3..37ddaf6 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserService.java @@ -1,4 +1,7 @@ package com.kbds.itamserveradmin.domain.user.service; +import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; + public interface UserService { + public UserInfoRes GetUserInfo(String userId); } diff --git a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java index ffe26ee..05b533b 100644 --- a/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/kbds/itamserveradmin/domain/user/service/UserServiceImpl.java @@ -1,16 +1,26 @@ package com.kbds.itamserveradmin.domain.user.service; -import com.kbds.itamserveradmin.domain.user.dto.MainRes; +import com.kbds.itamserveradmin.domain.department.entity.Department; +import com.kbds.itamserveradmin.domain.department.repository.DepartmentRepository; +import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; +import com.kbds.itamserveradmin.domain.user.entity.User; +import com.kbds.itamserveradmin.domain.user.entity.UserRole; import com.kbds.itamserveradmin.domain.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @Service +@Slf4j @RequiredArgsConstructor public class UserServiceImpl implements UserService{ private final UserRepository userRepository; - public MainRes GetUserInfo(String userId){ - return null; + private final DepartmentRepository departmentRepository; + public UserInfoRes GetUserInfo(String userId){ + System.out.println("userId : "+ userId); + UserInfoRes userInfoRes = userRepository.findUserInfoWithCooperationAndDepartmentByUserId(userId); + System.out.println(userInfoRes.toString()); + return userInfoRes; } } diff --git a/src/main/java/com/kbds/itamserveradmin/global/config/WebConfig.java b/src/main/java/com/kbds/itamserveradmin/global/config/WebConfig.java index f06c686..5cce1d6 100644 --- a/src/main/java/com/kbds/itamserveradmin/global/config/WebConfig.java +++ b/src/main/java/com/kbds/itamserveradmin/global/config/WebConfig.java @@ -6,6 +6,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.List; @@ -22,5 +23,11 @@ public void addArgumentResolvers(List resolvers) resolvers.add(userInfoArgumentResolver()); WebMvcConfigurer.super.addArgumentResolvers(resolvers); } + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.52.5/"); + } + } diff --git a/src/test/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplicationTests.java b/src/test/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplicationTests.java index b7fd6a6..15d1ebe 100644 --- a/src/test/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplicationTests.java +++ b/src/test/java/com/kbds/itamserveradmin/KbdsItamServerAdminApplicationTests.java @@ -1,8 +1,9 @@ package com.kbds.itamserveradmin; +import com.kbds.itamserveradmin.domain.user.dto.UserInfoRes; +import com.kbds.itamserveradmin.domain.user.service.UserService; import org.junit.jupiter.api.Test; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -10,8 +11,19 @@ @SpringBootTest class KbdsItamServerAdminApplicationTests { + @Autowired + private UserService userService; @Test void contextLoads() { } + @Test + public void testGetUser(){ + UserInfoRes userInfoRes =userService.GetUserInfo("L20"); + System.out.println(userInfoRes.toString()); + System.out.println(userInfoRes.getUserName()); + System.out.println(userInfoRes.getUserId()); + System.out.println(userInfoRes.getUserRole().getCode()); + System.out.println(userInfoRes.getUserRole().getValue()); + } }