diff options
author | Luca Matei Pintilie <luca@lucamatei.com> | 2024-10-30 20:59:53 +0000 |
---|---|---|
committer | Luca Matei Pintilie <luca@lucamatei.com> | 2024-10-30 20:59:53 +0000 |
commit | dc1938dbb98dc9edf16558e505b2961246c83e6e (patch) | |
tree | 7953186976085ceca6c03a208d1ffd9596f745be /Api/Controllers | |
parent | fc3c7e3b3c955cc274d4668768466fecb8fb727b (diff) | |
download | wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.tar wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.tar.gz wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.tar.bz2 wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.tar.lz wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.tar.xz wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.tar.zst wikiwaka-dc1938dbb98dc9edf16558e505b2961246c83e6e.zip |
Diffstat (limited to 'Api/Controllers')
-rw-r--r-- | Api/Controllers/ContentApi.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Api/Controllers/ContentApi.cs b/Api/Controllers/ContentApi.cs new file mode 100644 index 0000000..757fd78 --- /dev/null +++ b/Api/Controllers/ContentApi.cs @@ -0,0 +1,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; + } +} |