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.

84 lines
2.0 KiB

  1. use std::rc::Rc;
  2. use diesel::SqliteConnection;
  3. use crate::{actions, errors, models, types::DbPool};
  4. pub trait UserService {
  5. fn find_user_by_uid(
  6. &self,
  7. uid: i32,
  8. ) -> Result<Option<models::UserDTO>, errors::DomainError>;
  9. fn _find_user_by_name(
  10. &self,
  11. user_name: String,
  12. ) -> Result<Option<models::UserDTO>, errors::DomainError>;
  13. fn get_all(
  14. &self,
  15. ) -> Result<Option<Vec<models::UserDTO>>, errors::DomainError>;
  16. fn insert_new_user(
  17. &self,
  18. nu: models::NewUser,
  19. ) -> Result<models::UserDTO, errors::DomainError>;
  20. // fn woot(&self) -> i32;
  21. fn verify_password<'a>(
  22. &self,
  23. user_name: &'a String,
  24. given_password: &'a String,
  25. ) -> Result<bool, errors::DomainError>;
  26. }
  27. #[derive(Clone)]
  28. pub struct UserServiceImpl {
  29. pub pool: DbPool,
  30. }
  31. impl UserService for UserServiceImpl {
  32. fn find_user_by_uid(
  33. &self,
  34. uid: i32,
  35. ) -> Result<Option<models::UserDTO>, errors::DomainError> {
  36. let conn = self.pool.get()?;
  37. actions::find_user_by_uid(uid, &conn)
  38. }
  39. fn _find_user_by_name(
  40. &self,
  41. user_name: String,
  42. ) -> Result<Option<models::UserDTO>, errors::DomainError> {
  43. let conn = self.pool.get()?;
  44. actions::_find_user_by_name(user_name, &conn)
  45. }
  46. fn get_all(
  47. &self,
  48. ) -> Result<Option<Vec<models::UserDTO>>, errors::DomainError> {
  49. let conn = self.pool.get()?;
  50. actions::get_all(&conn)
  51. }
  52. fn insert_new_user(
  53. &self,
  54. nu: models::NewUser,
  55. ) -> Result<models::UserDTO, errors::DomainError> {
  56. let conn = self.pool.get()?;
  57. actions::insert_new_user(nu, &conn)
  58. }
  59. fn verify_password<'b>(
  60. &self,
  61. user_name: &'b String,
  62. given_password: &'b String,
  63. ) -> Result<bool, errors::DomainError> {
  64. let conn = self.pool.get()?;
  65. actions::verify_password(user_name, given_password, &conn)
  66. }
  67. // async fn woot(&self) -> i32 {
  68. // 1
  69. // }
  70. }