blob: 757fd78977b785a30402bf6f49480367039e0844 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
using Microsoft.AspNetCore.Mvc;
using WikiWaka.Api.Contract;
using WikiWaka.Api.Models;
namespace WikiWaka.Api.Controllers;
[ApiController]
[Route("[controller]")]
public class ContentApiController(DbWikiWakaContext dbContext) : Controller
{
[HttpGet(nameof(Content))]
public IAsyncEnumerable<Content> GetContents()
{
return dbContext.Content.AsAsyncEnumerable();
}
[HttpPost(nameof(Content))]
public async Task<Content> PostContents(NewContent newContent)
{
Language language = dbContext.Language.Single(l => l.LanguageCode == newContent.LanguageCode);
Content content = new();
Models.Version version = new();
Property property = new()
{
Content = content,
Language = language,
Version = version,
Text = newContent.Text,
};
await dbContext.Content.AddAsync(content);
await dbContext.Version.AddAsync(version);
await dbContext.Property.AddAsync(property);
await dbContext.SaveChangesAsync();
return content;
}
}
|