domain

package
v0.0.0-...-2b514f4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StrongPasswordTag = "strongpassword"
	NotTooOldTag      = "nottooold"
	NotFutureDateTag  = "notfuturedate"
	ValidateImagesTag = "validateImages"
	General           = "general"
	MaxAgeInYears     = 200
	MaxImagesAllowed  = 3
	MaxImageSize      = 5 * 1024 * 1024
)

Variables

View Source
var (
	ErrCreateCinema   = errors.New("error to create a new cinema")
	ErrGetCinema      = errors.New("error to get cinema")
	ErrCinemaNotFound = errors.New("cinema not found")
	ErrDeleteCinema   = errors.New("error to delete cinema")
)
View Source
var (
	ErrGetAllIndicativeRating    = errors.New("error to obtain all indicative ratings")
	ErrIndicativeRatingsNotFound = errors.New("indicative ratings not found")
	ErrIndicativeRatingNotFound  = errors.New("indicative rating not found")
	ErrCreateMovie               = errors.New("error to create a new movie")
	ErrGetMoviesByUserID         = errors.New("error to get all movies by userID")
	ErrGetMoviesByID             = errors.New("error to get movies by id")
	ErrMoviesNotFoundByUserID    = errors.New("no movies found for this user")
	ErrMoviesNotFound            = errors.New("no movie found")
	ErrUpdateMovie               = errors.New("error to update a movie")
	ErrMovieNotBelongUser        = errors.New("the movie does not belong to the user")
)
View Source
var (
	ErrTokenInvalid           = errors.New("invalid token")
	ErrSessionNotFound        = errors.New("token not found")
	ErrorUnexpectedMethod     = errors.New("unexpected signing method")
	ErrTokenNotFoundInContext = errors.New("token not found in context")
	ErrSessionMismatch        = errors.New("session icompatible for user requested")
	ErrCreateSession          = errors.New("create session fails")
	ErrCreateToken            = errors.New("create session fails")
)
View Source
var (
	ErrUserNotFound          = errors.New("user not found")
	ErrEmailAlreadyRegister  = errors.New("email already exists")
	ErrInvalidPassword       = errors.New("invalid password")
	ErrUserNotFoundInContext = errors.New("user not found in context")
	ErrGetUserByEmail        = errors.New("get user by email fail")
)
View Source
var AllowedImagesExtensions = map[string]bool{
	".png":  true,
	".jpg":  true,
	".jpeg": true,
}
View Source
var ValidationMessages = ValidationErrors{
	"required":        "This field is required",
	"email":           "Invalid email format",
	"min":             "Value is too short",
	"max":             "Value is too long",
	"eqfield":         "Fields do not match",
	"gt":              "The value must be greater than zero",
	"datetime":        "Invalid birth date",
	StrongPasswordTag: "Password must be at least 8 characters long, contain an uppercase letter, a number, and a special character",
	NotTooOldTag:      "The date of birth indicates an age greater than the allowed maximum of 200 years",
	NotFutureDateTag:  "The date of birth cannot be in the future",
	General:           "At least one field must be provided for update.",
}

Functions

func AccessDeniedAPIErrorResponse

func AccessDeniedAPIErrorResponse(ctx echo.Context) error

func CannotBindPayloadAPIErrorResponse

func CannotBindPayloadAPIErrorResponse(ctx echo.Context) error

func InternalServerAPIErrorResponse

func InternalServerAPIErrorResponse(ctx echo.Context) error

func NewCustomValidationAPIErrorResponse

func NewCustomValidationAPIErrorResponse(ctx echo.Context, statusCode int, validationErrors ValidationErrors, title, details string) error

func NewValidationAPIErrorResponse

func NewValidationAPIErrorResponse(ctx echo.Context, statusCode int, validationErrors ValidationErrors) error

func SetupCustomValidations

func SetupCustomValidations(validator *validator.Validate) error

Types

type Cinema

type Cinema struct {
	ID        uuid.UUID `gorm:"column:id;type:char(36);primaryKey"`
	Name      string    `gorm:"column:name;type:varchar(255);not null"`
	Location  string    `gorm:"column:location;type:varchar(255);not null"`
	UserID    uuid.UUID `gorm:"column:userId;type:char(36);not null"`
	User      User      `gorm:"foreignKey:UserID"`
	CreatedAt time.Time `gorm:"column:createdAt;not null"`
	UpdatedAt time.Time `gorm:"column:updatedAt;default:NULL"`
}

