Mbonea commited on
Commit
1e7e130
·
1 Parent(s): f30e75c

Android files

Browse files
Files changed (2) hide show
  1. App/Android/Android.py +57 -0
  2. App/Android/Schema.py +101 -0
App/Android/Android.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import httpx
2
+ from typing import Optional
3
+ from .Schema import (
4
+ RegisterUserRequest,
5
+ LoginRequest,
6
+ SetUserStatusRequest,
7
+ APIResponse,
8
+ )
9
+ from App.Portals.PortalRoutes import ANDROID
10
+ from App.Portals.Model import Portal
11
+
12
+
13
+ class AndroidClient:
14
+ def __init__(self):
15
+ self.base_url = "http://127.0.0.1:8080/"
16
+ self.client = httpx.AsyncClient(base_url=self.base_url)
17
+
18
+ async def register_user(self, request: RegisterUserRequest) -> APIResponse:
19
+ """Register a new user."""
20
+ response = await self.client.post("/users/register", json=request.dict())
21
+ return APIResponse(**response.json())
22
+
23
+ async def login_user(self, request: LoginRequest) -> APIResponse:
24
+ """Login an existing user."""
25
+ response = await self.client.post("/login", json=request.dict())
26
+ return APIResponse(**response.json())
27
+
28
+ async def logout_user(self, phone: str) -> APIResponse:
29
+ """Logout a user by phone."""
30
+ response = await self.client.post(f"/logout/{phone}")
31
+ return APIResponse(**response.json())
32
+
33
+ async def get_active_users(self) -> APIResponse:
34
+ """Retrieve all active users."""
35
+ response = await self.client.get("/users/active")
36
+ print(response.json())
37
+ return APIResponse(**response.json())
38
+
39
+ async def set_user_status(self, request: SetUserStatusRequest) -> APIResponse:
40
+ """Enable or disable a user."""
41
+ response = await self.client.patch("/user/status", json=request.dict())
42
+ return APIResponse(**response.json())
43
+
44
+ async def get_users_list(self) -> APIResponse:
45
+ """Retrieve all users (active and inactive)."""
46
+ response = await self.client.get("/users")
47
+ return APIResponse(**response.json())
48
+
49
+ async def get_user_stats(self, phone: Optional[str] = None) -> APIResponse:
50
+ """Retrieve user statistics for a specific user or all users."""
51
+ url = f"/user/stats/{phone}" if phone else "/user/stats"
52
+ response = await self.client.get(url)
53
+ return APIResponse(**response.json())
54
+
55
+ async def close(self):
56
+ """Close the client session."""
57
+ await self.client.aclose()
App/Android/Schema.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+ from typing import Optional, Dict, Any, List
3
+
4
+
5
+ # Request Schemas
6
+
7
+
8
+ class RegisterUserRequest(BaseModel):
9
+ phone: str
10
+ password: str
11
+ profile: Optional[str] = "default"
12
+
13
+
14
+ class LoginRequest(BaseModel):
15
+ phone: str
16
+ password: str
17
+ mac_address: str
18
+ ip_address: str
19
+
20
+
21
+ class SetUserStatusRequest(BaseModel):
22
+ phone: str
23
+ disabled: bool
24
+
25
+
26
+ # Response Schemas
27
+
28
+
29
+ class UserUsage(BaseModel):
30
+ bytes_in: int
31
+ bytes_out: int
32
+ total_bytes: int
33
+ download_mb: float
34
+ upload_mb: float
35
+ total_mb: float
36
+
37
+
38
+ class ActiveUser(BaseModel):
39
+ phone: str
40
+ uptime: str
41
+ mac_address: str
42
+ ip_address: str
43
+ usage: UserUsage
44
+
45
+
46
+ class UserStats(BaseModel):
47
+ phone: str
48
+ profile: str
49
+ status: str
50
+ uptime: str
51
+ usage: UserUsage
52
+
53
+
54
+ class UserListItem(BaseModel):
55
+ phone: str
56
+ profile: str
57
+ status: str
58
+ disabled: bool
59
+ comment: str
60
+ usage: UserUsage
61
+
62
+
63
+ # Base Response Schema
64
+
65
+
66
+ class APIResponse(BaseModel):
67
+ success: bool
68
+ message: str
69
+ data: Optional[Dict[str, Any]] = None
70
+ error: Optional[str] = None
71
+
72
+
73
+ # Specific Response Schemas
74
+
75
+
76
+ class RegisterUserResponse(APIResponse):
77
+ data: Optional[Dict[str, Any]] = None
78
+
79
+
80
+ class LoginResponse(APIResponse):
81
+ data: Optional[Dict[str, Any]] = None
82
+
83
+
84
+ class LogoutResponse(APIResponse):
85
+ data: Optional[Dict[str, Any]] = None
86
+
87
+
88
+ class UserStatusResponse(APIResponse):
89
+ data: Optional[Dict[str, Any]] = None
90
+
91
+
92
+ class ActiveUsersResponse(APIResponse):
93
+ data: Optional[List[ActiveUser]] = None
94
+
95
+
96
+ class UsersListResponse(APIResponse):
97
+ data: Optional[List[UserListItem]] = None
98
+
99
+
100
+ class UserStatsResponse(APIResponse):
101
+ data: Optional[List[UserStats]] = None