Renamed Student to Attendee

This commit is contained in:
Jose Selesan
2026-09-17 18:58:00 -03:00
parent e8bca3a5ae
commit fa30fe2cff
22 changed files with 120 additions and 104 deletions

View File

@@ -0,0 +1,18 @@
import type { AttendeeQuery } from '@gruperly/shared';
import { AttendeeQuerySchema } from '@gruperly/shared';
import { Hono } from 'hono';
import { resultJson } from '@/http/problem-details';
import { validate } from '@/http/validate';
import { ListAttendees } from './use-case';
const route = new Hono();
route.get('/', validate.query(AttendeeQuerySchema), async (c) => {
const query = c.req.valid('query') as AttendeeQuery;
const useCase = new ListAttendees();
const result: Awaited<ReturnType<typeof useCase.execute>> = await useCase.execute(query);
return resultJson(c, result);
});
export default route;

View File

@@ -1,14 +1,14 @@
import type { PrismaClient } from '@generated/prisma/client';
import type { ProblemDetails, Result, StudentDto, StudentList, StudentQuery } from '@gruperly/shared';
import type { AttendeeDto, AttendeeList, AttendeeQuery, ProblemDetails, Result } from '@gruperly/shared';
import { ok } from '@gruperly/shared';
import { getPaginationMetadata, getPaginationOffset } from '@/lib/pagination';
import prisma from '@/lib/prisma';
type ListStudentsDeps = {
db?: Pick<PrismaClient, 'student'>;
type ListAttendeesDeps = {
db?: Pick<PrismaClient, 'attendee'>;
};
type StudentRecord = {
type AttendeeRecord = {
id: string;
groupId: string;
fullName: string;
@@ -21,7 +21,7 @@ type StudentRecord = {
updatedAt: Date;
};
function toStudentDto(record: StudentRecord): StudentDto {
function toAttendeeDto(record: AttendeeRecord): AttendeeDto {
return {
id: record.id,
groupId: record.groupId,
@@ -36,22 +36,22 @@ function toStudentDto(record: StudentRecord): StudentDto {
};
}
export class ListStudents {
constructor(private readonly deps: ListStudentsDeps = {}) {}
export class ListAttendees {
constructor(private readonly deps: ListAttendeesDeps = {}) {}
async execute(query: StudentQuery): Promise<Result<StudentList, ProblemDetails>> {
async execute(query: AttendeeQuery): Promise<Result<AttendeeList, ProblemDetails>> {
const db = this.deps.db ?? prisma;
const [records, total] = await Promise.all([
db.student.findMany({
db.attendee.findMany({
skip: getPaginationOffset(query),
take: query.pageSize,
orderBy: { createdAt: 'desc' },
}),
db.student.count(),
db.attendee.count(),
]);
return ok({
data: records.map(toStudentDto),
data: records.map(toAttendeeDto),
pagination: getPaginationMetadata(query, total),
});
}

View File

@@ -0,0 +1 @@
export { default as attendeesRoutes } from './routes';

View File

@@ -11,7 +11,7 @@ type ListPaymentsDeps = {
type PaymentRecord = {
id: string;
groupId: string;
studentId: string;
attendeeId: string;
amount: { toString(): string };
currency: string;
status: PaymentDto['status'];
@@ -25,7 +25,7 @@ function toPaymentDto(record: PaymentRecord): PaymentDto {
return {
id: record.id,
groupId: record.groupId,
studentId: record.studentId,
attendeeId: record.attendeeId,
amount: Number(record.amount.toString()),
currency: record.currency,
status: record.status,

View File

@@ -1,18 +0,0 @@
import type { StudentQuery } from '@gruperly/shared';
import { StudentQuerySchema } from '@gruperly/shared';
import { Hono } from 'hono';
import { resultJson } from '@/http/problem-details';
import { validate } from '@/http/validate';
import { ListStudents } from './use-case';
const route = new Hono();
route.get('/', validate.query(StudentQuerySchema), async (c) => {
const query = c.req.valid('query') as StudentQuery;
const useCase = new ListStudents();
const result: Awaited<ReturnType<typeof useCase.execute>> = await useCase.execute(query);
return resultJson(c, result);
});
export default route;

View File

@@ -1 +0,0 @@
export { default as studentsRoutes } from './routes';