feat(sgw): Implement Create or Update Banzone functionality with map integration

This commit is contained in:
Lê Tuấn Anh
2026-01-27 12:17:11 +07:00
parent c9aeca0ed9
commit a11e2c2991
46 changed files with 4660 additions and 39 deletions

View File

@@ -17,3 +17,4 @@ declare namespace MasterModel {
direction?: string;
}
}
7;

View File

@@ -0,0 +1,36 @@
import {
SGW_ROUTE_CREATE_OR_UPDATE_FISH,
SGW_ROUTE_GET_FISH,
} from '@/constants/slave/sgw/routes';
import { request } from '@umijs/max';
export async function apiGetFishSpecies(
body?: SgwModel.SearchFishPaginationBody,
): Promise<SgwModel.FishSpeciesResponse> {
return request<SgwModel.FishSpeciesResponse>(SGW_ROUTE_GET_FISH, {
method: 'POST',
data: body,
});
}
export async function apiCreateFishSpecies(body?: SgwModel.Fish) {
return request<SgwModel.CreateFishResponse>(SGW_ROUTE_CREATE_OR_UPDATE_FISH, {
method: 'POST',
data: [body],
getResponse: true,
});
}
export async function apiUpdateFishSpecies(body?: SgwModel.Fish) {
return request(SGW_ROUTE_CREATE_OR_UPDATE_FISH, {
method: 'PUT',
data: body,
getResponse: true,
});
}
export async function apiDeleteFishSpecies(id?: string) {
return request(`${SGW_ROUTE_CREATE_OR_UPDATE_FISH}/${id}`, {
method: 'DELETE',
getResponse: true,
});
}

View File

@@ -1,38 +1,80 @@
import { SGW_ROUTE_PHOTO } from '@/constants/slave/sgw/routes';
import {
SGW_ROUTE_PHOTO,
SGW_ROUTE_PHOTO_TAGS,
} from '@/constants/slave/sgw/routes';
import { request } from '@umijs/max';
/**
* Get photo from server
* @param type Type of photo ('ship' or 'people')
* @param type Type of photo ('ship' or 'people' or 'fish')
* @param id ID of the entity
* @returns Photo as ArrayBuffer
* @param tag Photo tag (default: 'main')
* @returns Photo response with ArrayBuffer data
*/
export async function apiGetPhoto(
type: SgwModel.PhotoGetParams['type'],
id: string,
): Promise<ArrayBuffer> {
return request<ArrayBuffer>(`${SGW_ROUTE_PHOTO}/${type}/${id}/main`, {
method: 'GET',
responseType: 'arraybuffer',
});
id: string | number,
tag: string = 'main',
): Promise<{ status: number; data: ArrayBuffer }> {
const response = await request<ArrayBuffer>(
`${SGW_ROUTE_PHOTO}/${type}/${id}/${tag}`,
{
method: 'GET',
responseType: 'arraybuffer',
getResponse: true,
},
);
return {
status: 200,
data: response.data,
};
}
export async function apiGetTagsPhoto(
type: SgwModel.PhotoGetParams['type'],
id: string | number,
) {
return request<SgwModel.GetTagsResponse>(
`${SGW_ROUTE_PHOTO_TAGS}/${type}/${id}`,
);
}
/**
* Upload photo to server
* @param type Type of photo ('ship' or 'people')
* @param type Type of photo ('ship' or 'people' or 'fish')
* @param id ID of the entity
* @param file File to upload
* @param tag Photo tag (default: 'main')
*/
export async function apiUploadPhoto(
type: SgwModel.PhotoUploadParams['type'],
id: string,
file: File,
): Promise<void> {
tag: string = 'main',
): Promise<{ status: number }> {
const formData = new FormData();
formData.append('file', file);
return request<void>(`${SGW_ROUTE_PHOTO}/${type}/${id}/main`, {
await request<void>(`${SGW_ROUTE_PHOTO}/${type}/${id}/${tag}`, {
method: 'POST',
data: formData,
});
return { status: 200 };
}
/**
* Delete photo from server
*/
export async function apiDeletePhoto(
type: SgwModel.PhotoGetParams['type'],
id: string | number,
tag: string = 'main',
): Promise<{ status: number }> {
await request(`${SGW_ROUTE_PHOTO}/${type}/${id}/${tag}`, {
method: 'DELETE',
});
return { status: 200 };
}

View File

@@ -9,7 +9,7 @@ import { request } from '@umijs/max';
* @param body Search and pagination parameters
*/
export async function apiGetAllBanzones(
body: MasterModel.SearchPaginationBody,
body: SgwModel.SearchZonePaginationBody,
) {
return request<SgwModel.ZoneResponse>(SGW_ROUTE_BANZONES_LIST, {
method: 'POST',

View File

@@ -1,8 +1,54 @@
declare namespace SgwModel {
interface FishSpeciesResponse {
id: number;
fishes: Fish[];
total: number;
}
interface FishCreateRequest {
name: string;
scientific_name?: string;
description?: string;
group_name?: string;
rarity_level?: number;
note?: string;
}
interface FishUpdateRequest extends FishCreateRequest {
id: number;
}
interface Fish {
id?: number;
name?: string;
scientific_name?: string;
group_name?: string;
species_code?: string;
note?: string;
default_unit?: string;
rarity_level?: number;
created_at?: Date;
updated_at?: Date;
is_deleted?: boolean;
}
interface FishRarity {
id: number;
code: string;
label: string;
description: string;
iucn_code: string | null;
cites_appendix: string | null;
vn_law: boolean;
}
interface CreateFishResponse {
name_ids?: number[];
}
interface SearchFishPaginationBody extends MasterModel.SearchPaginationBody {
order?: string;
metadata?: {
group_name?: string;
rarity_level?: number;
};
}
}

View File

@@ -5,13 +5,19 @@ declare namespace SgwModel {
// }
interface PhotoGetParams {
type: 'ship' | 'people';
type: 'ship' | 'people' | 'fish';
id: string;
tag: 'main' | string;
}
interface PhotoUploadParams {
type: 'ship' | 'people';
type: 'ship' | 'people' | 'fish';
id: string;
file: File;
tag: 'main' | string;
}
interface GetTagsResponse {
tags?: string[];
}
}

View File

@@ -32,7 +32,28 @@ declare namespace SgwModel {
geom_radius?: number;
}
interface ZoneBodyRequest {
name: string;
group_id: string;
type: number;
conditions: Condition[];
description?: string;
enabled?: boolean;
geom: string;
province_code: string;
}
interface ZoneResponse extends Partial<MasterModel.PaginationResponse> {
banzones?: Banzone[];
total?: number;
}
interface SearchZonePaginationBody extends MasterModel.SearchPaginationBody {
order?: string;
metadata?: {
province_code?: string;
type?: number;
enabled?: boolean;
};
}
}