save_everything

This commit is contained in:
Dmitrii Kollerov
2023-03-22 12:02:46 +07:00
parent 388ebd964b
commit 5d280daf74
8 changed files with 69 additions and 39 deletions

View File

@@ -4,19 +4,22 @@ using Cuipod;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace Chatter.Logic.Actions
{
public static class ListActionManager
public class ListActionManager
{
public static Action<Request, Response, ILogger<App>> GetListAction() =>
(request, response, logger) => {
var service = new MessageService();
public readonly IMessageService _messageService;
IEnumerable<MessageModel> messages = service.GetMessages();
public ListActionManager(IMessageService messageService)
{
_messageService = messageService;
}
public Action<Request, Response, ILogger<App>> GetListAction() =>
(request, response, logger) => {
IEnumerable<MessageModel> messages = _messageService.GetMessages();
response.RenderPlainTextLine("# Chatter");
response.RenderPlainTextLine("");
@@ -47,7 +50,7 @@ namespace Chatter.Logic.Actions
//todo: pagination here?
};
public static Action<Request, Response, ILogger<App>> PostAction() =>
public Action<Request, Response, ILogger<App>> PostAction() =>
(request, response, logger) => {
if (string.IsNullOrEmpty(request.Parameters))
{
@@ -56,17 +59,23 @@ namespace Chatter.Logic.Actions
}
else
{
// redirect to show/ route with input parameters
var model = new PostModel()
{
Text = request.Parameters
Text = WebUtility.UrlDecode(request.Parameters)
};
var service = new MessageService();
service.AddMessage(model);
_messageService.AddMessage(model);
response.SetRedirectURL(request.BaseURL + "/list");
response.Status = StatusCode.RedirectTemp;
}
};
public Action<Request, Response, ILogger<App>> LoginAction() =>
(request, response, logger) => {
response.RenderPlainTextLine("Cert required");
response.Status = StatusCode.ClientCertRequired;
};
}
}