@@ -7,33 +7,27 @@ import (
7
7
"log"
8
8
"net/http"
9
9
10
- "github.com/mattn/go-sqlite3"
11
10
"github.com/twitchdev/twitch-cli/internal/database"
12
11
"github.com/twitchdev/twitch-cli/internal/mock_api/mock_errors"
13
12
"github.com/twitchdev/twitch-cli/internal/models"
14
13
)
15
14
16
15
var followMethodsSupported = map [string ]bool {
17
16
http .MethodGet : true ,
18
- http .MethodPost : true ,
19
- http .MethodDelete : true ,
17
+ http .MethodPost : false ,
18
+ http .MethodDelete : false ,
20
19
http .MethodPatch : false ,
21
20
http .MethodPut : false ,
22
21
}
23
22
24
23
var followScopesByMethod = map [string ][]string {
25
24
http .MethodGet : {},
26
- http .MethodPost : {"user:edit:follows" },
27
- http .MethodDelete : {"user:edit:follows" },
25
+ http .MethodPost : {},
26
+ http .MethodDelete : {},
28
27
http .MethodPatch : {},
29
28
http .MethodPut : {},
30
29
}
31
30
32
- type PostFollowBody struct {
33
- ToID string `json:"to_id"`
34
- FromID string `json:"from_id"`
35
- }
36
-
37
31
type FollowsEndpoint struct {}
38
32
39
33
func (e FollowsEndpoint ) Path () string { return "/users/follows" }
@@ -52,10 +46,6 @@ func (e FollowsEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
52
46
switch r .Method {
53
47
case http .MethodGet :
54
48
getFollows (w , r )
55
- case http .MethodPost :
56
- postFollows (w , r )
57
- case http .MethodDelete :
58
- deleteFollows (w , r )
59
49
default :
60
50
w .WriteHeader (http .StatusMethodNotAllowed )
61
51
return
@@ -103,49 +93,3 @@ func getFollows(w http.ResponseWriter, r *http.Request) {
103
93
json , _ := json .Marshal (body )
104
94
w .Write (json )
105
95
}
106
-
107
- func deleteFollows (w http.ResponseWriter , r * http.Request ) {
108
- to := r .URL .Query ().Get ("to_id" )
109
- from := r .URL .Query ().Get ("from_id" )
110
-
111
- if len (to ) == 0 || len (from ) == 0 {
112
- w .WriteHeader (http .StatusBadRequest )
113
- return
114
- }
115
-
116
- err := db .NewQuery (r , 100 ).DeleteFollow (from , to )
117
- if err != nil {
118
- http .Error (w , err .Error (), http .StatusInternalServerError )
119
- return
120
- }
121
-
122
- w .WriteHeader (http .StatusNoContent )
123
- }
124
-
125
- func postFollows (w http.ResponseWriter , r * http.Request ) {
126
- var body PostFollowBody
127
-
128
- err := json .NewDecoder (r .Body ).Decode (& body )
129
- if err != nil {
130
- mock_errors .WriteBadRequest (w , "error reading body" )
131
- return
132
- }
133
- if body .FromID == "" || body .ToID == "" {
134
- mock_errors .WriteBadRequest (w , "from_id and to_id are required" )
135
- return
136
- }
137
-
138
- err = db .NewQuery (r , 100 ).AddFollow (database.UserRequestParams {UserID : body .FromID , BroadcasterID : body .ToID })
139
- if err != nil {
140
- if database .DatabaseErrorIs (err , sqlite3 .ErrConstraintForeignKey ) || database .DatabaseErrorIs (err , sqlite3 .ErrConstraintUnique ) || database .DatabaseErrorIs (err , sqlite3 .ErrConstraintPrimaryKey ) {
141
- http .Error (w , err .Error (), http .StatusUnprocessableEntity )
142
- return
143
- }
144
- log .Printf ("%#v\n %#v" , err , sqlite3 .ErrConstraintUnique )
145
- w .WriteHeader (http .StatusInternalServerError )
146
- return
147
- }
148
-
149
- w .WriteHeader (http .StatusNoContent )
150
- return
151
- }
0 commit comments