model

package
v0.0.0-...-bc49051 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EdgeTypeFollow = "follow"
	EdgeTypeBlock  = "block"
	EdgeTypeMute   = "mute"
)

EdgeType values.

View Source
const (
	NotificationTypeFollow = "follow"
	NotificationTypeLike   = "like"
)

NotificationTypes

Variables

This section is empty.

Functions

func Migrations

func Migrations(opts ...migration.SuiteOption) *migration.Suite

Migrations returns the migration suite to bootstrap the database.

Types

type Audit

type Audit struct {
	ID           uuid.UUID `db:"id,pk,auto"`
	TimestampUTC time.Time `db:"timestamp_utc"`
	UserID       uuid.UUID `db:"user_id"`
	Verb         string    `db:"verb"`
	Noun         string    `db:"noun"`
	Subject      string    `db:"subject"`
}

Audit records an action by a user.

func (Audit) TableName

func (a Audit) TableName() string

TableName returns the mapped table name.

type Chirp

type Chirp struct {
	ID           uuid.UUID         `db:"id,pk,auto"`
	UserID       uuid.UUID         `db:"user_id"`
	CreatedUTC   time.Time         `db:"created_utc"`
	PublishedUTC *time.Time        `db:"published_utc"`
	Text         string            `db:"text"`
	ReplyID      *uuid.UUID        `db:"reply_id"`
	QuotedID     *uuid.UUID        `db:"quoted_id"`
	Attachments  []ChirpAttachment `db:"attachments,json"`
}

Chirp is the main primitive of the app.

It is either a text post, a rechirp, and can include attachments.

func (Chirp) TableName

func (c Chirp) TableName() string

TableName returns the mapped table name.

type ChirpAttachment

type ChirpAttachment struct {
	Type string `db:"type"`
	URL  string `db:"url"`
}

ChirpAttachment is an attachment, e.g. a picture to a chrip.

type ChirpFull

type ChirpFull struct {
	Chirp
	User     apputil.User
	UserInfo UserInfo
	Status   ChirpStatus
	Stats    ChirpStats
	ReplyTo  *ChirpFull
	Quoted   *ChirpFull
}

ChirpFull is a hydrated chirp with all the extra stuff on it.

func (*ChirpFull) Populate

func (cf *ChirpFull) Populate(r db.Rows) error

Populate implements db.Populatable and allows us to add more complicated logic for populating the struct from database rows.

type ChirpLike

type ChirpLike struct {
	ChirpID      uuid.UUID `db:"chirp_id,pk"`
	UserID       uuid.UUID `db:"user_id,pk"`
	TimestampUTC time.Time `db:"timestamp_utc"`
}

ChirpLike are stats about chrips e.g. likes and rechirps.

func (ChirpLike) TableName

func (c ChirpLike) TableName() string

TableName is the mapped table name.

type ChirpStats

type ChirpStats struct {
	ChirpID  uuid.UUID `db:"chirp_id,pk"`
	UserID   uuid.UUID `db:"user_id"`
	Replies  uint64    `db:"replies"`
	Likes    uint64    `db:"likes"`
	Rechirps uint64    `db:"rechirps"`
}

ChirpStats are stats about chrips e.g. likes and rechirps.

func (ChirpStats) TableName

func (c ChirpStats) TableName() string

TableName is the mapped table name.

type ChirpStatus

type ChirpStatus struct {
	IsLiked     bool `db:"is_liked,readonly"`
	IsRetweeted bool `db:"is_retweeted,readonly"`
}

type EdgeType

type EdgeType string

EdgeType is a constant for each "type" of graph edge.

type Feed

type Feed struct {
	UserID       uuid.UUID `db:"user_id,pk"`
	ChirpID      uuid.UUID `db:"chirp_id,pk"`
	TimestampUTC time.Time `db:"timestamp_utc"`
}

Feed is the record of specific chirps mapped to relevant (following) users.

func (Feed) TableName

func (f Feed) TableName() string

TableName returns the mapped table name.

type Graph

type Graph struct {
	UserID       uuid.UUID `db:"user_id,pk"`
	TargetID     uuid.UUID `db:"target_id,pk"`
	Type         string    `db:"type,pk"`
	TimestampUTC time.Time `db:"timestamp_utc"`
}

Graph holds the following, mute and block relationships between users.

func (Graph) TableName

