Documentation
¶
Overview ¶
Polls routes and controllers logic package for the backend.
Index ¶
- Constants
- func NewPollRepository(cache db.Cacher) models.PollRepositoryInterface
- func NewPollRouter(pollController *PollController) chi.Router
- func NewPollService(pollRepository models.PollRepositoryInterface, ...) models.PollServiceInterface
- type PollController
- func (c *PollController) Create(w http.ResponseWriter, r *http.Request)
- func (c *PollController) Delete(w http.ResponseWriter, r *http.Request)
- func (c *PollController) GetAll(w http.ResponseWriter, r *http.Request)
- func (c *PollController) GetByID(w http.ResponseWriter, r *http.Request)
- func (c *PollController) Update(w http.ResponseWriter, r *http.Request)
- type PollCreateRequest
- type PollRepository
- func (r *PollRepository) Delete(pollID string) error
- func (r *PollRepository) GetAll() (*map[string]models.Poll, error)
- func (r *PollRepository) GetByID(pollID string) (*models.Poll, error)
- func (r *PollRepository) GetPage(pageOpts interface{}) (*map[string]models.Poll, error)
- func (r *PollRepository) Save(poll *models.Poll) error
- type PollService
- func (s *PollService) Create(ctx context.Context, pollI interface{}) error
- func (s *PollService) Delete(ctx context.Context, pollID string) error
- func (s *PollService) FindAll(ctx context.Context) (*map[string]models.Poll, *models.User, error)
- func (s *PollService) FindByID(ctx context.Context, pollID string) (*models.Poll, *models.User, error)
- func (s *PollService) Update(ctx context.Context, pollI interface{}) error
- type PollUpdateRequest
Constants ¶
View Source
const (
LOGGER_WORKER_NAME string = "pollController"
)
Variables ¶
This section is empty.
Functions ¶
func NewPollRepository ¶ added in v0.44.22
func NewPollRepository(cache db.Cacher) models.PollRepositoryInterface
func NewPollRouter ¶ added in v0.44.22
func NewPollRouter(pollController *PollController) chi.Router
func NewPollService ¶ added in v0.44.22
func NewPollService( pollRepository models.PollRepositoryInterface, postRepository models.PostRepositoryInterface, userRepository models.UserRepositoryInterface, ) models.PollServiceInterface
Types ¶
type PollController ¶ added in v0.44.22
type PollController struct {
// contains filtered or unexported fields
}
func NewPollController ¶ added in v0.44.22
func NewPollController(pollService models.PollServiceInterface) *PollController
func (*PollController) Create ¶ added in v0.44.22
func (c *PollController) Create(w http.ResponseWriter, r *http.Request)
addNewPoll ensures a new polls is created and saved.
@Summary Add new poll @Description This function call handles a new poll request to the poll service, where new poll creation is ensured. @Tags polls @Accept json @Produce json @Param request body polls.PollCreateRequest true "A new poll's simplified body." @Success 201 {object} common.APIResponse{data=models.Stub} "A new poll has been created successfully." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid input data." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious problem occurred while processing the create request." @Router /polls [post]
func (*PollController) Delete ¶ added in v0.44.22
func (c *PollController) Delete(w http.ResponseWriter, r *http.Request)
Delete removes a poll.
@Summary Delete a poll by ID @Description This function call takes in a `pollID` parameter, which is used to identify a poll to be purged. @Tags polls @Produce json @Param pollID path string true "A poll's ID to be deleted." @Success 200 {object} common.APIResponse{data=models.Stub} "The poll has been deleted." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid input data." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 403 {object} common.APIResponse{data=models.Stub} "User unauthorized. May occur when one tries to delete a foreign poll (the poll's author differs)." @Failure 404 {object} common.APIResponse{data=models.Stub} "Poll not found in the database." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while the request was being processed." @Router /polls/{pollID} [delete]
func (*PollController) GetAll ¶ added in v0.44.22
func (c *PollController) GetAll(w http.ResponseWriter, r *http.Request)
GellAll gets a list of polls
@Summary Get a list of polls @Description This function call retrieves a single page of polls according to the optional `X-Page-No` header (default is 0). @Tags polls @Produce json @Param X-Page-No header integer false "A page number (default is 0)." @Success 200 {object} common.APIResponse{data=polls.GetAll.responseData} "The requested page of polls is returned." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid input data." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while the request was being processed." @Router /polls [get]
func (*PollController) GetByID ¶ added in v0.44.22
func (c *PollController) GetByID(w http.ResponseWriter, r *http.Request)
GetByID return just one specified poll.
@Summary Get single poll @Description This function call retrieves a single requested poll's data. Such poll's ID is to be provided as the URL parameter. @Tags polls @Produce json @Param pollID path string true "A poll's ID to retrieve." @Success 200 {object} common.APIResponse{data=polls.GetByID.responseData} "The requested poll's data returned successfully." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid input data." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 404 {object} common.APIResponse{data=models.Stub} "Poll not found in the database." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while the request was being processed." @Router /polls/{pollID} [get]
func (*PollController) Update ¶ added in v0.44.22
func (c *PollController) Update(w http.ResponseWriter, r *http.Request)
Update updates a given poll.
@Summary Update a poll @Description This function call updates the poll specified using the `pollID` parameter. The fields to be updated are the counts of the poll's options. Only a single incrementation related to the current state stored in the database is allowed to be processed. @Tags polls @Accept json @Produce json @Param updatedPoll body polls.PollUpdateRequest true "A poll's body to update." @Param pollID path string true "A poll's unique ID." @Success 200 {object} common.APIResponse{data=models.Stub} "The poll has been updated successfully." @Failure 400 {object} common.APIResponse{data=models.Stub} "Invalid input data." @Failure 401 {object} common.APIResponse{data=models.Stub} "User unauthorized." @Failure 429 {object} common.APIResponse{data=models.Stub} "Too many requests, try again later." @Failure 500 {object} common.APIResponse{data=models.Stub} "A serious internal problem occurred while the request was being processed." @Router /polls/{pollID} [patch]
type PollCreateRequest ¶ added in v0.45.30
type PollCreateRequest struct { // Question is to describe the main purpose of such poll. Question string `json:"question" example:"which one is your favourite?"` // OptionOne is the answer numero uno. OptionOne string `json:"option_one" example:"apple"` // OptionTwo is the answer numero dos. OptionTwo string `json:"option_two" example:"banana"` // OptionThree is the answer numero tres. OptionThree string `json:"option_three" example:"cashew"` }
type PollRepository ¶ added in v0.44.22
type PollRepository struct {
// contains filtered or unexported fields
}
The implementation of pkg/models.PollRepositoryInterface.
func (*PollRepository) Delete ¶ added in v0.44.22
func (r *PollRepository) Delete(pollID string) error
func (*PollRepository) GetAll ¶ added in v0.44.22
func (r *PollRepository) GetAll() (*map[string]models.Poll, error)
func (*PollRepository) GetByID ¶ added in v0.44.22
func (r *PollRepository) GetByID(pollID string) (*models.Poll, error)
type PollService ¶ added in v0.44.22
type PollService struct {
// contains filtered or unexported fields
}
func (*PollService) Create ¶ added in v0.44.22
func (s *PollService) Create(ctx context.Context, pollI interface{}) error
func (*PollService) Delete ¶ added in v0.44.22
func (s *PollService) Delete(ctx context.Context, pollID string) error
type PollUpdateRequest ¶ added in v0.45.30
type PollUpdateRequest struct { // The poll's ID is specified using an URL param. // The purpose of this field is to transfer the ID from the controller to the service in a more smooth way. ID string `json:"-" example:"1234567890000" swaggerignore:"true"` // These fields are to be filled in the request body data. OptionOneCount int64 `json:"option_one_count" example:"3"` OptionTwoCount int64 `json:"option_two_count" example:"2"` OptionThreeCount int64 `json:"option_three_count" example:"6"` }
Click to show internal directories.
Click to hide internal directories.