Documentation ¶
Index ¶
- type CreateReviewRequest
- type DeleteReviewRequest
- type GetReviewRequest
- type GetReviewsByMovieIDRequest
- type GetReviewsByUserIDRequest
- type Handler
- func (h *Handler) CreateReview(c echo.Context) error
- func (h *Handler) DeleteReviewByID(c echo.Context) error
- func (h *Handler) GetReviewByID(c echo.Context) error
- func (h *Handler) GetReviewsByMovieID(c echo.Context) error
- func (h *Handler) GetReviewsByUserID(c echo.Context) error
- func (h *Handler) UpdateReviewByID(c echo.Context) error
- type Module
- type Repository
- func (r *Repository) CreateReview(ctx context.Context, req *CreateReviewRequest) (*Review, error)
- func (r *Repository) DeleteReview(ctx context.Context, reviewID int) error
- func (r *Repository) GetReviewByID(ctx context.Context, reviewID int) (*Review, error)
- func (r *Repository) GetReviewsByMovieID(ctx context.Context, movieID int, offset int, limit int, sort, order string) ([]*Review, int, error)
- func (r *Repository) GetReviewsByUserID(ctx context.Context, userID int, offset int, limit int, sort, order string) ([]*Review, int, error)
- func (r *Repository) UpdateReview(ctx context.Context, reviewID int, req *UpdateReviewRequest) (*Review, error)
- type Review
- type Service
- func (s *Service) CreateReview(ctx context.Context, req *CreateReviewRequest) (*Review, error)
- func (s *Service) DeleteReview(ctx context.Context, reviewID int) error
- func (s *Service) GetReviewByID(ctx context.Context, reviewID int) (*Review, error)
- func (s *Service) GetReviewsByMovieID(ctx context.Context, movieID int, offset int, limit int, sort, order string) ([]*Review, int, error)
- func (s *Service) GetReviewsByUserID(ctx context.Context, userID int, offset int, limit int, sort, order string) ([]*Review, int, error)
- func (s *Service) UpdateReview(ctx context.Context, reviewID int, req *UpdateReviewRequest) (*Review, error)
- type UpdateReviewRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateReviewRequest ¶
type DeleteReviewRequest ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 }
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 (*Repository) GetReviewsByMovieID ¶
func (*Repository) GetReviewsByUserID ¶
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 (*Service) DeleteReview ¶
func (*Service) GetReviewByID ¶
func (*Service) GetReviewsByMovieID ¶
func (*Service) GetReviewsByUserID ¶
func (*Service) UpdateReview ¶
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"` }