Skip to content

Commit 8a9e900

Browse files
committed
feat: add ProductController and UserController for product and user management
- Implemented ProductController with methods for creating, updating, and importing products. - Implemented UserController with methods for listing, creating, updating, and deleting users. - Added request validation for all controller methods. - Updated swagger configuration to remove unused tags.
1 parent 653e839 commit 8a9e900

3 files changed

Lines changed: 11 additions & 19 deletions

File tree

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Controller;
5+
namespace App\Controller\Api;
66

77
use App\Validator\ProductValidator;
88
use HPlus\Route\Annotation\ApiController;
@@ -11,11 +11,12 @@
1111
use HPlus\Validate\Annotations\RequestValidation;
1212
use Hyperf\HttpServer\Contract\RequestInterface;
1313
use Hyperf\HttpServer\Contract\ResponseInterface;
14+
use App\Controller\AbstractController;
1415

1516
/**
1617
* 产品管理
1718
*/
18-
#[ApiController(prefix: "/api/products", tag: "产品管理")]
19+
#[ApiController(tag: "产品管理")]
1920
class ProductController extends AbstractController
2021
{
2122
/**
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Controller;
5+
namespace App\Controller\Api;
66

77
use HPlus\Route\Annotation\ApiController;
88
use HPlus\Route\Annotation\GetApi;
@@ -12,11 +12,11 @@
1212
use HPlus\Validate\Annotations\RequestValidation;
1313
use Hyperf\HttpServer\Contract\RequestInterface;
1414
use Hyperf\HttpServer\Contract\ResponseInterface;
15-
15+
use App\Controller\AbstractController;
1616
/**
1717
* 用户管理
1818
*/
19-
#[ApiController(prefix: "/api/users", tag: "用户管理", description: "用户相关接口")]
19+
#[ApiController(tag: "用户管理", description: "用户相关接口")]
2020
class UserController extends AbstractController
2121
{
2222
/**
@@ -53,7 +53,8 @@ public function index(RequestInterface $request)
5353
'name' => 'required|string|max:50',
5454
'email' => 'required|email',
5555
'password' => 'required|min:6',
56-
'phone' => 'required|mobile'
56+
// 使用正则验证手机号(大陆 11 位)
57+
'phone|手机号' => 'required|regex:/^1[3-9]\\d{9}$/'
5758
])]
5859
public function store(RequestInterface $request)
5960
{
@@ -81,7 +82,8 @@ public function store(RequestInterface $request)
8182
#[RequestValidation(rules: [
8283
'name' => 'string|max:50',
8384
'email' => 'email',
84-
'phone|手机号' => 'mobile'
85+
// 非必填,但若传入则校验格式
86+
'phone|手机号' => 'regex:/^1[3-9]\\d{9}$/'
8587
])]
8688
public function update(int $id, RequestInterface $request)
8789
{

config/autoload/swagger.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,7 @@
6767

6868
// 标签定义
6969
'tags' => [
70-
[
71-
'name' => 'Users',
72-
'description' => 'User management operations',
73-
'externalDocs' => [
74-
'description' => 'More info',
75-
'url' => 'https://example.com/docs/users',
76-
],
77-
],
78-
[
79-
'name' => 'Auth',
80-
'description' => 'Authentication operations',
81-
],
70+
8271
],
8372

8473
// 外部文档

0 commit comments

Comments
 (0)