Implemented an API to update Buckets for grouping contacts. #68
Collaborator
- Get Tenant and Employee Info:
- Get the current tenant ID using _userHelper.GetTenantId().
- Get the currently logged-in employee using _userHelper.GetCurrentEmployeeAsync().
- Validate Input:
- Ensure bucketDto is not null and that the provided id matches bucketDto.Id.
- If invalid, log a warning and return a 400 Bad Request error response with a message: "User sent empty Payload".
- Fetch Bucket:
- Look for the bucket in the database where:
- Id matches bucketDto.Id
- TenantId matches the current tenant
- If the bucket is not found:
- Log a warning that the employee tried to update a non-existent bucket.
- Return a 404 Not Found error response with the message: "Bucket not found".
- Look for the bucket in the database where:
- Update Bucket Fields:
- Set the bucket’s Name and Description from bucketDto, using empty strings as fallbacks for null values.
- Log the Update:
- Create a new DirectoryUpdateLog entry capturing:
- The reference ID (bucket ID)
- The employee who made the change
- The update timestamp (DateTime.UtcNow)
- Add the log to the database context.
- Create a new DirectoryUpdateLog entry capturing:
- Save Changes:
- Persist the changes to the database with SaveChangesAsync().
- Prepare Response:
- Convert the updated bucket to a BucketVM (view model).
- Log a success message indicating the update and employee ID.
- Return a 200 OK success response with the updated bucket data.
- **Get Tenant and Employee Info**:
- Get the current tenant ID using _userHelper.GetTenantId().
- Get the currently logged-in employee using _userHelper.GetCurrentEmployeeAsync().
- **Validate Input**:
- Ensure bucketDto is not null and that the provided id matches bucketDto.Id.
- If invalid, log a warning and return a 400 Bad Request error response with a message: "User sent empty Payload".
- **Fetch Bucket**:
- Look for the bucket in the database where:
- Id matches bucketDto.Id
- TenantId matches the current tenant
- If the bucket is not found:
- Log a warning that the employee tried to update a non-existent bucket.
- Return a 404 Not Found error response with the message: "Bucket not found".
- **Update Bucket Fields**:
- Set the bucket’s Name and Description from bucketDto, using empty strings as fallbacks for null values.
- **Log the Update**:
- Create a new DirectoryUpdateLog entry capturing:
- The reference ID (bucket ID)
- The employee who made the change
- The update timestamp (DateTime.UtcNow)
- Add the log to the database context.
- **Save Changes**:
- Persist the changes to the database with SaveChangesAsync().
- **Prepare Response**:
- Convert the updated bucket to a BucketVM (view model).
- Log a success message indicating the update and employee ID.
- Return a 200 OK success response with the updated bucket data.
ashutosh.nehete
added 1 commit 2025-05-22 14:19:47 +00:00
Merge pull request 'Implemented an API to update Buckets for grouping contacts.' (#68) from Ashutosh_Task#250_Update_Bucket into Feature_Directory
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "Ashutosh_Task#250_Update_Bucket"
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?