Class: WinewooCore::Repositories::Mongo::WinesMongoRepo
- Inherits:
-
Object
- Object
- WinewooCore::Repositories::Mongo::WinesMongoRepo
- Defined in:
- lib/winewoo_core/repositories/mongo/wines_mongo_repo.rb
Instance Method Summary collapse
- #create(current_user, producer_id, wine_params, vintage_params) ⇒ Object
- #destroy(current_user, wine_id) ⇒ Object
- #find(filters) ⇒ Object
- #get(wine_id) ⇒ Object
- #update(current_user, wine_id, wine_params) ⇒ Object
Instance Method Details
#create(current_user, producer_id, wine_params, vintage_params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/winewoo_core/repositories/mongo/wines_mongo_repo.rb', line 17 def create(current_user, producer_id, wine_params, vintage_params) return unless producer_id producer = User.find(producer_id) return unless producer wine = producer.wines.build wine.modified_by = current_user.id base_vintage = wine.vintages.build(vintage_params) base_vintage.save if wine.update_attributes(wine_params) return wine end |
#destroy(current_user, wine_id) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/winewoo_core/repositories/mongo/wines_mongo_repo.rb', line 39 def destroy(current_user, wine_id) return unless wine_id wine = Wine.find(wine_id) return unless wine wine.modified_by = current_user.id wine.destroy return wine end |
#find(filters) ⇒ Object
10 11 12 13 14 |
# File 'lib/winewoo_core/repositories/mongo/wines_mongo_repo.rb', line 10 def find(filters) WinewooCore::Services::Finders::Wines::WinesFinderBuilder .build(filters) .find end |
#get(wine_id) ⇒ Object
4 5 6 7 |
# File 'lib/winewoo_core/repositories/mongo/wines_mongo_repo.rb', line 4 def get(wine_id) return unless wine_id Wine.find(wine_id) end |
#update(current_user, wine_id, wine_params) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/winewoo_core/repositories/mongo/wines_mongo_repo.rb', line 29 def update(current_user, wine_id, wine_params) return unless wine_id wine = Wine.find(wine_id) return unless wine wine.modified_by = current_user.id wine.update_attributes(wine_params) return wine end |