View getAllUsers_with_zod.ts
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; | |
}; |
View userViewModel_zod.ts
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(), |
View UserViewModel_ZodSchema.ts
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(), | |
}); |
View UserViewModel_renamed.cs
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); |
View usersService.ts
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); |
View userViewModel.ts
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; | |
} |
View UserViewModel.cs
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); |
View AspNetControllerAction.cs
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(); | |
} |
View ApiFetchSample.ts
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; | |
}; |
View AspNetControllerSample.cs
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