models

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(password, hash string) bool

CheckPassword checks if the provided password matches the hash

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a bcrypt hash from a password

func SetupDB

func SetupDB(dbPath string, migrations fs.FS) (*sql.DB, error)

SetupDB initializes a database connection and performs migrations

Types

type Attendance

type Attendance struct {
	TalkID    int              `json:"talk_id"`
	UserID    int              `json:"user_id"`
	Status    AttendanceStatus `json:"status"`
	Feedback  string           `json:"feedback,omitempty"`
	User      *User            `json:"user,omitempty"`
	Talk      *Talk            `json:"talk,omitempty"`
	CreatedAt time.Time        `json:"created_at"`
	UpdatedAt time.Time        `json:"updated_at"`
}

Attendance represents a user's attendance at a talk

type AttendanceRepository

type AttendanceRepository interface {
	FindByIDs(ctx context.Context, talkID, userID int) (*Attendance, error)
	Create(ctx context.Context, attendance *Attendance) error
	Update(ctx context.Context, attendance *Attendance) error
	Delete(ctx context.Context, talkID, userID int) error
	ListByTalk(ctx context.Context, talkID int) ([]*Attendance, error)
	ListByUser(ctx context.Context, userID int) ([]*Attendance, error)
	ListByStatus(ctx context.Context, status AttendanceStatus) ([]*Attendance, error)
	GetTalkAttendanceCount(ctx context.Context, talkID int) (int, error)
}

AttendanceRepository defines the interface for attendance data operations

type AttendanceStatus

type AttendanceStatus string

AttendanceStatus represents the status of a user's attendance at a talk

const (
	AttendanceStatusConfirmed AttendanceStatus = "confirmed"
	AttendanceStatusAttended  AttendanceStatus = "attended"
	AttendanceStatusDeclined  AttendanceStatus = "declined"
	AttendanceStatusNoShow    AttendanceStatus = "no-show"
)

Attendance status constants

type Repositories

type Repositories struct {
	User       UserRepository
	Talk       TalkRepository
	Vote       VoteRepository
	Attendance AttendanceRepository
	Resource   ResourceRepository
}

Repositories holds all the repository instances

func NewRepositories

func NewRepositories(db *sql.DB) (*Repositories, error)

NewRepositories creates new repository instances using the provided database

type Resource

type Resource struct {
	ID        int          `json:"id"`
	TalkID    int          `json:"talk_id"`
	Title     string       `json:"title"`
	URL       string       `json:"url"`
	Type      ResourceType `json:"type"`
	Talk      *Talk        `json:"talk,omitempty"`
	CreatedAt time.Time    `json:"created_at"`
	UpdatedAt time.Time    `json:"updated_at"`
}

Resource represents a resource attached to a talk

type ResourceRepository

type ResourceRepository interface {
	FindByID(ctx context.Context, id int) (*Resource, error)
	Create(ctx context.Context, resource *Resource) error
	Update(ctx context.Context, resource *Resource) error
	Delete(ctx context.Context, id int) error
	ListByTalk(ctx context.Context, talkID int) ([]*Resource, error)
	ListByType(ctx context.Context, resourceType ResourceType) ([]*Resource, error)
}

ResourceRepository defines the interface for resource data operations

type ResourceType

type ResourceType string

ResourceType represents the type of a resource

const (
	ResourceTypeSlides  ResourceType = "slides"
	ResourceTypeVideo   ResourceType = "video"
	ResourceTypeCode    ResourceType = "code"
	ResourceTypeArticle ResourceType = "article"
	ResourceTypeOther   ResourceType = "other"
)

Resource type constants

type SQLiteAttendanceRepository

type SQLiteAttendanceRepository struct {
	// contains filtered or unexported fields
}

SQLiteAttendanceRepository implements AttendanceRepository for SQLite

func NewSQLiteAttendanceRepository

func NewSQLiteAttendanceRepository(db *sql.DB) *SQLiteAttendanceRepository

