Location>code7788 >text

dotnet core microservices framework Jimu ~ Browse and Publish News Microservice

Popularity:892 ℃/2024-11-13 20:11:32
using System; using ; using ; using ; using Jimu; namespace { public class NewsService : INewsService { readonly ILogger _logger; readonly JimuPayload _jimuPayload; static List<News> _newsDb = new List<News>(); static NewsService() { // mock some news _newsDb.Add(new News { Id = ().ToString(), Director = "grissom", PostTime = (), Title = "World Cup: France has won!", Content = "HEADLINE: France wins 2018 World Cup, 10,000 words omitted afterward" }); _newsDb.Add(new News { Id = ().ToString(), Director = "grissom", PostTime = (), Title = "Jimu releases new version", Content = "News agency: Jimu (Jaeger) released a new version featuring, followed by the omission of 10,000 words" }); } public NewsService(ILogger logger, JimuPayload jimuPayload) { _logger = logger; _jimuPayload = jimuPayload; } public Task<List<News>> GetAllNews() { _logger.Debug($"member: {_jimuPayload.Items["username"]} getallnews"); return (_newsDb); } public Task<string> PostNews(News news) { _logger.Debug($"member: {_jimuPayload.Items["username"]} post an news which title is: {}"); = (); = new Guid().ToString(); = _jimuPayload.Items["username"].ToString(); _newsDb.Add(news); return (); } public News GetNews(string id) { _logger.Debug($"member: {_jimuPayload.Items["username"]} getnews by id: {id}"); var news = _newsDb.FirstOrDefault(x => == id); return news; } } }