diff --git a/Controllers/GetPosts.cs b/Controllers/GetPosts.cs index be53cfd..e244c68 100644 --- a/Controllers/GetPosts.cs +++ b/Controllers/GetPosts.cs @@ -9,11 +9,12 @@ namespace NeDvachAPI.Controllers { [HttpGet(Name = "GetPosts")] public string Get() - { + { + //Post[] posts = DBchat.DbList(); List posts = DBchat.DbList(); string postsJson = JsonSerializer.Serialize(posts); - Console.WriteLine("Запрошен список постов."); + Console.WriteLine("Запрошен список постов.); return postsJson ; diff --git a/DBchat.cs b/DBchat.cs index 92c5700..a35030f 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -65,10 +65,17 @@ namespace NeDvachAPI //); Post receivedPost = new() { +<<<<<<< HEAD Id = reader.GetInt32(0), Text = reader.GetString(1), Timestamp = reader.GetString(2), ImgURL = (string)reader.GetString(3) +======= + //Date = DateTime.Now, + Id = reader.GetInt32(0), + Text = reader.GetString(1), + Timestamp = reader.GetString(2) +>>>>>>> 10b089091585b363d2cf227a688da611f5870b5d }; posts.Add(receivedPost); //posts[postCount] = receivedPost; @@ -127,11 +134,16 @@ namespace NeDvachAPI conn.Open(); using (var command = new NpgsqlCommand(@" - INSERT INTO dvach " + @"(post_id, post, post_timestamp) - VALUES (DEFAULT, @postText, @postTimeStamp)", conn)) + INSERT INTO dvach (post_id, post, post_timestamp) + VALUES ( DEFAULT, @postText, ( + SELECT date_trunc( + 'second', + (now()::timestamp(0) AT TIME ZONE 'UTC+10')::TIMESTAMP + ) + ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); - command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); + //command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); int nRows = command.ExecuteNonQuery(); Console.Out.WriteLine("Добавлен пост");