func (Cinema) TableName

func (Cinema) TableName() string

func (*Cinema) ToCinemaResponse

func (c *Cinema) ToCinemaResponse() *CinemaResponse

type CinemaHandler

type CinemaHandler interface {
	Create(ctx echo.Context) error
	GetByID(ctx echo.Context) error
	GetAll(ctx echo.Context) error
	Delete(ctx echo.Context) error
}

type CinemaPayload

type CinemaPayload struct {
	Name     string `json:"name" validate:"required,min=1,max=255"`
	Location string `json:"location" validate:"required,min=1,max=255"`
}

func (*CinemaPayload) ToCinema

func (c *CinemaPayload) ToCinema(userID uuid.UUID) *Cinema

func (*CinemaPayload) Validate

func (c *CinemaPayload) Validate() ValidationErrors

type CinemaRepository

type CinemaRepository interface {
	Create(ctx context.Context, cinema Cinema) error
	GetByID(ctx context.Context, cinemaID uuid.UUID) (*Cinema, error)
	GetAll(ctx context.Context, userID uuid.UUID, pagination *Pagination) (*Pagination, error)
	Delete(ctx context.Context, cinemaID uuid.UUID) error
}

type CinemaResponse

type CinemaResponse struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Location  string    `json:"location"`
	CreatedAt time.Time `json:"createdAt"`
}

type CinemaRoom

type CinemaRoom struct {
	ID        uuid.UUID `gorm:"column:id;type:char(36);primaryKey"`
	Name      string    `gorm:"column:name;type:varchar(255);not null"`
	SeatCount int       `gorm:"column:seatCount;type:int;not null"`
	CinemaID  uuid.UUID `gorm:"column:cinemaId;type:char(36);not null"`
	Cinema    Cinema    `gorm:"foreignKey:CinemaID"`
	Rows      int       `gorm:"column:rows;type:int;not null"`
	Collumns  int       `gorm:"column:collumns;type:int;not null"`
	CreatedAt time.Time `gorm:"column:createdAt;not null"`
	UpdatedAt time.Time `gorm:"column:updatedAt;default:NULL"`
}

func (CinemaRoom) TableName

func (CinemaRoom) TableName() string

type CinemaService

type CinemaService interface {
	Create(ctx context.Context, payload CinemaPayload) (*CinemaResponse, error)
	GetByID(ctx context.Context, cinemaID uuid.UUID) (*CinemaResponse, error)
	GetAll(ctx context.Context, pagination *Pagination) (*Pagination, error)
	Delete(ctx context.Context, cinemaID uuid.UUID) error
}

type CinemaSession

type CinemaSession struct {
	ID           uuid.UUID  `gorm:"column:id;type:char(36);primaryKey"`
	CinemaRoomID uuid.UUID  `gorm:"column:cinemaRoomId;type:char(36);not null"`
	CinemaRoom   CinemaRoom `gorm:"foreignKey:CinemaRoomID"`
	MovieID      uuid.UUID  `gorm:"column:MovieId;type:char(36);not null"`
	Movie        Movie      `gorm:"foreignKey:MovieID"`
	UserID       uuid.UUID  `gorm:"column:userId;type:char(36);not null"`
	User         User       `gorm:"foreignKey:UserID"`
	StartTime    time.Time  `gorm:"column:startTime;type:time;not null"`
	EndTime      time.Time  `gorm:"column:endTime;type:time;not null"`
	CreatedAt    time.Time  `gorm:"column:createdAt;not null"`
	UpdatedAt    time.Time  `gorm:"column:updatedAt;default:NULL"`
}

func (CinemaSession) TableName

func (CinemaSession) TableName() string

type ContextKey

type ContextKey string
const (
	SessionKey ContextKey = "session"
)

type ErrorResponse

type ErrorResponse struct {
	StatusCode int               `json:"status"`
	Title      string            `json:"title"`
	Details    string            `json:"details"`
	Errors     []ValidationError `json:"errors,omitempty"`
}

type IndicativeRating

