Skip to content

Commit 90a6af4

Browse files
authored
Merge pull request #302 from Simply-Stream/fix/mock-api
Mock API updates
2 parents bca3aec + 0ae4052 commit 90a6af4

17 files changed

Lines changed: 381 additions & 383 deletions

File tree

internal/database/_schema.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ create table stream_schedule(
294294
id text not null primary key,
295295
broadcaster_id text not null,
296296
starttime text not null,
297-
endtime text not null,
298-
timezone text not null,
299-
is_vacation boolean not null default false,
297+
endtime text not null,
298+
timezone text not null,
299+
is_vacation boolean not null default false,
300300
is_recurring boolean not null default false,
301301
is_canceled boolean not null default false,
302302
title text,

internal/database/channel_points_redemptions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ChannelPointsRedemption struct {
1515
UserLogin string `db:"user_login" dbi:"false" json:"user_login"`
1616
UserName string `db:"user_name" dbi:"false" json:"user_name"`
1717
UserInput sql.NullString `db:"user_input" json:"-"`
18-
RealUserInput *string `json:"user_input"`
18+
RealUserInput string `json:"user_input"`
1919
RedemptionStatus string `db:"redemption_status" json:"status"`
2020
RedeemedAt string `db:"redeemed_at" json:"redeemed_at"`
2121
RewardID string `db:"reward_id" json:"-"`
@@ -25,7 +25,7 @@ type ChannelPointsRedemption struct {
2525
type ChannelPointsRedemptionRewardInfo struct {
2626
ID string `dbi:"false" db:"red_id" json:"id" dbs:"red.id"`
2727
Title string `dbi:"false" db:"title" json:"title"`
28-
RewardPrompt string `dbi:"false" db:"reward_prompt" json:"reward_prompt"`
28+
RewardPrompt string `dbi:"false" db:"reward_prompt" json:"prompt"`
2929
Cost int `dbi:"false" db:"cost" json:"cost"`
3030
}
3131

@@ -50,9 +50,9 @@ func (q *Query) GetChannelPointsRedemption(cpr ChannelPointsRedemption, sort str
5050
if err != nil {
5151
return nil, err
5252
}
53-
red.RealUserInput = &red.UserInput.String
53+
red.RealUserInput = red.UserInput.String
5454
if !red.UserInput.Valid {
55-
red.RealUserInput = nil
55+
red.RealUserInput = ""
5656
}
5757
r = append(r, red)
5858
}

internal/database/init.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/jmoiron/sqlx"
1111
)
1212

13-
const currentVersion = 6
13+
const currentVersion = 7
1414

1515
type migrateMap struct {
1616
SQL string
@@ -53,6 +53,10 @@ ALTER TABLE users ADD COLUMN content_labels text not null default '';`,
5353
SQL: `DROP TABLE IF EXISTS stream_tags;`,
5454
Message: `Removing deprecated stream_tags from database.`,
5555
},
56+
7: {
57+
SQL: `ALTER TABLE stream_schedule DROP COLUMN timezone;`,
58+
Message: `Removing deprecated stream_schedule.timezone from database`,
59+
},
5660
}
5761

5862
func checkAndUpdate(db sqlx.DB) error {
@@ -120,7 +124,7 @@ create table predictions ( id text not null primary key, broadcaster_id text not
120124
create table prediction_outcomes ( id text not null primary key, title text not null, users int not null default 0, channel_points int not null default 0, color text not null, prediction_id text not null, foreign key (prediction_id) references predictions(id) );
121125
create table prediction_predictions ( prediction_id text not null, user_id text not null, amount int not null, outcome_id text not null, primary key(prediction_id, user_id), foreign key(user_id) references users(id), foreign key(prediction_id) references predictions(id), foreign key(outcome_id) references prediction_outcomes(id) );
122126
create table clips ( id text not null primary key, broadcaster_id text not null, creator_id text not null, video_id text not null, game_id text not null, title text not null, view_count int default 0, created_at text not null, duration real not null, vod_offset int default 0, foreign key (broadcaster_id) references users(id), foreign key (creator_id) references users(id) );
123-
create table stream_schedule( id text not null primary key, broadcaster_id text not null, starttime text not null, endtime text not null, timezone text not null, is_vacation boolean not null default false, is_recurring boolean not null default false, is_canceled boolean not null default false, title text, category_id text, foreign key(broadcaster_id) references users(id), foreign key (category_id) references categories(id));
127+
create table stream_schedule( id text not null primary key, broadcaster_id text not null, starttime text not null, endtime text not null, is_vacation boolean not null default false, is_recurring boolean not null default false, is_canceled boolean not null default false, title text, category_id text, foreign key(broadcaster_id) references users(id), foreign key (category_id) references categories(id));
124128
create table chat_settings( broadcaster_id text not null primary key, slow_mode boolean not null default 0, slow_mode_wait_time int not null default 10, follower_mode boolean not null default 0, follower_mode_duration int not null default 60, subscriber_mode boolean not null default 0, emote_mode boolean not null default 0, unique_chat_mode boolean not null default 0, non_moderator_chat_delay boolean not null default 0, non_moderator_chat_delay_duration int not null default 10, shieldmode_is_active boolean not null default 0, shieldmode_moderator_id text not null default '', shieldmode_moderator_login text not null default '', shieldmode_moderator_name text not null default '', shieldmode_last_activated text not null default '' );
125129
create table vips ( broadcaster_id text not null, user_id text not null, created_at text not null default '', primary key (broadcaster_id, user_id), foreign key (broadcaster_id) references users(id), foreign key (user_id) references users(id) );`
126130

internal/database/predictions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Prediction struct {
1111
WinningOutcomeID *string `db:"winning_outcome_id" json:"winning_outcome_id"`
1212
PredictionWindow int `db:"prediction_window" json:"prediction_window"`
1313
Status string `db:"status" json:"status"`
14-
StartedAt string `db:"created_at" json:"started_at"`
14+
StartedAt string `db:"created_at" json:"created_at"`
1515
EndedAt *string `db:"ended_at" json:"ended_at"`
1616
LockedAt *string `db:"locked_at" json:"locked_at"`
1717
Outcomes []PredictionOutcome `json:"outcomes"`

internal/database/schedule.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type ScheduleSegment struct {
2424
IsVacation bool `db:"is_vacation" json:"-"`
2525
Category *SegmentCategory `json:"category"`
2626
UserID string `db:"broadcaster_id" json:"-"`
27-
Timezone string `db:"timezone" json:"timezone,omitempty"`
2827
CategoryID *string `db:"category_id" json:"-"`
2928
CategoryName *string `db:"category_name" dbi:"false" json:"-"`
3029
IsCanceled *bool `db:"is_canceled" json:"-"`

internal/database/subscriptions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type Subscription struct {
1616
UserLogin string `db:"user_login" json:"user_login"`
1717
UserName string `db:"user_name" json:"user_name"`
1818
IsGift bool `db:"is_gift" json:"is_gift"`
19-
GifterID *sql.NullString `db:"gifter_id" json:"gifter_id,omitempty"`
20-
GifterName *sql.NullString `db:"gifter_name" json:"gifter_name,omitempty"`
21-
GifterLogin *sql.NullString `db:"gifter_login" json:"gifter_login,omitempty"`
19+
GifterID *sql.NullString `db:"gifter_id" json:"gifter_id"`
20+
GifterName *sql.NullString `db:"gifter_name" json:"gifter_name"`
21+
GifterLogin *sql.NullString `db:"gifter_login" json:"gifter_login"`
2222
Tier string `db:"tier" json:"tier"`
2323
CreatedAt string `db:"created_at" json:"-"`
2424
// calculated fields

internal/database/videos.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Video struct {
2020
Viewable string `db:"viewable" json:"viewable"`
2121
ViewCount int `db:"view_count" json:"view_count"`
2222
Duration string `db:"duration" json:"duration"`
23-
VideoLanguage string `db:"video_language" json:"video_language"`
23+
VideoLanguage string `db:"video_language" json:"language"`
2424
MutedSegments []VideoMutedSegment `json:"muted_segments"`
2525
CategoryID *string `db:"category_id" dbs:"v.category_id" json:"-"`
2626
Type string `db:"type" json:"type"`
@@ -32,7 +32,7 @@ type Video struct {
3232

3333
type VideoMutedSegment struct {
3434
VideoID string `db:"video_id" json:"-"`
35-
VideoOffset int `db:"video_offset" json:"video_offset"`
35+
VideoOffset int `db:"video_offset" json:"offset"`
3636
Duration int `db:"duration" json:"duration"`
3737
}
3838

@@ -54,7 +54,7 @@ type Clip struct {
5454
// calculated fields
5555
URL string `json:"url"`
5656
ThumbnailURL string `json:"thumbnail_url"`
57-
EmbedURL string `json:"embed_urL"`
57+
EmbedURL string `json:"embed_url"`
5858
StartedAt string `db:"started_at" dbi:"false" json:"-"`
5959
EndedAt string `db:"ended_at" dbi:"false" json:"-"`
6060
}
@@ -129,6 +129,7 @@ func (q *Query) InsertVideo(v Video) error {
129129

130130
func (q *Query) DeleteVideo(id string) error {
131131
tx := q.DB.MustBegin()
132+
tx.MustExec("delete from stream_markers where video_id=$1", id)
132133
tx.MustExec("delete from video_muted_segments where video_id=$1", id)
133134
tx.MustExec("delete from videos where id = $1", id)
134135
return tx.Commit()

internal/mock_api/endpoints/bits/leaderboard.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ func getBitsLeaderboard(w http.ResponseWriter, r *http.Request) {
124124
// check if the started_at date is valid and then add it to the start/end range
125125
if period != "all" {
126126
if startedAt == "" {
127-
startedAt = time.Now().Format(time.RFC3339)
127+
w.Write(mock_errors.GetErrorBytes(http.StatusBadRequest, errors.New("Bad Request"), "invalid value provided for started_at"))
128+
w.WriteHeader(http.StatusBadRequest)
129+
return
128130
}
129131

130132
sa, err := time.Parse(time.RFC3339, startedAt)
@@ -199,12 +201,9 @@ func getBitsLeaderboard(w http.ResponseWriter, r *http.Request) {
199201

200202
length := len(bl)
201203
apiR := models.APIResponse{
202-
Data: bl,
203-
Total: &length,
204-
}
205-
206-
if dateRange.StartedAt != "" {
207-
apiR.DateRange = &dateRange
204+
Data: bl,
205+
DateRange: &dateRange,
206+
Total: &length,
208207
}
209208

210209
body, _ := json.Marshal(apiR)

internal/mock_api/endpoints/channel_points/channel_points_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestRedemption(t *testing.T) {
8686
a.Equal(400, resp.StatusCode)
8787

8888
q.Set("broadcaster_id", "2")
89+
q.Set("status", "FULFILLED")
8990
req.URL.RawQuery = q.Encode()
9091
resp, err = http.DefaultClient.Do(req)
9192
a.Nil(err)

internal/mock_api/endpoints/channel_points/redemptions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func getRedemptions(w http.ResponseWriter, r *http.Request) {
6868
status := r.URL.Query().Get("status")
6969
sort := r.URL.Query().Get("sort")
7070

71+
if id == "" && status == "" {
72+
mock_errors.WriteBadRequest(w, "The status query parameter is required if you don't specify the id query parameter.")
73+
return
74+
}
75+
7176
if !userCtx.MatchesBroadcasterIDParam(r) {
7277
mock_errors.WriteUnauthorized(w, "Broadcaster ID mismatch")
7378
return

0 commit comments

Comments
 (0)