1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// 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 v2
import (
"net/http"
"github.com/gin-gonic/gin"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/processing"
)
const (
// BasePath is the base path for serving the filters API, minus the 'api' prefix
BasePath = "/v2/filters"
// BasePathWithID is the base path with the ID key in it, for operations on an existing filter.
BasePathWithID = BasePath + "/:" + apiutil.IDKey
// FilterKeywordsPathWithID is the path for operations on an existing filter's keywords.
FilterKeywordsPathWithID = BasePathWithID + "/keywords"
// FilterStatusesPathWithID is the path for operations on an existing filter's statuses.
FilterStatusesPathWithID = BasePathWithID + "/statuses"
// KeywordPath is the base path for operations on filter keywords that don't require a filter ID.
KeywordPath = BasePath + "/keywords"
// KeywordPathWithKeywordID is the path for operations on an existing filter keyword.
KeywordPathWithKeywordID = KeywordPath + "/:" + apiutil.IDKey
// StatusPath is the base path for operations on filter statuses that don't require a filter ID.
StatusPath = BasePath + "/statuses"
// StatusPathWithStatusID is the path for operations on an existing filter status.
StatusPathWithStatusID = StatusPath + "/:" + apiutil.IDKey
)
// Module implements APIs for client-side aka "v1" filtering.
type Module struct {
processor *processing.Processor
}
func New(processor *processing.Processor) *Module {
return &Module{
processor: processor,
}
}
func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) {
attachHandler(http.MethodGet, BasePath, m.FiltersGETHandler)
attachHandler(http.MethodPost, BasePath, m.FilterPOSTHandler)
attachHandler(http.MethodGet, BasePathWithID, m.FilterGETHandler)
attachHandler(http.MethodPut, BasePathWithID, m.FilterPUTHandler)
attachHandler(http.MethodDelete, BasePathWithID, m.FilterDELETEHandler)
attachHandler(http.MethodGet, FilterKeywordsPathWithID, m.FilterKeywordsGETHandler)
attachHandler(http.MethodPost, FilterKeywordsPathWithID, m.FilterKeywordPOSTHandler)
attachHandler(http.MethodGet, KeywordPathWithKeywordID, m.FilterKeywordGETHandler)
attachHandler(http.MethodPut, KeywordPathWithKeywordID, m.FilterKeywordPUTHandler)
attachHandler(http.MethodDelete, KeywordPathWithKeywordID, m.FilterKeywordDELETEHandler)
attachHandler(http.MethodGet, FilterStatusesPathWithID, m.FilterStatusesGETHandler)
attachHandler(http.MethodPost, FilterStatusesPathWithID, m.FilterStatusPOSTHandler)
attachHandler(http.MethodGet, StatusPathWithStatusID, m.FilterStatusGETHandler)
attachHandler(http.MethodDelete, StatusPathWithStatusID, m.FilterStatusDELETEHandler)
}
|