mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
create MatchScore update API method
This commit is contained in:
@@ -27,7 +27,7 @@ namespace LiveGameFeed.Controllers
|
|||||||
{
|
{
|
||||||
_matchRepository = matchRepository;
|
_matchRepository = matchRepository;
|
||||||
_feedRepository = feedRepository;
|
_feedRepository = feedRepository;
|
||||||
timerService.TimerElapsed += _feed_Generate;
|
// timerService.TimerElapsed += _feed_Generate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
|
|||||||
@@ -43,9 +43,10 @@ namespace LiveGameFeed.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST api/values
|
// POST api/values
|
||||||
[HttpPost]
|
[HttpPost("update", Name = "UpdateScore")]
|
||||||
public void Post([FromBody]string value)
|
public void UpdateScore([FromBody]MatchScore matchScore)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/values/5
|
// PUT api/values/5
|
||||||
|
|||||||
11
Models/MatchScore.cs
Normal file
11
Models/MatchScore.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace LiveGameFeed.Models
|
||||||
|
{
|
||||||
|
public class MatchScore
|
||||||
|
{
|
||||||
|
public int MatchId { get; set; }
|
||||||
|
public int HostScore { get; set; }
|
||||||
|
public int GuestScore {get; set;}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Startup.cs
18
Startup.cs
@@ -55,8 +55,7 @@ namespace LiveGameFeed
|
|||||||
|
|
||||||
services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true);
|
services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true);
|
||||||
|
|
||||||
services.AddTask<SampleTask>();
|
services.AddTask<FeedEngine>();
|
||||||
services.AddSingleton<SampleTaskRunHistory>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
@@ -90,32 +89,23 @@ namespace LiveGameFeed
|
|||||||
|
|
||||||
LiveGameDbInitializer.Initialize(app.ApplicationServices);
|
LiveGameDbInitializer.Initialize(app.ApplicationServices);
|
||||||
|
|
||||||
app.StartTask<SampleTask>(TimeSpan.FromSeconds(15));
|
app.StartTask<FeedEngine>(TimeSpan.FromSeconds(15));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SampleTask : IRunnable
|
public class FeedEngine : IRunnable
|
||||||
{
|
{
|
||||||
private ILogger logger;
|
private ILogger logger;
|
||||||
|
|
||||||
private SampleTaskRunHistory runHistory;
|
public FeedEngine(ILogger<FeedEngine> logger)
|
||||||
|
|
||||||
public SampleTask(ILogger<SampleTask> logger, SampleTaskRunHistory runHistory)
|
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.runHistory = runHistory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run(TaskRunStatus taskRunStatus)
|
public void Run(TaskRunStatus taskRunStatus)
|
||||||
{
|
{
|
||||||
var msg = string.Format("Run at: {0}", DateTimeOffset.Now);
|
var msg = string.Format("Run at: {0}", DateTimeOffset.Now);
|
||||||
runHistory.Messages.Add(msg);
|
|
||||||
logger.LogDebug(msg);
|
logger.LogDebug(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SampleTaskRunHistory
|
|
||||||
{
|
|
||||||
public List<string> Messages { get; } = new List<string>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user