88 lines
2.1 KiB
JavaScript
88 lines
2.1 KiB
JavaScript
import http from '../utils/http';
|
|
|
|
/**
|
|
* @typedef {object} PenResponse
|
|
* @property {number} id
|
|
* @property {number} house_id
|
|
* @property {string} pen_number
|
|
* @property {number} capacity
|
|
* @property {number} current_pig_count
|
|
* @property {number} pig_batch_id
|
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} CreatePenRequest
|
|
* @property {number} house_id
|
|
* @property {string} pen_number
|
|
* @property {number} capacity
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} UpdatePenRequest
|
|
* @property {number} house_id
|
|
* @property {string} pen_number
|
|
* @property {number} capacity
|
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} UpdatePenStatusRequest
|
|
* @property {('空闲'|'使用中'|'病猪栏'|'康复栏'|'清洗消毒'|'维修中')} status
|
|
*/
|
|
|
|
/**
|
|
* 获取所有猪栏的列表
|
|
* @returns {Promise<Array<PenResponse>>}
|
|
*/
|
|
export const getPens = () => {
|
|
return http.get('/api/v1/pens');
|
|
};
|
|
|
|
/**
|
|
* 创建一个新的猪栏
|
|
* @param {CreatePenRequest} penData - 猪栏信息
|
|
* @returns {Promise<PenResponse>}
|
|
*/
|
|
export const createPen = (penData) => {
|
|
return http.post('/api/v1/pens', penData);
|
|
};
|
|
|
|
/**
|
|
* 根据ID获取单个猪栏信息
|
|
* @param {number} id - 猪栏ID
|
|
* @returns {Promise<PenResponse>}
|
|
*/
|
|
export const getPenById = (id) => {
|
|
return http.get(`/api/v1/pens/${id}`);
|
|
};
|
|
|
|
/**
|
|
* 更新一个已存在的猪栏信息
|
|
* @param {number} id - 猪栏ID
|
|
* @param {UpdatePenRequest} penData - 猪栏信息
|
|
* @returns {Promise<PenResponse>}
|
|
*/
|
|
export const updatePen = (id, penData) => {
|
|
return http.put(`/api/v1/pens/${id}`, penData);
|
|
};
|
|
|
|
/**
|
|
* 根据ID删除一个猪栏
|
|
* @param {number} id - 猪栏ID
|
|
* @returns {Promise<*>}
|
|
*/
|
|
export const deletePen = (id) => {
|
|
return http.delete(`/api/v1/pens/${id}`);
|
|
};
|
|
|
|
/**
|
|
* 更新指定猪栏的当前状态
|
|
* @param {number} id - 猪栏ID
|
|
* @param {UpdatePenStatusRequest} statusData - 新的猪栏状态
|
|
* @returns {Promise<PenResponse>}
|
|
*/
|
|
export const updatePenStatus = (id, statusData) => {
|
|
return http.put(`/api/v1/pens/${id}/status`, statusData);
|
|
};
|