mirror of
https://github.com/ryzij/ServerMonitor.git
synced 2026-07-14 03:46:58 +00:00
Compare commits
2 Commits
08aa1bbf90
...
20ea6645f9
| Author | SHA1 | Date | |
|---|---|---|---|
| 20ea6645f9 | |||
| 9db0542d6b |
@@ -5,7 +5,7 @@ public interface IServersRepository
|
|||||||
{
|
{
|
||||||
Task<IEnumerable<Server>> GetAllServersAsync();
|
Task<IEnumerable<Server>> GetAllServersAsync();
|
||||||
Task<Server?> GetServerByIdAsync(Guid id);
|
Task<Server?> GetServerByIdAsync(Guid id);
|
||||||
Task AddServerAsync(Server server);
|
Task<Guid> AddServerAsync(Server server);
|
||||||
Task UpdateServerAsync(Guid id, Server server);
|
Task<Guid> UpdateServerAsync(Guid id, string name, bool isHttps, string address, string? path, int port);
|
||||||
Task DeleteServerAsync(Guid id);
|
Task<Guid> DeleteServerAsync(Guid id);
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ public class ServerEntity
|
|||||||
public bool IsHttps { get; set; }
|
public bool IsHttps { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Address { get; set; } = null!;
|
public string Address { get; set; } = null!;
|
||||||
string? Path { get; set; }
|
public string? Path { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,31 +1,60 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using MonitorPanel.Core.Abstractions;
|
using MonitorPanel.Core.Abstractions;
|
||||||
using MonitorPanel.Core.Models;
|
using MonitorPanel.Core.Models;
|
||||||
|
using MonitorPanel.DataAccess.Entities;
|
||||||
namespace MonitorPanel.DataAccess.Repositories;
|
namespace MonitorPanel.DataAccess.Repositories;
|
||||||
|
|
||||||
public class ServersRepository : IServersRepository
|
public class ServersRepository(MonitorPanelDbContext db) : IServersRepository
|
||||||
{
|
{
|
||||||
public Task AddServerAsync(Server server)
|
public async Task<Guid> AddServerAsync(Server server)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var entity = new ServerEntity
|
||||||
|
{
|
||||||
|
Id = server.Id,
|
||||||
|
Name = server.Name,
|
||||||
|
IsHttps = server.IsHttps,
|
||||||
|
Address = server.Address,
|
||||||
|
Path = server.Path,
|
||||||
|
Port = server.Port
|
||||||
|
};
|
||||||
|
|
||||||
|
await db.Servers.AddAsync(entity);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
return entity.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task DeleteServerAsync(Guid id)
|
public async Task<Guid> DeleteServerAsync(Guid id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
await db.Servers.Where(s => s.Id == id).ExecuteDeleteAsync();
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IEnumerable<Server>> GetAllServersAsync()
|
public async Task<IEnumerable<Server>> GetAllServersAsync()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return await db.Servers.AsNoTracking()
|
||||||
|
.Select(s => new Server(s.Id, s.Name, s.IsHttps, s.Address, s.Path, s.Port))
|
||||||
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Server?> GetServerByIdAsync(Guid id)
|
public async Task<Server?> GetServerByIdAsync(Guid id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var entity = await db.Servers.FirstOrDefaultAsync(s => s.Id == id);
|
||||||
|
return entity == null ? null : new Server(entity.Id, entity.Name, entity.IsHttps, entity.Address, entity.Path, entity.Port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateServerAsync(Guid id, Server server)
|
public async Task<Guid> UpdateServerAsync(Guid id, string name, bool isHttps, string address, string? path, int port)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var entity = await db.Servers.FirstOrDefaultAsync(s => s.Id == id)
|
||||||
|
?? throw new InvalidOperationException("Server not found");
|
||||||
|
|
||||||
|
entity.Name = name;
|
||||||
|
entity.IsHttps = isHttps;
|
||||||
|
entity.Address = address;
|
||||||
|
entity.Path = path;
|
||||||
|
entity.Port = port;
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return entity.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user