Initial commit: 宁夏智慧养殖监管平台
This commit is contained in:
163
backend/routes/farms.js
Normal file
163
backend/routes/farms.js
Normal file
@@ -0,0 +1,163 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const farmController = require('../controllers/farmController');
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms:
|
||||
* get:
|
||||
* summary: 获取所有养殖场
|
||||
* tags: [Farms]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取养殖场列表
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* data:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Farm'
|
||||
*/
|
||||
router.get('/', farmController.getAllFarms);
|
||||
|
||||
// 公共路由必须在参数路由之前定义
|
||||
router.get('/public', farmController.getAllFarms);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms/{id}:
|
||||
* get:
|
||||
* summary: 根据ID获取养殖场
|
||||
* tags: [Farms]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 养殖场ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取养殖场详情
|
||||
* 404:
|
||||
* description: 养殖场不存在
|
||||
*/
|
||||
router.get('/:id', farmController.getFarmById);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms:
|
||||
* post:
|
||||
* summary: 创建新养殖场
|
||||
* tags: [Farms]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/FarmInput'
|
||||
* responses:
|
||||
* 201:
|
||||
* description: 养殖场创建成功
|
||||
* 400:
|
||||
* description: 请求参数错误
|
||||
*/
|
||||
router.post('/', farmController.createFarm);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms/{id}:
|
||||
* put:
|
||||
* summary: 更新养殖场信息
|
||||
* tags: [Farms]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 养殖场ID
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/FarmInput'
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 养殖场更新成功
|
||||
* 404:
|
||||
* description: 养殖场不存在
|
||||
*/
|
||||
router.put('/:id', farmController.updateFarm);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms/{id}:
|
||||
* delete:
|
||||
* summary: 删除养殖场
|
||||
* tags: [Farms]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 养殖场ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 养殖场删除成功
|
||||
* 404:
|
||||
* description: 养殖场不存在
|
||||
*/
|
||||
router.delete('/:id', farmController.deleteFarm);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms/{id}/animals:
|
||||
* get:
|
||||
* summary: 获取养殖场的动物列表
|
||||
* tags: [Farms]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 养殖场ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取动物列表
|
||||
* 404:
|
||||
* description: 养殖场不存在
|
||||
*/
|
||||
router.get('/:id/animals', farmController.getFarmAnimals);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/farms/{id}/devices:
|
||||
* get:
|
||||
* summary: 获取养殖场的设备列表
|
||||
* tags: [Farms]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: 养殖场ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功获取设备列表
|
||||
* 404:
|
||||
* description: 养殖场不存在
|
||||
*/
|
||||
router.get('/:id/devices', farmController.getFarmDevices);
|
||||
|
||||
// 公共农场数据接口(保留兼容性)
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user