models

package
v0.0.0-...-44ff033 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoRecord indicates that no matching record was found in the database or data source.
	ErrNoRecord = errors.New("models: no matching record found")

	// ErrInvalidCredentials indicates that the provided user credentials are
	// invalid or do not match any record in the system.
	ErrInvalidCredentials = errors.New("models: invalid credentials")

	// ErrDuplicateEmail indicates that the provided email already exists
	// in the system and cannot be used again.
	ErrDuplicateEmail = errors.New("models: duplicate email")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Id          int
	Title       string
	Description string
	Location    string
	EventDate   time.Time
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Event represents a scheduled occurrence with a title, description, date, and location.

type EventModel

type EventModel struct {
	DB *sql.DB
}

EventModel provides methods for managing and interacting with events in the database. It includes functionality to create, retrieve, and list event records. The `DB` field holds the database connection used for queries and operations.

func (*EventModel) Create

func (m *EventModel) Create(title, description string, eventDate time.Time, location string) (int, error)

Create adds a new event record to the database with the provided title, description, date, and location. It returns the ID of the newly created event or an error if the operation fails.

func (*EventModel) Delete

func (m *EventModel) Delete(id int) error

Delete removes an event record from the database by its unique ID and returns an error if the operation fails.

func (*EventModel) List

func (m *EventModel) List() ([]Event, error)

List retrieves all event records from the database and returns them as a slice of Event pointers or an error if it fails.

func (*EventModel) Retrieve

func (m *EventModel) Retrieve(id int) (Event, error)

Retrieve retrieves an event from the database by its unique ID. It returns the matching Event object or an error if the query fails or no event is found.

func (*EventModel) Update

func (m *EventModel) Update(id int, title, description string, eventDate time.Time, location string) error

Update modifies an existing event in the database using the provided ID and updated event details. Returns an error if the update operation fails or if no record is affected.

type User

type User struct {
	ID             int
	Name           string
	Email          string
	HashedPassword []byte
}

User represents a user entity with basic identification and authentication fields.

type UserModel

type UserModel struct {
	DB *sql.DB
}

UserModel provides methods to interact with the users' data in the database using an sql.DB instance.

func (*UserModel) Authenticate

func (m *UserModel) Authenticate(email, password string) (int, error)

Authenticate verifies a user's credentials and returns their ID if valid or an error if authentication fails.

func (*UserModel) Create

func (m *UserModel) Create(name, email, password string) error

Create adds a new user with the provided name, email, and hashed password to the database.

func (*UserModel) Exists

func (m *UserModel) Exists(id int) (bool, error)

Exists checks if a user with the specified ID exists in the database and returns a boolean result and an error.

Jump to

Keyboard shortcuts

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