Skip to content

Commit

Permalink
GET /teams/channels includes missing fields; GET /videos corrected fi…
Browse files Browse the repository at this point in the history
…eld names, and generates new video descriptions and types properly
  • Loading branch information
Xemdo committed Jan 5, 2023
1 parent f8f15cf commit ba22e4c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/database/videos.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Video struct {
BroadcasterLogin string `db:"broadcaster_login" json:"user_login" dbi:"false"`
BroadcasterName string `db:"broadcaster_name" json:"user_name" dbi:"false"`
Title string `db:"title" json:"title"`
VideoDescription string `db:"video_description" json:"video_description"`
VideoDescription string `db:"video_description" json:"description"`
CreatedAt string `db:"created_at" json:"created_at"`
PublishedAt string `db:"published_at" json:"published_at"`
Viewable string `db:"viewable" json:"viewable"`
Expand Down Expand Up @@ -98,6 +98,10 @@ func (q *Query) GetVideos(v Video, period string, sort string) (*DBResponse, err
return nil, err
}
r[i].MutedSegments = vms

if r[i].Type == "" {
r[i].Type = "archive"
}
}

dbr := DBResponse{
Expand Down
17 changes: 17 additions & 0 deletions internal/mock_api/endpoints/teams/channel_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type ChannelTeamResponse struct {
ThumbnailURL string `json:"thumbnail_url"`
TeamName string `json:"team_name"`
TeamDisplayName string `json:"team_display_name"`
BroadcasterID string `json:"broadcaster_id"`
BroadcasterName string `json:"broadcaster_name"`
BroadcasterLogin string `json:"broadcaster_login"`
}

func (e ChannelTeams) Path() string { return "/teams/channel" }
Expand Down Expand Up @@ -68,6 +71,17 @@ func getChannelTeams(w http.ResponseWriter, r *http.Request) {
return
}

// Get user information
userdbr, err := db.NewQuery(r, 1).GetUser(database.User{ID: r.URL.Query().Get("broadcaster_id")})
if err != nil {
mock_errors.WriteServerError(w, "error fetching user")
return
}
broadcasterID := r.URL.Query().Get("broadcaster_id")
broadcasterLogin := userdbr.UserLogin
broadcasterName := userdbr.DisplayName

// Get team information
dbr, err := db.NewQuery(r, 100).GetTeamByBroadcaster(r.URL.Query().Get("broadcaster_id"))
if err != nil {
mock_errors.WriteServerError(w, "error fetching team")
Expand All @@ -89,6 +103,9 @@ func getChannelTeams(w http.ResponseWriter, r *http.Request) {
ThumbnailURL: t.ThumbnailURL,
TeamName: t.TeamName,
TeamDisplayName: t.TeamDisplayName,
BroadcasterID: broadcasterID,
BroadcasterLogin: broadcasterLogin,
BroadcasterName: broadcasterName,
})
}

Expand Down
3 changes: 2 additions & 1 deletion internal/mock_api/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,14 @@ func generateUsers(ctx context.Context, count int) error {
StreamID: &s.ID,
BroadcasterID: s.Broacaster,
Title: "Sample stream!",
VideoDescription: "",
VideoDescription: "Such an interesting stream today...",
CreatedAt: util.GetTimestamp().Format(time.RFC3339),
PublishedAt: util.GetTimestamp().Format(time.RFC3339),
Viewable: "public",
ViewCount: 0,
Duration: "1h0m0s",
VideoLanguage: "en",
Type: "archive",
}
err := db.NewQuery(nil, 100).InsertVideo(v)
if err != nil {
Expand Down

0 comments on commit ba22e4c

Please # to comment.