Implemented an API endpoint that retrieves the attendance records for a specific project on a given date #71
Collaborator
- Get Tenant and Employee Info:
- Retrieves the current tenant ID using _userHelper.GetTenantId().
- Retrieves the logged-in employee's information for logging and auditing.
- Date Validation:
- Initializes currentDate to the current UTC date and time.
- If a date is provided:
- Tries to parse it into DateTime.
- If parsing fails:
- Logs an error: "user send invalid date"
- Returns a 400 Bad Request with message "Invalid date."
- Project Lookup:
- Fetches the project using the provided projectId.
- If the project is not found:
- Logs the event with employee ID and date.
- Returns a 404 Not Found response with message "Project not found".
- Fetch Active Project Allocations:
- Queries ProjectAllocations for active assignments to this project and tenant.
- Extracts distinct EmployeeIds from the allocations.
- Retrieve Employee Information:
- Fetches employee records whose IDs match the list of assigned employees.
- Fetch Attendance Records:
- Queries the Attendes table for attendance entries:
- Where EmployeeID is in the list
- ProjectID matches the target project
- InTime is not null
- InTime.Date equals the selected date
- Queries the Attendes table for attendance entries:
- Build Attendance View Models:
- For each matching attendance record:
- Finds the corresponding employee info.
- Creates an EmployeeAttendanceVM with:
- Employee name
- InTime, OutTime, and Comment
- Defaults InTime and OutTime to DateTime.UtcNow if missing (though logically they shouldn't be)
- For each matching attendance record:
- Construct Final Response Model:
- Creates a ProjectAttendanceVM:
- AttendanceTable: List of employee attendance VMs
- CheckedInEmployee: Count of attendance records for the day
- AssignedEmployee: Total employees assigned to the project
- Creates a ProjectAttendanceVM:
- Logging and Response:
- Logs the request with project ID, date, and employee ID.
- Returns a 200 OK response with the assembled project attendance data.
- **Get Tenant and Employee Info**:
- Retrieves the current tenant ID using _userHelper.GetTenantId().
- Retrieves the logged-in employee's information for logging and auditing.
- **Date Validation**:
- Initializes currentDate to the current UTC date and time.
- If a date is provided:
- Tries to parse it into DateTime.
- If parsing fails:
- Logs an error: "user send invalid date"
- Returns a 400 Bad Request with message "Invalid date."
- **Project Lookup**:
- Fetches the project using the provided projectId.
- If the project is not found:
- Logs the event with employee ID and date.
- Returns a 404 Not Found response with message "Project not found".
- **Fetch Active Project Allocations**:
- Queries ProjectAllocations for active assignments to this project and tenant.
- Extracts distinct EmployeeIds from the allocations.
- **Retrieve Employee Information**:
- Fetches employee records whose IDs match the list of assigned employees.
- **Fetch Attendance Records**:
- Queries the Attendes table for attendance entries:
- Where EmployeeID is in the list
- ProjectID matches the target project
- InTime is not null
- InTime.Date equals the selected date
- **Build Attendance View Models**:
- For each matching attendance record:
- Finds the corresponding employee info.
- Creates an EmployeeAttendanceVM with:
- Employee name
- InTime, OutTime, and Comment
- Defaults InTime and OutTime to DateTime.UtcNow if missing (though logically they shouldn't be)
- **Construct Final Response Model**:
- Creates a ProjectAttendanceVM:
- AttendanceTable: List of employee attendance VMs
- CheckedInEmployee: Count of attendance records for the day
- AssignedEmployee: Total employees assigned to the project
- **Logging and Response**:
- Logs the request with project ID, date, and employee ID.
- Returns a 200 OK response with the assembled project attendance data.
ashutosh.nehete
added 1 commit 2025-05-24 04:44:35 +00:00
Merge pull request 'Implemented an API endpoint that retrieves the attendance records for a specific project on a given date' (#71) from Ashutosh_Task#347_Project_Attendance_Report into Issue_May_4W
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "Ashutosh_Task#347_Project_Attendance_Report"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?