Skip to main content

import-user


ImportDataUserProfiles Function

Overview

The ImportDataUserProfiles function imports a slice of user profile data into a specified ImportDataStruct. It processes user profiles, matches them with their corresponding calendar schedules, and appends the resulting structured data into the import data object.


Function Definition

func ImportDataUserProfiles(
importData *entity.ImportDataStruct,
userProfiles []entity.UserProfileTable,
cache *caching.AllCacheStruct
)

Parameters


  • importData (*entity.ImportDataStruct):A pointer to the data structure where the processed import data will be stored.

  • userProfiles ([]entity.UserProfileTable):A slice of user profile data to be imported.

  • cache (*caching.AllCacheStruct):A pointer to a caching structure that provides methods to retrieve cached data such as users, shifts, and calendar schedules.

Process Overview


  1. Retrieve Month and YearExtracts the month and year from the importData.

  2. Iterate Over User ProfilesLoops through each user profile in the provided slice.

  3. Create User Import StructInitializes an ImportDataUser object with the user's CustomID and FullName.

  4. Match Calendar SchedulesFor each day of the specified month:
    • Formats the date (YYYY-MM-DD).
    • Retrieves the user's calendar schedule from the cache using the date.

  5. Populate ShiftsBased on the retrieved calendar schedule:
    • If no details exist, an empty shift is appended.
    • Otherwise, retrieves associated shifts and adds them to the ShiftStruct.

  6. Append Processed DataAdds the constructed ImportDataUser object to the importData.

Key Structures

entity.ImportDataUser

Represents a single user's data to be imported.Fields:

  • Id (string): User's unique identifier (CustomID).
  • Name (string): Full name of the user.
  • Shifts ([]entity.ShiftStruct): List of shift details for each day.

entity.ShiftStruct

Represents shift information for a specific day.Fields:

  • ShiftList ([]string): List of short labels for the shifts.
  • AutoShift (bool): Indicates if the shifts are automatically assigned.

Example Workflow

  1. A user profile with CustomID: "U001" and FullName: "John Doe" is processed.
  2. For the specified month (e.g., January 2024):
    • For each day, retrieve the calendar schedule.
    • Populate shift details if schedule exists.
  3. Add ImportDataUser containing Id, Name, and Shifts to the importData.Data.

Edge Cases


  • **No Calendar Schedule:**Appends an empty ShiftStruct if no schedule is found.

  • **No Schedule Details:**Appends an empty ShiftStruct if a calendar schedule exists but contains no details.

Dependencies

  • entity.ImportDataStruct
  • entity.UserProfileTable
  • entity.CalendarScheduleTable
  • entity.ShiftStruct
  • caching.AllCacheStruct

Notes

  • The function assumes all cache methods (FindUserByCustomID, FindCalendarSchedulesByPersonByDate, and GetShiftByID) will handle errors or missing data gracefully.
  • The function supports dynamic calendar configurations, adapting to the details provided in the schedules.