GetAllIdentitiesPaginated retrieves identities from the database with pagination support. Parameters: - limit: The maximum number of identities to return. - offset: The offset to start fetching identities from (for pagination). Returns: - A slice of Identity objects if successful, or an error if any
(limit, offset int)
| 308 | // Returns: |
| 309 | // - A slice of Identity objects if successful, or an error if any operation fails. |
| 310 | func (d Datasource) GetAllIdentitiesPaginated(limit, offset int) ([]model.Identity, error) { |
| 311 | if limit <= 0 || limit > 100 { |
| 312 | limit = 20 |
| 313 | } |
| 314 | |
| 315 | rows, err := d.Conn.QueryContext(context.Background(), ` |
| 316 | SELECT identity_id, identity_type, first_name, last_name, other_names, gender, dob, email_address, phone_number, nationality, organization_name, category, street, country, state, post_code, city, created_at, meta_data |
| 317 | FROM ledgerforge.identity |
| 318 | ORDER BY created_at DESC |
| 319 | LIMIT $1 OFFSET $2 |
| 320 | `, limit, offset) |
| 321 | if err != nil { |
| 322 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to retrieve identities", err) |
| 323 | } |
| 324 | defer func() { _ = rows.Close() }() |
| 325 | |
| 326 | var identities []model.Identity |
| 327 | |
| 328 | for rows.Next() { |
| 329 | identity := model.Identity{} |
| 330 | var metaDataJSON []byte |
| 331 | |
| 332 | err = rows.Scan( |
| 333 | &identity.IdentityID, &identity.IdentityType, |
| 334 | &identity.FirstName, &identity.LastName, &identity.OtherNames, &identity.Gender, &identity.DOB, &identity.EmailAddress, &identity.PhoneNumber, &identity.Nationality, |
| 335 | &identity.OrganizationName, &identity.Category, |
| 336 | &identity.Street, &identity.Country, &identity.State, &identity.PostCode, &identity.City, &identity.CreatedAt, &metaDataJSON, |
| 337 | ) |
| 338 | if err != nil { |
| 339 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to scan identity data", err) |
| 340 | } |
| 341 | |
| 342 | err = json.Unmarshal(metaDataJSON, &identity.MetaData) |
| 343 | if err != nil { |
| 344 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Failed to unmarshal metadata", err) |
| 345 | } |
| 346 | |
| 347 | identities = append(identities, identity) |
| 348 | } |
| 349 | |
| 350 | if err = rows.Err(); err != nil { |
| 351 | return nil, apierror.NewAPIError(apierror.ErrInternalServer, "Error occurred while iterating over identities", err) |
| 352 | } |
| 353 | |
| 354 | return identities, nil |
| 355 | } |
| 356 | |
| 357 | // GetAllIdentitiesWithFilter retrieves identities with advanced filtering support. |
| 358 | // It delegates to GetAllIdentitiesWithFilterAndOptions with nil options. |
nothing calls this directly
no test coverage detected