micrach/controllers/threads_controller.go

50 lines
1.1 KiB
Go
Raw Normal View History

2021-08-26 20:23:55 +03:00
package controlers
import (
2021-09-05 00:36:55 +03:00
"log"
2021-08-26 20:23:55 +03:00
"net/http"
2021-09-05 00:36:55 +03:00
"strconv"
2021-08-26 20:23:55 +03:00
"github.com/gin-gonic/gin"
Repositories "micrach/repositories"
2021-08-26 20:23:55 +03:00
)
func GetThreads(c *gin.Context) {
2021-08-31 22:10:24 +03:00
threads, err := Repositories.Posts.Get(10, 10)
2021-08-30 12:09:27 +03:00
if err != nil {
2021-09-05 00:36:55 +03:00
// TODO: наверное, тут 500 будет
log.Println("error:", err)
2021-08-30 12:09:27 +03:00
c.JSON(http.StatusOK, gin.H{"error": true})
return
}
c.HTML(http.StatusOK, "index.html", threads)
2021-08-26 20:23:55 +03:00
}
func GetThread(c *gin.Context) {
2021-09-05 00:36:55 +03:00
threadIDString := c.Param("threadID")
threadID, err := strconv.Atoi(threadIDString)
if err != nil {
// TODO: тут 400 будет
log.Println("error:", err)
c.JSON(http.StatusOK, gin.H{"error": true})
return
}
thread, err := Repositories.Posts.GetThreadByPostID(threadID)
if err != nil {
// TODO: наверное, тут 500 будет
log.Println("error:", err)
c.JSON(http.StatusOK, gin.H{"error": true})
return
}
c.HTML(http.StatusOK, "thread.html", thread)
2021-08-26 20:23:55 +03:00
}
func CreateThread(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"route": "create thread"})
}
func UpdateThread(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"route": "update thread"})
}