30 lines
695 B
Go
30 lines
695 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 i := range post.Attachments {
|
|
post.Attachments[i].RemoteUrl = services.GetRemoteUrl(post.Attachments[i].RemoteUrl)
|
|
post.Attachments[i].PreviewUrl = services.GetPreviewUrl(post.Attachments[i].RemoteUrl)
|
|
}
|
|
c.JSON(200, post)
|
|
}
|