Files
CatsOfMastodonGo/internal/web/handlers/apiEndpoint.go

30 lines
671 B
Go

package handlers
import (
"CatsOfMastodonBotGo/internal/services"
"github.com/gin-gonic/gin"
)
type ApiEndpointHandler struct {
PostService services.PostService
}
var ApiEndpointHandlerInstance *ApiEndpointHandler
func InitApiEndpointHandler() {
ApiEndpointHandlerInstance = &ApiEndpointHandler{
PostService: *services.PostServiceInstance,
}
}
func (ps *ApiEndpointHandler) GetRandomPost(c *gin.Context) {
post := ps.PostService.GetRandomPost()
for _, attachment := range post.Attachments {
attachment.RemoteUrl = services.GetRemoteUrl(attachment.RemoteUrl)
attachment.PreviewUrl = services.GetPreviewUrl(attachment.RemoteUrl)
}
c.JSON(200, post)
}