From a472f46a8dcc674c90b4f3d01731be48dec48da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Sun, 10 May 2020 23:55:19 +0800 Subject: [PATCH] feat($auth-center): provide remote service for `api-portal`: get role list --- ...emoteApi.java => AuthCenterRemoteApi.java} | 19 +++- .../remoteapi/authcenter/package-info.java | 1 - .../impl/CustomUserDetailsServiceImpl.java | 34 ++++--- .../role/controller/RoleController.java | 29 ++++++ .../role/entity/RolePersistence.java | 37 ++++++++ .../authcenter/role/mapper/RoleMapper.java | 75 +++++++++++++++ .../role/remote/RoleRemoteApiController.java | 35 +++++++ .../authcenter/role/service/RoleService.java | 75 +++++++++++++++ .../role/service/impl/RoleServiceImpl.java | 72 ++++++++++++++ .../universal/mapper/RoleMapper.java | 79 ---------------- .../universal/service/RoleService.java | 81 ---------------- .../service/impl/RoleServiceImpl.java | 65 ------------- .../user/remote/UserRemoteApiController.java | 2 +- .../src/main/resources/mapper/RoleMapper.xml | 94 +++++++++++++++++++ .../common/bean/ResponseBodyBean.java | 8 +- .../role/GetRoleListByUserIdPayload.java | 19 ++++ .../role/GetRoleListByUserIdResponse.java | 25 +++++ .../user/GetUserByLoginTokenResponse.java | 1 - 18 files changed, 503 insertions(+), 248 deletions(-) rename api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/{authcenter/user/UserRemoteApi.java => AuthCenterRemoteApi.java} (55%) delete mode 100644 api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/package-info.java create mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/role/controller/RoleController.java create mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/role/entity/RolePersistence.java create mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/role/mapper/RoleMapper.java create mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/role/remote/RoleRemoteApiController.java create mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/role/service/RoleService.java create mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/role/service/impl/RoleServiceImpl.java delete mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/universal/mapper/RoleMapper.java delete mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/RoleService.java delete mode 100644 auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/impl/RoleServiceImpl.java create mode 100644 auth-center/src/main/resources/mapper/RoleMapper.xml create mode 100644 common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdPayload.java create mode 100644 common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdResponse.java diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/user/UserRemoteApi.java b/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java similarity index 55% rename from api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/user/UserRemoteApi.java rename to api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java index 9f50a3aa..9c4ea247 100644 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/user/UserRemoteApi.java +++ b/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java @@ -1,6 +1,8 @@ -package com.jmsoftware.apiportal.remoteapi.authcenter.user; +package com.jmsoftware.apiportal.remoteapi; import com.jmsoftware.common.bean.ResponseBodyBean; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdResponse; import com.jmsoftware.common.domain.authcenter.user.GetUserByLoginTokenPayload; import com.jmsoftware.common.domain.authcenter.user.GetUserByLoginTokenResponse; import org.springframework.cloud.openfeign.FeignClient; @@ -8,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody; /** - *

UserRemoteApi

+ *

AuthCenterRemoteApi

*

* Change description here. * @@ -16,13 +18,22 @@ * @date 5/10/20 4:50 PM */ @FeignClient(name = "auth-center") -public interface UserRemoteApi { +public interface AuthCenterRemoteApi { /** * Gets user by login token. * * @param payload the payload * @return the user by login token */ - @PostMapping("/user/get-user-by-login-token") + @PostMapping("/user-remote-api/get-user-by-login-token") ResponseBodyBean getUserByLoginToken(@RequestBody GetUserByLoginTokenPayload payload); + + /** + * Gets role list by user id. + * + * @param payload the payload + * @return the role list by user id + */ + @PostMapping("/role-remote-api/get-role-list-by-user-id") + ResponseBodyBean getRoleListByUserId(@RequestBody GetRoleListByUserIdPayload payload); } diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/package-info.java b/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/package-info.java deleted file mode 100644 index 007d4df3..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/authcenter/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.jmsoftware.apiportal.remoteapi.authcenter; diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java index 3c901b01..9bcf1dae 100644 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java +++ b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java @@ -3,14 +3,15 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; -import com.jmsoftware.apiportal.remoteapi.authcenter.user.UserRemoteApi; +import com.jmsoftware.apiportal.remoteapi.AuthCenterRemoteApi; import com.jmsoftware.apiportal.universal.domain.PermissionPO; import com.jmsoftware.apiportal.universal.domain.RolePO; import com.jmsoftware.apiportal.universal.domain.UserPO; import com.jmsoftware.apiportal.universal.domain.UserPrincipal; import com.jmsoftware.apiportal.universal.mapper.PermissionMapper; -import com.jmsoftware.apiportal.universal.service.RoleService; import com.jmsoftware.common.constant.HttpStatus; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdResponse; import com.jmsoftware.common.domain.authcenter.user.GetUserByLoginTokenPayload; import com.jmsoftware.common.exception.SecurityException; import lombok.RequiredArgsConstructor; @@ -21,6 +22,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; +import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -35,31 +37,39 @@ @Service @RequiredArgsConstructor public class CustomUserDetailsServiceImpl implements UserDetailsService { - private final RoleService roleService; private final PermissionMapper permissionMapper; - private final UserRemoteApi userRemoteApi; + private final AuthCenterRemoteApi authCenterRemoteApi; @Override public UserDetails loadUserByUsername(String credentials) throws UsernameNotFoundException { val payload = new GetUserByLoginTokenPayload(); payload.setLoginToken(credentials); - var response = userRemoteApi.getUserByLoginToken(payload); + val response = authCenterRemoteApi.getUserByLoginToken(payload); val data = response.getData(); if (ObjectUtil.isNull(data)) { - String errorMessage = "User's account not found: " + credentials; + val errorMessage = String.format("User's account not found, credentials: %s", credentials); log.error(errorMessage); throw new UsernameNotFoundException(errorMessage); } - List rolesByUserId = roleService.getRolesByUserId(data.getId()); - if (CollUtil.isEmpty(rolesByUserId)) { + val payload1 = new GetRoleListByUserIdPayload(); + payload1.setUserId(data.getId()); + val response2 = authCenterRemoteApi.getRoleListByUserId(payload1); + val roleList = response2.getData().getRoleList(); + if (CollUtil.isEmpty(roleList)) { throw new SecurityException(HttpStatus.ROLE_NOT_FOUND); } - List roleIds = rolesByUserId.stream() - .map(RolePO::getId) + List roleIdList = roleList.stream() + .map(GetRoleListByUserIdResponse.Role::getId) .collect(Collectors.toList()); - List permissionList = permissionMapper.selectByRoleIdList(roleIds); + List permissionList = permissionMapper.selectByRoleIdList(roleIdList); var user = new UserPO(); BeanUtil.copyProperties(data, user); - return UserPrincipal.create(user, rolesByUserId, permissionList); + List rolePOList = new LinkedList<>(); + roleList.forEach(role -> { + val rolePO = new RolePO(); + BeanUtil.copyProperties(role, rolePO); + rolePOList.add(rolePO); + }); + return UserPrincipal.create(user, rolePOList, permissionList); } } diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/role/controller/RoleController.java b/auth-center/src/main/java/com/jmsoftware/authcenter/role/controller/RoleController.java new file mode 100644 index 00000000..f76f23a7 --- /dev/null +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/role/controller/RoleController.java @@ -0,0 +1,29 @@ +package com.jmsoftware.authcenter.role.controller; + +import com.jmsoftware.authcenter.role.entity.RolePersistence; +import com.jmsoftware.authcenter.role.service.RoleService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + + /** + *

RoleController

+ *

+ * Controller implementation of Role.(Role) + * + * @author Johnny Miller (鍾俊) + * @date 2020-05-10 22:39:51 + */ +@RestController +@RequestMapping("role") +public class RoleController { + @Resource + private RoleService roleService; + + @GetMapping("selectOne") + public RolePersistence selectOne(Long id) { + return this.roleService.queryById(id); + } +} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/role/entity/RolePersistence.java b/auth-center/src/main/java/com/jmsoftware/authcenter/role/entity/RolePersistence.java new file mode 100644 index 00000000..b92e903e --- /dev/null +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/role/entity/RolePersistence.java @@ -0,0 +1,37 @@ +package com.jmsoftware.authcenter.role.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * Role.(Role) Persistence object class + * + * @author Johnny Miller (鍾俊) + * @since 2020-05-10 22:39:45 + */ +@Data +public class RolePersistence implements Serializable { + private static final long serialVersionUID = -81197803690669820L; + /** + * Primary key + */ + private Long id; + /** + * Role name + */ + private String name; + /** + * Role description + */ + private String description; + /** + * Created time + */ + private Date createdTime; + /** + * Modified time + */ + private Date modifiedTime; +} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/role/mapper/RoleMapper.java b/auth-center/src/main/java/com/jmsoftware/authcenter/role/mapper/RoleMapper.java new file mode 100644 index 00000000..c471ef7e --- /dev/null +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/role/mapper/RoleMapper.java @@ -0,0 +1,75 @@ +package com.jmsoftware.authcenter.role.mapper; + +import com.jmsoftware.authcenter.role.entity.RolePersistence; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

RoleMapper

+ *

+ * Mapper of Role.(Role) + * + * @author Johnny Miller (鍾俊) + * @date 2020 -05-10 22:39:48 + */ +@Mapper +public interface RoleMapper { + /** + * Query by id role. + * + * @param id the id + * @return the role + */ + RolePersistence queryById(Long id); + + /** + * Query all by limit list. + * + * @param offset the offset + * @param limit the limit + * @return the list + */ + List queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit); + + /** + * Query all list. + * + * @param rolePersistence the role + * @return the list + */ + List queryAll(RolePersistence rolePersistence); + + /** + * Insert int. + * + * @param rolePersistence the role + * @return the int + */ + int insert(RolePersistence rolePersistence); + + /** + * Update int. + * + * @param rolePersistence the role + * @return the int + */ + int update(RolePersistence rolePersistence); + + /** + * Delete by id int. + * + * @param id the id + * @return the int + */ + int deleteById(Long id); + + /** + * Select role list by user id list. + * + * @param userId the user id + * @return the list + */ + List selectRoleListByUserId(Long userId); +} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/role/remote/RoleRemoteApiController.java b/auth-center/src/main/java/com/jmsoftware/authcenter/role/remote/RoleRemoteApiController.java new file mode 100644 index 00000000..505fce60 --- /dev/null +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/role/remote/RoleRemoteApiController.java @@ -0,0 +1,35 @@ +package com.jmsoftware.authcenter.role.remote; + +import com.jmsoftware.authcenter.role.service.RoleService; +import com.jmsoftware.common.bean.ResponseBodyBean; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdResponse; +import io.swagger.annotations.Api; +import lombok.RequiredArgsConstructor; +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.RestController; + +import javax.validation.Valid; + +/** + *

RoleRemoteApiController

+ *

+ * Change description here. + * + * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com + * @date 5/10/20 10:43 PM + **/ +@RestController +@RequiredArgsConstructor +@RequestMapping("/role-remote-api") +@Api(tags = {"Role Remote API Controller"}) +public class RoleRemoteApiController { + private final RoleService roleService; + + @PostMapping("/get-role-list-by-user-id") + public ResponseBodyBean getRoleListByUserId(@Valid @RequestBody GetRoleListByUserIdPayload payload) { + return ResponseBodyBean.ofSuccess(roleService.getRoleListByUserId(payload)); + } +} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/role/service/RoleService.java b/auth-center/src/main/java/com/jmsoftware/authcenter/role/service/RoleService.java new file mode 100644 index 00000000..249c601c --- /dev/null +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/role/service/RoleService.java @@ -0,0 +1,75 @@ +package com.jmsoftware.authcenter.role.service; + +import com.jmsoftware.authcenter.role.entity.RolePersistence; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdResponse; +import lombok.NonNull; + +import java.util.List; + +/** + *

RoleService

+ *

+ * Service of Role.(Role) + * + * @author Johnny Miller (鍾俊) + * @date 2020 -05-10 22:39:49 + */ +public interface RoleService { + /** + * Query by ID + * + * @param id the primary key ID + * @return the entity + */ + RolePersistence queryById(Long id); + + /** + * Gets role list by user id. + * + * @param payload the payload + * @return the role list by user id + */ + GetRoleListByUserIdResponse getRoleListByUserId(GetRoleListByUserIdPayload payload); + + /** + * Gets role list by user id. + * + * @param userId the user id + * @return the role list by user id + */ + List getRoleListByUserId(@NonNull Long userId); + + /** + * Query all by limit + * + * @param offset the offset + * @param limit the limit + * @return the entity list + */ + List queryAllByLimit(int offset, int limit); + + /** + * Insert + * + * @param rolePersistence the entity + * @return the entity + */ + RolePersistence insert(RolePersistence rolePersistence); + + /** + * Update + * + * @param rolePersistence the entity + * @return the entity + */ + RolePersistence update(RolePersistence rolePersistence); + + /** + * Delete by ID + * + * @param id the primary key ID + * @return the boolean + */ + boolean deleteById(Long id); +} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/role/service/impl/RoleServiceImpl.java b/auth-center/src/main/java/com/jmsoftware/authcenter/role/service/impl/RoleServiceImpl.java new file mode 100644 index 00000000..8e924990 --- /dev/null +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/role/service/impl/RoleServiceImpl.java @@ -0,0 +1,72 @@ +package com.jmsoftware.authcenter.role.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import com.jmsoftware.authcenter.role.entity.RolePersistence; +import com.jmsoftware.authcenter.role.mapper.RoleMapper; +import com.jmsoftware.authcenter.role.service.RoleService; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdResponse; +import lombok.NonNull; +import lombok.val; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + *

RoleServiceImpl

+ *

+ * Service implementation of Role.(Role) + * + * @author Johnny Miller (鍾俊) + * @date 2020-05-10 22:39:50 + */ +@Service("roleService") +public class RoleServiceImpl implements RoleService { + @Resource + private RoleMapper roleMapper; + + @Override + public RolePersistence queryById(Long id) { + return this.roleMapper.queryById(id); + } + + @Override + public GetRoleListByUserIdResponse getRoleListByUserId(GetRoleListByUserIdPayload payload) { + val roleList = this.getRoleListByUserId(payload.getUserId()); + GetRoleListByUserIdResponse response = new GetRoleListByUserIdResponse(); + roleList.forEach(rolePersistence -> { + GetRoleListByUserIdResponse.Role role = new GetRoleListByUserIdResponse.Role(); + BeanUtil.copyProperties(rolePersistence, role); + response.getRoleList().add(role); + }); + return response; + } + + @Override + public List getRoleListByUserId(@NonNull Long userId) { + return roleMapper.selectRoleListByUserId(userId); + } + + @Override + public List queryAllByLimit(int offset, int limit) { + return this.roleMapper.queryAllByLimit(offset, limit); + } + + @Override + public RolePersistence insert(RolePersistence rolePersistence) { + this.roleMapper.insert(rolePersistence); + return rolePersistence; + } + + @Override + public RolePersistence update(RolePersistence rolePersistence) { + this.roleMapper.update(rolePersistence); + return this.queryById(rolePersistence.getId()); + } + + @Override + public boolean deleteById(Long id) { + return this.roleMapper.deleteById(id) > 0; + } +} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/universal/mapper/RoleMapper.java b/auth-center/src/main/java/com/jmsoftware/authcenter/universal/mapper/RoleMapper.java deleted file mode 100644 index af2123e3..00000000 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/universal/mapper/RoleMapper.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.jmsoftware.authcenter.universal.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.authcenter.universal.domain.RolePO; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - *

RoleMapper

- *

CRUD operations for table `t_role`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-02 17:52 - **/ -@Mapper -@Component -public interface RoleMapper extends BaseMapper { - /** - * Select role by user ID. - * - * @param userId User ID - * @return Roles - */ - List selectByUserId(Long userId); - - /** - * Select page list - * - * @param page page object - * @return role page list - */ - List selectPageList(Page page); - - /** - * Check role name's uniqueness - *

- * If id is null, then check for creating role's name; otherwise, check for created role's name - * - * @param po persistence object - * @return the occurrence of the name of role - */ - Integer checkRoleName(RolePO po); - - /** - * Insert role - * - * @param po persistence object - * @return primary key - */ - Long insertRole(RolePO po); - - /** - * Select role by name - * - * @param name role name - * @return role - */ - RolePO selectRoleByName(String name); - - /** - * Update role by ID - * - * @param po persistence object - * @return affected row - */ - int updateRoleById(RolePO po); - - /** - * Selection role list for selection - * - * @param page pagination object - * @return role page list - */ - IPage selectRoleListForSelection(Page page); -} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/RoleService.java b/auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/RoleService.java deleted file mode 100644 index 0d91132f..00000000 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/RoleService.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.jmsoftware.authcenter.universal.service; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.authcenter.universal.domain.RolePO; - -import java.util.List; - -/** - *

RoleService

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-18 12:03 - **/ -public interface RoleService { - /** - * Get role list - * - * @param page page object - * @return role list - */ - List getList(Page page); - - /** - * Check the uniqueness of name of role - *

- * If id is null, then check for creating role's name; otherwise, check for created role's name - * - * @param po persistence object - * @return true - available; false - not available - */ - boolean checkRoleName(RolePO po); - - /** - * Insert a role - * - * @param po persistence object - * @return true - insert successfully; false - insert failure - */ - boolean insertRole(RolePO po); - - /** - * Handle the name of role - * - * @param roleName the name of role - * @return processed role name - */ - String handleRoleName(String roleName); - - /** - * Search role by name - * - * @param roleName role name - * @return role - */ - RolePO searchRole(String roleName); - - /** - * Update role - * - * @param po persistence object - * @return true - update successfully; false - update failure - */ - boolean updateRole(RolePO po); - - /** - * Get roles by user ID - * - * @param userId user ID - * @return role list - */ - List getRolesByUserId(Long userId); - - /** - * Get role list for selection - * - * @param page page object - * @return role list - */ - List getListForSelection(Page page); -} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/impl/RoleServiceImpl.java b/auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/impl/RoleServiceImpl.java deleted file mode 100644 index 8f629e4a..00000000 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/universal/service/impl/RoleServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.jmsoftware.authcenter.universal.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.authcenter.universal.domain.RolePO; -import com.jmsoftware.authcenter.universal.mapper.RoleMapper; -import com.jmsoftware.authcenter.universal.service.RoleService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - *

RoleServiceImpl

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-18 12:03 - **/ -@Service -@RequiredArgsConstructor -public class RoleServiceImpl implements RoleService { - private final RoleMapper roleMapper; - - @Override - public List getList(Page page) { - return roleMapper.selectPageList(page); - } - - @Override - public boolean checkRoleName(RolePO po) { - return roleMapper.checkRoleName(po) == 0; - } - - @Override - public boolean insertRole(RolePO po) { - return roleMapper.insertRole(po) > 0; - } - - @Override - public String handleRoleName(String roleName) { - String processedRoleName = StrUtil.trim(roleName).toLowerCase(); - return processedRoleName.replaceAll("\\s", "_"); - } - - @Override - public RolePO searchRole(String roleName) { - return roleMapper.selectRoleByName(roleName); - } - - @Override - public boolean updateRole(RolePO po) { - return roleMapper.updateRoleById(po) == 1; - } - - @Override - public List getRolesByUserId(Long userId) { - return roleMapper.selectByUserId(userId); - } - - @Override - public List getListForSelection(Page page) { - return roleMapper.selectRoleListForSelection(page).getRecords(); - } -} diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/user/remote/UserRemoteApiController.java b/auth-center/src/main/java/com/jmsoftware/authcenter/user/remote/UserRemoteApiController.java index 3fecf098..9a7d0fcf 100644 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/user/remote/UserRemoteApiController.java +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/user/remote/UserRemoteApiController.java @@ -23,7 +23,7 @@ * @date 5/10/20 12:36 PM **/ @RestController -@RequestMapping("/user") +@RequestMapping("/user-remote-api") @RequiredArgsConstructor @Api(tags = {"User Remote API Controller"}) public class UserRemoteApiController { diff --git a/auth-center/src/main/resources/mapper/RoleMapper.xml b/auth-center/src/main/resources/mapper/RoleMapper.xml new file mode 100644 index 00000000..4ef4662c --- /dev/null +++ b/auth-center/src/main/resources/mapper/RoleMapper.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + insert into muscle_and_fitness.role(name, description, created_time, modified_time) + values (#{name}, #{description}, #{createdTime}, #{modifiedTime}) + + + + + update muscle_and_fitness.role + + + name = #{name}, + + + description = #{description}, + + + created_time = #{createdTime}, + + + modified_time = #{modifiedTime}, + + + where id = #{id} + + + + + DELETE FROM muscle_and_fitness.role WHERE id = #{id} + + + + diff --git a/common/src/main/java/com/jmsoftware/common/bean/ResponseBodyBean.java b/common/src/main/java/com/jmsoftware/common/bean/ResponseBodyBean.java index a7112f1d..41b10097 100644 --- a/common/src/main/java/com/jmsoftware/common/bean/ResponseBodyBean.java +++ b/common/src/main/java/com/jmsoftware/common/bean/ResponseBodyBean.java @@ -156,7 +156,7 @@ public static ResponseBodyBean ofSu * @param data data to be responded to client. * @return response body */ - public static ResponseBodyBean ofSuccess(@NonNull final ResponseBodyDataType data) { + public static ResponseBodyBean ofSuccess(final ResponseBodyDataType data) { return ResponseBodyBean.builder() .timestamp(new Date()) .status(HttpStatus.OK.getCode()) @@ -187,7 +187,7 @@ public static ResponseBodyBean ofSu * @param message message to be responded * @return response body */ - public static ResponseBodyBean ofSuccess(@NonNull final ResponseBodyDataType data, + public static ResponseBodyBean ofSuccess(final ResponseBodyDataType data, @NonNull final String message) { return ResponseBodyBean.builder().timestamp(new Date()) .status(HttpStatus.OK.getCode()) @@ -214,7 +214,7 @@ public static ResponseBodyBean ofFa * @param data data to be responded * @return response body */ - public static ResponseBodyBean ofFailure(@NonNull final ResponseBodyDataType data) { + public static ResponseBodyBean ofFailure(final ResponseBodyDataType data) { throw new BusinessException(data); } @@ -226,7 +226,7 @@ public static ResponseBodyBean ofFa * @param message message to be responded * @return response body */ - public static ResponseBodyBean ofFailure(@NonNull final ResponseBodyDataType data, + public static ResponseBodyBean ofFailure(final ResponseBodyDataType data, @NonNull final String message) { throw new BusinessException(data, message); } diff --git a/common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdPayload.java b/common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdPayload.java new file mode 100644 index 00000000..450238b8 --- /dev/null +++ b/common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdPayload.java @@ -0,0 +1,19 @@ +package com.jmsoftware.common.domain.authcenter.role; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + *

GetRoleListByUserIdPayload

+ *

+ * Change description here. + * + * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com + * @date 5/10/20 10:52 PM + **/ +@Data +public class GetRoleListByUserIdPayload { + @NotNull + private Long userId; +} diff --git a/common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdResponse.java b/common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdResponse.java new file mode 100644 index 00000000..4384e9c9 --- /dev/null +++ b/common/src/main/java/com/jmsoftware/common/domain/authcenter/role/GetRoleListByUserIdResponse.java @@ -0,0 +1,25 @@ +package com.jmsoftware.common.domain.authcenter.role; + +import lombok.Data; + +import java.util.LinkedList; +import java.util.List; + +/** + *

GetRoleListByUserIdResponse

+ *

+ * Change description here. + * + * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com + * @date 5/10/20 10:55 PM + **/ +@Data +public class GetRoleListByUserIdResponse { + private final List roleList = new LinkedList<>(); + + @Data + public static class Role { + private Long id; + private String name; + } +} diff --git a/common/src/main/java/com/jmsoftware/common/domain/authcenter/user/GetUserByLoginTokenResponse.java b/common/src/main/java/com/jmsoftware/common/domain/authcenter/user/GetUserByLoginTokenResponse.java index 9778d479..db021d12 100644 --- a/common/src/main/java/com/jmsoftware/common/domain/authcenter/user/GetUserByLoginTokenResponse.java +++ b/common/src/main/java/com/jmsoftware/common/domain/authcenter/user/GetUserByLoginTokenResponse.java @@ -14,7 +14,6 @@ **/ @Data public class GetUserByLoginTokenResponse { - /** * Primary key */