Documentation ¶
Overview ¶
Polls routes and controllers logic package for the backend.
Index ¶
- 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 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, poll *models.Poll) 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, poll *models.Poll) error
Constants ¶
This section is empty.
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 add new poll @Tags polls @Accept json @Produce json @Param request body models.Poll true "new poll's body" @Success 201 {object} common.APIResponse{data=models.Stub} "success" @Failure 400 {object} common.APIResponse{data=models.Stub} "bad/malformed input data, invalid cookies" @Failure 500 {object} common.APIResponse{data=models.Stub} "the poll saving process failed" @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 delete a poll by ID @Tags polls @Produce json @Param pollID path string true "poll's ID to delete" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 403 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @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 get a list of polls @Tags polls @Produce json @Param X-Page-No header string true "page number" @Success 200 {object} common.APIResponse{data=polls.GetAll.responseData} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @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 get single poll @Tags polls @Produce json @Param pollID path string true "poll ID" @Success 200 {object} common.APIResponse{data=polls.GetByID.responseData} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 404 {object} common.APIResponse{data=models.Stub} @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 update a poll @Tags polls @Accept json @Produce json @Param updatedPoll body models.Poll true "update poll's body" @Param pollID path string true "poll's ID" @Success 200 {object} common.APIResponse{data=models.Stub} @Failure 400 {object} common.APIResponse{data=models.Stub} @Failure 500 {object} common.APIResponse{data=models.Stub} @Router /polls/{pollID} [put]
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) Delete ¶ added in v0.44.22
func (s *PollService) Delete(ctx context.Context, pollID string) error