Commit 4df0736d authored by Darshan M N's avatar Darshan M N
Browse files

Adding the User Role Dashboard API

Showing with 84 additions and 3 deletions
+84 -3
......@@ -144,6 +144,11 @@ public class UserController {
public String getNumberOfRoles() throws JsonProcessingException {
return ResponseGenerator.successResponse(userService.getNumberOfRoles());
}
@RequestMapping(value = PathRoutes.UserRoutes.NUMBER_OF_USERS_ROLES_GET, method = RequestMethod.GET)
public String getNumberOfUserAndRoles() throws JsonProcessingException {
return ResponseGenerator.successResponse(userService.getNumberOfUsersAndRoles());
}
@RequestMapping(value = PathRoutes.UserRoutes.USER_BY_ID_GET, method = RequestMethod.GET)
public String getOne(@RequestParam(value = "id", required = true) Long id,
......
......@@ -10,6 +10,7 @@ import com.tarento.retail.dto.UserMasterRoleCountryOrgDto;
import com.tarento.retail.dto.UserRoleDto;
import com.tarento.retail.model.Action;
import com.tarento.retail.model.Country;
import com.tarento.retail.model.KeyValue;
import com.tarento.retail.model.SearchRequest;
import com.tarento.retail.model.User;
import com.tarento.retail.model.UserAuthentication;
......@@ -254,5 +255,7 @@ public interface UserDao {
UserProfile getUserProfile(String username);
public UserProfileMapper findAll(SearchRequest searchRequest);
public List<KeyValue> getNumberOfUsersAndRoles();
}
......@@ -32,6 +32,7 @@ import com.tarento.retail.dto.UserMasterRoleCountryOrgDto;
import com.tarento.retail.dto.UserRoleDto;
import com.tarento.retail.model.Action;
import com.tarento.retail.model.Country;
import com.tarento.retail.model.KeyValue;
import com.tarento.retail.model.Role;
import com.tarento.retail.model.SearchRequest;
import com.tarento.retail.model.User;
......@@ -961,4 +962,15 @@ public class UserDaoImpl implements UserDao {
}
return Boolean.TRUE;
}
@Override
public List<KeyValue> getNumberOfUsersAndRoles() {
List<KeyValue> userList = new ArrayList<>();
try {
userList = jdbcTemplate.query(UserQueries.GET_NUMBER_USER_ROLES, new SqlDataMapper().new UserRoleCountMapper());
} catch (Exception e) {
LOGGER.error("Encountered an Exception while fetching the User by Username : " + e);
}
return userList;
}
}
package com.tarento.retail.model;
public class KeyValue {
private String key;
private Object value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
package com.tarento.retail.model;
import java.util.List;
public class KeyValueList {
private List<KeyValue> keyValues;
public List<KeyValue> getKeyValues() {
return keyValues;
}
public void setKeyValues(List<KeyValue> keyValues) {
this.keyValues = keyValues;
}
}
......@@ -18,6 +18,7 @@ import com.tarento.retail.dto.UserDto;
import com.tarento.retail.model.Action;
import com.tarento.retail.model.ActionRole;
import com.tarento.retail.model.Country;
import com.tarento.retail.model.KeyValue;
import com.tarento.retail.model.Role;
import com.tarento.retail.model.User;
import com.tarento.retail.model.UserAuthentication;
......@@ -310,6 +311,15 @@ public class SqlDataMapper {
return action;
}
}
public class UserRoleCountMapper implements RowMapper<KeyValue> {
public KeyValue mapRow(ResultSet rs, int rowNum) throws SQLException {
KeyValue keyValue = new KeyValue();
keyValue.setKey(rs.getString("roleName"));
keyValue.setValue(rs.getObject("numberOfUsers"));
return keyValue;
}
}
public class RoleMapper implements RowMapper<Role> {
public Role mapRow(ResultSet rs, int rowNum) throws SQLException {
......
......@@ -10,12 +10,10 @@ import com.tarento.retail.dto.MasterRoleDto;
import com.tarento.retail.dto.UserCountryDto;
import com.tarento.retail.dto.UserDto;
import com.tarento.retail.dto.UserMasterRoleCountryOrgDto;
import com.tarento.retail.dto.UserMasterRoleDto;
import com.tarento.retail.dto.UserRoleDto;
import com.tarento.retail.model.Action;
import com.tarento.retail.model.Country;
import com.tarento.retail.model.LoginAuthentication;
import com.tarento.retail.model.LoginDto;
import com.tarento.retail.model.KeyValue;
import com.tarento.retail.model.Role;
import com.tarento.retail.model.SearchRequest;
import com.tarento.retail.model.User;
......@@ -236,5 +234,7 @@ public interface UserService {
Boolean validateUserOTP(String username, String otp);
public List<UserProfile> findAll(SearchRequest searchRequest);
List<KeyValue> getNumberOfUsersAndRoles();
}
\ No newline at end of file
......@@ -38,6 +38,7 @@ import com.tarento.retail.dto.UserMasterRoleCountryOrgDto;
import com.tarento.retail.dto.UserRoleDto;
import com.tarento.retail.model.Action;
import com.tarento.retail.model.Country;
import com.tarento.retail.model.KeyValue;
import com.tarento.retail.model.LoginAuthentication;
import com.tarento.retail.model.Role;
import com.tarento.retail.model.SearchRequest;
......@@ -590,4 +591,9 @@ public class UserServiceImpl implements UserDetailsService, UserService {
return profileList;
}
@Override
public List<KeyValue> getNumberOfUsersAndRoles() {
return userDao.getNumberOfUsersAndRoles();
}
}
......@@ -38,6 +38,7 @@ public interface PathRoutes {
final String GET_USERS_BY_MASTER_ROLE = "getUsersByMasterRole";
final String MAP_USER_MASTER_ROLE_COUNTRY_ORG = "mapUserMasterRoleCountryOrg";
final String REQUEST_OTP = "/requestOTP";
final String NUMBER_OF_USERS_ROLES_GET = "/getNumberOfUsersAndRoles";
}
public interface AuthenticationRoutes {
......
......@@ -174,6 +174,7 @@ public interface Sql {
final String GET_USER_ID = "SELECT id FROM user WHERE username = ? OR email_id = ? OR phone_no = ?";
final String GET_USER_PROFILE = "SELECT user.id, user.username, user.email_id as emailId, user.phone_no as phoneNo, user.avatar_url as avatarUrl, user_profile.first_name, user_profile.last_name, user_profile.dob FROM user LEFT JOIN user_profile on user_profile.user_id = user.id WHERE (user.username = ? or user.email_id = ? ) and is_active is TRUE";
final String GET_NUMBER_USER_ROLES = "SELECT count(*) as 'numberOfUsers', r.role_name as 'roleName' from user usr LEFT JOIN user_role ur ON usr.id = ur.user_id LEFT JOIN role r ON ur.role_id = r.id where r.id > 2090 group by r.role_name ";
}
public interface NamedUserQueries {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment