reviews

package
v0.0.0-...-63997f1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateReviewRequest

type CreateReviewRequest struct {
	MovieID int    `json:"movieId" validate:"nonzero"`
	UserID  int    `json:"-" param:"userId" validate:"nonzero"`
	Title   string `json:"title" validate:"max=100"`
	Content string `json:"description" validate:"max=1000"`
	Rating  int    `json:"rating" validate:"min=1,max=10"`
}

type DeleteReviewRequest

type DeleteReviewRequest struct {
	UserID   int `json:"-" param:"userId" validate:"nonzero"`
	ReviewID int `json:"-" param:"reviewId" validate:"nonzero"`
}

type GetReviewRequest

type GetReviewRequest struct {
	ReviewID int `json:"-" param:"reviewId" validate:"nonzero"`
}

type GetReviewsByMovieIDRequest

type GetReviewsByMovieIDRequest struct {
	pagination.PaginatedRequestOrdered
	MovieID int `json:"-" param:"movieId" validate:"nonzero"`
}

type GetReviewsByUserIDRequest

type GetReviewsByUserIDRequest struct {
	pagination.PaginatedRequestOrdered
	UserID int `json:"-" param:"userId" validate:"nonzero"`
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service *Service, paginationConfig *config.PaginationConfig) *Handler

func (*Handler) CreateReview

func (h *Handler) CreateReview(c echo.Context) error

CreateReview godoc @Summary Create review @Description Create review @ID create-review @Tags reviews @Accept json @Produce json @Param request body contracts.CreateReviewRequest true "Create review request, movieId and userId are required be unique" @Success 201 {object} contracts.Review "Review" @Failure 400 {object} apperrors.Error "Invalid request, invalid parameter or missing parameter" @Failure 401 {object} apperrors.Error "Unauthorized" @Failure 403 {object} apperrors.Error "Forbidden" @Failure 409 {object} apperrors.Error "Review already exists" @Failure 500 {object} apperrors.Error "Internal server error" @Router /users/{userId}/reviews [post]

func (*Handler) DeleteReviewByID

func (h *Handler) DeleteReviewByID(c echo.Context) error

DeleteReviewByID godoc @Summary Delete review by ID @Description Delete review by ID @ID delete-review-by-id @Tags reviews @Accept json @Param reviewId path int true "Review ID" @Success 200 "Review deleted (softly deleting)" @Failure 400 {object} apperrors.Error "Invalid request, invalid parameter or missing parameter" @Failure 401 {object} apperrors.Error "Unauthorized" @Failure 403 {object} apperrors.Error "Forbidden" @Failure 404 {object} apperrors.Error "Not found" @Failure 500 {object} apperrors.Error "Internal server error" @Router /users/{userId}/reviews/{reviewId} [delete]

func (*Handler) GetReviewByID

func (h *Handler) GetReviewByID(c echo.Context) error

GetReviewByID godoc @Summary Get review by ID @Description Get review by ID @ID get-review-by-id @Tags reviews @Accept json @Produce json @Param reviewId path int true "Review ID" @Success 200 {object} contracts.Review "Review" @Failure 400 {object} apperrors.Error "Invalid request, invalid parameter or missing parameter" @Failure 404 {object} apperrors.Error "Review not found" @Failure 500 {object} apperrors.Error "Internal server error" @Router /reviews/{reviewId} [get]

func (*Handler) GetReviewsByMovieID

func (h *Handler) GetReviewsByMovieID(c echo.Context) error

GetReviewsByMovieID godoc @Summary Get reviews by movie ID @Description Get reviews by movie ID @ID get-reviews-by-movie-id @Tags reviews @Accept json @Produce json @Param movieId path int true "Movie ID" @Param request body contracts.GetReviewsByMovieIDRequest false "Pagination request, if request body empty, default values will be used" @Success 200 {object} pagination.PaginatedResponse[contracts.Review] "PaginatedResponse of Reviews, total number of reviews, or nil if none found" @Failure 400 {object} apperrors.Error "Invalid request, invalid parameter or missing parameter" @Failure 500 {object} apperrors.Error "Internal server error" @Router /movies/{movieId}/reviews [get]

func (*Handler) GetReviewsByUserID

func (h *Handler) GetReviewsByUserID(c echo.Context) error

GetReviewsByUserID godoc @Summary Get reviews by user ID @Description Get reviews by user ID @ID get-reviews-by-user-id @Tags reviews @Accept json @Produce json @Param userId path int true "User ID" @Param request body contracts.GetReviewsByUserIDRequest false "Pagination request, if request body empty, default values will be used" @Success 200 {object} pagination.PaginatedResponse[contracts.Review] "PaginatedResponse of Reviews, total number of reviews, or nil if none found" @Failure 400 {object} apperrors.Error "Invalid request, invalid parameter or missing parameter" @Failure 500 {object} apperrors.Error "Internal server error" @Router /users/{userId}/reviews [get]

func (*Handler) UpdateReviewByID

func (h *Handler) UpdateReviewByID(c echo.Context) error

UpdateReviewByID godoc @Summary Update review by ID @Description Update review by ID @ID update-review-by-id @Tags reviews @Accept json @Produce json @Param reviewId path int true "Review ID" @Param request body contracts.UpdateReviewRequest true "Update review request, at least one field is required, if optional fields are empty, it will set default values" @Success 200 {object} contracts.Review "Review" @Failure 400 {object} apperrors.Error "Invalid request, invalid parameter or missing parameter" @Failure 401 {object} apperrors.Error "Unauthorized" @Failure 403 {object} apperrors.Error "Forbidden" @Failure 404 {object} apperrors.Error "Not found" @Failure 500 {object} apperrors.Error "Internal server error" @Router /users/{userId}/reviews/{reviewId} [put]

type Module

type Module struct {
	Handler    *Handler
	Service    *Service
	Repository *Repository
}

func NewModule

func NewModule(db *pgxpool.Pool, moviesModule *movies.Module, paginationConfig config.PaginationConfig) *Module

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(db *pgxpool.Pool, movieRepo *movies.Repository) *Repository

func (*Repository) CreateReview

func (r *Repository) CreateReview(ctx context.Context, req *CreateReviewRequest) (*Review, error)

func (*Repository) DeleteReview

func (r *Repository) DeleteReview(ctx context.Context, reviewID int) error

func (*Repository) GetReviewByID

func (r *Repository) GetReviewByID(ctx context.Context, reviewID int) (*Review, error)

func (*Repository) GetReviewsByMovieID

func (r *Repository) GetReviewsByMovieID(ctx context.Context, movieID int, offset int, limit int, sort, order string) ([]*Review, int, error)

func (*Repository) GetReviewsByUserID

func (r *Repository) GetReviewsByUserID(ctx context.Context, userID int, offset int, limit int, sort, order string) ([]*Review, int, error)

func (*Repository) UpdateReview

func (r *Repository) UpdateReview(ctx context.Context, reviewID int, req *UpdateReviewRequest) (*Review, error)

type Review

type Review struct {
	ID        int        `json:"id"`
	MovieID   int        `json:"movieId"`
	UserID    int        `json:"userId"`
	Rating    int        `json:"rating"`
	Title     string     `json:"title"`
	Content   string     `json:"description"`
	CreatedAt time.Time  `json:"createdAt"`
	UpdatedAt *time.Time `json:"updatedAt,omitempty"`
	DeletedAt *time.Time `json:"deletedAt,omitempty"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(repo *Repository) *Service

func (*Service) CreateReview

func (s *Service) CreateReview(ctx context.Context, req *CreateReviewRequest) (*Review, error)

func (*Service) DeleteReview

func (s *Service) DeleteReview(ctx context.Context, reviewID int) error

func (*Service) GetReviewByID

func (s *Service) GetReviewByID(ctx context.Context, reviewID int) (*Review, error)

func (*Service) GetReviewsByMovieID

func (s *Service) GetReviewsByMovieID(ctx context.Context, movieID int, offset int, limit int, sort, order string) ([]*Review, int, error)

func (*Service) GetReviewsByUserID

func (s *Service) GetReviewsByUserID(ctx context.Context, userID int, offset int, limit int, sort, order string) ([]*Review, int, error)

func (*Service) UpdateReview

func (s *Service) UpdateReview(ctx context.Context, reviewID int, req *UpdateReviewRequest) (*Review, error)

type UpdateReviewRequest

type UpdateReviewRequest struct {
	UserID   int     `json:"-" param:"userId" validate:"nonzero"`
	ReviewID int     `json:"-" param:"reviewId" validate:"nonzero"`
	MovieID  int     `json:"movieId" validate:"nonzero"`
	Title    *string `json:"title,omitempty" validate:"max=100"`
	Content  *string `json:"description,omitempty" validate:"max=1000"`
	Rating   *int    `json:"rating,omitempty" validate:"min=1,max=10"`
}

Jump to

Keyboard shortcuts

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