完善订单相关逻辑和商品推荐逻辑,添加接口注释
This commit is contained in:
146
routes/coupon.js
146
routes/coupon.js
@@ -2,7 +2,58 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getDB } = require('../database');
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/coupon:
|
||||
* get:
|
||||
* summary: 获取用户优惠券
|
||||
* description: 返回用户所有优惠券,包含是否已领取状态
|
||||
* tags: [coupon]
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: user_id
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: 用户ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功返回用户优惠券
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* example: true
|
||||
* data:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* example: "1"
|
||||
* name:
|
||||
* type: string
|
||||
* example: "满减优惠券"
|
||||
* discount:
|
||||
* type: number
|
||||
* example: 100
|
||||
* remain:
|
||||
* type: number
|
||||
* example: 10
|
||||
* got:
|
||||
* type: boolean
|
||||
* example: false
|
||||
* description: 是否已领取
|
||||
*
|
||||
* 400:
|
||||
* description: 缺少用户ID参数
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const useId = req.query.user_id;
|
||||
@@ -33,6 +84,43 @@ router.get('/', async (req, res) => {
|
||||
res.status(500).json({ error: '获取优惠券失败' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/coupon/{id}:
|
||||
* get:
|
||||
* summary: 用户领取优惠券
|
||||
* description: 用户通过优惠券ID领取优惠券,优惠券数量减一
|
||||
* tags: [coupon]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: 用户ID
|
||||
* - in: query
|
||||
* name: coupon_id
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: 优惠券ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功领取优惠券
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* example: true
|
||||
* 400:
|
||||
* description: 缺少用户ID或优惠券ID参数
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const db = getDB();
|
||||
@@ -68,6 +156,62 @@ router.get('/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/coupon/user/{id}:
|
||||
* get:
|
||||
* summary: 获取用户优惠券
|
||||
* description: 返回用户领取的优惠券,包括优惠券信息和商品信息
|
||||
* tags: [coupon]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: 用户ID
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功返回用户优惠券
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* example: true
|
||||
* data:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* example: "1"
|
||||
* name:
|
||||
* type: string
|
||||
* example: "满减优惠券"
|
||||
* discount:
|
||||
* type: number
|
||||
* example: 100
|
||||
* products_id:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: "1"
|
||||
* remain:
|
||||
* type: number
|
||||
* example: 100
|
||||
* get_time:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* example: "2023-01-01T00:00:00.000Z"
|
||||
* 400:
|
||||
* description: 缺少用户ID参数
|
||||
* 500:
|
||||
* description: 服务器内部错误
|
||||
*/
|
||||
router.get('/user/:id', async (req, res) => {
|
||||
try {
|
||||
const db = getDB();
|
||||
|
||||
Reference in New Issue
Block a user