type IndicativeRating struct {
	ID          uuid.UUID `gorm:"column:id;type:char(36);primaryKey"`
	Description string    `gorm:"column:description;type:char(4);not null;uniqueIndex"`
	ImageURL    string    `gorm:"column:imageUrl;type:varchar(255);not null"`
	CreatedAt   time.Time `gorm:"column:createdAt;not null"`
	UpdatedAt   time.Time `gorm:"column:updatedAt;default:NULL"`
}

func (IndicativeRating) TableName

func (IndicativeRating) TableName() string

func (*IndicativeRating) ToIndicativeRatingResponse

func (i *IndicativeRating) ToIndicativeRatingResponse() *IndicativeRatingResponse

type IndicativeRatingResponse

type IndicativeRatingResponse struct {
	ID          uuid.UUID `json:"id"`
	Description string    `json:"description"`
	ImageURL    string    `json:"imageUrl"`
}

type Movie

type Movie struct {
	ID                 uuid.UUID        `gorm:"column:id;type:char(36);primaryKey"`
	IndicativeRatingID uuid.UUID        `gorm:"column:indicativeRatingId;type:char(36);not null"`
	UserID             uuid.UUID        `gorm:"column:userId;type:char(36);not null"`
	Title              string           `gorm:"column:title;type:varchar(255);not null;index"`
	Duration           int              `gorm:"column:duration;type:int;not null"`
	User               User             `gorm:"foreignKey:UserID"`
	IndicativeRating   IndicativeRating `gorm:"foreignKey:IndicativeRatingID"`
	CreatedAt          time.Time        `gorm:"column:createdAt;not null"`
	UpdatedAt          time.Time        `gorm:"column:updatedAt;default:NULL"`
	Images             []MovieImage     `gorm:"foreignKey:MovieID"`
}

func (Movie) TableName

func (Movie) TableName() string

func (*Movie) ToMovieResponse

func (m *Movie) ToMovieResponse() *MovieResponse

type MovieHandler

type MovieHandler interface {
	GetAllIndicativeRatings(ctx echo.Context) error
	Create(ctx echo.Context) error
	GetAllByUserID(ctx echo.Context) error
	Update(ctx echo.Context) error
	Delete(ctx echo.Context) error
}

type MovieImage

type MovieImage struct {
	ID           uuid.UUID `gorm:"column:id;type:char(36);primaryKey"`
	MovieID      uuid.UUID `gorm:"column:movieId;type:char(36);not null"`
	ImageURL     string    `gorm:"column:imageUrl;type:varchar(255);not null"`
	CloudFlareID uuid.UUID `gorm:"column:cloudFlareId;type:char(36);not null;uniqueIndex"`
	CreatedAt    time.Time `gorm:"column:createdAt;not null"`
	UpdatedAt    time.Time `gorm:"column:updatedAt;default:NULL"`
}

func (MovieImage) TableName

func (MovieImage) TableName() string

func (*MovieImage) ToMovieImageResponse

func (m *MovieImage) ToMovieImageResponse() *MovieImageResponse

type MovieImageDeleteTask

type MovieImageDeleteTask struct {
	CloudFlareID uuid.UUID `json:"cloudFlareId"`
}

type MovieImageResponse

type MovieImageResponse struct {
	ID       uuid.UUID `json:"id"`
	ImageURL string    `json:"imageUrl,omitempty"`
}

type MovieImageUploadTask

type MovieImageUploadTask struct {
	MovieID uuid.UUID `json:"movieId"`
	Image   []byte    `json:"image"`
	UserID  uuid.UUID `json:"userId"`
}

type MoviePayload

type MoviePayload struct {
	Images             []*multipart.FileHeader `json:"images" validate:"validateImages"`
	IndicativeRatingID uuid.UUID               `json:"indicativeRatingId" validate:"required,uuid"`
	Title              string                  `json:"title" validate:"required,min=1,max=255"`
	Duration           int                     `json:"duration" validate:"required,gt=0"`
}

func (*MoviePayload) ToMovie

func (payload *MoviePayload) ToMovie(userID uuid.UUID) *Movie

func (*MoviePayload) Validate

func (m *MoviePayload) Validate() ValidationErrors

type MovieRepository

