This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getAllUsers = async (): Promise<UserViewModel[]> => { | |
const url = `${this.apiEndpoint}/AllUsers`; | |
const response = await fetch(url); | |
const usersJson = await response.json(); | |
const users = z.array(UserViewModelSchema).parse(usersJson); | |
return users; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from "zod"; | |
import { AddressViewModelSchema } from "./addressViewModel"; | |
export const UserViewModelSchema = z.object({ | |
id: z.string().uuid(), | |
name: z.string(), | |
lastName: z.string(), | |
login: z.string(), | |
isActive: z.boolean(), | |
loyaltyPoints: z.number(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const UserViewModelSchema = z.object({ | |
id: z.string().uuid(), | |
name: z.string(), | |
lastName: z.string(), | |
login: z.string(), | |
isActive: z.boolean(), | |
loyaltyPoints: z.number(), | |
address: AddressViewModelSchema.nullable(), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public record UserViewModel(Guid Id, string Name, string LastName, | |
string Login, bool IsActive, int FidelityPoints, AddressViewModel? Address = null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class UsersService { | |
private apiEndpoint: string; | |
constructor() { | |
this.apiEndpoint = "https://localhost:7131/Users"; | |
} | |
getAllUsers = async (): Promise<UserViewModel[]> => { | |
const url = `${this.apiEndpoint}/AllUsers`; | |
const response = await fetch(url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface UserViewModel { | |
id: Guid; | |
name: string; | |
lastName: string; | |
login: string; | |
isActive: boolean; | |
loyaltyPoints: number; | |
address: AddressViewModel | null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public record UserViewModel(Guid Id, string Name, string LastName, | |
string Login, bool IsActive, int LoyaltyPoints, AddressViewModel? Address = null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<UserViewModel> AllUsers() | |
{ | |
var usersViewModels = TestDataGenerator.GetTestUsers(); | |
return usersViewModels.OrderBy(uvm => uvm.Name).ToList(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getAllUsers = async (): Promise<UserViewModel[]> => { | |
const url = `${this.apiEndpoint}/AllUsers`; | |
const response = await fetch(url); | |
const users = (await response.json()) as UserViewModel[]; | |
return users; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public record UserViewModel(Guid Id, string Name, string LastName, string Login, | |
bool IsActive, int LoyaltyPoints, AddressViewModel? Address = null); | |
// ... | |
public List<UserViewModel> AllUsers() | |
{ | |
var usersViewModels = TestDataGenerator.GetTestUsers(); | |
return usersViewModels.OrderBy(uvm => uvm.Name).ToList(); | |
} |
NewerOlder