Skip to content

Commit a1d05a2

Browse files
feature: this commit introduces identityClient and profilesClient for user and profile management
1 parent 23081c3 commit a1d05a2

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Result } from "@/patterns/result";
2+
import { AxiosInstance } from "axios";
3+
import { AuthenticationCredentials, AuthenticationResult, UserScheme } from "../contracts/identity-schemes";
4+
5+
export class IdentityClient {
6+
private readonly httpClient: AxiosInstance;
7+
8+
public constructor(httpClient: AxiosInstance) {
9+
this.httpClient = httpClient;
10+
}
11+
12+
public async register(parameters: AuthenticationCredentials): Promise<Result<UserScheme>> {
13+
var response = await this.httpClient.post("/api/v1/identity", parameters);
14+
if (response.status < 200 || response.status >= 300) {
15+
return Result.failure<UserScheme>(response.data);
16+
}
17+
18+
return Result.success<UserScheme>(response.data);
19+
}
20+
21+
public async authenticate(parameters: AuthenticationCredentials): Promise<Result<AuthenticationResult>> {
22+
var response = await this.httpClient.post("/api/v1/identity/authenticate", parameters);
23+
if (response.status < 200 || response.status >= 300) {
24+
return Result.failure<AuthenticationResult>(response.data);
25+
}
26+
27+
return Result.success<AuthenticationResult>(response.data);
28+
}
29+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { AxiosInstance } from "axios";
2+
import { OwnerScheme, ProfileCreationScheme } from "../contracts/profiles-schemes";
3+
import { Result } from "@/patterns/result";
4+
5+
export class ProfilesClient {
6+
private readonly httpClient: AxiosInstance;
7+
8+
public constructor(httpClient: AxiosInstance) {
9+
this.httpClient = httpClient;
10+
}
11+
12+
public async createOwner(parameters: ProfileCreationScheme): Promise<Result<OwnerScheme>> {
13+
var response = await this.httpClient.post("/api/v1/profiles/owner", parameters);
14+
if (response.status < 200 || response.status >= 300) {
15+
return Result.failure<OwnerScheme>(response.data);
16+
}
17+
18+
return Result.success<OwnerScheme>(response.data);
19+
}
20+
}

0 commit comments

Comments
 (0)