add postgres trade stuff
This commit is contained in:
		
							parent
							
								
									eb0689a1fe
								
							
						
					
					
						commit
						4a6bd47c9e
					
				
							
								
								
									
										5
									
								
								src/entity/gateway/postgres/migrations/V0005__trade.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/entity/gateway/postgres/migrations/V0005__trade.sql
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| create table trades ( | ||||
|   id serial primary key not null, | ||||
|   character1 integer references character (id) not null, | ||||
|   character2 integer references character (id) not null, | ||||
| ); | ||||
| @ -858,3 +858,19 @@ impl From<(CharacterEntityId, EquippedEntity)> for PgEquipped { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, sqlx::FromRow)] | ||||
| pub struct PgTradeEntity { | ||||
|     id: i32, | ||||
|     character1: i32, | ||||
|     character2: i32, | ||||
| } | ||||
| 
 | ||||
| impl From<PgTradeEntity> for TradeEntity { | ||||
|     fn from(other: PgTradeEntity) -> TradeEntity { | ||||
|         TradeEntity { | ||||
|             id: TradeId(other.id as u32), | ||||
|             character1: CharacterEntityId(other.character1 as u32), | ||||
|             character2: CharacterEntityId(other.character2 as u32), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -558,6 +558,16 @@ async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntit | ||||
|     Ok(Meseta(meseta.0 as u32)) | ||||
| } | ||||
| 
 | ||||
| async fn create_trade(conn: &mut sqlx::PgConnection, char_id1: &CharacterEntityId, char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError> | ||||
| { | ||||
|     let trade = sqlx::query_as::<_, PgTradeEntity>(r#"insert into trades (character1, character2) values ($1, $2) returning *;"#) | ||||
|         .bind(char_id1.0) | ||||
|         .bind(char_id2.0) | ||||
|         .fetch_one(conn) | ||||
|         .await?; | ||||
|     Ok(trade.into()) | ||||
| } | ||||
| 
 | ||||
| #[async_trait::async_trait] | ||||
| impl EntityGateway for PostgresGateway { | ||||
|     async fn transaction<'a>(&'a mut self) -> Result<Box<dyn EntityGatewayTransaction + 'a>, GatewayError> | ||||
| @ -693,6 +703,10 @@ impl EntityGateway for PostgresGateway { | ||||
|     async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName) -> Result<Meseta, GatewayError> { | ||||
|         get_bank_meseta(&mut *self.pool.acquire().await?, char_id, bank).await | ||||
|     } | ||||
| 
 | ||||
|     async fn create_trade(&mut self, char_id1: &CharacterEntityId, char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError> { | ||||
|         create_trade(&mut *self.pool.acquire().await?, char_id1, char_id2).await | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -809,5 +823,9 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { | ||||
|     async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName) -> Result<Meseta, GatewayError> { | ||||
|         get_bank_meseta(&mut *self.pgtransaction, char_id, bank).await | ||||
|     } | ||||
| 
 | ||||
|     async fn create_trade(&mut self, char_id1: &CharacterEntityId, char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError> { | ||||
|         create_trade(&mut *self.pgtransaction, char_id1, char_id2).await | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user