Documentation ¶
Index ¶
- func Create(ctx context.Context, db sqlx.ExtContext, course Course) error
- func HandleCreate(db *sqlx.DB) web.Handler
- func HandleList(db *sqlx.DB) web.Handler
- func HandleListOwned(db *sqlx.DB) web.Handler
- func HandleShow(db *sqlx.DB) web.Handler
- func HandleUpdate(db *sqlx.DB) web.Handler
- type Course
- func Fetch(ctx context.Context, db sqlx.ExtContext, id string) (Course, error)
- func FetchAll(ctx context.Context, db sqlx.ExtContext) ([]Course, error)
- func FetchByOwner(ctx context.Context, db sqlx.ExtContext, userID string) ([]Course, error)
- func FetchOwned(ctx context.Context, db sqlx.ExtContext, courseID string, userID string) (Course, error)
- func Update(ctx context.Context, db sqlx.ExtContext, course Course) (Course, error)
- type CourseNew
- type CourseUp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleCreate ¶
HandleCreate allows administrators to add new courses.
func HandleList ¶
HandleList allows users to fetch all available courses.
func HandleListOwned ¶
HandleList allows users to fetch courses they own.
func HandleShow ¶
HandleShow allows users to fetch the information of a specific course.
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 FetchByOwner ¶
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.
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.
Click to show internal directories.
Click to hide internal directories.