feature/wasm
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use crate::signup::GithubEmail; |
| 2 | use serde::{Deserialize, Serialize}; |
| 3 | use serde_repr::{Deserialize_repr, Serialize_repr}; |
| 4 | use std::fmt::{Display, Formatter}; |
| 5 | use tsify::Tsify; |
| 6 | |
| 7 | // SMBPNDK Users. |
| 8 | #[derive(Debug, Serialize, Deserialize, Tsify)] |
| 9 | #[tsify(into_wasm_abi)] |
| 10 | pub struct User { |
| 11 | pub id: i32, |
| 12 | pub email: String, |
| 13 | } |
| 14 | |
| 15 | impl Display for User { |
| 16 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 17 | write!(f, "User: id: {}, email: {}", self.id, self.email) |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | #[derive(Debug, Serialize, Deserialize, Tsify)] |
| 22 | #[tsify(into_wasm_abi)] |
| 23 | pub struct Status { |
| 24 | pub code: Option<i32>, |
| 25 | pub message: String, |
| 26 | } |
| 27 | |
| 28 | #[derive(Debug, Serialize, Deserialize, Tsify)] |
| 29 | #[tsify(into_wasm_abi)] |
| 30 | pub struct Data { |
| 31 | id: i32, |
| 32 | email: String, |
| 33 | created_at: String, |
| 34 | } |
| 35 | |
| 36 | // This is smb authorization model. |
| 37 | #[derive(Debug, Serialize, Deserialize, Tsify)] |
| 38 | #[tsify(into_wasm_abi)] |
| 39 | pub struct SmbAuthorization { |
| 40 | pub message: String, |
| 41 | pub user: Option<User>, |
| 42 | pub user_email: Option<GithubEmail>, |
| 43 | pub user_info: Option<GithubInfo>, |
| 44 | pub error_code: Option<ErrorCode>, |
| 45 | } |
| 46 | |
| 47 | #[derive(Debug, Serialize_repr, Deserialize_repr, PartialEq, Tsify)] |
| 48 | #[tsify(namespace)] |
| 49 | #[repr(u32)] |
| 50 | pub enum ErrorCode { |
| 51 | EmailNotFound = 1000, |
| 52 | EmailUnverified = 1001, |
| 53 | PasswordNotSet = 1003, |
| 54 | GithubNotLinked = 1004, |
| 55 | } |
| 56 | |
| 57 | impl Display for ErrorCode { |
| 58 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 59 | match self { |
| 60 | ErrorCode::EmailNotFound => write!(f, "Email not found."), |
| 61 | ErrorCode::EmailUnverified => write!(f, "Email not verified."), |
| 62 | ErrorCode::PasswordNotSet => write!(f, "Password not set."), |
| 63 | ErrorCode::GithubNotLinked => write!(f, "Github not connected."), |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | impl Copy for ErrorCode {} |
| 69 | |
| 70 | impl Clone for ErrorCode { |
| 71 | fn clone(&self) -> Self { |
| 72 | *self |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | #[derive(Debug, Serialize, Deserialize, Tsify)] |
| 77 | #[tsify(into_wasm_abi)] |
| 78 | pub struct GithubInfo { |
| 79 | pub id: i64, |
| 80 | pub login: String, |
| 81 | pub name: String, |
| 82 | pub avatar_url: String, |
| 83 | pub html_url: String, |
| 84 | pub email: Option<String>, |
| 85 | pub created_at: String, |
| 86 | pub updated_at: String, |
| 87 | } |
| 88 | |
| 89 | #[cfg(test)] |
| 90 | mod tests { |
| 91 | use super::*; |
| 92 | use serde_json::json; |
| 93 | #[test] |
| 94 | fn test_smb_authorization() { |
| 95 | let smb_authorization = SmbAuthorization { |
| 96 | message: "test".to_owned(), |
| 97 | user: None, |
| 98 | user_email: None, |
| 99 | user_info: None, |
| 100 | error_code: Some(ErrorCode::EmailUnverified), |
| 101 | }; |
| 102 | let json = json!({ |
| 103 | "message": "test", |
| 104 | "user": null, |
| 105 | "user_email": null, |
| 106 | "user_info": null, |
| 107 | "error_code": 1001, |
| 108 | }); |
| 109 | assert_eq!(serde_json::to_value(smb_authorization).unwrap(), json); |
| 110 | } |
| 111 | } |