NewSQLiteAttendanceRepository creates a new SQLiteAttendanceRepository

func (*SQLiteAttendanceRepository) Create

func (r *SQLiteAttendanceRepository) Create(ctx context.Context, attendance *Attendance) error

Create creates a new attendance record

func (*SQLiteAttendanceRepository) Delete

func (r *SQLiteAttendanceRepository) Delete(ctx context.Context, talkID, userID int) error

Delete deletes an attendance record

func (*SQLiteAttendanceRepository) FindByIDs

func (r *SQLiteAttendanceRepository) FindByIDs(ctx context.Context, talkID, userID int) (*Attendance, error)

FindByIDs finds an attendance record by talk ID and user ID

func (*SQLiteAttendanceRepository) GetTalkAttendanceCount

func (r *SQLiteAttendanceRepository) GetTalkAttendanceCount(ctx context.Context, talkID int) (int, error)

GetTalkAttendanceCount returns the total number of confirmed attendees for a talk

func (*SQLiteAttendanceRepository) ListByStatus

func (r *SQLiteAttendanceRepository) ListByStatus(ctx context.Context, status AttendanceStatus) ([]*Attendance, error)

ListByStatus returns all attendance records with a given status

func (*SQLiteAttendanceRepository) ListByTalk

func (r *SQLiteAttendanceRepository) ListByTalk(ctx context.Context, talkID int) ([]*Attendance, error)

ListByTalk returns all attendance records for a talk

func (*SQLiteAttendanceRepository) ListByUser

func (r *SQLiteAttendanceRepository) ListByUser(ctx context.Context, userID int) ([]*Attendance, error)

ListByUser returns all attendance records for a user

func (*SQLiteAttendanceRepository) Update

func (r *SQLiteAttendanceRepository) Update(ctx context.Context, attendance *Attendance) error

Update updates an existing attendance record

type SQLiteResourceRepository

type SQLiteResourceRepository struct {
	// contains filtered or unexported fields
}

SQLiteResourceRepository implements ResourceRepository for SQLite

func NewSQLiteResourceRepository

func NewSQLiteResourceRepository(db *sql.DB) *SQLiteResourceRepository

NewSQLiteResourceRepository creates a new SQLiteResourceRepository

func (*SQLiteResourceRepository) Create

func (r *SQLiteResourceRepository) Create(ctx context.Context, resource *Resource) error

Create creates a new resource

func (*SQLiteResourceRepository) Delete

func (r *SQLiteResourceRepository) Delete(ctx context.Context, id int) error

Delete deletes a resource by ID

func (*SQLiteResourceRepository) FindByID

func (r *SQLiteResourceRepository) FindByID(ctx context.Context, id int) (*Resource, error)

FindByID finds a resource by ID

func (*SQLiteResourceRepository) ListByTalk

func (r *SQLiteResourceRepository) ListByTalk(ctx context.Context, talkID int) ([]*Resource, error)

ListByTalk returns all resources for a talk

func (*SQLiteResourceRepository) ListByType

func (r *SQLiteResourceRepository) ListByType(ctx context.Context, resourceType ResourceType) ([]*Resource, error)

ListByType returns all resources of a given type

func (*SQLiteResourceRepository) Update

func (r *SQLiteResourceRepository) Update(ctx context.Context, resource *Resource) error

Update updates an existing resource

type SQLiteTalkRepository

type SQLiteTalkRepository struct {
	// contains filtered or unexported fields
}

SQLiteTalkRepository implements TalkRepository for SQLite

func NewSQLiteTalkRepository

func NewSQLiteTalkRepository(db *sql.DB) *SQLiteTalkRepository

NewSQLiteTalkRepository creates a new SQLiteTalkRepository

func (*SQLiteTalkRepository) Create

func (r *SQLiteTalkRepository) Create(ctx context.Context, talk *Talk) error

Create creates a new talk

func (*SQLiteTalkRepository) Delete

