import-user
sidebar_position: 9
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
Retrieve Month and YearExtracts the month and year from theimportData
.
Iterate Over User ProfilesLoops through each user profile in the provided slice.
Create User Import StructInitializes anImportDataUser
object with the user'sCustomID
andFullName
.
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.
- Formats the date (
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
.
Append Processed DataAdds the constructedImportDataUser
object to theimportData
.
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
- A user profile with
CustomID: "U001"
andFullName: "John Doe"
is processed. - For the specified month (e.g., January 2024):
- For each day, retrieve the calendar schedule.
- Populate shift details if schedule exists.
- Add
ImportDataUser
containingId
,Name
, andShifts
to theimportData.Data
.
Edge Cases
**No Calendar Schedule:**Appends an emptyShiftStruct
if no schedule is found.
**No Schedule Details:**Appends an emptyShiftStruct
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
, andGetShiftByID
) will handle errors or missing data gracefully. - The function supports dynamic calendar configurations, adapting to the details provided in the schedules.