|
|
|
@ -82,18 +82,9 @@ func (r *Room) CheckVersion(version uint32) bool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) UpdateMovie(movieId string, movie *model.MovieBase) error {
|
|
|
|
|
cid := r.current.current.Movie.ID
|
|
|
|
|
if cid != "" {
|
|
|
|
|
if cid == movieId {
|
|
|
|
|
return errors.New("cannot update current movie")
|
|
|
|
|
}
|
|
|
|
|
ok, err := r.IsParentOf(cid, movieId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("check parent failed: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if ok {
|
|
|
|
|
return errors.New("cannot update current movie's parent")
|
|
|
|
|
}
|
|
|
|
|
err := r.checkCanModifyMovie(movieId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return r.movies.Update(movieId, movie)
|
|
|
|
|
}
|
|
|
|
@ -328,49 +319,69 @@ func (r *Room) SetPassword(password string) error {
|
|
|
|
|
return db.SetRoomHashedPassword(r.ID, hashedPassword)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) IsParentOf(movieID, parentID string) (bool, error) {
|
|
|
|
|
if parentID == "" {
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
return r.movies.IsParentOf(movieID, parentID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) DeleteMovieByID(id string) error {
|
|
|
|
|
func (r *Room) checkCanModifyMovie(id string) error {
|
|
|
|
|
if id == "" {
|
|
|
|
|
return errors.New("movie id is nil")
|
|
|
|
|
if r.current.current.Movie.ID != "" {
|
|
|
|
|
return errors.New("cannot modify current movie")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
cid := r.current.current.Movie.ID
|
|
|
|
|
if cid != "" {
|
|
|
|
|
if cid == id {
|
|
|
|
|
return errors.New("cannot delete current movie")
|
|
|
|
|
return errors.New("cannot modify current movie")
|
|
|
|
|
}
|
|
|
|
|
ok, err := r.IsParentOf(cid, id)
|
|
|
|
|
ok, err := r.movies.IsParentFolder(cid, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("check parent failed: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if ok {
|
|
|
|
|
return errors.New("cannot delete current movie's parent")
|
|
|
|
|
return errors.New("cannot modify current movie's parent")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return r.movies.DeleteMovieByID(id)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) DeleteMoviesByID(ids []string) error {
|
|
|
|
|
func (r *Room) checkCanModifyMovies(ids []string) error {
|
|
|
|
|
if len(ids) == 0 {
|
|
|
|
|
return errors.New("ids is nil")
|
|
|
|
|
}
|
|
|
|
|
cid := r.current.current.Movie.ID
|
|
|
|
|
if cid != "" {
|
|
|
|
|
for _, id := range ids {
|
|
|
|
|
for _, id := range ids {
|
|
|
|
|
if id == "" {
|
|
|
|
|
if cid != "" {
|
|
|
|
|
return errors.New("cannot modify current movie")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if cid != "" {
|
|
|
|
|
if id == cid {
|
|
|
|
|
return errors.New("cannot delete current movie")
|
|
|
|
|
return errors.New("cannot modify current movie")
|
|
|
|
|
}
|
|
|
|
|
ok, err := r.IsParentOf(cid, id)
|
|
|
|
|
ok, err := r.movies.IsParentFolder(cid, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("check parent failed: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if ok {
|
|
|
|
|
return errors.New("cannot delete current movie's parent")
|
|
|
|
|
return errors.New("cannot modify current movie's parent")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) DeleteMovieByID(id string) error {
|
|
|
|
|
err := r.checkCanModifyMovie(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return r.movies.DeleteMovieByID(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) DeleteMoviesByID(ids []string) error {
|
|
|
|
|
err := r.checkCanModifyMovies(ids)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return r.movies.DeleteMoviesByID(ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -379,15 +390,9 @@ func (r *Room) ClearMovies() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *Room) ClearMoviesByParentID(parentID string) error {
|
|
|
|
|
cid := r.current.current.Movie.ID
|
|
|
|
|
if cid != "" {
|
|
|
|
|
ok, err := r.IsParentOf(cid, parentID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("check parent failed: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if ok {
|
|
|
|
|
return errors.New("cannot delete current movie's parent")
|
|
|
|
|
}
|
|
|
|
|
err := r.checkCanModifyMovie(parentID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return r.movies.DeleteMovieByParentID(parentID)
|
|
|
|
|
}
|
|
|
|
|