func (r *SQLiteTalkRepository) Delete(ctx context.Context, id int) error

Delete deletes a talk by ID

func (*SQLiteTalkRepository) FindByID

func (r *SQLiteTalkRepository) FindByID(ctx context.Context, id int) (*Talk, error)

FindByID finds a talk by ID

func (*SQLiteTalkRepository) FindProposedWithPreferredDate

func (r *SQLiteTalkRepository) FindProposedWithPreferredDate(ctx context.Context, date time.Time) ([]*Talk, error)

FindProposedWithPreferredDate finds proposed talks with a preferred date

func (*SQLiteTalkRepository) List

func (r *SQLiteTalkRepository) List(ctx context.Context) ([]*Talk, error)

List returns all talks

func (*SQLiteTalkRepository) ListBySpeaker

func (r *SQLiteTalkRepository) ListBySpeaker(ctx context.Context, speakerID int) ([]*Talk, error)

ListBySpeaker returns all talks by a given speaker

func (*SQLiteTalkRepository) ListByStatus

func (r *SQLiteTalkRepository) ListByStatus(ctx context.Context, status TalkStatus) ([]*Talk, error)

ListByStatus returns all talks with a given status

func (*SQLiteTalkRepository) Update

func (r *SQLiteTalkRepository) Update(ctx context.Context, talk *Talk) error

Update updates an existing talk

type SQLiteUserRepository

type SQLiteUserRepository struct {
	// contains filtered or unexported fields
}

SQLiteUserRepository implements UserRepository for SQLite

func NewSQLiteUserRepository

func NewSQLiteUserRepository(db *sql.DB) *SQLiteUserRepository

NewSQLiteUserRepository creates a new SQLiteUserRepository

func (*SQLiteUserRepository) Create

func (r *SQLiteUserRepository) Create(ctx context.Context, user *User) error

Create creates a new user

func (*SQLiteUserRepository) FindByEmail

func (r *SQLiteUserRepository) FindByEmail(ctx context.Context, email string) (*User, error)

FindByEmail finds a user by email

func (*SQLiteUserRepository) FindByID

func (r *SQLiteUserRepository) FindByID(ctx context.Context, id int) (*User, error)

FindByID finds a user by ID

func (*SQLiteUserRepository) List

func (r *SQLiteUserRepository) List(ctx context.Context) ([]*User, error)

List returns all users

func (*SQLiteUserRepository) Update

func (r *SQLiteUserRepository) Update(ctx context.Context, user *User) error

Update updates an existing user

type SQLiteVoteRepository

type SQLiteVoteRepository struct {
	// contains filtered or unexported fields
}

SQLiteVoteRepository implements VoteRepository for SQLite

func NewSQLiteVoteRepository

func NewSQLiteVoteRepository(db *sql.DB) *SQLiteVoteRepository

NewSQLiteVoteRepository creates a new SQLiteVoteRepository

func (*SQLiteVoteRepository) Create

func (r *SQLiteVoteRepository) Create(ctx context.Context, vote *Vote) error

Create creates a new vote

func (*SQLiteVoteRepository) Delete

func (r *SQLiteVoteRepository) Delete(ctx context.Context, userID, talkID int) error

Delete deletes a vote

func (*SQLiteVoteRepository) FindByIDs

func (r *SQLiteVoteRepository) FindByIDs(ctx context.Context, userID, talkID int) (*Vote, error)

FindByIDs finds a vote by user ID and talk ID

func (*SQLiteVoteRepository) GetAvailabilityForDate

func (r *SQLiteVoteRepository) GetAvailabilityForDate(ctx context.Context, talkID int, date time.Time) (map[int]bool, error)

GetAvailabilityForDate returns a map of user IDs to their availability for a specific date

func (*SQLiteVoteRepository) GetTalkInterestCount

func (r *SQLiteVoteRepository) GetTalkInterestCount(ctx context.Context, talkID int) (int, error)

