Skip to content

Commit

Permalink
ILeaveReportRepository.cs - removed used of access token as parameter
Browse files Browse the repository at this point in the history
LeaveReportRepository.cs - removed used of access token as parameter
IOauthCallHttpContextRespository.cs - separated the method from OAuthCallRepository which use HttpContext
OauthCallHttpContextRespository.cs - separated the method from OAuthCallRepository which use HttpContext
IOauthCallRespository.cs - separated the method from OAuthCallRepository which use HttpContext
OauthCallRespository.cs - separated the method from OAuthCallRepository which use HttpContext
IScrumReportRepository.cs - removed used of access token as parameter
ScrumReportRepository.cs - removed used of access token as parameter
SlackRepository.cs - used GetUserByUserIdAsync instead of GetUserByEmployeeIdAsync
ITaskMailReportRepository.cs - separated the method of task mail report from task mail repository
TaskMailReportRepository.cs - separated the method of task mail report from task mail repository
ITaskMailRepository.cs - separated the method of task mail report from task mail repository
TaskMailRepository.cs - separated the method of task mail report from task mail repository
AutofacConfig.cs(Test) - Added new services and mocking of HttpContext
LeaveReportRepositoryTest.cs - added mocking of HttpContext and updated test cases
OauthCallsRepositoryTest.cs - added mocking of HttpContext and updated test cases
ScrumReportRepositoryTest.cs - added mocking of HttpContext and updated test cases
TaskMailRepositoryTest.cs - added mocking of HttpContext and updated test cases
LeaveReportController.cs - removed the use of access token as parameter
ScrumReportController.cs - removed the use of access token as parameter
TaskReportController.cs - removed the use of access token as parameter
AutofacConfig.cs - register services of OauthCallHttpContextRespository, TaskMailReportRepository and AutofacWebTypesModule

Fixes - #102
  • Loading branch information
siddharthashw committed Feb 13, 2017
1 parent a53bd33 commit 6ccebd7
Show file tree
Hide file tree
Showing 24 changed files with 885 additions and 625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ public interface ILeaveReportRepository
/// <summary>
/// Method that returns the list of employees with their leave status based on their roles
/// </summary>
/// <param name="accessToken"></param>
/// <param name="userId"></param>
/// <param name="userId">userId of user</param>
/// <returns>List of employees with leave status based on roles</returns>
Task<IEnumerable<LeaveReport>> LeaveReportAsync(string accessToken,string userId);
Task<IEnumerable<LeaveReport>> LeaveReportAsync(string userId);

