This commit is contained in:
parent
4aab13329f
commit
2c984eaf0b
@ -14,9 +14,11 @@
|
||||
{
|
||||
public static string Host = "postgres.vdk2ch.ru";
|
||||
public static string User = "postgres";
|
||||
public static string DBname = "postgres";
|
||||
public static string DBname = "dvaach";
|
||||
public static string Password = "postgres";
|
||||
public static string Port = "5432";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,16 +11,12 @@ namespace NeDvachAPI.Controllers
|
||||
public class ListController : ControllerBase
|
||||
{
|
||||
[HttpGet(Name = "GetPosts")]
|
||||
public string Get([FromUri] string board = null)
|
||||
public string Get([FromUri] string board, int thread)
|
||||
{
|
||||
|
||||
//Post[] posts = DBchat.DbList();
|
||||
List<Post> posts = DBchat.DbList(board);
|
||||
List<Post> posts = DBchat.DbList(board, thread);
|
||||
string postsJson = JsonSerializer.Serialize(posts);
|
||||
Console.WriteLine("Запрошен список постов из борды " + board);
|
||||
Console.WriteLine("Запрошен список постов из борды " + board + " и треда# " + thread );
|
||||
return postsJson ;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
DBchat.cs
25
DBchat.cs
@ -8,7 +8,7 @@ namespace NeDvachAPI
|
||||
// Obtain connection string information from the portal
|
||||
|
||||
|
||||
public static List<Post> DbList(string boardName)
|
||||
public static List<Post> DbList(string boardName, int thread)
|
||||
{
|
||||
// Build connection string using parameters from portal
|
||||
//Post[] posts = new Post[10];
|
||||
@ -20,7 +20,7 @@ namespace NeDvachAPI
|
||||
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
||||
AuthInfo.DB.Host,
|
||||
AuthInfo.DB.User,
|
||||
boardName,
|
||||
AuthInfo.DB.DBname,
|
||||
AuthInfo.DB.Port,
|
||||
AuthInfo.DB.Password);
|
||||
|
||||
@ -40,11 +40,12 @@ namespace NeDvachAPI
|
||||
// )
|
||||
// subquery
|
||||
// ORDER BY post_id ASC", conn) )
|
||||
using ( var command = new NpgsqlCommand(@"
|
||||
using ( var command = new NpgsqlCommand($@"
|
||||
SELECT * FROM
|
||||
(
|
||||
SELECT post_id, post, post_timestamp, post_pic
|
||||
FROM dvach
|
||||
SELECT post_id, post_text, content, post_timestamp
|
||||
FROM posts
|
||||
WHERE thread_id = {thread}
|
||||
ORDER BY post_id DESC
|
||||
) subquery
|
||||
ORDER BY post_id ASC", conn) )
|
||||
@ -64,8 +65,8 @@ namespace NeDvachAPI
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Text = reader.GetString(1),
|
||||
Timestamp = reader.GetString(2),
|
||||
ImgURL = (string)reader.GetString(3)
|
||||
ImgURL = reader.IsDBNull(2) ? null : reader.GetFieldValue<string[]>(2),
|
||||
Timestamp = reader.GetString(3)
|
||||
|
||||
};
|
||||
posts.Add(receivedPost);
|
||||
@ -123,13 +124,16 @@ namespace NeDvachAPI
|
||||
|
||||
Console.Out.WriteLine("Opening connection");
|
||||
conn.Open();
|
||||
int postNum = 14;
|
||||
|
||||
using (var command = new NpgsqlCommand(@"
|
||||
INSERT INTO dvach (post_id, post, post_pic, post_timestamp)
|
||||
INSERT INTO posts (post_id, post_text, post_number, content, thread_id, post_timestamp)
|
||||
VALUES (
|
||||
DEFAULT,
|
||||
@postText,
|
||||
@postNum,
|
||||
@postImgUrl,
|
||||
@threadId,
|
||||
(
|
||||
SELECT date_trunc(
|
||||
'second',
|
||||
@ -138,11 +142,12 @@ namespace NeDvachAPI
|
||||
) )", conn))
|
||||
{
|
||||
command.Parameters.AddWithValue("postText", postToSend.Text);
|
||||
command.Parameters.AddWithValue("postNum", postNum);
|
||||
command.Parameters.AddWithValue("postImgUrl", postToSend.ImgURL);
|
||||
command.Parameters.AddWithValue("threadId", postToSend.Thread_Id);
|
||||
//command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm"));
|
||||
|
||||
int nRows = command.ExecuteNonQuery();
|
||||
Console.Out.WriteLine("Добавлен пост");
|
||||
Console.Out.WriteLine("Добавлен пост с текстом " + postToSend.Text + " номером " + 22);
|
||||
}
|
||||
}
|
||||
|
||||
|
10
Post.cs
10
Post.cs
@ -2,12 +2,12 @@ namespace NeDvachAPI
|
||||
{
|
||||
public class Post
|
||||
{
|
||||
public string? Timestamp { get; set; }
|
||||
|
||||
public string Timestamp { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public string ImgURL { get; set; }
|
||||
public string[] ImgURL { get; set; }
|
||||
public int Thread_Id { get; set; }
|
||||
public bool Is_OP { get; set; }
|
||||
public bool Is_Deleted { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user