go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/chirp/pkg/model/user_full.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package model
     9  
    10  import (
    11  	"go.charczuk.com/sdk/apputil"
    12  	"go.charczuk.com/sdk/db"
    13  	"go.charczuk.com/sdk/uuid"
    14  )
    15  
    16  // UserFull is all relevant information about a user.
    17  type UserFull struct {
    18  	apputil.User
    19  	Info   UserInfo
    20  	Status UserStatus
    21  }
    22  
    23  var (
    24  	prefixUserMeta       = db.TypeMetaFor(apputil.User{}).CopyWithColumnPrefix("user_")
    25  	prefixUserInfoMeta   = db.TypeMetaFor(UserInfo{}).CopyWithColumnPrefix("userinfo_")
    26  	prefixUserStatusMeta = db.TypeMetaFor(UserStatus{}).CopyWithColumnPrefix("userstatus_")
    27  )
    28  
    29  func (uf *UserFull) Populate(r db.Rows) error {
    30  	if populateErr := db.PopulateByName(&uf.User, r, prefixUserMeta); populateErr != nil {
    31  		return populateErr
    32  	}
    33  	if populateErr := db.PopulateByName(&uf.Info, r, prefixUserInfoMeta); populateErr != nil {
    34  		return populateErr
    35  	}
    36  	if populateErr := db.PopulateByName(&uf.Status, r, prefixUserStatusMeta); populateErr != nil {
    37  		return populateErr
    38  	}
    39  	return nil
    40  }
    41  
    42  // UserStatus is some extra readonly data.
    43  type UserStatus struct {
    44  	UserID      uuid.UUID `db:"user_id,readonly"`
    45  	IsFollowing bool      `db:"is_following,readonly"`
    46  	IsSelf      bool      `db:"is_self,readonly"`
    47  }