fighting weird bug with branches
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System.Net;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public class CreatePost : SecuredRoute
|
||||
{
|
||||
public static void HandleRequest(HttpListenerRequest request, HttpListenerResponse response)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> bodyParamNames = ["message"];
|
||||
string user_id = ExtractUserId(request);
|
||||
var bodyParamValues = ExtractBody(request, bodyParamNames);
|
||||
ValidateParams(bodyParamValues);
|
||||
|
||||
bodyParamNames.Add("user_id");
|
||||
bodyParamValues["user_id"] = user_id;
|
||||
|
||||
MySqlCommand cmd = new(CreateInsertQuery("post", bodyParamNames));
|
||||
|
||||
cmd = AddValuesToCmd(bodyParamValues, cmd);
|
||||
|
||||
using MySqlConnection conn = new(connectionString);
|
||||
conn.Open();
|
||||
cmd.Connection = conn;
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
SendSuccess(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SendError(response, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateParams(Dictionary<string, string> paramsToValidate)
|
||||
{
|
||||
if (paramsToValidate["message"].Length > 1000)
|
||||
{
|
||||
throw new Exception("Wrong parameters");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user