diff options
| author | 2021-07-09 18:32:48 +0200 | |
|---|---|---|
| committer | 2021-07-09 18:32:48 +0200 | |
| commit | c7da64922f8b41daaee1cb8fc2961f7fa1336737 (patch) | |
| tree | b1f9c946bd223267f87f2a77a7455974d8d5e5e9 /internal/api/client/favourites/favouritesget.go | |
| parent | Docs (#94) (diff) | |
| download | gotosocial-c7da64922f8b41daaee1cb8fc2961f7fa1336737.tar.xz | |
favourites GET implementation (#95)
Diffstat (limited to 'internal/api/client/favourites/favouritesget.go')
| -rw-r--r-- | internal/api/client/favourites/favouritesget.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/api/client/favourites/favouritesget.go b/internal/api/client/favourites/favouritesget.go new file mode 100644 index 000000000..76eb921e0 --- /dev/null +++ b/internal/api/client/favourites/favouritesget.go @@ -0,0 +1,57 @@ +package favourites + +import ( + "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 := m.log.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(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) +} |
