Class: WorldTopMovies::DB::Note

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/world_top_movies/models/note.rb

Class Method Summary collapse

Class Method Details

.create_note(movie_url:, note_message:, user:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/world_top_movies/models/note.rb', line 6

def self.create_note(movie_url:, note_message:, user:)
  #Creates a note to a movie that is created if it's not in the database, and appends it to the user
  attributes = WorldTopMovies::DB::Movie.generate_attributes_from_url(movie_url)
  if !WorldTopMovies::DB::Movie.find_by(url: movie_url)
    movie_record = WorldTopMovies::DB::Movie.create(attributes)
  else
    movie_record = WorldTopMovies::DB::Movie.find_by(url: movie_url)
  end
  note_record = self.create(note_message: note_message, movie_id: movie_record.id)
  user.notes << note_record
end

.delete_note_instance_from_user(user:, note_id:) ⇒ Object



18
19
20
# File 'lib/world_top_movies/models/note.rb', line 18

def self.delete_note_instance_from_user(user:, note_id:)
  user.notes.delete(user.find_note_from_id(note_id))
end