Implement an API to store employee information with a captured image and update employee information. #78

Merged
ashutosh.nehete merged 1 commits from Ashutosh_Enhancement#413_Manage_Employee into Issue_May_5W 2025-05-30 12:29:50 +00:00
Collaborator

1.Tenant Identification

  • The method starts by retrieving the tenant ID using a helper class. This supports multi-tenancy by tying all operations to a specific tenant.

2. Null Input Check

  • It checks if the incoming data model is null. If so, it logs a warning and returns a 400 Bad Request response, indicating that invalid data was submitted.

3. Required Fields Validation

  • It validates that both the first name and phone number are provided. If either is missing or empty, it logs another warning and returns a 400 response with an appropriate message.

4. Determine Operation Type

  • The method checks if the model contains an ID:
    • If no ID is provided, it's treated as a new employee creation.
    • If an ID is present, it's treated as an update to an existing employee.

5. Profile Image Handling

  • If a profile image string is provided, the method attempts to decode it from Base64 format.
  • If the decoding fails (e.g., due to an invalid format), it returns a 400 Bad Request with an error message.

6. New Employee Creation Flow

  • Converts the data model into an employee entity, including the optional photo.
  • Adds the employee to the database and saves the changes.
  • Maps the new employee to a view model format for the response.
  • Logs the creation action and returns a 200 OK response with the new employee details.

7. Existing Employee Update Flow

  • Searches for the employee in the database using the provided ID.
  • If the employee is not found, it logs an error and returns a 404 Not Found response.
  • If found, it decodes the new image (if provided) or keeps the existing photo.
  • Updates the employee’s information with new values from the input model.
  • Saves the changes to the database.
  • Maps the updated employee to a view model.
  • Logs the update action and returns a 200 OK response with the updated employee details.

8. Logging and Response Handling

  • Throughout the method, logging is used to track important events (like invalid input, successful creation, or updates).
  • All responses are wrapped using a custom API response format for consistency.

Method: POST
Endpoint: api/employee/manage-mobile

**1.Tenant Identification** - The method starts by retrieving the tenant ID using a helper class. This supports multi-tenancy by tying all operations to a specific tenant. **2. Null Input Check** - It checks if the incoming data model is null. If so, it logs a warning and returns a 400 Bad Request response, indicating that invalid data was submitted. **3. Required Fields Validation** - It validates that both the first name and phone number are provided. If either is missing or empty, it logs another warning and returns a 400 response with an appropriate message. **4. Determine Operation Type** - The method checks if the model contains an ID: - If no ID is provided, it's treated as a new employee creation. - If an ID is present, it's treated as an update to an existing employee. **5. Profile Image Handling** - If a profile image string is provided, the method attempts to decode it from Base64 format. - If the decoding fails (e.g., due to an invalid format), it returns a 400 Bad Request with an error message. **6. New Employee Creation Flow** - Converts the data model into an employee entity, including the optional photo. - Adds the employee to the database and saves the changes. - Maps the new employee to a view model format for the response. - Logs the creation action and returns a 200 OK response with the new employee details. **7. Existing Employee Update Flow** - Searches for the employee in the database using the provided ID. - If the employee is not found, it logs an error and returns a 404 Not Found response. - If found, it decodes the new image (if provided) or keeps the existing photo. - Updates the employee’s information with new values from the input model. - Saves the changes to the database. - Maps the updated employee to a view model. - Logs the update action and returns a 200 OK response with the updated employee details. **8. Logging and Response Handling** - Throughout the method, logging is used to track important events (like invalid input, successful creation, or updates). - All responses are wrapped using a custom API response format for consistency. **Method**: POST **Endpoint**: api/employee/manage-mobile
ashutosh.nehete added 1 commit 2025-05-30 11:28:01 +00:00
ashutosh.nehete merged commit b479c7cf19 into Issue_May_5W 2025-05-30 12:29:50 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/marco.pms.api#78
No description provided.