Skip to content

Commit

Permalink
Merge pull request #14 from daystram/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
daystram authored Feb 6, 2021
2 parents e3329a4 + 27ccbb6 commit 94138a0
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 289 deletions.
14 changes: 12 additions & 2 deletions cast-be/controller/v1/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *VideoController) GetList(variant, author string, count, offset int) dat
if author == "" {
videos, err = c.Handler.CastList(variant, count, offset)
} else {
videos, err = c.Handler.AuthorList(author, count, offset)
videos, err = c.Handler.AuthorList(author, false, count, offset)
}
if err != nil {
fmt.Printf("[VideoController::GetList] failed retrieving video list. %+v\n", err)
Expand Down Expand Up @@ -91,13 +91,23 @@ func (c *VideoControllerAuth) Prepare() {
// @Title Get List
// @Success 200 {object} models.Object
// @Param variant query string false "variant"
// @Param author query string false "author"
// @Param count query int false 8 "count"
// @Param offset query int false 0 "offset"
// @router /list [get]
func (c *VideoControllerAuth) GetList(variant string, count, offset int) datatransfers.Response {
func (c *VideoControllerAuth) GetList(variant, author string, count, offset int) datatransfers.Response {
var videos []datatransfers.Video
var err error
videos, err = c.Handler.CastList(variant, count, offset, c.userID)
if author == "" {
videos, err = c.Handler.CastList(variant, count, offset)
} else {
// var user datatransfers.User
if _, err = c.Handler.UserGetOneByID(c.userID); err != nil {
return datatransfers.Response{Error: "Failed retrieving user info", Code: http.StatusInternalServerError}
}
// videos, err = c.Handler.AuthorList(author, author == user.Username, count, offset)
}
if err != nil {
fmt.Printf("[VideoControllerAuth::GetList] failed retrieving video list. %+v\n", err)
return datatransfers.Response{Error: "Failed retrieving video list", Code: http.StatusInternalServerError}
Expand Down
3 changes: 2 additions & 1 deletion cast-be/handlers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ type Handler interface {
Register(idToken data.UserRegister) (err error)

UserDetails(userID string) (detail data.UserDetail, err error)
UserGetOneByID(userID string) (user data.User, err error)

CastList(variant string, count, offset int, userID ...string) (videos []data.Video, err error)
AuthorList(author string, count, offset int) (videos []data.Video, err error)
AuthorList(author string, withUnlisted bool, count, offset int) (videos []data.Video, err error)
SearchVideo(query string, tags []string, count, offset int) (videos []data.Video, err error)
VideoDetails(hash string) (video data.Video, err error)
CreateVOD(upload data.VideoUpload, controller beego.Controller, userID string) (ID primitive.ObjectID, err error)
Expand Down
9 changes: 8 additions & 1 deletion cast-be/handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (m *module) UserDetails(userID string) (detail data.UserDetail, err error)
if user, err = m.db.userOrm.GetOneByID(userID); err != nil {
return data.UserDetail{}, errors.New(fmt.Sprintf("[UserDetails] user not found. %+v\n", err))
}
if videos, err = m.db.videoOrm.GetAllVODByAuthor(userID); err != nil {
if videos, err = m.db.videoOrm.GetAllVODByAuthor(userID, true); err != nil {
return data.UserDetail{}, errors.New(fmt.Sprintf("[UserDetails] cannot retrieve all user videos. %+v\n", err))
}
if subscriberCount, err = m.db.subscriptionOrm.GetCountByAuthorID(user.ID); err != nil {
Expand All @@ -34,3 +34,10 @@ func (m *module) UserDetails(userID string) (detail data.UserDetail, err error)
}
return
}

func (m *module) UserGetOneByID(userID string) (user data.User, err error) {
if user, err = m.db.userOrm.GetOneByID(userID); err != nil {
return data.User{}, fmt.Errorf("[UserGetOneByID] user not found. %+v\n", err)
}
return
}
4 changes: 2 additions & 2 deletions cast-be/handlers/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func (m *module) CastList(variant string, count int, offset int, userID ...strin
}
return
}
func (m *module) AuthorList(username string, count, offset int) (videos []data.Video, err error) {
func (m *module) AuthorList(username string, withUnlisted bool, count, offset int) (videos []data.Video, err error) {
var author data.User
if author, err = m.db.userOrm.GetOneByUsername(username); err != nil {
return nil, errors.New(fmt.Sprintf("[AuthorList] author not found. %+v", err))
}
if videos, err = m.db.videoOrm.GetAllVODByAuthorPaginated(author.ID, count, offset); err != nil {
if videos, err = m.db.videoOrm.GetAllVODByAuthorPaginated(author.ID, withUnlisted, count, offset); err != nil {
return nil, errors.New(fmt.Sprintf("[AuthorList] error retrieving VODs. %+v", err))
}
return
Expand Down
16 changes: 10 additions & 6 deletions cast-be/models/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type VideoOrmer interface {
GetTrending(count int, offset int) (videos []datatransfers.Video, err error)
GetLiked(userID string, count int, offset int) (videos []datatransfers.Video, err error)
GetSubscribed(userID string, count int, offset int) (videos []datatransfers.Video, err error)
GetAllVODByAuthor(author string) (videos []datatransfers.Video, err error)
GetAllVODByAuthorPaginated(author string, count int, offset int) (videos []datatransfers.Video, err error)
GetAllVODByAuthor(author string, withUnlisted bool) (videos []datatransfers.Video, err error)
GetAllVODByAuthorPaginated(author string, withUnlisted bool, count int, offset int) (videos []datatransfers.Video, err error)
Search(query string, count, offset int) (videos []datatransfers.Video, err error)
GetLiveByAuthor(userID string) (datatransfers.Video, error)
GetOneByHash(hash string) (datatransfers.Video, error)
Expand Down Expand Up @@ -187,7 +187,7 @@ func (o *videoOrm) GetTrending(count int, offset int) (result []datatransfers.Vi
return
}

func (o *videoOrm) GetAllVODByAuthor(author string) (videos []datatransfers.Video, err error) {
func (o *videoOrm) GetAllVODByAuthor(author string, withUnlisted bool) (videos []datatransfers.Video, err error) {
query := &mongo.Cursor{}
if query, err = o.collection.Aggregate(context.Background(), mongo.Pipeline{ // unlisted VODs included
{{"$match", bson.D{{"author", author}}}},
Expand All @@ -207,12 +207,14 @@ func (o *videoOrm) GetAllVODByAuthor(author string) (videos []datatransfers.Vide
if err = query.Decode(&video); err != nil {
return
}
videos = append(videos, video)
if withUnlisted || !video.Unlisted {
videos = append(videos, video)
}
}
return
}

func (o *videoOrm) GetAllVODByAuthorPaginated(author string, count int, offset int) (videos []datatransfers.Video, err error) {
func (o *videoOrm) GetAllVODByAuthorPaginated(author string, withUnlisted bool, count int, offset int) (videos []datatransfers.Video, err error) {
query := &mongo.Cursor{}
if query, err = o.collection.Aggregate(context.Background(), mongo.Pipeline{ // unlisted VODs included
{{"$match", bson.D{{"author", author}}}},
Expand Down Expand Up @@ -244,7 +246,9 @@ func (o *videoOrm) GetAllVODByAuthorPaginated(author string, count int, offset i
if err = query.Decode(&video); err != nil {
return
}
videos = append(videos, video)
if withUnlisted || !video.Unlisted {
videos = append(videos, video)
}
}
return
}
Expand Down
1 change: 1 addition & 0 deletions cast-be/routers/commentsRouter_controller_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func init() {
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(
param.New("variant"),
param.New("author"),
param.New("count", param.Default("false")),
param.New("offset", param.Default("false")),
),
Expand Down
12 changes: 10 additions & 2 deletions cast-fe/src/components/Cast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ function Cast(props) {
LIVE
</Badge>
)}
<Badge pill style={style.cast_viewer_tag}>
{props.video.unlisted && (
<Badge pill style={{ ...style.cast_tag, ...style.cast_tag_unlisted }}>
<i className="fas fa-lock" /> Unlisted
</Badge>
)}
<Badge pill style={style.cast_tag}>
{abbreviate().number(props.video.views)}{" "}
{props.video.type === "live" ? "viewers" : "views"}
</Badge>
Expand Down Expand Up @@ -94,7 +99,7 @@ let style = {
fontSize: 16,
fontWeight: 400,
},
cast_viewer_tag: {
cast_tag: {
background: "#8B2803AA",
color: "#DDD",
borderRadius: 8,
Expand All @@ -106,6 +111,9 @@ let style = {
marginRight: 8,
marginBottom: 8,
},
cast_tag_unlisted: {
background: "rgb(3,69,139)",
},
cast_detail: {
display: "flex",
},
Expand Down
6 changes: 3 additions & 3 deletions cast-fe/src/views/Manage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class Manage extends Component {

fetchVideos() {
api.cast
.list({
.listCurated({
author: authManager.getUser().preferred_username,
count: 8,
count: 512,
offset: 0,
})
.then((response) => {
Expand Down Expand Up @@ -482,7 +482,7 @@ class Manage extends Component {
</Row>
))
) : (
<h5 style={style.h5}>No videos uploaded yet!</h5>
<h5 style={style.h5}>No casts uploaded yet!</h5>
))}
{this.state.loading && (
<Spinner
Expand Down
Loading

0 comments on commit 94138a0

Please sign in to comment.