add basic app

This commit is contained in:
Dmitrii Kollerov
2022-03-10 15:39:31 +07:00
parent a3823f4bbd
commit 388ebd964b
15 changed files with 657 additions and 4 deletions

View File

@@ -0,0 +1,72 @@
using Chatter.Models;
using Chatter.Service;
using Cuipod;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Chatter.Logic.Actions
{
public static class ListActionManager
{
public static Action<Request, Response, ILogger<App>> GetListAction() =>
(request, response, logger) => {
var service = new MessageService();
IEnumerable<MessageModel> messages = service.GetMessages();
response.RenderPlainTextLine("# Chatter");
response.RenderPlainTextLine("");
response.RenderPlainTextLine("## Message list");
response.RenderPlainTextLine("=> /post Post");
response.RenderPlainTextLine("===============================================");
foreach(var msg in messages)
{
response.RenderPlainTextLine("");
var dateString = msg.CreateDate.ToString("yyyy-MM-dd HH:mm:ss");
response.RenderPlainTextLine(
string.IsNullOrWhiteSpace(msg.User)
? string.Format("### [{0}]", dateString)
: string.Format("### [{0}] {1}", dateString, msg.User)
);
response.RenderPlainTextLine(msg.Text);
response.RenderPlainTextLine("");
response.RenderPlainTextLine("");
}
response.RenderPlainTextLine("===============================================");
response.RenderPlainTextLine("=> /post Post");
//todo: pagination here?
};
public static Action<Request, Response, ILogger<App>> PostAction() =>
(request, response, logger) => {
if (string.IsNullOrEmpty(request.Parameters))
{
response.SetInputHint("Your message: ");
response.Status = StatusCode.Input;
}
else
{
// redirect to show/ route with input parameters
var model = new PostModel()
{
Text = request.Parameters
};
var service = new MessageService();
service.AddMessage(model);
response.SetRedirectURL(request.BaseURL + "/list");
response.Status = StatusCode.RedirectTemp;
}
};
}
}