@@ -39,5 +39,58 @@ public async Task<AuthResponse> LoginAsync(LoginRequest request, CancellationTok
3939 var auth = JsonSerializer . Deserialize < AuthResponse > ( body , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
4040 return auth ;
4141 }
42+
43+ public async Task < UpdatePermissionsResponse > UpdatePermissions ( UpdatePermissionsRequest operations , CancellationToken ct = default )
44+ {
45+ var resp = await _http . PostAsJsonAsync ( "api/users/updatepermissions" , operations , ct ) ;
46+
47+ resp . EnsureSuccessStatusCode ( ) ; // throw if failed
48+
49+ // if you expect a structured response, deserialize it
50+ var result = await resp . Content . ReadAsStringAsync ( ct ) ;
51+ if ( ! resp . IsSuccessStatusCode )
52+ {
53+ throw new HttpRequestException ( $ "Failed to update permissions: { result } ") ;
54+ }
55+ else
56+ {
57+ return new UpdatePermissionsResponse ( result ) ;
58+ }
59+
60+ }
61+
62+ public async Task < UserPermissionsDto > GetPermissions ( int userId , CancellationToken ct = default )
63+ {
64+ var resp = await _http . GetAsync ( $ "api/users/{ userId } /permissions", ct ) ;
65+
66+ resp . EnsureSuccessStatusCode ( ) ;
67+
68+ return await resp . Content . ReadFromJsonAsync < UserPermissionsDto > ( cancellationToken : ct ) ;
69+
70+ }
71+
72+ public async Task < object > GetState ( int userId , CancellationToken ct = default )
73+ {
74+ var resp = await _http . GetAsync ( $ "api/users/{ userId } /getstate", ct ) ;
75+
76+ // Throws if 4xx/5xx
77+ resp . EnsureSuccessStatusCode ( ) ;
78+
79+ // Read JSON
80+ var json = await resp . Content . ReadAsStringAsync ( ct ) ;
81+
82+ // Optional extra defensive check
83+ if ( ! resp . IsSuccessStatusCode )
84+ throw new HttpRequestException ( $ "Failed to fetch permissions for user { userId } : { json } ") ;
85+
86+ // Deserialize to your DTO
87+ var dto = System . Text . Json . JsonSerializer . Deserialize < object > ( json ) ;
88+
89+ // Safety check (should not happen unless server returns null JSON)
90+ if ( dto == null )
91+ throw new InvalidOperationException ( $ "Empty or invalid permissions payload for user { userId } .") ;
92+
93+ return dto ;
94+ }
4295 }
4396}
0 commit comments