add feed_mag entity_gateway function
This commit is contained in:
		
							parent
							
								
									3184c79c3c
								
							
						
					
					
						commit
						a68fcb9b10
					
				| @ -60,6 +60,10 @@ pub trait EntityGateway: Send + Sync + Clone { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| 
 | ||||
|     async fn feed_mag(&mut self, _mag_item_id: &ItemEntityId, _tool_item_id: &ItemEntityId) { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| 
 | ||||
|     async fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<ItemEntity> { | ||||
|         unimplemented!(); | ||||
|     } | ||||
|  | ||||
| @ -13,6 +13,7 @@ pub struct InMemoryGateway { | ||||
|     user_settings: Arc<Mutex<BTreeMap<UserSettingsId, UserSettingsEntity>>>, | ||||
|     characters: Arc<Mutex<BTreeMap<CharacterEntityId, CharacterEntity>>>, | ||||
|     items: Arc<Mutex<BTreeMap<ItemEntityId, ItemEntity>>>, | ||||
|     mag_feedings: Arc<Mutex<BTreeMap<ItemEntityId, Vec<ItemEntityId>>>>, | ||||
| } | ||||
| 
 | ||||
| impl InMemoryGateway { | ||||
| @ -22,6 +23,7 @@ impl InMemoryGateway { | ||||
|             user_settings: Arc::new(Mutex::new(BTreeMap::new())), | ||||
|             characters: Arc::new(Mutex::new(BTreeMap::new())), | ||||
|             items: Arc::new(Mutex::new(BTreeMap::new())), | ||||
|             mag_feedings: Arc::new(Mutex::new(BTreeMap::new())), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -165,6 +167,13 @@ impl EntityGateway for InMemoryGateway { | ||||
|             }); | ||||
|     } | ||||
| 
 | ||||
|     async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) { | ||||
|         self.mag_feedings.lock().unwrap() | ||||
|             .entry(*mag_item_id) | ||||
|             .or_insert(Vec::new()) | ||||
|             .push(*tool_item_id); | ||||
|     } | ||||
| 
 | ||||
|     async fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> { | ||||
|         let items = self.items.lock().unwrap(); | ||||
|         items | ||||
| @ -179,6 +188,25 @@ impl EntityGateway for InMemoryGateway { | ||||
|             .map(|(_, k)| { | ||||
|                 k.clone() | ||||
|             }) | ||||
|             .map(|mut item| { | ||||
|                 item.item = match item.item { | ||||
|                     ItemDetail::Mag(mut mag) => { | ||||
|                         self.mag_feedings.lock().unwrap().get(&item.id).map(|mag_feedings| { | ||||
|                             for mag_feed_id in mag_feedings.iter() { | ||||
|                                 items.get(&mag_feed_id).map(|mag_feed| { | ||||
|                                     match mag_feed.item { | ||||
|                                         ItemDetail::Tool(mag_feed) => mag.feed(mag_feed.tool), | ||||
|                                         _ => {} | ||||
|                                     } | ||||
|                                 }); | ||||
|                             } | ||||
|                         }); | ||||
|                         ItemDetail::Mag(mag) | ||||
|                     } | ||||
|                     _ => item.item | ||||
|                 }; | ||||
|                 item | ||||
|             }) | ||||
|             .collect() | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user