GetTalkInterestCount returns the total number of users interested in a talk (interest level >= 3)

func (*SQLiteVoteRepository) ListByTalk

func (r *SQLiteVoteRepository) ListByTalk(ctx context.Context, talkID int) ([]*Vote, error)

ListByTalk returns all votes for a talk

func (*SQLiteVoteRepository) ListByUser

func (r *SQLiteVoteRepository) ListByUser(ctx context.Context, userID int) ([]*Vote, error)

ListByUser returns all votes by a user

func (*SQLiteVoteRepository) Update

func (r *SQLiteVoteRepository) Update(ctx context.Context, vote *Vote) error

Update updates an existing vote

type Talk

type Talk struct {
	ID             int        `json:"id"`
	Title          string     `json:"title"`
	Description    string     `json:"description"`
	SpeakerID      int        `json:"speaker_id"`
	Speaker        *User      `json:"speaker,omitempty"`
	ScheduledDate  *time.Time `json:"scheduled_date"`
	PreferredDates []string   `json:"preferred_dates"`
	Status         TalkStatus `json:"status"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
}

Talk represents a talk in the system

type TalkRepository

type TalkRepository interface {
	FindByID(ctx context.Context, id int) (*Talk, error)
	Create(ctx context.Context, talk *Talk) error
	Update(ctx context.Context, talk *Talk) error
	Delete(ctx context.Context, id int) error
	List(ctx context.Context) ([]*Talk, error)
	ListByStatus(ctx context.Context, status TalkStatus) ([]*Talk, error)
	ListBySpeaker(ctx context.Context, speakerID int) ([]*Talk, error)
	FindProposedWithPreferredDate(ctx context.Context, date time.Time) ([]*Talk, error)
}

TalkRepository defines the interface for talk data operations

type TalkStatus

type TalkStatus string

TalkStatus represents the status of a talk

const (
	TalkStatusProposed  TalkStatus = "proposed"
	TalkStatusScheduled TalkStatus = "scheduled"
	TalkStatusCompleted TalkStatus = "completed"
	TalkStatusCanceled  TalkStatus = "canceled"
)

Talk status constants

type User

type User struct {
	ID           int       `json:"id"`
	Name         string    `json:"name"`
	Email        string    `json:"email"`
	PasswordHash string    `json:"-"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

User represents a user in the system

type UserRepository

type UserRepository interface {
	FindByID(ctx context.Context, id int) (*User, error)
	FindByEmail(ctx context.Context, email string) (*User, error)
	Create(ctx context.Context, user *User) error
	Update(ctx context.Context, user *User) error
	List(ctx context.Context) ([]*User, error)
}

UserRepository defines the interface for user data operations

type Vote

type Vote struct {
	UserID        int             `json:"user_id"`
	TalkID        int             `json:"talk_id"`
	InterestLevel int             `json:"interest_level"` // 1-5
	Availability  map[string]bool `json:"availability"`   // Map of date strings to availability
	User          *User           `json:"user,omitempty"`
	Talk          *Talk           `json:"talk,omitempty"`
	CreatedAt     time.Time       `json:"created_at"`
	UpdatedAt     time.Time       `json:"updated_at"`
}

Vote represents a user's vote on a talk

type VoteRepository

type VoteRepository interface {
	FindByIDs(ctx context.Context, userID, talkID int) (*Vote, error)
	Create(ctx context.Context, vote *Vote) error
	Update(ctx context.Context, vote *Vote) error
	Delete(ctx context.Context, userID, talkID int) error
	ListByTalk(ctx context.Context, talkID int) ([]*Vote, error)
	ListByUser(ctx context.Context, userID int) ([]*Vote, error)
	GetTalkInterestCount(ctx context.Context, talkID int) (int, error)
	GetAvailabilityForDate(ctx context.Context, talkID int, date time.Time) (map[int]bool, error)
}

VoteRepository defines the interface for vote data operations

Jump to

Keyboard shortcuts

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