func (g Graph) TableName() string

TableName returns the mapped table name.

type Manager

type Manager struct {
	dbutil.BaseManager
}

Manager is the datumsbase manager.

func (Manager) Audit

func (m Manager) Audit(ctx context.Context, userID uuid.UUID, verb, noun, subject string) error

Audit creates a new audit log record.

func (Manager) Block

func (m Manager) Block(ctx context.Context, userID, targetUserID uuid.UUID) error

Block blocks a user.

func (Manager) BlocksForUserID

func (m Manager) BlocksForUserID(ctx context.Context, userID uuid.UUID) (output []uuid.UUID, err error)

BlocksForUserID gets the users a given user blocks.

func (Manager) Chirp

func (m Manager) Chirp(ctx context.Context, userID, id uuid.UUID) (c ChirpFull, found bool, err error)

Chirp gets a chirp by ID (and infers status based on the provided userID).

func (Manager) ChirpReplies

func (m Manager) ChirpReplies(ctx context.Context, selfUserID, chirpID uuid.UUID) (output []ChirpFull, err error)

ChirpReplies returns the replies for a given chirp id.

func (Manager) CreateChirp

func (m Manager) CreateChirp(ctx context.Context, c *Chirp) (err error)

CreateChirp creates the chirp staging it for publishing.

func (Manager) DeleteChirp

func (m Manager) DeleteChirp(ctx context.Context, c Chirp) (deleted bool, err error)

DeleteChirp deletes a chirp and removes it from any referenced table(s).

func (Manager) EnsureUserInfoOnCreate

func (m Manager) EnsureUserInfoOnCreate(ctx context.Context, user *apputil.User) error

EnsureUserInfoOnCreate creates the rest of the user components on login.

func (Manager) EnsureUserInfoOnFetch

func (m Manager) EnsureUserInfoOnFetch(ctx context.Context, session *web.Session) error

EnsureUserInfoOnFetch fetches the rest of the user components.

func (Manager) FeedForUserID

func (m Manager) FeedForUserID(ctx context.Context, userID uuid.UUID, take int, afterChirpID *uuid.UUID) (output []ChirpFull, err error)

FeedForUserID returns the feed for a given user, optionally after a given chirpID.

func (Manager) Follow

func (m Manager) Follow(ctx context.Context, userID, targetUserID uuid.UUID) error

Follow adds a graph record that a given user follows a target user as well as adds that target user's chirps to the given user's feed.

func (Manager) FollowingForUserID

func (m Manager) FollowingForUserID(ctx context.Context, userID uuid.UUID) (output []uuid.UUID, err error)

FollowingForUserID gets the users that a given user follows.

func (Manager) FollowsForUserID

func (m Manager) FollowsForUserID(ctx context.Context, userID uuid.UUID) (output []uuid.UUID, err error)

FollowsForUserID gets the users that follow a given user.

func (Manager) LikeChirp

func (m Manager) LikeChirp(ctx context.Context, userID uuid.UUID, chirp Chirp) error

LikeChirp applies a like to a chirp.

func (Manager) MarkNotificationsRead

func (m Manager) MarkNotificationsRead(ctx context.Context, userID uuid.UUID, notificationIDs []uuid.UUID) error

MarkNotificationsRead marks a list of notifications as read.

func (Manager) Mute

func (m Manager) Mute(ctx context.Context, userID, targetUserID uuid.UUID) error

Mute adds a graph record to indicate we should not show a target user's chirps in a given user's feed but we should not block the target user from following the given user or seeing their chirps.

func (Manager) MutesForUserID

func (m Manager) MutesForUserID(ctx context.Context, userID uuid.UUID) (output []uuid.UUID, err error)

BlocksForUserID gets the users a given user has muted.

func (Manager) Notifications

func (m Manager) Notifications(ctx context.Context, userID uuid.UUID, take int, afterNotificationID *uuid.UUID) (output []NotificationFull, err error)

Notifications yields the last N notifications for a user

func (Manager) NotificationsUnread

func (m Manager) NotificationsUnread(ctx context.Context, userID uuid.UUID) (output int, err error)

NotificationsUnread returns the unread notification count.

func (Manager) ProfileLikes

func (m Manager) ProfileLikes(ctx context.Context, selfUserID, targetUserID uuid.UUID, take int, afterChirpID *uuid.UUID) (output []ChirpFull, err error)

