api 5045포트 연결

This commit is contained in:
DESKTOP-F6681KC\llk
2024-06-02 20:48:47 +09:00
parent 1be2f7c5a7
commit 9dfe0b6d30
3 changed files with 33 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
</Project>

View File

@@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Mvc;
namespace Bitget_Server.Controller
{
[ApiController, Route("api/push")]
[ApiController, Route("api")]
public class PushAlarmController : ControllerBase
{
private readonly BitgetContext context;
@@ -15,10 +15,30 @@ namespace Bitget_Server.Controller
context = _context;
}
[HttpGet, Route("newalarm")]
[HttpGet, Route("getalarm")]
public List<PushAlarm> GetAlarm(int index)
{
return context.PushAlarms.Where(x => x.Id > index).ToList();
}
[HttpGet, Route("setalarm")]
public bool SetAlarm(string title,string contents)
{
try
{
context.PushAlarms.Add(new PushAlarm {Title = title,Contents = contents,AlarmTime = DateTime.Now});
context.SaveChanges();
return true;
}
catch (Exception e)
{
return false;
}
}
}
}

View File

@@ -1,5 +1,6 @@
using Bitget_Server.EFCore;
using Microsoft.EntityFrameworkCore;
using System.Net;
namespace Bitget_Server
{
@@ -9,6 +10,11 @@ namespace Bitget_Server
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<BitgetContext>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllersWithViews();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
@@ -18,10 +24,13 @@ namespace Bitget_Server
context.Database.Migrate();
}
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.MapGet("/", () => "Hello World!");
app.Run();
app.Run($"http://{IPAddress.Any}:{5045}");
}
}
}