type MovieRepository interface {
	GetAllIndicativeRating(ctx context.Context) ([]*IndicativeRating, error)
	GetIndicativeRatingByID(ctx context.Context, id uuid.UUID) (*IndicativeRating, error)
	Create(ctx context.Context, movie Movie) error
	CreateMovieImage(ctx context.Context, movieImage MovieImage) error
	AddUploadTaskToQueue(ctx context.Context, task MovieImageUploadTask) error
	GetNextUploadTask(ctx context.Context) (*MovieImageUploadTask, error)
	GetALlByUserID(ctx context.Context, userID uuid.UUID, pagination *Pagination) (*Pagination, error)
	Update(ctx context.Context, movie Movie) error
	GetByID(ctx context.Context, ID uuid.UUID, withPreload bool) (*Movie, error)
	DeleteMovieImage(ctx context.Context, cloudFlareID uuid.UUID) error
	AddDeleteTaskToQueue(ctx context.Context, task MovieImageDeleteTask) error
	GetNextDeleteTask(ctx context.Context) (*MovieImageDeleteTask, error)
}

type MovieResponse

type MovieResponse struct {
	ID               uuid.UUID                 `json:"id"`
	Title            string                    `json:"title"`
	Duration         int                       `json:"duration"`
	IndicativeRating *IndicativeRatingResponse `json:"indicativeRating,omitempty"`
	MovieImages      []*MovieImageResponse     `json:"movieImages"`
}

type MovieService

type MovieService interface {
	GetAllIndicativeRatings(ctx context.Context) ([]*IndicativeRatingResponse, error)
	Create(ctx context.Context, payload MoviePayload) (*MovieResponse, error)
	ProcessUploadQueue(ctx context.Context, task MovieImageUploadTask) error
	GetAllByUserID(ctx context.Context, pagination *Pagination) (*Pagination, error)
	Update(ctx context.Context, ID uuid.UUID, payload MovieUpdatePayload) (*MovieResponse, error)
	Delete(ctx context.Context, ID uuid.UUID) error
	ProcessDeleteQueue(ctx context.Context, task MovieImageDeleteTask) error
}

type MovieUpdatePayload

type MovieUpdatePayload struct {
	IndicativeRatingID *uuid.UUID `json:"indicativeRatingId,omitempty" validate:"omitempty,uuid"`
	Title              *string    `json:"title,omitempty" validate:"omitempty,min=1,max=255"`
	Duration           *int       `json:"duration,omitempty" validate:"omitempty,gt=0"`
}

func (*MovieUpdatePayload) Validate

func (m *MovieUpdatePayload) Validate() ValidationErrors

type Pagination

type Pagination struct {
	Limit      int    `json:"limit,omitempty" query:"limit"`
	Page       int    `json:"page,omitempty" query:"page"`
	Sort       string `json:"sort,omitempty" query:"sort"`
	TotalRows  int64  `json:"totalRows"`
	TotalPages int    `json:"totalPages"`
	Rows       any    `json:"rows"`
}

func (*Pagination) GetLimit

func (p *Pagination) GetLimit() int

func (*Pagination) GetOffset

func (p *Pagination) GetOffset() int

func (*Pagination) GetPage

func (p *Pagination) GetPage() int

func (*Pagination) GetSort

func (p *Pagination) GetSort() string

func (*Pagination) SetLimit

func (p *Pagination) SetLimit(limit string)

func (*Pagination) SetPage

func (p *Pagination) SetPage(page string)

func (*Pagination) SetSort

func (p *Pagination) SetSort(sort string)

type Seat

type Seat struct {
	ID             uuid.UUID  `gorm:"column:id;type:char(36);primaryKey"`
	CinemaRoomID   uuid.UUID  `gorm:"column:cinemaRoomId;type:char(36);not null"`
	CinemaRoom     CinemaRoom `gorm:"foreignKey:CinemaRoomID"`
	SeatIdentifier string     `gorm:"column:seatIdentifier;type:char(5);not null"`
	CreatedAt      time.Time  `gorm:"column:createdAt;not null"`
	UpdatedAt      time.Time  `gorm:"column:updatedAt;default:NULL"`
}

func (Seat) TableName

func (Seat) TableName() string

type SeatPayload

type SeatPayload struct {
	SeatIdentifier string
}

type SeatRepository

type SeatRepository interface {
	Create(ctx context.Context, seat Seat) error
	GetByID(ctx context.Context, seatID uuid.UUID) (*Seat, error)
	GetAll(ctx context.Context) ([]Seat, error)
	Delete(ctx context.Context, seatID uuid.UUID) error
}

