mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-18 03:13:46 +00:00
adding hidden basic asp.net core backend (#30)
Base functionality:
DB
email sending
user registration & login
storing new characters and reading them back
Notes:
Functionality is "hidden" with no links pointing to it.
Most pages are scaffolded and not reviewed at all :(
local Dev db setup is pushed to git
NO local email setup :(
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using Kemkas.Web.Db;
|
||||
using Kemkas.Web.Db.Models;
|
||||
using Kemkas.Web.Services.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kemkas.Web.Services.Character;
|
||||
|
||||
public interface ICharacterPersistenceService
|
||||
{
|
||||
public Task<Guid> StoreNewCharacter(V1Karakter karakter);
|
||||
|
||||
public Task<V1Karakter?> GetCharacterById(Guid id);
|
||||
}
|
||||
|
||||
public class CharacterPersistenceService(
|
||||
ApplicationDbContext dbContext,
|
||||
ICurrentUserService currentUserService
|
||||
) : ICharacterPersistenceService
|
||||
{
|
||||
|
||||
public async Task<Guid> StoreNewCharacter(V1Karakter karakter)
|
||||
{
|
||||
var currentUser = await currentUserService.GetCurrentUser();
|
||||
karakter.OwnerUserId = currentUser?.Id;
|
||||
karakter.Id = Guid.Empty;
|
||||
dbContext.Karakterek.Add(karakter);
|
||||
await dbContext.SaveChangesAsync();
|
||||
return karakter.Id;
|
||||
}
|
||||
|
||||
public async Task<V1Karakter?> GetCharacterById(Guid id)
|
||||
{
|
||||
var entity = await dbContext.Karakterek
|
||||
.Include(x => x.KarakterKepzettsegek)
|
||||
.Include(x => x.Szintlepesek)
|
||||
.Include(x => x.Felszereles)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (entity?.OwnerUserId is null || entity.IsPublic)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
var currentUser = await currentUserService.GetCurrentUser();
|
||||
return entity.OwnerUserId == currentUser?.Id ? entity : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user