feat(api): 初始化笔记应用后端基础架构
- 添加环境配置文件 .env.example 包含数据库、JWT、CORS等配置 - 创建 .gitignore 文件忽略敏感文件和临时文件 - 配置 Apache 重写规则支持路由转发 - 实现 JWT 认证中间件提供用户身份验证功能 - 添加 MySQL 数据库初始化脚本包含分组、图片、笔记表结构
This commit is contained in:
57
biji-php/src/Models/Grouping.php
Normal file
57
biji-php/src/Models/Grouping.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Utils\Database;
|
||||
use PDO;
|
||||
|
||||
class Grouping
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = Database::getInstance()->getConnection();
|
||||
}
|
||||
|
||||
public function getAll($parentId = null)
|
||||
{
|
||||
if ($parentId === null) {
|
||||
$stmt = $this->db->prepare("SELECT * FROM `grouping` WHERE is_deleted = 0 ORDER BY id");
|
||||
} else {
|
||||
$stmt = $this->db->prepare("SELECT * FROM `grouping` WHERE parentId = ? AND is_deleted = 0 ORDER BY id");
|
||||
$stmt->execute([$parentId]);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function findById($id)
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM `grouping` WHERE id = ? AND is_deleted = 0");
|
||||
$stmt->execute([$id]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
public function create($grouping, $parentId = 0)
|
||||
{
|
||||
$stmt = $this->db->prepare("INSERT INTO `grouping` (`grouping`, parentId) VALUES (?, ?)");
|
||||
$stmt->execute([$grouping, $parentId]);
|
||||
return $this->db->lastInsertId();
|
||||
}
|
||||
|
||||
public function update($id, $grouping)
|
||||
{
|
||||
$stmt = $this->db->prepare("UPDATE `grouping` SET `grouping` = ? WHERE id = ?");
|
||||
return $stmt->execute([$grouping, $id]);
|
||||
}
|
||||
|
||||
public function softDelete($id, $userId)
|
||||
{
|
||||
$stmt = $this->db->prepare(
|
||||
"UPDATE `grouping` SET is_deleted = 1, deleted_at = NOW(), deleted_by = ? WHERE id = ?"
|
||||
);
|
||||
return $stmt->execute([$userId, $id]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user