release 2e

This commit is contained in:
2024-02-23 18:31:39 +01:00
parent aca949c614
commit ed53c25ea1
6 changed files with 130 additions and 80 deletions
@@ -113,28 +113,19 @@ public class CharacterPersistenceService(
})
.ToListAsync();
var characters2ERaw = await dbContext.Karakterek2E.Include(k => k.Szintlepesek)
var characters2E = await dbContext.Karakterek2E.Include(k => k.Szintlepesek)
.Where(k => k.OwnerUserId == currentUser.Id)
.Select(k => new
.Select(k => new CharacterListItemDto
{
k.Id,
k.Nev,
k.Szint,
k.Faj,
Osztalyok = k.Szintlepesek.Select(x => x.Osztaly).ToList(),
Id = k.Id,
Name = k.Nev,
Szint = k.Szint,
Faj = k.Faj.Convert(),
Osztaly = k.Szintlepesek.OrderBy(x => x.KarakterSzint).Select(x => x.Osztaly).First().Convert(),
Edition = "2e"
})
.ToListAsync();
var characters2E = characters2ERaw.Select(k => new CharacterListItemDto
{
Id = k.Id,
Name = k.Nev,
Szint = k.Szint,
Faj = k.Faj.Convert(),
Osztaly = string.Join('/', k.Osztalyok.Select(o => o.Convert())),
Edition = "2e"
});
characters.AddRange(characters2E);
return characters;
+2 -2
View File
@@ -3,7 +3,7 @@ import './App.css';
import {Faro} from "@grafana/faro-web-sdk";
import {createBrowserRouter, redirect, RouterProvider} from "react-router-dom";
import CreateCharacter from "./first-edition/pages/CreateCharacter";
import CharacterList from "./first-edition/pages/CharacterList";
import CharacterList from "./shared/pages/CharacterList";
import ErrorBoundary from "./shared/ErrorBoundary";
import Header from "./shared/Header";
import Footer from "./shared/Footer";
@@ -42,7 +42,7 @@ function App(props: {faro?: Faro}) {
const router = createBrowserRouter([
{
path: "/",
loader: () => fetchedUser.data == null ? redirect("/1e/karakter") : redirect("/karaktereim")
loader: () => fetchedUser.data == null ? redirect("/2e/karakter") : redirect("/karaktereim")
},
{
path: "/karaktereim",
@@ -1,26 +0,0 @@
import * as React from "react";
import {Osztaly, OsztalyLabel} from "../domain-models/osztaly";
import {Faj, FajLabel} from "../domain-models/faj";
export interface CharacterListItemDto {
id: string,
name: string,
szint: number,
faj: Faj,
osztaly: Osztaly,
edition: "1e" | "2e"
}
function CharacterListItem(props: {
character: CharacterListItemDto,
}) {
const {character:c} = props
return <>
<td><a href={`/${c.edition}/karakter/${c.id}`}>{c.name}</a></td>
<td>{c.szint}. szintű</td>
<td>{FajLabel(c.faj)}</td>
<td>{OsztalyLabel(c.osztaly)}</td>
</>
}
export default CharacterListItem;
@@ -1,35 +0,0 @@
import * as React from "react";
import {useLoaderData} from "react-router-dom";
import CharacterListItem, {CharacterListItemDto} from "../components/CharacterListItem";
function CharacterList(props: {}) {
const characters = useLoaderData() as CharacterListItemDto[];
return <div className="container">
<div className="container-fluid p-5 bg-black text-white text-center">
<h1>Karakterek</h1>
</div>
<div className="d-grid gap-2 m-5">
<a className="btn btn-dark btn-lg" href="/" type="button">Új karakter létrehozása</a>
</div>
<table className="table mt-3">
<thead>
<tr>
<th scope="col">Név</th>
<th scope="col">Szint</th>
<th scope="col">Faj</th>
<th scope="col">Osztály</th>
</tr>
</thead>
<tbody>
{characters.map(c => (
<tr key={c.id}>
<CharacterListItem character={c}/>
</tr>
))}
</tbody>
</table>
</div>
}
export default CharacterList;
@@ -0,0 +1,19 @@
import * as React from "react";
import {CharacterListItemViewModel} from "../pages/CharacterList";
function CharacterListItem(props: {
character: CharacterListItemViewModel,
}) {
const {character:c} = props
return <>
<td><a href={`/${c.edition}/karakter/${c.id}`}>{c.name}</a></td>
<td>{c.szint}. szintű</td>
<td>{c.faj}</td>
<td>{c.osztaly}</td>
<td>{c.edition}</td>
</>
}
export default CharacterListItem;
@@ -0,0 +1,101 @@
import * as React from "react";
import {useLoaderData} from "react-router-dom";
import CharacterListItem from "../components/CharacterListItem";
import {Faj, FajLabel as FajLabel1E} from "../../first-edition/domain-models/faj";
import {Faj2E, FajLabel as FajLabel2E} from "../../second-edition/domain-models/faj2E";
import {Osztaly, OsztalyLabel as OsztalyLabel1E} from "../../first-edition/domain-models/osztaly";
import {Osztaly2E, OsztalyLabel as OsztalyLabel2E} from "../../second-edition/domain-models/osztaly2E";
export interface CharacterListItemViewModel {
id: string,
name: string,
szint: number,
faj: string,
osztaly: string,
edition: "1e" | "2e"
}
interface CharacterListItemDto1E {
id: string,
name: string,
szint: number,
faj: Faj,
osztaly: Osztaly,
edition: "1e"
}
interface CharacterListItemDto2E {
id: string,
name: string,
szint: number,
faj: Faj2E,
osztaly: Osztaly2E,
edition: "2e"
}
type CharacterListItemDto = CharacterListItemDto1E | CharacterListItemDto2E;
function mapDtoToViewModel(dto: CharacterListItemDto): CharacterListItemViewModel {
if (dto.edition === "1e") {
return {
id: dto.id,
name: dto.name,
edition: dto.edition,
szint: dto.szint,
faj: FajLabel1E(dto.faj),
osztaly: OsztalyLabel1E(dto.osztaly),
}
}
else {
return {
id: dto.id,
name: dto.name,
edition: dto.edition,
szint: dto.szint,
faj: FajLabel2E(dto.faj),
osztaly: OsztalyLabel2E(dto.osztaly),
}
}
}
function CharacterList(props: {}) {
const characters = useLoaderData() as CharacterListItemDto[];
return <div className="container">
<div className="container-fluid p-5 bg-black text-white text-center">
<h1>Karakterek</h1>
</div>
<div className="row">
<div className="col-6">
<div className="d-grid gap-1 m-3 m-lg-5">
<a className="btn btn-dark btn-lg" href="/2e/karakter/" type="button">Új 2e karakter létrehozása</a>
</div>
</div>
<div className="col-6">
<div className="d-grid gap-1 m-3 m-lg-5">
<a className="btn btn-dark btn-lg" href="/1e/karakter/" type="button">Új 1e karakter létrehozása</a>
</div>
</div>
</div>
<table className="table mt-3">
<thead>
<tr>
<th scope="col">Név</th>
<th scope="col">Szint</th>
<th scope="col">Faj</th>
<th scope="col">Osztály</th>
<th scope="col">Kiadás</th>
</tr>
</thead>
<tbody>
{characters.map(c => (
<tr key={c.id}>
<CharacterListItem character={mapDtoToViewModel(c)}/>
</tr>
))}
</tbody>
</table>
</div>
}
export default CharacterList;