43 lines
811 B
Go
43 lines
811 B
Go
package routes
|
|
|
|
import (
|
|
"context"
|
|
rest_api_stuff "enshi/REST_API_stuff"
|
|
db_repo "enshi/db/go_queries"
|
|
"enshi/db_connection"
|
|
"enshi/middleware/getters"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetCommentsForPost(c *gin.Context) {
|
|
var params db_repo.GetCommentsForPostAscParams
|
|
|
|
postId, err := getters.GetInt64Param(c, "post-id")
|
|
if err != nil {
|
|
rest_api_stuff.BadRequestAnswer(c, err)
|
|
return
|
|
}
|
|
|
|
offset, err := strconv.Atoi(c.DefaultQuery("offset", "10"))
|
|
if err != nil {
|
|
params.Offset = int32(0)
|
|
}
|
|
|
|
params.Offset = int32(offset)
|
|
params.PostID = postId
|
|
|
|
comments, err := db_repo.New(db_connection.Dbx).GetCommentsForPostAsc(
|
|
context.Background(),
|
|
params,
|
|
)
|
|
if err != nil {
|
|
rest_api_stuff.InternalErrorAnswer(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, comments)
|
|
}
|