Added Timestamp Feature
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
RakVhalate 2022-10-29 04:20:10 +10:00
parent 8b0c988a7f
commit b04841fb1d
3 changed files with 11 additions and 15 deletions

View File

@ -46,7 +46,7 @@ namespace NeDvachAPI
using ( var command = new NpgsqlCommand(@" using ( var command = new NpgsqlCommand(@"
SELECT * FROM SELECT * FROM
( (
SELECT post_id, post SELECT post_id, post, post_timestamp
FROM dvach FROM dvach
ORDER BY post_id DESC ORDER BY post_id DESC
) subquery ) subquery
@ -65,9 +65,9 @@ namespace NeDvachAPI
//); //);
Post receivedPost = new() Post receivedPost = new()
{ {
Date = DateTime.Now,
Id = reader.GetInt32(0), Id = reader.GetInt32(0),
Text = reader.GetString(1) Text = reader.GetString(1),
Timestamp = reader.GetString(2)
}; };
posts.Add(receivedPost); posts.Add(receivedPost);
//posts[postCount] = receivedPost; //posts[postCount] = receivedPost;
@ -81,7 +81,6 @@ namespace NeDvachAPI
public static void DbUpdate(string id, string text) public static void DbUpdate(string id, string text)
{ {
// Build connection string using parameters from portal
string connString = string connString =
String.Format( String.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer", "Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
@ -93,8 +92,6 @@ namespace NeDvachAPI
using (var conn = new NpgsqlConnection(connString)) using (var conn = new NpgsqlConnection(connString))
{ {
//Console.Out.WriteLine("Opening connection");
conn.Open(); conn.Open();
using (var command = new NpgsqlCommand("UPDATE dvach " + using (var command = new NpgsqlCommand("UPDATE dvach " +
@ -111,10 +108,8 @@ namespace NeDvachAPI
Console.WriteLine("Данные обновлены!"); Console.WriteLine("Данные обновлены!");
Console.ReadLine(); Console.ReadLine();
} }
public static void SendPost(Post postToSend) public static void SendPost(Post postToSend) //добавлялка
{ {
// Build connection string using parameters from portal
//
string connString = string connString =
String.Format( String.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer", "Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
@ -131,17 +126,17 @@ namespace NeDvachAPI
conn.Open(); conn.Open();
using (var command = new NpgsqlCommand(@" using (var command = new NpgsqlCommand(@"
INSERT INTO dvach " + @"(post_id, post) INSERT INTO dvach " + @"(post_id, post, post_timestamp)
VALUES (DEFAULT, @postText)", conn)) VALUES (DEFAULT, @postText, @postTimeStamp)", conn))
{ {
command.Parameters.AddWithValue("postText", postToSend.Text); command.Parameters.AddWithValue("postText", postToSend.Text);
command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm"));
int nRows = command.ExecuteNonQuery(); int nRows = command.ExecuteNonQuery();
Console.Out.WriteLine(String.Format("Number of rows updated={0}", nRows)); Console.Out.WriteLine("Добавлен пост");
} }
} }
Console.WriteLine("С добавлением закончено");
} }
public static void DeletePost(string idToDel) //удалялка public static void DeletePost(string idToDel) //удалялка
{ {

View File

@ -2,7 +2,7 @@ namespace NeDvachAPI
{ {
public class Post public class Post
{ {
public DateTime Date { get; set; } public string? Timestamp { get; set; }
public int Id { get; set; } public int Id { get; set; }

View File

@ -12,7 +12,8 @@ builder.Services.AddCors(setup =>
setup.AddDefaultPolicy(policyBuilder => setup.AddDefaultPolicy(policyBuilder =>
{ {
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("PUT", "POST").WithHeaders("*"); //policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("GET", "POST").WithHeaders("*");
policyBuilder.WithOrigins("http://localhost:4200").WithMethods("GET", "POST").WithHeaders("*");
}); });
}); });