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