type SeatReservation

type SeatReservation struct {
	ID              uuid.UUID     `gorm:"column:id;type:char(36);primaryKey"`
	CinemaSessionID uuid.UUID     `gorm:"column:cinemaSessionId;type:char(36);not null"`
	CinemaSession   CinemaSession `gorm:"foreignKey:CinemaSessionID"`
	SeatID          uuid.UUID     `gorm:"column:SeatId;type:char(36);not null"`
	Seat            Seat          `gorm:"foreignKey:SeatID"`
	UserID          uuid.UUID     `gorm:"column:UserID;type:char(36);not null"`
	User            User          `gorm:"foreignKey:SeatID"`
	CreatedAt       time.Time     `gorm:"column:createdAt;not null"`
	UpdatedAt       time.Time     `gorm:"column:updatedAt;default:NULL"`
}

func (SeatReservation) TableName

func (SeatReservation) TableName() string

type Session

type Session struct {
	Token     string    `json:"token"`
	FirstName string    `json:"firstName"`
	LastName  string    `json:"lastName"`
	UserID    uuid.UUID `json:"MoviePassId"`
	Email     string    `json:"email"`
}

type SessionRepository

type SessionRepository interface {
	Create(ctx context.Context, session Session) error
	GetSession(ctx context.Context, userID uuid.UUID) (*Session, error)
}

type SessionService

type SessionService interface {
	Create(ctx context.Context, user User) (string, error)
	GetSession(ctx context.Context, token string) (*Session, error)
}

type SignInPayload

type SignInPayload struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password,omitempty" validate:"required"`
}

func (*SignInPayload) Validate

func (s *SignInPayload) Validate() ValidationErrors

type SignInResponse

type SignInResponse struct {
	Token string `json:"token"`
}

type User

type User struct {
	ID           uuid.UUID `gorm:"column:id;type:char(36);primaryKey"`
	FirstName    string    `gorm:"column:firstName;type:varchar(255);not null"`
	LastName     string    `gorm:"column:lastName;type:varchar(255);not null"`
	Email        string    `gorm:"column:email;type:varchar(255);uniqueIndex;not null"`
	BirthDate    time.Time `gorm:"column:birthDate;type:date;not null"`
	PasswordHash string    `gorm:"column:passwordHash;type:varchar(255);not null"`
	CreatedAt    time.Time `gorm:"column:createdAt;not null"`
	UpdatedAt    time.Time `gorm:"column:updatedAt;default:NULL"`
}

func (User) TableName

func (User) TableName() string

type UserHandler

type UserHandler interface {
	Create(ctx echo.Context) error
	SignIn(ctx echo.Context) error
}

type UserPayload

type UserPayload struct {
	FirstName       string    `json:"firstName" validate:"required,min=1,max=255"`
	LastName        string    `json:"lastName" validate:"required,min=1,max=255"`
	Email           string    `json:"email" validate:"required,email,max=255"`
	ConfirmEmail    string    `json:"confirmEmail" validate:"required,eqfield=Email"`
	Password        string    `json:"password,omitempty" validate:"required,max=255,strongpassword"`
	ConfirmPassword string    `json:"confirmPassword" validate:"required,eqfield=Password"`
	BirthDate       time.Time `json:"birthDate" validate:"required,nottooold,notfuturedate"`
}

func (*UserPayload) ToUser

func (u *UserPayload) ToUser(passwordHash string) *User

func (*UserPayload) Validate

func (u *UserPayload) Validate() ValidationErrors

type UserRepository

type UserRepository interface {
	Create(ctx context.Context, user User) error
	GetByEmail(ctx context.Context, email string) (*User, error)
}

type UserResponse

type UserResponse struct {
	ID        string    `json:"id"`
	FirstName string    `json:"firstName"`
	LastName  string    `json:"lastName"`
	Email     string    `json:"email"`
	BirthDate time.Time `json:"birthDate"`
}

type UserService

type UserService interface {
	Create(ctx context.Context, payload UserPayload) error
	SignIn(ctx context.Context, payload SignInPayload) (*SignInResponse, error)
}

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

type ValidationErrors

type ValidationErrors map[string]string

func ValidateStruct

func ValidateStruct(s any) ValidationErrors

Jump to

Keyboard shortcuts

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