refactor: 重构数据库相关操作
This commit is contained in:
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
using server.Services;
|
||||
using Database;
|
||||
|
||||
namespace server.Controllers;
|
||||
|
||||
@@ -12,12 +11,15 @@ namespace server.Controllers;
|
||||
[EnableCors("Users")]
|
||||
public class HdmiVideoStreamController : ControllerBase
|
||||
{
|
||||
private readonly HttpHdmiVideoStreamService _videoStreamService;
|
||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public HdmiVideoStreamController(HttpHdmiVideoStreamService videoStreamService)
|
||||
private readonly HttpHdmiVideoStreamService _videoStreamService;
|
||||
private readonly Database.UserManager _userManager;
|
||||
|
||||
public HdmiVideoStreamController(HttpHdmiVideoStreamService videoStreamService, Database.UserManager userManager)
|
||||
{
|
||||
_videoStreamService = videoStreamService;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
// 管理员获取所有板子的 endpoints
|
||||
@@ -40,11 +42,7 @@ public class HdmiVideoStreamController : ControllerBase
|
||||
if (string.IsNullOrEmpty(userName))
|
||||
return Unauthorized("User name not found in claims.");
|
||||
|
||||
var db = new AppDataConnection();
|
||||
if (db == null)
|
||||
return NotFound("Database connection failed.");
|
||||
|
||||
var userRet = db.GetUserByName(userName);
|
||||
var userRet = _userManager.GetUserByName(userName);
|
||||
if (!userRet.IsSuccessful || !userRet.Value.HasValue)
|
||||
return NotFound("User not found.");
|
||||
|
||||
@@ -53,7 +51,7 @@ public class HdmiVideoStreamController : ControllerBase
|
||||
if (boardId == Guid.Empty)
|
||||
return NotFound("No board bound to this user.");
|
||||
|
||||
var boardRet = db.GetBoardByID(boardId);
|
||||
var boardRet = _userManager.GetBoardByID(boardId);
|
||||
if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
|
||||
return NotFound("Board not found.");
|
||||
|
||||
@@ -70,11 +68,7 @@ public class HdmiVideoStreamController : ControllerBase
|
||||
if (string.IsNullOrEmpty(userName))
|
||||
return Unauthorized("User name not found in claims.");
|
||||
|
||||
var db = new AppDataConnection();
|
||||
if (db == null)
|
||||
return NotFound("Database connection failed.");
|
||||
|
||||
var userRet = db.GetUserByName(userName);
|
||||
var userRet = _userManager.GetUserByName(userName);
|
||||
if (!userRet.IsSuccessful || !userRet.Value.HasValue)
|
||||
return NotFound("User not found.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user