/// <summary>
/// Method that returns the details of leave for an employee
/// </summary>
/// <param name="employeeId"></param>
/// <param name="accessToken"></param>
/// <param name="employeeId">userId of user</param>
/// <returns>Details of leave for an employee</returns>
Task<IEnumerable<LeaveReportDetails>> LeaveReportDetailsAsync(string employeeId, string accessToken);
Task<IEnumerable<LeaveReportDetails>> LeaveReportDetailsAsync(string employeeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public class LeaveReportRepository : ILeaveReportRepository

#region Private Variables
private readonly IRepository<LeaveRequest> _leaveRequest;
private readonly IOauthCallsRepository _oauthCallsRepository;
private readonly IOauthCallHttpContextRespository _oauthCallsRepository;
private readonly IStringConstantRepository _stringConstant;
#endregion

#region Constructor
public LeaveReportRepository(IRepository<LeaveRequest> leaveRequest, IStringConstantRepository stringConstant, IOauthCallsRepository oauthCallsRepository)
public LeaveReportRepository(IRepository<LeaveRequest> leaveRequest, IStringConstantRepository stringConstant,
IOauthCallHttpContextRespository oauthCallsRepository)
{
_leaveRequest = leaveRequest;
_stringConstant = stringConstant;
Expand All @@ -31,16 +32,15 @@ public LeaveReportRepository(IRepository<LeaveRequest> leaveRequest, IStringCons
/// <summary>
/// Method to return the list of leave reports
/// </summary>
/// <param name="distinctLeaveRequests"></param>
/// <param name="accessToken"></param>
/// <param name="distinctLeaveRequests">list of LeaveRequest</param>
/// <returns>List of leave reports</returns>
private async Task<List<LeaveReport>> GetLeaveReportListAsync(List<LeaveRequest> distinctLeaveRequests, string accessToken)
private async Task<List<LeaveReport>> GetLeaveReportListAsync(List<LeaveRequest> distinctLeaveRequests)
{
List<LeaveReport> leaveReports = new List<LeaveReport>();
foreach (var leaveRequest in distinctLeaveRequests)
{
//Get details of the employee from oauth server
User user = await GetEmployeeByIdAsync(leaveRequest.EmployeeId, accessToken);
User user = await GetEmployeeByIdAsync(leaveRequest.EmployeeId);
if (user != null)
{
LeaveReport leaveReport = new LeaveReport
Expand All @@ -65,7 +65,7 @@ private async Task<List<LeaveReport>> GetLeaveReportListAsync(List<LeaveRequest>
/// <summary>
/// Method to calculate number of casual leaves used by a specific employee
/// </summary>
/// <param name="employeeId"></param>
/// <param name="employeeId">userId of user</param>
/// <returns>Number of casual leaves utilised</returns>
private async Task<double> GetUtilisedCasualLeavesByEmployeeAsync(string employeeId)
{
Expand All @@ -86,7 +86,7 @@ private async Task<double> GetUtilisedCasualLeavesByEmployeeAsync(string employe
/// <summary>
/// Method to calculate number of sick leaves used by a specific employee
/// </summary>
/// <param name="employeeId"></param>
/// <param name="employeeId">userId of user</param>
/// <returns>Number of sick leaves utilised</returns>
private async Task<double> GetUtilisedSickLeavesByEmployeeAsync(string employeeId)
{
Expand All @@ -107,12 +107,11 @@ private async Task<double> GetUtilisedSickLeavesByEmployeeAsync(string employeeI
/// <summary>
/// Method to get user details from the Oauth server using their id and access token
/// </summary>
/// <param name="employeeId"></param>
/// <param name="accessToken"></param>
/// <param name="employeeId">userId of user</param>
/// <returns>User details</returns>
private async Task<User> GetEmployeeByIdAsync(string employeeId, string accessToken)
private async Task<User> GetEmployeeByIdAsync(string employeeId)
{
User user = await _oauthCallsRepository.GetUserByEmployeeIdAsync(employeeId, accessToken);
User user = await _oauthCallsRepository.GetUserByEmployeeIdAsync(employeeId);
return user;
}

Expand All @@ -122,17 +121,16 @@ private async Task<User> GetEmployeeByIdAsync(string employeeId, string accessTo
/// <summary>
/// Method that returns leave report based on the role of logged in user
/// </summary>
/// <param name="accessToken"></param>
/// <param name="userId"></param>
/// <returns>Leave report</returns>
public async Task<IEnumerable<LeaveReport>> LeaveReportAsync(string accessToken,string userId )
/// <param name="userId">userId of user</param>
/// <returns>list of Leave report</returns>
public async Task<IEnumerable<LeaveReport>> LeaveReportAsync(string userId)
{
//Get all approved leave requests
List<LeaveRequest> leaveRequests = _leaveRequest.GetAll().ToList().FindAll(x => x.Status.Equals(Condition.Approved));
List<LeaveReport> leaveReports = new List<LeaveReport>();

//Get details of logged in user
User loginUser = await GetEmployeeByIdAsync(userId, accessToken);
User loginUser = await GetEmployeeByIdAsync(userId);

//Check if there exists any approved leave request
if(leaveRequests.Any())
Expand All @@ -142,24 +140,24 @@ public async Task<IEnumerable<LeaveReport>> LeaveReportAsync(string accessToken,
if (loginUser.Role.Equals(_stringConstant.Admin))
{
List<LeaveRequest> distinctLeaveRequests = leaveRequests.GroupBy(x => x.EmployeeId).Select(x => x.FirstOrDefault()).ToList();
leaveReports = await GetLeaveReportListAsync(distinctLeaveRequests, accessToken);
leaveReports = await GetLeaveReportListAsync(distinctLeaveRequests);
return leaveReports;
}
//For employee, only his leave report
else if (loginUser.Role.Equals(_stringConstant.Employee))
{
List<LeaveRequest> distinctLeaveRequests = leaveRequests.FindAll(x => x.EmployeeId == loginUser.Id);
leaveReports = await GetLeaveReportListAsync(distinctLeaveRequests, accessToken);
leaveReports = await GetLeaveReportListAsync(distinctLeaveRequests);
return leaveReports;
}
//For teamleader, leave report of all the team member(s)
else if (loginUser.Role.Equals(_stringConstant.TeamLeader))
{
List<User> projectUsers = await _oauthCallsRepository.GetProjectUsersByTeamLeaderIdAsync(loginUser.Id, accessToken);
List<User> projectUsers = await _oauthCallsRepository.GetProjectUsersByTeamLeaderIdAsync(loginUser.Id);
foreach (var projectUser in projectUsers)
{
List<LeaveRequest> distinctLeaveRequests = leaveRequests.Where(x => x.EmployeeId.Contains(projectUser.Id)).GroupBy(x => x.EmployeeId).Select(x => x.FirstOrDefault()).ToList();
List<LeaveReport> leaveReport = await GetLeaveReportListAsync(distinctLeaveRequests, accessToken);
List<LeaveReport> leaveReport = await GetLeaveReportListAsync(distinctLeaveRequests);
leaveReports.AddRange(leaveReport);
}
return leaveReports;
Expand All @@ -172,13 +170,12 @@ public async Task<IEnumerable<LeaveReport>> LeaveReportAsync(string accessToken,
/// <summary>
/// Method that returns the details of leave for an employee
/// </summary>
/// <param name="employeeId"></param>
/// <param name="accessToken"></param>
/// <param name="employeeId">userId of user</param>
/// <returns>Details of leave for an employee</returns>
public async Task <IEnumerable<LeaveReportDetails>> LeaveReportDetailsAsync(string employeeId,string accessToken)
public async Task <IEnumerable<LeaveReportDetails>> LeaveReportDetailsAsync(string employeeId)
{
//Get user details
User user = await GetEmployeeByIdAsync(employeeId,accessToken);
User user = await GetEmployeeByIdAsync(employeeId);
List<LeaveReportDetails> leaveReportDetails = new List<LeaveReportDetails>();

if (user != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Promact.Erp.DomainModel.ApplicationClass;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Promact.Core.Repository.OauthCallsRepository
{
public interface IOauthCallHttpContextRespository
{
/// <summary>
/// Method to call an api from project oAuth server and get Employee detail by their Id. - GA
/// </summary>
/// <param name="employeeId">id of employee</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>User Details. Object of User</returns>
Task<User> GetUserByEmployeeIdAsync(string employeeId);

/// <summary>
/// Method to call an api from oauth server and get all the projects under a specific teamleader id along with users in it. - GA
/// </summary>
/// <param name="teamLeaderId">id of the team leader</param>
/// <returns>list of users in a project.List of object of User</returns>
Task<List<User>> GetProjectUsersByTeamLeaderIdAsync(string teamLeaderId);

/// <summary>
/// Method is used to call an api from oauth server and return list of all the projects. - GA
/// </summary>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>list of all the projects</returns>
Task<List<ProjectAc>> GetAllProjectsAsync();

/// <summary>
/// Method to call an api from oauth server and get the details of a project using projecId. - GA
/// </summary>
/// <param name="projectId">id of project</param>
/// <returns>Details of a project</returns>
Task<ProjectAc> GetProjectDetailsAsync(int projectId);

/// <summary>
/// Used to get user role. - RS
/// </summary>
/// <param name="userId">id of user</param>
/// <returns>user details. List of object of UserRoleAc</returns>
Task<List<UserRoleAc>> GetUserRoleAsync(string userId);

/// <summary>
/// List of employee under this employee. - RS
/// </summary>
/// <param name="userId">id of user</param>
/// <returns>List of user. List of object of UserRoleAc</returns>
Task<List<UserRoleAc>> GetListOfEmployeeAsync(string userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public interface IOauthCallsRepository
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>management details.List of object of User</returns>
Task<List<User>> GetManagementUserNameAsync(string accessToken);


/// <summary>
/// Used to get user role. - RS
/// </summary>
/// <param name="userId">id of user</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>user details. List of object of UserRoleAc</returns>
Task<List<UserRoleAc>> GetUserRoleAsync(string userId, string accessToken);


/// <summary>
Expand All @@ -52,14 +43,6 @@ public interface IOauthCallsRepository
Task<ProjectAc> GetProjectDetailsAsync(string channelName, string accessToken);


/// <summary>
/// List of employee under this employee. - RS
/// </summary>
/// <param name="userId">id of user</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>List of user. List of object of UserRoleAc</returns>
Task<List<UserRoleAc>> GetListOfEmployeeAsync(string userId, string accessToken);

/// <summary>
/// This method is used to fetch list of users/employees of the given group name. - JJ
/// </summary>
Expand All @@ -78,48 +61,12 @@ public interface IOauthCallsRepository
Task<LeaveAllowed> AllowedLeave(string userId, string accessToken);


/// <summary>
/// Method to call an api from project oAuth server and get Employee detail by their Id. - GA
/// </summary>
/// <param name="employeeId">id of employee</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>User Details. Object of User</returns>
Task<User> GetUserByEmployeeIdAsync(string employeeId, string accessToken);


/// <summary>
/// Method to call an api from oauth server and get all the projects under a specific teamleader id along with users in it. - GA
/// </summary>
/// <param name="teamLeaderId">id of the team leader</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>list of users in a project.List of object of User</returns>
Task<List<User>> GetProjectUsersByTeamLeaderIdAsync(string teamLeaderId, string accessToken);


/// <summary>
/// Method to call an api from oAuth server and get whether user is admin or not. - SS
/// </summary>
/// <param name="userId">userId of user</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>true if user has admin role else false</returns>
Task<bool> UserIsAdminAsync(string userId, string accessToken);


/// <summary>
/// Method is used to call an api from oauth server and return list of all the projects. - GA
/// </summary>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>list of all the projects</returns>
Task<List<ProjectAc>> GetAllProjectsAsync(string accessToken);


/// <summary>
/// Method to call an api from oauth server and get the details of a project using projecId. - GA
/// </summary>
/// <param name="projectId">id of project</param>
/// <param name="accessToken">user's access token from Promact OAuth Server</param>
/// <returns>Details of a project</returns>
Task<ProjectAc> GetProjectDetailsAsync(int projectId, string accessToken);

}
}

0 comments on commit 6ccebd7

Please sign in to comment.