ProfileLikes returns the liked chirps for a given user.

func (Manager) ProfilePosts

func (m Manager) ProfilePosts(ctx context.Context, selfUserID, userID uuid.UUID, take int, afterChirpID *uuid.UUID) (output []ChirpFull, err error)

ProfilePosts returns the posts (non-reply, non-likes) for a given user, optionally after a given chirpID.

func (Manager) ProfileReplies

func (m Manager) ProfileReplies(ctx context.Context, selfUserID, userID uuid.UUID, take int, afterChirpID *uuid.UUID) (output []ChirpFull, err error)

ProfileReplies returns the posts (non-reply, non-likes) for a given user, optionally after a given chirpID.

func (Manager) PublishChirp

func (m Manager) PublishChirp(ctx context.Context, c *Chirp) (err error)

PublishChirp publishes the chirp, adding attachments and forwarding to the feed table.

func (Manager) SearchUsers

func (m Manager) SearchUsers(ctx context.Context, userID uuid.UUID, query string) (output []UserFull, err error)

SearchUsers returns a list of users that match a search query.

func (Manager) Unblock

func (m Manager) Unblock(ctx context.Context, userID, targetUserID uuid.UUID) error

Unblock unblocks a user.

func (Manager) Unfollow

func (m Manager) Unfollow(ctx context.Context, userID, targetUserID uuid.UUID) error

Unfollow is the reverse of follow and removes a target user's chirps from a given user's feed and removes the graph record that the given user follows the target user.

func (Manager) UnlikeChirp

func (m Manager) UnlikeChirp(ctx context.Context, userID, chirpID uuid.UUID) error

UnlikeChirp undoes a like to a chirp.

func (Manager) Unmute

func (m Manager) Unmute(ctx context.Context, userID, targetUserID uuid.UUID) error

Unmute is the reverse of mute and allows a target user's chirps to appear in a given user's feed.

func (Manager) User

func (m Manager) User(ctx context.Context, selfUserID, userID uuid.UUID) (output UserFull, found bool, err error)

User returns a user by ID.

func (Manager) UserByUsername

func (m Manager) UserByUsername(ctx context.Context, selfUserID uuid.UUID, username string) (output UserFull, found bool, err error)

UserByUsername returns a user by username.

type Notification

type Notification struct {
	ID           uuid.UUID  `db:"id,pk,auto"`
	UserID       uuid.UUID  `db:"user_id"`
	CreatedUTC   time.Time  `db:"created_utc"`
	ReadUTC      *time.Time `db:"read_utc"`
	ActingUserID uuid.UUID  `db:"acting_user_id"`
	ChirpID      *uuid.UUID `db:"chirp_id"`
	Type         string     `db:"type"`
}

Notification is someting we're going to show in the UI at some point.

func (Notification) TableName

func (n Notification) TableName() string

TableName is a name of a table.

type NotificationFull

type NotificationFull struct {
	Notification
	ActingUser UserFull
	Chirp      *Chirp
}

NotificationFull is a notification with associated information.

func (*NotificationFull) Populate

func (nf *NotificationFull) Populate(row db.Rows) error

Populate implements the populate body for database query methods.

type NotificationType

type NotificationType string

NotificationType is a type of notification.

type SessionState

type SessionState struct {
	apputil.SessionState
	UnreadNotifications int
	UserInfo            UserInfo
}

SessionState is an application specific session state.

type UserFull

type UserFull struct {
	apputil.User
	Info   UserInfo
	Status UserStatus
}

UserFull is all relevant information about a user.

func (*UserFull) Populate

func (uf *UserFull) Populate(r db.Rows) error

type UserInfo

type UserInfo struct {
	UserID      uuid.UUID `db:"user_id,pk"`
	IsPrivate   bool      `db:"is_private"`
	IsAdmin     bool      `db:"is_admin"`
	Description string    `db:"description"`
	HeroURL     string    `db:"hero_url"`
}

UserInfo contains additional user data outside what we get from apputil.User.

func (UserInfo) TableName

func (ui UserInfo) TableName() string

TableName returns the mapped table name.

type UserStatus

type UserStatus struct {
	UserID      uuid.UUID `db:"user_id,readonly"`
	IsFollowing bool      `db:"is_following,readonly"`
	IsSelf      bool      `db:"is_self,readonly"`
}

UserStatus is some extra readonly data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL