feat: start develop a comment logic
This commit is contained in:
72
backend/internal/handlers/comments_handlers.go
Normal file
72
backend/internal/handlers/comments_handlers.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type CommentsHandlers struct {
|
||||
logger *logger.Logger
|
||||
}
|
||||
|
||||
func NewCommentsHandlers() *CommentsHandlers {
|
||||
return &CommentsHandlers{logger: logger.New(false)}
|
||||
}
|
||||
|
||||
// GetAllComments godoc
|
||||
// @Summary Get all comments
|
||||
// @Description Get all comments
|
||||
// @Tags comments
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} models.SuccessResponse{data=[]storage.Comment}
|
||||
// @Failure 404 {object} models.ErrorResponse "No Comment found"
|
||||
// @Failure 500 {object} models.ErrorResponse "Internal server error"
|
||||
// @Router /comments [get]
|
||||
func (h *CommentsHandlers) GetAllComments(c *gin.Context) {
|
||||
}
|
||||
|
||||
// GetCommentsOfPost godoc
|
||||
// @Summary Get comments of post
|
||||
// @Description Get comments of post
|
||||
// @Tags comments
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Post ID"
|
||||
// @Success 200 {object} models.SuccessResponse{data=[]storage.Comment}
|
||||
// @Failure 404 {object} models.ErrorResponse "No Comment found"
|
||||
// @Failure 500 {object} models.ErrorResponse "Internal server error"
|
||||
// @Router /posts/{id}/comments [get]
|
||||
func (h *CommentsHandlers) GetCommentsOfPost(c *gin.Context) {
|
||||
}
|
||||
|
||||
// CreateComment godoc
|
||||
// @Summary Create comment
|
||||
// @Description Create new comment
|
||||
// @Tags comments
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param comment body storage.CommentCreate true "Comment data"
|
||||
// @Security Bearer
|
||||
// @Success 200 {object} models.SuccessResponse{data=storage.Comment}
|
||||
// @Failure 400 {object} models.ErrorResponse "Invalid request"
|
||||
// @Failure 500 {object} models.ErrorResponse "Internal server error"
|
||||
// @Router /comments [post]
|
||||
func (h *CommentsHandlers) CreateComment(c *gin.Context) {
|
||||
}
|
||||
|
||||
// DeleteComment godoc
|
||||
// @Summary Delete comment
|
||||
// @Description Delete comment
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "Comment ID"
|
||||
// @Success 200 {object} models.SuccessResponse{data=storage.Comment}
|
||||
// @Failure 400 {object} models.ErrorResponse "Invalid ID format"
|
||||
// @Failure 404 {object} models.ErrorResponse "Comment not found"
|
||||
// @Failure 500 {object} models.ErrorResponse "Internal server error"
|
||||
// @Router admin/comments/{id} [delete]
|
||||
func (h *CommentsHandlers) DeleteComment(c *gin.Context) {
|
||||
}
|
||||
@@ -110,6 +110,7 @@ func (h *PostHandlers) CreatePost(c *gin.Context) {
|
||||
post := storage.Post{
|
||||
Title: req.Title,
|
||||
Content: req.Content,
|
||||
Tags: req.Tags,
|
||||
}
|
||||
|
||||
if err := h.repo.Create(c.Request.Context(), post); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user