feat: mock exercise template api (#613)

* feat: move mock exercise template to api

* feat: add template migration file

* chore:
- remove exercise templates form api
- rework api to pull exercise templates from db
- add exercise template seed to seed file
- declutter seed file

* chore:
- refactor template fetch to be dependent on the selected tag
- add tag to schema, remote db and template's seed file
- clear remote db's template table and replace data and their respective tags

* chore: add number of questions and center loading screen on the frontend

* chore: pr fixes

* chore: type fixes

* chore:
- move seed functionality to /seed folder
- add typing for individual seed functions
- pr fixes

* chore: pr fixes v2

* update output css

* refactor: update seeding script and schema definitions

- Renamed `seedTypes` to `seedQuestionTypes` for clarity in the seeding process.
- Enhanced the seeding script to include a command-line interface for better usability, allowing specific seed functions to be executed based on flags.
- Removed redundant unique constraints in the schema definitions for `courseNewsfeedComment` and `exerciseTemplate` to streamline database structure.

* feat: add email verification error handling page and update session management

- Introduced a new page for handling email verification errors, providing user-friendly messages based on error types.
- Updated session management logic to improve handling of public routes and session states.
- Enhanced security policies in the Svelte configuration to include additional sources for styles and scripts.
- Removed the old email verification error page to streamline the codebase.

* move the exercise template to cloudflare cdn

---------

Co-authored-by: Rotimi Best <best@classroomio.com>
This commit is contained in:
Adeyemi Adetunji
2025-12-25 05:09:27 +01:00
committed by GitHub
co-authored by Rotimi Best
parent ac3f35a97f
commit 50d6ee3111
263 changed files with 1568 additions and 37195 deletions
@@ -0,0 +1 @@
export * from './template.svelte';
@@ -0,0 +1,39 @@
import { BaseApi, classroomio } from '$lib/utils/services/api';
import type { TExerciseTemplate } from '@cio/db/types';
import type { GetTemplateByIdResponse, GetTemplateByTagData, GetTemplateByTagResponse } from '../utils/types';
/**
* API class for exercise templates
*/
class ExerciseTemplateApi extends BaseApi {
templates = $state<GetTemplateByTagData>([]);
template = $state<TExerciseTemplate>({} as TExerciseTemplate);
/**
* Fetches an exercise template metadata
*/
async fetchTemplateById(id: string) {
await this.execute<GetTemplateByIdResponse>({
requestFn: () => classroomio.exercise.template[':id'].$get({ param: { id } }),
logContext: 'fetching exercise template by id',
onSuccess: (response) => {
this.template = response.data;
}
});
}
/**
* Fetches an exercise template metadata
*/
async fetchTemplatesByTag(tag: string) {
await this.execute<GetTemplateByTagResponse>({
requestFn: () => classroomio.exercise.template.tag[':tag'].$get({ param: { tag } }),
logContext: 'fetching exercise template by tag',
onSuccess: (response) => {
this.templates = response.data;
}
});
}
}
export const exerciseTemplateApi = new ExerciseTemplateApi();
@@ -0,0 +1,12 @@
export const TAGS = {
HTML: 'HTML',
CSS: 'CSS',
JS: 'JS',
Typescript: 'Typescript',
ReactJS: 'ReactJS',
VueJS: 'VueJS',
NodeJS: 'NodeJS',
Python: 'Python',
PHP: 'PHP',
GIT: 'GIT'
};
@@ -0,0 +1,16 @@
import { classroomio, type InferResponseType } from '$lib/utils/services/api';
export type GetAllTemplatesMetadataResponse = typeof classroomio.exercise.template.$get;
export type GetAllTemplatesMetadataSuccess = Extract<
InferResponseType<GetAllTemplatesMetadataResponse>,
{ success: true }
>;
export type GetAllTemplatesMetadataData = GetAllTemplatesMetadataSuccess['data'];
export type GetTemplateByTagResponse = (typeof classroomio.exercise.template)['tag'][':tag']['$get'];
export type GetTemplateByTagSuccess = Extract<InferResponseType<GetTemplateByTagResponse>, { success: true }>;
export type GetTemplateByTagData = GetTemplateByTagSuccess['data'];
export type GetTemplateByIdResponse = (typeof classroomio.exercise.template)[':id']['$get'];
export type GetTemplateByIdSuccess = Extract<InferResponseType<GetTemplateByIdResponse>, { success: true }>;
export type GetTemplateByIdData = GetTemplateByIdSuccess['data'];