mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 20:26:39 +00:00
083099a957
* reference logrus' global logger instead of passing and storing a logger reference everywhere * always directly use global logrus logger instead of referencing an instance * test suites should also directly use the global logrus logger * rename gin logging function to clarify that it's middleware * correct comments which erroneously referenced removed logger parameter * setting log level for tests now uses logrus' exported type instead of the string value, to guarantee error isn't possible
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package favourites
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
|
)
|
|
|
|
// FavouritesGETHandler handles GETting favourites.
|
|
func (m *Module) FavouritesGETHandler(c *gin.Context) {
|
|
l := logrus.WithField("func", "PublicTimelineGETHandler")
|
|
|
|
authed, err := oauth.Authed(c, true, true, true, true)
|
|
if err != nil {
|
|
l.Debugf("error authing: %s", err)
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
|
return
|
|
}
|
|
|
|
maxID := ""
|
|
maxIDString := c.Query(MaxIDKey)
|
|
if maxIDString != "" {
|
|
maxID = maxIDString
|
|
}
|
|
|
|
minID := ""
|
|
minIDString := c.Query(MinIDKey)
|
|
if minIDString != "" {
|
|
minID = minIDString
|
|
}
|
|
|
|
limit := 20
|
|
limitString := c.Query(LimitKey)
|
|
if limitString != "" {
|
|
i, err := strconv.ParseInt(limitString, 10, 64)
|
|
if err != nil {
|
|
l.Debugf("error parsing limit string: %s", err)
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse limit query param"})
|
|
return
|
|
}
|
|
limit = int(i)
|
|
}
|
|
|
|
resp, errWithCode := m.processor.FavedTimelineGet(c.Request.Context(), authed, maxID, minID, limit)
|
|
if errWithCode != nil {
|
|
l.Debugf("error from processor FavedTimelineGet: %s", errWithCode)
|
|
c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
|
|
return
|
|
}
|
|
|
|
if resp.LinkHeader != "" {
|
|
c.Header("Link", resp.LinkHeader)
|
|
}
|
|
c.JSON(http.StatusOK, resp.Statuses)
|
|
}
|