refactor: 枚举移入Models目录,命名空间更新为Rainbow.Entity.Models
大石头 authored at 2026-07-02 12:54:58
1.53 KiB
RainbowBridge
using Microsoft.AspNetCore.Mvc;
using Rainbow.Entity;
using Rainbow.Services;

namespace Rainbow.Web.Controllers;

[ApiController]
[Route("api/pppoe")]
public class PppoeController : ControllerBase
{
    private readonly PppManager _pppManager;

    public PppoeController(PppManager pppManager) { _pppManager = pppManager; }

    [HttpGet("status")] public async Task<ActionResult> GetStatus() { var s = await _pppManager.GetStatusAsync(); return Ok(s); }

    [HttpPost("connect")] public async Task<ActionResult> Connect() { var r = await _pppManager.ConnectAsync(); return Ok(new { success = r.Success }); }

    [HttpPost("disconnect")] public async Task<ActionResult> Disconnect() { var r = await _pppManager.DisconnectAsync(); return Ok(new { success = r.Success }); }

    [HttpGet("account")] public ActionResult<IList<PppoeAccount>> GetAccounts() => Ok(PppoeAccount.FindAllWithCache());

    [HttpPost("account")]
    public ActionResult SaveAccount([FromBody] PppoeAccount account)
    {
        var existing = PppoeAccount.Find(PppoeAccount._.Interface == account.Interface);
        if (existing != null) { existing.Name = account.Name; existing.Password = account.Password; existing.Interface = account.Interface; existing.Enable = account.Enable; existing.Update(); }
        else account.Insert();
        return Ok(new { success = true });
    }

    [HttpDelete("account/{id}")]
    public ActionResult DeleteAccount(Int32 id) { var e = PppoeAccount.FindById(id); if (e == null) return NotFound(); e.Delete(); return Ok(new { success = true }); }
}