Opt: change current can reset

pull/31/head
zijiren233 3 years ago
parent 54347c52ee
commit a5810f5730

@ -55,13 +55,13 @@ func (c *current) Movie() model.Movie {
return c.current.Movie
}
func (c *current) SetMovie(movie model.Movie) {
func (c *current) SetMovie(movie model.Movie, play bool) {
c.lock.Lock()
defer c.lock.Unlock()
c.current.Movie = movie
c.current.SetSeek(0, 0)
c.current.Status.Playing = true
c.current.Status.Playing = play
}
func (c *current) Status() Status {

@ -148,15 +148,19 @@ func (r *Room) Current() *Current {
return &c
}
func (r *Room) ChangeCurrentMovie(id string) error {
func (r *Room) ChangeCurrentMovie(id string, play bool) error {
m, err := r.movies.GetMovieByID(id)
if err != nil {
return err
}
r.current.SetMovie(*m.Movie)
r.current.SetMovie(*m.Movie, play)
return nil
}
func (r *Room) SetCurrentMovie(movie *model.Movie, play bool) {
r.current.SetMovie(*movie, play)
}
func (r *Room) SwapMoviePositions(id1, id2 string) error {
return r.movies.SwapMoviePositions(id1, id2)
}

@ -394,13 +394,15 @@ func ChangeCurrentMovie(ctx *gin.Context) {
room := ctx.MustGet("room").(*op.Room)
user := ctx.MustGet("user").(*op.User)
req := model.IdReq{}
req := model.IdCanEmptyReq{}
if err := model.Decode(ctx, &req); err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorResp(err))
return
}
if err := room.ChangeCurrentMovie(req.Id); err != nil {
if req.Id == "" {
room.SetCurrentMovie(&dbModel.Movie{}, false)
} else if err := room.ChangeCurrentMovie(req.Id, true); err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorResp(err))
return
}

@ -74,6 +74,21 @@ func (i *IdReq) Validate() error {
return nil
}
type IdCanEmptyReq struct {
Id string `json:"id"`
}
func (i *IdCanEmptyReq) Decode(ctx *gin.Context) error {
return json.NewDecoder(ctx.Request.Body).Decode(i)
}
func (i *IdCanEmptyReq) Validate() error {
if len(i.Id) != 32 && i.Id != "" {
return ErrId
}
return nil
}
type EditMovieReq struct {
IdReq
PushMovieReq

Loading…
Cancel
Save