This commit is contained in:
commit
2a71885a85
@ -10,7 +10,8 @@ namespace NeDvachAPI.Controllers
|
|||||||
[HttpGet(Name = "GetPosts")]
|
[HttpGet(Name = "GetPosts")]
|
||||||
public string Get()
|
public string Get()
|
||||||
{
|
{
|
||||||
Post[] posts = DBchat.DbList();
|
//Post[] posts = DBchat.DbList();
|
||||||
|
List<Post> posts = DBchat.DbList();
|
||||||
string postsJson = JsonSerializer.Serialize(posts);
|
string postsJson = JsonSerializer.Serialize(posts);
|
||||||
Console.WriteLine("Запрошен список постов.");
|
Console.WriteLine("Запрошен список постов.");
|
||||||
return postsJson ;
|
return postsJson ;
|
||||||
|
29
DBchat.cs
29
DBchat.cs
@ -12,11 +12,12 @@ namespace NeDvachAPI
|
|||||||
private static string Password = "postgres";
|
private static string Password = "postgres";
|
||||||
private static string Port = "5432";
|
private static string Port = "5432";
|
||||||
|
|
||||||
public static Post[] DbList()
|
public static List<Post> DbList()
|
||||||
{
|
{
|
||||||
// Build connection string using parameters from portal
|
// Build connection string using parameters from portal
|
||||||
Post[] posts = new Post[10];
|
//Post[] posts = new Post[10];
|
||||||
int postCount = 0;
|
List<Post> posts = new List<Post>();
|
||||||
|
//int postCount = 0;
|
||||||
string received = "";
|
string received = "";
|
||||||
string connString =
|
string connString =
|
||||||
String.Format(
|
String.Format(
|
||||||
@ -34,13 +35,22 @@ namespace NeDvachAPI
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
|
|
||||||
|
// using ( var command = new NpgsqlCommand(@"
|
||||||
|
// SELECT * FROM
|
||||||
|
// (SELECT post_id, substring(post,1,200)
|
||||||
|
// FROM dvach
|
||||||
|
// ORDER BY post_id DESC
|
||||||
|
// limit 10
|
||||||
|
// )
|
||||||
|
// subquery ORDER BY post_id ASC", conn) )
|
||||||
using ( var command = new NpgsqlCommand(@"
|
using ( var command = new NpgsqlCommand(@"
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(SELECT post_id, substring(post,1,200)
|
(
|
||||||
|
SELECT post_id, post
|
||||||
FROM dvach
|
FROM dvach
|
||||||
ORDER BY post_id
|
ORDER BY post_id DESC
|
||||||
DESC limit 10)
|
) subquery
|
||||||
subquery ORDER BY post_id ASC", conn))
|
ORDER BY post_id ASC", conn) )
|
||||||
{
|
{
|
||||||
|
|
||||||
var reader = command.ExecuteReader();
|
var reader = command.ExecuteReader();
|
||||||
@ -59,8 +69,9 @@ namespace NeDvachAPI
|
|||||||
Id = reader.GetInt32(0),
|
Id = reader.GetInt32(0),
|
||||||
Text = reader.GetString(1)
|
Text = reader.GetString(1)
|
||||||
};
|
};
|
||||||
posts[postCount] = receivedPost;
|
posts.Add(receivedPost);
|
||||||
postCount++;
|
//posts[postCount] = receivedPost;
|
||||||
|
//postCount++;
|
||||||
}
|
}
|
||||||
reader.Close();
|
reader.Close();
|
||||||
}
|
}
|
||||||
|
12
Program.cs
12
Program.cs
@ -6,14 +6,26 @@ builder.Services.AddControllers();
|
|||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
>>>>>>> 0efca3b0b5781ab54d78c97a62b20b0f47d7dabf
|
||||||
builder.Services.AddCors(setup =>
|
builder.Services.AddCors(setup =>
|
||||||
{
|
{
|
||||||
setup.AddDefaultPolicy(policyBuilder =>
|
setup.AddDefaultPolicy(policyBuilder =>
|
||||||
{
|
{
|
||||||
|
<<<<<<< HEAD
|
||||||
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("PUT", "POST").WithHeaders("*");
|
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("PUT", "POST").WithHeaders("*");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
=======
|
||||||
|
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
//builder.Services.AddSwaggerGen();
|
||||||
|
>>>>>>> 0efca3b0b5781ab54d78c97a62b20b0f47d7dabf
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user