gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

accounts.go (3715B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package accounts
     19 
     20 import (
     21 	"net/http"
     22 
     23 	"github.com/gin-gonic/gin"
     24 	"github.com/superseriousbusiness/gotosocial/internal/processing"
     25 )
     26 
     27 const (
     28 	ExcludeReblogsKey = "exclude_reblogs"
     29 	ExcludeRepliesKey = "exclude_replies"
     30 	LimitKey          = "limit"
     31 	MaxIDKey          = "max_id"
     32 	MinIDKey          = "min_id"
     33 	OnlyMediaKey      = "only_media"
     34 	OnlyPublicKey     = "only_public"
     35 	PinnedKey         = "pinned"
     36 
     37 	BasePath       = "/v1/accounts"
     38 	IDKey          = "id"
     39 	BasePathWithID = BasePath + "/:" + IDKey
     40 
     41 	BlockPath         = BasePathWithID + "/block"
     42 	DeletePath        = BasePath + "/delete"
     43 	FollowersPath     = BasePathWithID + "/followers"
     44 	FollowingPath     = BasePathWithID + "/following"
     45 	FollowPath        = BasePathWithID + "/follow"
     46 	ListsPath         = BasePathWithID + "/lists"
     47 	LookupPath        = BasePath + "/lookup"
     48 	RelationshipsPath = BasePath + "/relationships"
     49 	SearchPath        = BasePath + "/search"
     50 	StatusesPath      = BasePathWithID + "/statuses"
     51 	UnblockPath       = BasePathWithID + "/unblock"
     52 	UnfollowPath      = BasePathWithID + "/unfollow"
     53 	UpdatePath        = BasePath + "/update_credentials"
     54 	VerifyPath        = BasePath + "/verify_credentials"
     55 )
     56 
     57 type Module struct {
     58 	processor *processing.Processor
     59 }
     60 
     61 func New(processor *processing.Processor) *Module {
     62 	return &Module{
     63 		processor: processor,
     64 	}
     65 }
     66 
     67 func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) {
     68 	// create account
     69 	attachHandler(http.MethodPost, BasePath, m.AccountCreatePOSTHandler)
     70 
     71 	// get account
     72 	attachHandler(http.MethodGet, BasePathWithID, m.AccountGETHandler)
     73 
     74 	// delete account
     75 	attachHandler(http.MethodPost, DeletePath, m.AccountDeletePOSTHandler)
     76 
     77 	// verify account
     78 	attachHandler(http.MethodGet, VerifyPath, m.AccountVerifyGETHandler)
     79 
     80 	// modify account
     81 	attachHandler(http.MethodPatch, UpdatePath, m.AccountUpdateCredentialsPATCHHandler)
     82 
     83 	// get account's statuses
     84 	attachHandler(http.MethodGet, StatusesPath, m.AccountStatusesGETHandler)
     85 
     86 	// get following or followers
     87 	attachHandler(http.MethodGet, FollowersPath, m.AccountFollowersGETHandler)
     88 	attachHandler(http.MethodGet, FollowingPath, m.AccountFollowingGETHandler)
     89 
     90 	// get relationship with account
     91 	attachHandler(http.MethodGet, RelationshipsPath, m.AccountRelationshipsGETHandler)
     92 
     93 	// follow or unfollow account
     94 	attachHandler(http.MethodPost, FollowPath, m.AccountFollowPOSTHandler)
     95 	attachHandler(http.MethodPost, UnfollowPath, m.AccountUnfollowPOSTHandler)
     96 
     97 	// block or unblock account
     98 	attachHandler(http.MethodPost, BlockPath, m.AccountBlockPOSTHandler)
     99 	attachHandler(http.MethodPost, UnblockPath, m.AccountUnblockPOSTHandler)
    100 
    101 	// account lists
    102 	attachHandler(http.MethodGet, ListsPath, m.AccountListsGETHandler)
    103 
    104 	// search for accounts
    105 	attachHandler(http.MethodGet, SearchPath, m.AccountSearchGETHandler)
    106 	attachHandler(http.MethodGet, LookupPath, m.AccountLookupGETHandler)
    107 }