func ToJSON(reader models.MovieReader, studioReader models.StudioReader, movie *models.Movie) (*jsonschema.Movie, error) {
	newMovieJSON := jsonschema.Movie{
		CreatedAt: json.JSONTime{Time: movie.CreatedAt.Timestamp},
		UpdatedAt: json.JSONTime{Time: movie.UpdatedAt.Timestamp},
	}

	if movie.Name.Valid {
		newMovieJSON.Name = movie.Name.String
	}
	if movie.Aliases.Valid {
		newMovieJSON.Aliases = movie.Aliases.String
	}
	if movie.Date.Valid {
		newMovieJSON.Date = utils.GetYMDFromDatabaseDate(movie.Date.String)
	}
	if movie.Rating.Valid {
		newMovieJSON.Rating = int(movie.Rating.Int64)
	}
	if movie.Duration.Valid {
		newMovieJSON.Duration = int(movie.Duration.Int64)
	}

	if movie.Director.Valid {
		newMovieJSON.Director = movie.Director.String
	}

	if movie.Synopsis.Valid {
		newMovieJSON.Synopsis = movie.Synopsis.String
	}

	if movie.URL.Valid {
		newMovieJSON.URL = movie.URL.String
	}

	if movie.StudioID.Valid {
		studio, err := studioReader.Find(int(movie.StudioID.Int64))
		if err != nil {
			return nil, fmt.Errorf("error getting movie studio: %v", err)
		}

		if studio != nil {
			newMovieJSON.Studio = studio.Name.String
		}
	}

	frontImage, err := reader.GetFrontImage(movie.ID)
	if err != nil {
		return nil, fmt.Errorf("error getting movie front image: %v", err)
	}

	if len(frontImage) > 0 {
		newMovieJSON.FrontImage = utils.GetBase64StringFromData(frontImage)
	}

	backImage, err := reader.GetBackImage(movie.ID)
	if err != nil {
		return nil, fmt.Errorf("error getting movie back image: %v", err)
	}

	if len(backImage) > 0 {
		newMovieJSON.BackImage = utils.GetBase64StringFromData(backImage)
	}

	return &newMovieJSON, nil
}
// ToJSON converts a Movie into its JSON equivalent.
ToJSON converts a Movie into its JSON equivalent.
// ToJSON converts a Movie into its JSON equivalent .
func ToJSON(reader models.MovieReader, studioReader models.StudioReader, movie *models.Movie) (*jsonschema.Movie, error) {
	newMovieJSON := jsonschema.Movie{
		CreatedAt: json.JSONTime{Time: movie.CreatedAt.Timestamp},
		UpdatedAt: json.JSONTime{Time: movie.UpdatedAt.Timestamp},
	}
	if movie.Name.Valid {
		newMovieJSON.Name = movie.Name.String
	}
	if movie.Aliases.Valid {
		newMovieJSON.Aliases = movie.Aliases.String
	}
	if movie.Date.Valid {
		newMovieJSON.Date = utils.GetYMDFromDatabaseDate(movie.Date.String)
	}
	if movie.Rating.Valid {
		newMovieJSON.Rating = int(movie.Rating.Int64)
	}
	if movie.Duration.Valid {
		newMovieJSON.Duration = int(movie.Duration.Int64)
	}
	if movie.Director.Valid {
		newMovieJSON.Director = movie.Director.String
	}
	if movie.Synopsis.Valid {
		newMovieJSON.Synopsis = movie.Synopsis.String
	}
	if movie.URL.Valid {
		newMovieJSON.URL = movie.URL.String
	}
	if movie.StudioID.Valid {
		studio, err := studioReader.Find(int(movie.StudioID.Int64))
		if err != nil {
			return nil, fmt.Errorf("error getting movie studio: %v", err)
		}
		if studio != nil {
			newMovieJSON.Studio = studio.Name.String
		}
	}
	frontImage, err := reader.GetFrontImage(movie.ID)
	if err != nil {
		return nil, fmt.Errorf("error getting movie front image: %v", err)
	}
	if len(frontImage) > 0 {
		newMovieJSON.FrontImage = utils.GetBase64StringFromData(frontImage)
	}
	backImage, err := reader.GetBackImage(movie.ID)
	if err != nil {
		return nil, fmt.Errorf("error getting movie back image: %v", err)
	}
	if len(backImage) > 0 {
		newMovieJSON.BackImage = utils.GetBase64StringFromData(backImage)
	}
	return &newMovieJSON, nil
}
func ToJSON ( reader models . MovieReader , studioReader models . StudioReader , movie * models . Movie ) ( * jsonschema . Movie , error ) { newMovieJSON := jsonschema . Movie { CreatedAt : json . JSONTime { Time : movie . CreatedAt . Timestamp } , UpdatedAt : json . JSONTime { Time : movie . UpdatedAt . Timestamp } , } if movie . Name . Valid { newMovieJSON . Name = movie . Name . String } if movie . Aliases . Valid { newMovieJSON . Aliases = movie . Aliases . String } if movie . Date . Valid { newMovieJSON . Date = utils . GetYMDFromDatabaseDate ( movie . Date . String ) } if movie . Rating . Valid { newMovieJSON . Rating = int ( movie . Rating . Int64 ) } if movie . Duration . Valid { newMovieJSON . Duration = int ( movie . Duration . Int64 ) } if movie . Director . Valid { newMovieJSON . Director = movie . Director . String } if movie . Synopsis . Valid { newMovieJSON . Synopsis = movie . Synopsis . String } if movie . URL . Valid { newMovieJSON . URL = movie . URL . String } if movie . StudioID . Valid { studio , err := studioReader . Find ( int ( movie . StudioID . Int64 ) ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if studio != nil { newMovieJSON . Studio = studio . Name . String } } frontImage , err := reader . GetFrontImage ( movie . ID ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if len ( frontImage ) > 0 { newMovieJSON . FrontImage = utils . GetBase64StringFromData ( frontImage ) } backImage , err := reader . GetBackImage ( movie . ID ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if len ( backImage ) > 0 { newMovieJSON . BackImage = utils . GetBase64StringFromData ( backImage ) } return & newMovieJSON , nil }
ToJSON converts a Movie into its JSON equivalent.
ToJSON converts a Movie into its JSON equivalent .