You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.4 KiB

5 years ago
5 years ago
4 years ago
3 years ago
3 years ago
2 years ago
  1. use std::convert::From;
  2. use thiserror::Error;
  3. use futures::Future;
  4. use crate::entity::account::*;
  5. use crate::entity::character::*;
  6. use crate::entity::item::*;
  7. // TODO: better granularity?
  8. //#[derive(Error, Debug)]
  9. #[derive(Error, Debug)]
  10. #[error("")]
  11. pub enum GatewayError {
  12. Error,
  13. PgError(#[from] sqlx::Error)
  14. }
  15. #[async_trait::async_trait]
  16. pub trait EntityGateway: Send + Sync {
  17. async fn transaction<'a>(&'a mut self) -> Result<Box<dyn EntityGatewayTransaction + 'a>, GatewayError>
  18. {
  19. unimplemented!();
  20. }
  21. async fn with_transaction<'a, F, Fut, R, E>(&'a mut self, _func: F) -> Result<R, E>
  22. where
  23. Fut: Future<Output = Result<(Box<dyn EntityGatewayTransaction + 'a>, R), E>> + Send + 'a,
  24. F: FnOnce(Box<dyn EntityGatewayTransaction + 'a>) -> Fut + Send,
  25. R: Send,
  26. E: From<GatewayError>,
  27. Self: Sized
  28. {
  29. unimplemented!();
  30. }
  31. async fn create_user(&mut self, _user: NewUserAccountEntity) -> Result<UserAccountEntity, GatewayError> {
  32. unimplemented!()
  33. }
  34. async fn get_user_by_id(&mut self, _id: UserAccountId) -> Result<UserAccountEntity, GatewayError> {
  35. unimplemented!();
  36. }
  37. async fn get_user_by_name(&mut self, _username: String) -> Result<UserAccountEntity, GatewayError> {
  38. unimplemented!();
  39. }
  40. async fn save_user(&mut self, _user: &UserAccountEntity) -> Result<(), GatewayError> {
  41. unimplemented!();
  42. }
  43. async fn create_user_settings(&mut self, _settings: NewUserSettingsEntity) -> Result<UserSettingsEntity, GatewayError> {
  44. unimplemented!();
  45. }
  46. async fn get_user_settings_by_user(&mut self, _user: &UserAccountEntity) -> Result<UserSettingsEntity, GatewayError> {
  47. unimplemented!();
  48. }
  49. async fn save_user_settings(&mut self, _settings: &UserSettingsEntity) -> Result<(), GatewayError> {
  50. unimplemented!();
  51. }
  52. async fn create_character(&mut self, _char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
  53. unimplemented!();
  54. }
  55. // TODO: just make this a vec sorted by slot order?
  56. async fn get_characters_by_user(&mut self, _user: &UserAccountEntity) -> Result<[Option<CharacterEntity>; 4], GatewayError> {
  57. unimplemented!();
  58. }
  59. async fn save_character(&mut self, _char: &CharacterEntity) -> Result<(), GatewayError> {
  60. unimplemented!();
  61. }
  62. async fn get_guild_card_data_by_user(&mut self, _user: &UserAccountEntity) -> Result<GuildCardDataEntity, GatewayError> {
  63. unimplemented!();
  64. }
  65. async fn create_item(&mut self, _item: NewItemEntity) -> Result<ItemEntity, GatewayError> {
  66. unimplemented!();
  67. }
  68. async fn add_item_note(&mut self, _item_id: &ItemEntityId, _item_note: ItemNote) -> Result<(), GatewayError> {
  69. unimplemented!();
  70. }
  71. async fn feed_mag(&mut self, _mag_item_id: &ItemEntityId, _tool_item_id: &ItemEntityId) -> Result<(), GatewayError> {
  72. unimplemented!();
  73. }
  74. async fn change_mag_owner(&mut self, _mag_item_id: &ItemEntityId, _character: &CharacterEntity) -> Result<(), GatewayError> {
  75. unimplemented!();
  76. }
  77. async fn use_mag_cell(&mut self, _mag_item_id: &ItemEntityId, _mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> {
  78. unimplemented!();
  79. }
  80. async fn add_weapon_modifier(&mut self, _item_id: &ItemEntityId, _modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
  81. unimplemented!();
  82. }
  83. async fn get_character_inventory(&mut self, _char_id: &CharacterEntityId) -> Result<InventoryEntity, GatewayError> {
  84. unimplemented!();
  85. }
  86. async fn get_character_bank(&mut self, _char_id: &CharacterEntityId, _bank_name: &BankName) -> Result<BankEntity, GatewayError> {
  87. unimplemented!();
  88. }
  89. async fn set_character_inventory(&mut self, _char_id: &CharacterEntityId, _inventory: &InventoryEntity) -> Result<(), GatewayError> {
  90. unimplemented!();
  91. }
  92. async fn set_character_bank(&mut self, _char_id: &CharacterEntityId, _inventory: &BankEntity, _bank_name: &BankName) -> Result<(), GatewayError> {
  93. unimplemented!();
  94. }
  95. async fn get_character_equips(&mut self, _char_id: &CharacterEntityId) -> Result<EquippedEntity, GatewayError> {
  96. unimplemented!();
  97. }
  98. async fn set_character_equips(&mut self, _char_id: &CharacterEntityId, _equips: &EquippedEntity) -> Result<(), GatewayError> {
  99. unimplemented!();
  100. }
  101. async fn get_character_meseta(&mut self, _char_id: &CharacterEntityId) -> Result<Meseta, GatewayError> {
  102. unimplemented!();
  103. }
  104. async fn set_character_meseta(&mut self, _char_id: &CharacterEntityId, _amount: Meseta) -> Result<(), GatewayError> {
  105. unimplemented!();
  106. }
  107. async fn get_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: &BankName) -> Result<Meseta, GatewayError> {
  108. unimplemented!();
  109. }
  110. async fn set_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: &BankName, _amount: Meseta) -> Result<(), GatewayError> {
  111. unimplemented!();
  112. }
  113. async fn create_trade(&mut self, _char_id1: &CharacterEntityId, _char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError> {
  114. unimplemented!();
  115. }
  116. }
  117. #[async_trait::async_trait]
  118. pub trait EntityGatewayTransaction: Send + Sync {
  119. fn gateway(&mut self) -> &mut dyn EntityGateway {
  120. unimplemented!()
  121. }
  122. async fn commit(self: Box<Self>) -> Result<(), GatewayError> {
  123. unimplemented!()
  124. }
  125. }