course

package
v0.0.0-...-53bd342 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, db sqlx.ExtContext, course Course) error

Create inserts a new course.

func HandleCreate

func HandleCreate(db *sqlx.DB) web.Handler

HandleCreate allows administrators to add new courses.

func HandleList

func HandleList(db *sqlx.DB) web.Handler

HandleList allows users to fetch all available courses.

func HandleListOwned

func HandleListOwned(db *sqlx.DB) web.Handler

HandleList allows users to fetch courses they own.

func HandleShow

func HandleShow(db *sqlx.DB) web.Handler

HandleShow allows users to fetch the information of a specific course.

func HandleUpdate

func HandleUpdate(db *sqlx.DB) web.Handler

HandleUpdate allows administrators to update existing courses.

Types

type Course

type Course struct {
	ID          string    `json:"id" db:"course_id"`
	Name        string    `json:"name" db:"name"`
	Description string    `json:"description" db:"description"`
	ImageURL    string    `json:"imageUrl" db:"image_url"`
	Price       int       `json:"price" db:"price"`
	CreatedAt   time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt   time.Time `json:"updatedAt" db:"updated_at"`
	Version     int       `json:"-" db:"version"`
}

Course models courses. A user can own many courses and a course can be owned by many users.

func Fetch

func Fetch(ctx context.Context, db sqlx.ExtContext, id string) (Course, error)

Fetch returns information of a specific course.

func FetchAll

func FetchAll(ctx context.Context, db sqlx.ExtContext) ([]Course, error)

FetchAll returns all courses.

func FetchByOwner

func FetchByOwner(ctx context.Context, db sqlx.ExtContext, userID string) ([]Course, error)

FetchByOwner returns all the courses owned by the passed user.

func FetchOwned

func FetchOwned(ctx context.Context, db sqlx.ExtContext, courseID string, userID string) (Course, error)

FetchOwned returns the specified course if the passed user owns it.

func Update

func Update(ctx context.Context, db sqlx.ExtContext, course Course) (Course, error)

Update updates the details of a specific course. It relies on optimistic lock to deal with data races.

type CourseNew

type CourseNew struct {
	Name        string `json:"name" validate:"required"`
	Description string `json:"description" validate:"required"`
	Price       int    `json:"price" validate:"required,gte=0,lte=10000"`
	ImageURL    string `json:"imageUrl" validate:"required"`
}

CourseNew contains the information needed to create a new course.

type CourseUp

type CourseUp struct {
	Name        *string `json:"name"`
	Description *string `json:"description"`
	Price       *int    `json:"price" validate:"omitempty,gte=0,lte=10000"`
	ImageURL    *string `json:"imageUrl"`
}

CourseUp contains the information of a course that can be updated.

Jump to

Keyboard shortcuts

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