summaryrefslogtreecommitdiff
path: root/internal/api/client/account
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client/account')
-rw-r--r--internal/api/client/account/account.go34
-rw-r--r--internal/api/client/account/block.go49
-rw-r--r--internal/api/client/account/unblock.go49
3 files changed, 126 insertions, 6 deletions
diff --git a/internal/api/client/account/account.go b/internal/api/client/account/account.go
index 3a820c0ea..42aca3283 100644
--- a/internal/api/client/account/account.go
+++ b/internal/api/client/account/account.go
@@ -61,10 +61,14 @@ const (
GetFollowingPath = BasePathWithID + "/following"
// GetRelationshipsPath is for showing an account's relationship with other accounts
GetRelationshipsPath = BasePath + "/relationships"
- // PostFollowPath is for POSTing new follows to, and updating existing follows
- PostFollowPath = BasePathWithID + "/follow"
- // PostUnfollowPath is for POSTing an unfollow
- PostUnfollowPath = BasePathWithID + "/unfollow"
+ // FollowPath is for POSTing new follows to, and updating existing follows
+ FollowPath = BasePathWithID + "/follow"
+ // UnfollowPath is for POSTing an unfollow
+ UnfollowPath = BasePathWithID + "/unfollow"
+ // BlockPath is for creating a block of an account
+ BlockPath = BasePathWithID + "/block"
+ // UnblockPath is for removing a block of an account
+ UnblockPath = BasePathWithID + "/unblock"
)
// Module implements the ClientAPIModule interface for account-related actions
@@ -85,15 +89,33 @@ func New(config *config.Config, processor processing.Processor, log *logrus.Logg
// Route attaches all routes from this module to the given router
func (m *Module) Route(r router.Router) error {
+ // create account
r.AttachHandler(http.MethodPost, BasePath, m.AccountCreatePOSTHandler)
+
+ // get account
r.AttachHandler(http.MethodGet, BasePathWithID, m.muxHandler)
+
+ // modify account
r.AttachHandler(http.MethodPatch, BasePathWithID, m.muxHandler)
+
+ // get account's statuses
r.AttachHandler(http.MethodGet, GetStatusesPath, m.AccountStatusesGETHandler)
+
+ // get following or followers
r.AttachHandler(http.MethodGet, GetFollowersPath, m.AccountFollowersGETHandler)
r.AttachHandler(http.MethodGet, GetFollowingPath, m.AccountFollowingGETHandler)
+
+ // get relationship with account
r.AttachHandler(http.MethodGet, GetRelationshipsPath, m.AccountRelationshipsGETHandler)
- r.AttachHandler(http.MethodPost, PostFollowPath, m.AccountFollowPOSTHandler)
- r.AttachHandler(http.MethodPost, PostUnfollowPath, m.AccountUnfollowPOSTHandler)
+
+ // follow or unfollow account
+ r.AttachHandler(http.MethodPost, FollowPath, m.AccountFollowPOSTHandler)
+ r.AttachHandler(http.MethodPost, UnfollowPath, m.AccountUnfollowPOSTHandler)
+
+ // block or unblock account
+ r.AttachHandler(http.MethodPost, BlockPath, m.AccountBlockPOSTHandler)
+ r.AttachHandler(http.MethodPost, UnblockPath, m.AccountUnblockPOSTHandler)
+
return nil
}
diff --git a/internal/api/client/account/block.go b/internal/api/client/account/block.go
new file mode 100644
index 000000000..c83837c2a
--- /dev/null
+++ b/internal/api/client/account/block.go
@@ -0,0 +1,49 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package account
+
+import (
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+ "github.com/superseriousbusiness/gotosocial/internal/oauth"
+)
+
+// AccountBlockPOSTHandler handles the creation of a block from the authed account targeting the given account ID.
+func (m *Module) AccountBlockPOSTHandler(c *gin.Context) {
+ authed, err := oauth.Authed(c, true, true, true, true)
+ if err != nil {
+ c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
+ return
+ }
+
+ targetAcctID := c.Param(IDKey)
+ if targetAcctID == "" {
+ c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"})
+ return
+ }
+
+ relationship, errWithCode := m.processor.AccountBlockCreate(authed, targetAcctID)
+ if errWithCode != nil {
+ c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
+ return
+ }
+
+ c.JSON(http.StatusOK, relationship)
+}
diff --git a/internal/api/client/account/unblock.go b/internal/api/client/account/unblock.go
new file mode 100644
index 000000000..1cb959db9
--- /dev/null
+++ b/internal/api/client/account/unblock.go
@@ -0,0 +1,49 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package account
+
+import (
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+ "github.com/superseriousbusiness/gotosocial/internal/oauth"
+)
+
+// AccountUnblockPOSTHandler handles the removal of a block from the authed account targeting the given account ID.
+func (m *Module) AccountUnblockPOSTHandler(c *gin.Context) {
+ authed, err := oauth.Authed(c, true, true, true, true)
+ if err != nil {
+ c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
+ return
+ }
+
+ targetAcctID := c.Param(IDKey)
+ if targetAcctID == "" {
+ c.JSON(http.StatusBadRequest, gin.H{"error": "no account id specified"})
+ return
+ }
+
+ relationship, errWithCode := m.processor.AccountBlockRemove(authed, targetAcctID)
+ if errWithCode != nil {
+ c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()})
+ return
+ }
+
+ c.JSON(http.StatusOK, relationship)
+}