GetUserProfile returns the user profile with a given username. Returns ErrUserNotFound when the user does not exist.
(ctx context.Context, r repo.Repository, username string)
| 78 | // GetUserProfile returns the user profile with a given username. |
| 79 | // Returns ErrUserNotFound when the user does not exist. |
| 80 | func GetUserProfile(ctx context.Context, r repo.Repository, username string) (*Profile, error) { |
| 81 | manifests, err := r.FindManifests(ctx, map[string]string{ |
| 82 | manifest.TypeLabelKey: ManifestType, |
| 83 | UsernameAtHostnameLabel: username, |
| 84 | }) |
| 85 | if err != nil { |
| 86 | return nil, errors.Wrap(err, "error looking for user profile") |
| 87 | } |
| 88 | |
| 89 | if len(manifests) == 0 { |
| 90 | return nil, errors.Wrap(ErrUserNotFound, username) |
| 91 | } |
| 92 | |
| 93 | p := &Profile{} |
| 94 | if _, err := r.GetManifest(ctx, manifest.PickLatestID(manifests), p); err != nil { |
| 95 | return nil, errors.Wrap(err, "error loading user profile") |
| 96 | } |
| 97 | |
| 98 | return p, nil |
| 99 | } |
| 100 | |
| 101 | // GetNewProfile returns a profile for a new user with the given username. |
| 102 | // Returns ErrUserAlreadyExists when the user already exists. |