video

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: 12 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, video Video) error

Create inserts a new video with the passed information.

func HandleCreate

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

HandleCreate allows administrators to insert a new video in a course.

func HandleList

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

HandleList returns all the available videos. It doesn't return the actual URL of videos, so it can be safely exposed.

func HandleListByCourse

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

HandleListByCourse returns all the available videos of a course. It doesn't return the actual URL of videos, so it can be safely exposed.

func HandleListProgressByCourse

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

HandleListProgressByCourse returns all the progress of a user on a specific course.

func HandleShow

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

HandleShow returns the information of a specific video. It doesn't return the actual URL of videos, so it can be safely exposed.

func HandleShowFree

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

HandleShowFree returns all information useful for presenting the video to users. Only free videos can be retrieved with this function. Thus, it can be safely exposed.

func HandleShowFull

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

HandleShowFull returns all data useful for presenting the video to users. This returns the URL also, so only owners of a video are allowed to call this.

func HandleUpdate

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

HandleUpdate allows administrators to update videos' information.

func HandleUpdateProgress

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

HandleUpdateProgress inserts a progress on a video for a specific user.

func UpdateProgress

func UpdateProgress(ctx context.Context, db sqlx.ExtContext, userID string, videoID string, value int) error

UpdateProgress upserts user's progress on a video.

Types

type Progress

type Progress struct {
	VideoID   string    `json:"videoId" db:"video_id"`
	UserID    string    `json:"userId" db:"user_id"`
	Progress  int       `json:"progress" db:"progress"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}

Progress models users' progress on videos.

func FetchUserProgressByCourse

func FetchUserProgressByCourse(ctx context.Context, db sqlx.ExtContext, userID string, courseID string) ([]Progress, error)

FetchUserProgressByCourse returns user's progress on videos of a specific course.

type ProgressUp

type ProgressUp struct {
	Progress int `json:"progress" validate:"gte=0,lte=100"`
}

ProgressUp contains the data of a progress which can be updated.

type Video

type Video struct {
	ID          string    `json:"id" db:"video_id"`
	CourseID    string    `json:"courseId" db:"course_id"`
	Index       int       `json:"index" db:"index"`
	Name        string    `json:"name" db:"name"`
	Description string    `json:"description" db:"description"`
	Free        bool      `json:"free" db:"free"`
	URL         string    `json:"-" db:"url"`
	ImageURL    string    `json:"imageUrl" db:"image_url"`
	CreatedAt   time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt   time.Time `json:"updatedAt" db:"updated_at"`
	Version     int       `json:"-" db:"version"`
}

Video models videos. A course can contain many videos. A video can be contained by a course only. URL is not marhsalled to JSON to avoid security issues.

func Fetch

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

Fetch returns a video given its id.

func FetchAll

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

FetchAll returns all available videos.

func FetchAllByCourse

func FetchAllByCourse(ctx context.Context, db sqlx.ExtContext, courseID string) ([]Video, error)

FetchAllByCourse returns all available videos belonging to a specific course.

func Update

func Update(ctx context.Context, db sqlx.ExtContext, video Video) (Video, error)

Update updates a video with the passed information. It relies on optimistic lock to deal with data races.

type VideoNew

type VideoNew struct {
	CourseID    string `json:"courseId" validate:"required"`
	Index       int    `json:"index" validate:"required,gte=0"`
	Name        string `json:"name" validate:"required"`
	Description string `json:"description" validate:"required"`
	Free        bool   `json:"free" validate:"required"`
	URL         string `json:"url" validate:"omitempty,url"`
	ImageURL    string `json:"imageUrl" validate:"required"`
}

VideoNew contains all the information needed to insert a new video.

type VideoUp

type VideoUp struct {
	CourseID    *string `json:"courseId"`
	Index       *int    `json:"index" validate:"omitempty,gte=0"`
	Name        *string `json:"name"`
	Description *string `json:"description"`
	Free        *bool   `json:"free"`
	URL         *string `json:"url" validate:"omitempty,url"`
	ImageURL    *string `json:"imageUrl"`
}

VideoUp specifies the data of videos that can be updated.

Jump to

Keyboard shortcuts

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