Skip to content

Commit 90cffb5

Browse files
author
lleadbet
committed
updating ban events to match production
1 parent 3388f14 commit 90cffb5

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

docs/mock-api.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,12 @@ None.
4040

4141
## start
4242

43-
The `start` function starts a new mock server for use with testing functionality. Currently, this replicates a large majority of the current API endpoints on the new API, but are ommitting:
44-
45-
* GET /analytics/extensions
46-
* GET /analytics/games
47-
* GET /extensions/transactions
48-
* POST /eventsub/subscriptions
49-
* DELETE /eventsub/subscriptions
50-
* GET /eventsub/subscriptions
51-
* GET /users/extensions/list
52-
* GET /users/extensions
53-
* PUT /users/extensions
54-
* GET /webhooks/subscriptions
43+
The `start` function starts a new mock server for use with testing functionality. Currently, this replicates a large majority of the current API endpoints on the new API, but are omitting:
44+
45+
* Extensions endpoints
46+
* Code entitlement endpoints
47+
* Websub endpoints
48+
* EventSub endpoints
5549

5650
For many of these, we are exploring how to better integrate this with existing features (for example, allowing events to be triggered on unit creation or otherwise), and for others, the value is minimal compared to the docs. All other endpoints should be currently supported, however it is possible to be out of date- if so, [please raise an issue](https://github.com/twitchdev/twitch-cli/issues).
5751

internal/database/moderation.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ type ModeratorActionEvent struct {
4040
}
4141

4242
type BanActionEvent struct {
43-
BroadcasterID string `db:"broadcaster_id" json:"broadcaster_id"`
44-
BroadcasterLogin string `db:"broadcaster_login" json:"broadcaster_login"`
45-
BroadcasterName string `db:"broadcaster_name" json:"broadcaster_name"`
46-
UserID string `db:"user_id" json:"user_id"`
47-
UserLogin string `db:"user_login" json:"user_login"`
48-
UserName string `db:"user_name" json:"user_name"`
49-
ExpiresAt *string `db:"expires_at" json:"expires_at"`
43+
BroadcasterID string `db:"broadcaster_id" json:"broadcaster_id"`
44+
BroadcasterLogin string `db:"broadcaster_login" json:"broadcaster_login"`
45+
BroadcasterName string `db:"broadcaster_name" json:"broadcaster_name"`
46+
UserID string `db:"user_id" json:"user_id"`
47+
UserLogin string `db:"user_login" json:"user_login"`
48+
UserName string `db:"user_name" json:"user_name"`
49+
ExpiresAt *string `db:"expires_at" json:"expires_at"`
50+
Reason string `json:"reason"`
51+
ModeratorID string `json:"moderator_id"`
52+
ModeratorUserLogin string `json:"moderator_login"`
53+
ModeratorUserName string `json:"moderator_user_name"`
5054
}
5155

5256
type BanEvent struct {
@@ -57,10 +61,14 @@ type BanEvent struct {
5761
BanActionEvent `json:"event_data"`
5862
}
5963
type Ban struct {
60-
UserID string `db:"user_id" json:"user_id"`
61-
UserLogin string `db:"user_login" json:"user_login"`
62-
UserName string `db:"user_name" json:"user_name"`
63-
ExpiresAt *string `db:"expires_at" json:"expires_at"`
64+
UserID string `db:"user_id" json:"user_id"`
65+
UserLogin string `db:"user_login" json:"user_login"`
66+
UserName string `db:"user_name" json:"user_name"`
67+
ExpiresAt *string `db:"expires_at" json:"expires_at"`
68+
Reason string `json:"reason"`
69+
ModeratorID string `json:"moderator_id"`
70+
ModeratorUserLogin string `json:"moderator_login"`
71+
ModeratorUserName string `json:"moderator_user_name"`
6472
}
6573

6674
var es = ""
@@ -192,6 +200,7 @@ func (q *Query) GetBans(p UserRequestParams) (*DBResponse, error) {
192200
if b.ExpiresAt == nil {
193201
b.ExpiresAt = &es
194202
}
203+
b.Reason = "CLI ban"
195204
r = append(r, b)
196205
}
197206
dbr := DBResponse{
@@ -228,6 +237,7 @@ func (q *Query) GetBanEvents(p UserRequestParams) (*DBResponse, error) {
228237
if b.ExpiresAt == nil {
229238
b.ExpiresAt = &es
230239
}
240+
b.Reason = "CLI ban"
231241
r = append(r, b)
232242
}
233243
dbr := DBResponse{

internal/mock_api/endpoints/moderation/banned.go

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ func getBans(w http.ResponseWriter, r *http.Request) {
6161
mock_errors.WriteUnauthorized(w, "broadcaster_id does not match token")
6262
return
6363
}
64+
broadcaster, err := db.NewQuery(r, 100).GetUser(database.User{ID: userCtx.UserID})
65+
if err != nil {
66+
mock_errors.WriteServerError(w, "error fetching broadcaster")
67+
return
68+
}
69+
6470
bans := []database.Ban{}
6571
userIDs := r.URL.Query()["user_id"]
6672
if len(userIDs) > 0 {
@@ -81,6 +87,11 @@ func getBans(w http.ResponseWriter, r *http.Request) {
8187
}
8288
bans = append(bans, dbr.Data.([]database.Ban)...)
8389
}
90+
for i := range bans {
91+
bans[i].ModeratorID = broadcaster.ID
92+
bans[i].ModeratorUserLogin = broadcaster.UserLogin
93+
bans[i].ModeratorUserName = broadcaster.DisplayName
94+
}
8495
apiResponse := models.APIResponse{Data: bans}
8596
if dbr.Cursor != "" {
8697
apiResponse.Pagination = &models.APIPagination{Cursor: dbr.Cursor}

internal/mock_api/endpoints/moderation/banned_events.go

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func getBanEvents(w http.ResponseWriter, r *http.Request) {
6060
mock_errors.WriteUnauthorized(w, "broadcaster_id does not match token")
6161
return
6262
}
63+
64+
broadcaster, err := db.NewQuery(r, 100).GetUser(database.User{ID: userCtx.UserID})
65+
if err != nil {
66+
mock_errors.WriteServerError(w, "error fetching broadcaster")
67+
return
68+
}
69+
6370
bans := []database.BanEvent{}
6471
userIDs := r.URL.Query()["user_id"]
6572
if len(userIDs) > 0 {
@@ -80,6 +87,11 @@ func getBanEvents(w http.ResponseWriter, r *http.Request) {
8087
}
8188
bans = append(bans, dbr.Data.([]database.BanEvent)...)
8289
}
90+
for i := range bans {
91+
bans[i].ModeratorID = broadcaster.ID
92+
bans[i].ModeratorUserLogin = broadcaster.UserLogin
93+
bans[i].ModeratorUserName = broadcaster.DisplayName
94+
}
8395
apiResponse := models.APIResponse{Data: bans}
8496
if dbr.Cursor != "" {
8597
apiResponse.Pagination = &models.APIPagination{Cursor: dbr.Cursor}

0 commit comments

Comments
 (0)