Enhance user profiles with character class feature: Add character class field to user model and update related API routes, UI components, and validation logic. This update improves user profile customization and leaderboard entries by allowing users to select and display their character class.

This commit is contained in:
Julien Froidefond
2025-12-09 22:03:51 +01:00
parent 3a0dd57bb6
commit b245be3bf4
17 changed files with 438 additions and 25 deletions

View File

@@ -15,6 +15,7 @@ export async function GET() {
level: true,
avatar: true,
bio: true,
characterClass: true,
},
});
@@ -27,6 +28,7 @@ export async function GET() {
level: number;
avatar: string | null;
bio: string | null;
characterClass: string | null;
},
index: number
) => ({
@@ -36,6 +38,7 @@ export async function GET() {
level: user.level,
avatar: user.avatar,
bio: user.bio,
characterClass: user.characterClass,
})
);

View File

@@ -1,6 +1,7 @@
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { CharacterClass } from "@/prisma/generated/prisma/enums";
export async function GET() {
try {
@@ -18,6 +19,7 @@ export async function GET() {
username: true,
avatar: true,
bio: true,
characterClass: true,
hp: true,
maxHp: true,
xp: true,
@@ -51,7 +53,7 @@ export async function PUT(request: Request) {
}
const body = await request.json();
const { username, avatar, bio } = body;
const { username, avatar, bio, characterClass } = body;
// Validation
if (username !== undefined) {
@@ -101,8 +103,35 @@ export async function PUT(request: Request) {
}
}
// Validation characterClass
const validClasses = [
"WARRIOR",
"MAGE",
"ROGUE",
"RANGER",
"PALADIN",
"ENGINEER",
"MERCHANT",
"SCHOLAR",
"BERSERKER",
"NECROMANCER",
];
if (characterClass !== undefined && characterClass !== null) {
if (!validClasses.includes(characterClass)) {
return NextResponse.json(
{ error: "Classe de personnage invalide" },
{ status: 400 }
);
}
}
// Mettre à jour l'utilisateur
const updateData: { username?: string; avatar?: string | null; bio?: string | null } = {};
const updateData: {
username?: string;
avatar?: string | null;
bio?: string | null;
characterClass?: CharacterClass | null;
} = {};
if (username !== undefined) {
updateData.username = username.trim();
}
@@ -112,6 +141,9 @@ export async function PUT(request: Request) {
if (bio !== undefined) {
updateData.bio = bio.trim() || null;
}
if (characterClass !== undefined) {
updateData.characterClass = (characterClass as CharacterClass) || null;
}
const updatedUser = await prisma.user.update({
where: { id: session.user.id },
@@ -122,6 +154,7 @@ export async function PUT(request: Request) {
username: true,
avatar: true,
bio: true,
characterClass: true,
hp: true,
maxHp: true,
xp: true,