website refactor

This commit is contained in:
2026-01-13 01:36:27 +01:00
parent d18e2979ba
commit e981ebd9e9
5 changed files with 623 additions and 96 deletions

View File

@@ -21,15 +21,16 @@ Mutations are the write equivalent of PageQueries.
import { AdminUserMutation } from '@/lib/mutations/admin/AdminUserMutation';
import { revalidatePath } from 'next/cache';
export async function updateUserStatus(userId: string, status: string): Promise<void> {
try {
const mutation = new AdminUserMutation();
await mutation.updateUserStatus(userId, status);
revalidatePath('/admin/users');
} catch (error) {
console.error('updateUserStatus failed:', error);
export async function updateUserStatus(userId: string, status: string) {
const mutation = new AdminUserMutation();
const result = await mutation.updateUserStatus(userId, status);
if (result.isErr()) {
console.error('updateUserStatus failed:', result.getError());
throw new Error('Failed to update user status');
}
revalidatePath('/admin/users');
}
```
@@ -37,6 +38,8 @@ export async function updateUserStatus(userId: string, status: string): Promise<
```typescript
// lib/mutations/admin/AdminUserMutation.ts
import { Result, ResultFactory } from '@/lib/contracts/Result';
export class AdminUserMutation {
private service: AdminService;
@@ -53,12 +56,22 @@ export class AdminUserMutation {
this.service = new AdminService(apiClient);
}
async updateUserStatus(userId: string, status: string): Promise<void> {
await this.service.updateUserStatus(userId, status);
async updateUserStatus(userId: string, status: string): Promise<Result<void, string>> {
try {
await this.service.updateUserStatus(userId, status);
return ResultFactory.ok(undefined);
} catch (error) {
return ResultFactory.error('UPDATE_USER_STATUS_FAILED');
}
}
async deleteUser(userId: string): Promise<void> {
await this.service.deleteUser(userId);
async deleteUser(userId: string): Promise<Result<void, string>> {
try {
await this.service.deleteUser(userId);
return ResultFactory.ok(undefined);
} catch (error) {
return ResultFactory.error('DELETE_USER_FAILED');
}
}
}
```
@@ -108,12 +121,12 @@ lib/
| Location | `lib/page-queries/` | `lib/mutations/` |
| Framework | Called from RSC | Called from Server Actions |
| Infrastructure | Manual DI | Manual DI |
| Returns | Page DTO | void or result |
| Returns | `Result<ApiDto, string>` | `Result<void, string>` |
| Revalidation | N/A | Server Action handles it |
## 9) Example Flow
**Read:**
**Read (RSC):**
```
RSC page.tsx
@@ -123,10 +136,14 @@ Service
API Client
Page DTO
Result<ApiDto, string>
ViewDataBuilder
Template
```
**Write:**
**Write (Server Action):**
```
Client Component
@@ -138,6 +155,8 @@ Service
API Client
Result<void, string>
Revalidation
```