Skip to content

Commit

Permalink
Fixed: Cannot delete video with viewing status #110
Browse files Browse the repository at this point in the history
  • Loading branch information
dularion committed Dec 31, 2015
1 parent 66324c0 commit f62577a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ class BootStrap {

def marshallerService
def defaultDataService
def migrationService

def init = { servletContext ->
marshallerService.init()
defaultDataService.createDefaultRoles()
defaultDataService.createDefaultUsers()
defaultDataService.createDefaultSettings()
migrationService.setDefaultDeletedFlag()
}
def destroy = {
}
Expand Down
4 changes: 2 additions & 2 deletions grails-app/controllers/streama/DashController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class DashController {

def searchMedia() {
String query = params.query
def movies = Movie.list()
def shows = TvShow.list()
def movies = Movie.findAllByDeletedNotEqual(true)
def shows = TvShow.findAllByDeletedNotEqual(true)


def result = [
Expand Down
6 changes: 4 additions & 2 deletions grails-app/controllers/streama/EpisodeController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EpisodeController {

def index() {
TvShow show = TvShow.get(params.getLong("showId"))
respond Episode.findAllByShow(show), [status: OK]
respond Episode.findAllByShowAndDeletedNotEqual(show, true), [status: OK]
}

@Transactional
Expand Down Expand Up @@ -59,7 +59,9 @@ class EpisodeController {
return
}

episodeInstance.delete flush:true
episodeInstance.deleted = true
episodeInstance.save failOnError: true, flush: true

render status: NO_CONTENT
}
}
5 changes: 3 additions & 2 deletions grails-app/controllers/streama/MovieController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MovieController {
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

def index() {
respond Movie.list(), [status: OK]
respond Movie.findAllByDeletedNotEqual(true), [status: OK]
}

@Transactional
Expand Down Expand Up @@ -50,7 +50,8 @@ class MovieController {
return
}

movieInstance.delete flush: true
movieInstance.deleted = true
movieInstance.save failOnError: true, flush: true
render status: NO_CONTENT
}
}
8 changes: 5 additions & 3 deletions grails-app/controllers/streama/VideoController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class VideoController {


def index() {
respond Video.list(), [status: OK]
respond Video.findAllByDeletedNotEqual(true), [status: OK]
}

def dash() {
Expand All @@ -31,11 +31,12 @@ class VideoController {
eq("user", currentUser)
video{
isNotEmpty("files")
ne("deleted", true)
}
eq("completed", false)
order("lastUpdated", "desc")
}
def movies = Movie.list().findAll{ Movie movie ->
def movies = Movie.findAllByDeletedNotEqual(true).findAll{ Movie movie ->
return (!continueWatching.find{it.video.id == movie.id} && movie.files)
}

Expand Down Expand Up @@ -115,7 +116,8 @@ class VideoController {
return
}

videoInstance.delete flush:true
videoInstance.deleted = true
videoInstance.save failOnError: true, flush: true
render status: NO_CONTENT
}

Expand Down
1 change: 1 addition & 0 deletions grails-app/domain/streama/Video.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Video {
Integer vote_count
Double popularity

Boolean deleted = false
String imdb_id

static hasMany = [files: File]
Expand Down
16 changes: 16 additions & 0 deletions grails-app/services/streama/MigrationService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package streama

import grails.transaction.Transactional

@Transactional
class MigrationService {

def setDefaultDeletedFlag() {
def videos = Video.findAllByDeletedIsNull()

videos.each{
it.deleted = false
it.save(failOnError: true)
}
}
}

0 comments on commit f62577a

Please sign in to comment.