import { Controller , Get , Post , Body , Param } from '@nestjs/common' ; import { AIDModel , CreateModelDto } from './model.schema' ; import { ModelService } from './model.service' ; import { ApiTags } from '@nestjs/swagger' ; import { fetchGithubSummary , getGitHubDetails } from '../services/github' ; @ ApiTags ( 'Model' ) @ Controller ( 'model' ) export class ModelController { constructor ( private readonly modelService ) { } @ Get ( ) async findAll ( ) { return this . modelService . findAll ( ) ; } @ Get ( "/keyword/:keyword" ) async findByKeyword ( @ Param ( "keyword" ) keyword ) { return this . modelService . findByKeyword ( keyword ) ; } @ Get ( "/meta/:packageId" ) async fetchMetaInformation ( @ Param ( "packageId" ) packageId ) { const model = await this . modelService . findById ( packageId ) ; if ( model . githubURL !== "" ) { const infos = model . githubURL . split ( "/" ) ; return fetchGithubSummary ( infos [ infos . length - 2 ] , infos [ infos . length - 1 ] ) ; } else { return { } ; } } @ Get ( "/info/:vendor/:name" ) async fetchInformation ( @ Param ( "vendor" ) vendor , @ Param ( "name" ) name ) { return getGitHubDetails ( vendor , name ) ; } @ Post ( ) async create ( @ Body ( ) createDto ) { return this . modelService . create ( createDto ) ; } }