feat: add API

- try localhost:1225/search?search_term=akk
This commit is contained in:
Sheldon Cooper 2025-09-11 23:15:08 -04:00
parent fdae502ec7
commit 38919f3a5a
13 changed files with 367 additions and 161 deletions

View file

@ -1,124 +1,120 @@
import "reflect-metadata"
import "reflect-metadata";
import {
Entity,
PrimaryGeneratedColumn,
Column,
PrimaryColumn,
BaseEntity,
ManyToOne,
OneToMany,
OneToOne,
ManyToMany,
JoinTable,
ColumnType
Entity,
PrimaryGeneratedColumn,
Column,
PrimaryColumn,
BaseEntity,
ManyToOne,
OneToMany,
OneToOne,
ManyToMany,
JoinTable,
ColumnType,
} from "typeorm";
@Entity()
export class Lemma extends BaseEntity {
@PrimaryColumn({type: 'text'})
lemma_name: string;
@PrimaryColumn({ type: "text" })
lemma_name: string;
@OneToMany(() => WordForm, (word_form) => word_form.lemma)
word_forms: WordForm[];
@OneToMany(() => WordForm, (word_form) => word_form.lemma, { cascade: true})
word_forms: WordForm[];
@OneToMany(() => Example, (example) => example.lemma)
examples: Example[];
@OneToMany(() => Example, (example) => example.lemma)
examples: Example[];
@OneToMany(() => Definition, (definition) => definition.lemma)
definitions: Definition[];
@OneToMany(() => Definition, (definition) => definition.lemma)
definitions: Definition[];
@OneToMany(() => Comment, (comment) => comment.lemma)
comments: Comment[];
@OneToMany(() => Comment, (comment) => comment.lemma)
comments: Comment[];
@OneToMany(() => Media, (media) => media.lemma)
media: Media[];
@ManyToMany(() => PartOfSpeech)
@JoinTable()
parts_of_speech: PartOfSpeech[];
@OneToMany(() => Media, (media) => media.lemma)
media: Media[];
@ManyToMany(() => PartOfSpeech)
@JoinTable()
parts_of_speech: PartOfSpeech[];
}
@Entity()
export class Lect extends BaseEntity {
@PrimaryColumn({type: 'text'})
name: string;
@OneToMany(() => WordForm, (w) => w.lect)
word_forms: WordForm[];
@PrimaryColumn({ type: "text" })
name: string;
@OneToMany(() => WordForm, (w) => w.lect)
word_forms: WordForm[];
}
@Entity()
export class WordForm extends BaseEntity {
@PrimaryColumn({type: 'integer'})
word_form_id: number
@Column({type: 'text'})
word_form: string;
@PrimaryColumn({ type: "integer" })
word_form_id: number;
@ManyToOne(() => Lemma, (lemma) => lemma.word_forms)
lemma: Lemma;
@Column({ type: "text" })
word_form: string;
@ManyToOne(() => Lect, (lect) => lect.word_forms)
lect: Lect;
@ManyToOne(() => Lemma, (lemma) => lemma.word_forms)
lemma: Lemma;
@ManyToOne(() => Lect, (lect) => lect.word_forms)
lect: Lect;
}
@Entity()
export class Example extends BaseEntity {
@PrimaryGeneratedColumn()
example_id: number;
@PrimaryGeneratedColumn()
example_id: number;
@Column({ nullable: false, type: 'text' })
example_text: string;
@Column({ nullable: false, type: "text" })
example_text: string;
@ManyToOne(() => Lemma, (lemma) => lemma.examples)
lemma: Lemma;
@ManyToOne(() => Lemma, (lemma) => lemma.examples)
lemma: Lemma;
}
@Entity()
export class Media extends BaseEntity {
@PrimaryGeneratedColumn()
media_id: number;
@PrimaryGeneratedColumn()
media_id: number;
@Column({ nullable: false, type: 'text'})
media_url: string;
@Column({ nullable: false, type: "text" })
media_url: string;
@ManyToOne(() => Lemma, (lemma) => lemma.media)
lemma: Lemma;
@ManyToOne(() => Lemma, (lemma) => lemma.media)
lemma: Lemma;
}
@Entity()
export class Definition extends BaseEntity {
@PrimaryGeneratedColumn()
definition_id: number;
@PrimaryGeneratedColumn()
definition_id: number;
@Column({ nullable: false, type: 'text' })
definition_text: string;
@Column({ nullable: false, type: "text" })
definition_text: string;
@ManyToOne(() => Lemma, (lemma) => lemma.definitions)
lemma: Lemma;
@ManyToOne(() => Lemma, (lemma) => lemma.definitions)
lemma: Lemma;
}
@Entity()
export class Comment extends BaseEntity {
@PrimaryGeneratedColumn()
comment_id: number;
@PrimaryGeneratedColumn()
comment_id: number;
@Column({ nullable: false, type: 'text' })
comment_text: string;
@Column({ nullable: false, type: "text" })
comment_text: string;
@ManyToOne(() => Lemma, (lemma) => lemma.comments)
lemma: Lemma;
@ManyToOne(() => Lemma, (lemma) => lemma.comments)
lemma: Lemma;
}
@Entity()
export class PartOfSpeech extends BaseEntity {
@PrimaryColumn({type: 'text'})
long_form: string;
@PrimaryColumn({ type: "text" })
long_form: string;
@Column({ nullable: false, unique: true, type: 'text' })
short_form: string;
@Column({ nullable: false, unique: true, type: "text" })
short_form: string;
}