Class: WinewooCore::Repositories::Mongo::CommentsMongoRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/winewoo_core/repositories/mongo/comments_mongo_repo.rb

Instance Method Summary collapse

Instance Method Details

#create(winewoo_user, wine_id, vintage_id, comment_params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/winewoo_core/repositories/mongo/comments_mongo_repo.rb', line 21

def create(winewoo_user, wine_id, vintage_id, comment_params)
  return unless (wine_id && vintage_id)
  wine = Wine.find(wine_id)
  return unless wine
  vintage = wine.vintages.find(vintage_id)
  return unless vintage
  comment = UserComment.create(comment_params)
  comment.vintage = vintage
  comment.winewoo_user = winewoo_user
  comment.wine = wine
  comment.save
  return comment
end

#destroy(wine_id, vintage_id, comment_id) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/winewoo_core/repositories/mongo/comments_mongo_repo.rb', line 49

def destroy(wine_id, vintage_id, comment_id)
  return unless (wine_id && vintage_id && comment_id)
  wine = Wine.find(wine_id)
  return unless wine
  vintage = wine.vintages.find(vintage_id)
  return unless vintage
  comment = vintage.user_comments.find(comment_id)
  return unless comment
  comment.destroy
  return comment
end

#find(current_winewoo_user, wine_id, vintage_id, winewoo_user_id, filters) ⇒ Object



14
15
16
17
18
# File 'lib/winewoo_core/repositories/mongo/comments_mongo_repo.rb', line 14

def find(current_winewoo_user, wine_id, vintage_id, winewoo_user_id, filters)
  return WinewooCore::Services::Finders::Comments::CommentsFinderBuilder
    .build(current_winewoo_user, wine_id, vintage_id, winewoo_user_id, filters)
    .find
end

#show(wine_id, vintage_id, comment_id) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/winewoo_core/repositories/mongo/comments_mongo_repo.rb', line 4

def show(wine_id, vintage_id, comment_id)
  return unless (wine_id && vintage_id && comment_id)
  wine = Wine.find(wine_id)
  return unless wine
  vintage = wine.vintages.find(vintage_id)
  return unless vintage
  vintage.user_comments.find(comment_id)
end

#update(wine_id, vintage_id, comment_id, comment_params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/winewoo_core/repositories/mongo/comments_mongo_repo.rb', line 36

def update(wine_id, vintage_id, comment_id, comment_params)
  return unless (wine_id && vintage_id && comment_id)
  wine = Wine.find(wine_id)
  return unless wine
  vintage = wine.vintages.find(vintage_id)
  return unless vintage
  comment = vintage.user_comments.find(comment_id)
  return unless comment
  comment.update_attributes(comment_params)
  return comment
end