update,
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# GUIDELINES
|
||||
|
||||
This folder contains drivers for `LessonCategory`/`LessonCategories` records using PocketBase:
|
||||
This folder contains drivers for `Vocabulary`/`Vocabularies` records using PocketBase:
|
||||
|
||||
## File Structure
|
||||
|
||||
- create (Create.tsx)
|
||||
- read (GetById.tsx)
|
||||
@@ -8,23 +10,71 @@ This folder contains drivers for `LessonCategory`/`LessonCategories` records usi
|
||||
- count (GetAllCount.tsx)
|
||||
- delete (Delete.tsx)
|
||||
- list (GetAll.tsx)
|
||||
- types (type.d.tsx)
|
||||
|
||||
the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src`
|
||||
|
||||
## Assumption and Requirements
|
||||
|
||||
- assume `pb` is located in `@/lib/pb`
|
||||
- no need to handle error in this function, i'll handle it in the caller
|
||||
- type information defined in `@/db/LessonCategories/type.d.tsx`
|
||||
|
||||
simple template:
|
||||
## Implementation Template
|
||||
|
||||
```typescript
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_LESSON_CATEGORIES } from '@/constants';
|
||||
import { COL_VOCABULARIES } from '@/constants';
|
||||
import type { Vocabulary, CreateVocabularyProps } from './type.d.tsx';
|
||||
|
||||
export async function createLessonCategory(data: CreateFormProps) {
|
||||
// ...content
|
||||
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||
export async function createVocabulary(data: CreateVocabularyProps): Promise<Vocabulary> {
|
||||
return pb.collection(COL_VOCABULARIES).create(data);
|
||||
}
|
||||
```
|
||||
|
||||
## Vocabulary-Specific Features
|
||||
|
||||
### Field Definitions
|
||||
|
||||
```typescript
|
||||
interface Vocabulary {
|
||||
term: string;
|
||||
definition: string;
|
||||
language: string;
|
||||
difficulty: 'beginner'|'intermediate'|'advanced';
|
||||
relatedTerms: string[]; // Array of vocabulary IDs
|
||||
}
|
||||
```
|
||||
|
||||
### Common Patterns
|
||||
|
||||
```typescript
|
||||
// Search by term
|
||||
export async function searchVocabularies(term: string) {
|
||||
return pb.collection(COL_VOCABULARIES)
|
||||
.getFullList({ filter: `term ~ "${term}"` });
|
||||
}
|
||||
|
||||
// Get by difficulty level
|
||||
export async function getVocabulariesByDifficulty(level: string) {
|
||||
return pb.collection(COL_VOCABULARIES)
|
||||
.getFullList({ filter: `difficulty = "${level}"` });
|
||||
}
|
||||
```
|
||||
|
||||
## Type Safety
|
||||
|
||||
```typescript
|
||||
// Recommended types to use
|
||||
type CreateVocabularyProps = Omit<Vocabulary, 'id'|'created'|'updated'>;
|
||||
type UpdateVocabularyProps = Partial<CreateVocabularyProps>;
|
||||
```
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
- Add indexes on: term, language, difficulty
|
||||
- Consider full-text search for term/definition fields
|
||||
- Cache frequently accessed vocabulary items
|
||||
- Batch operations for bulk imports
|
||||
|
||||
## Testing Guidelines
|
||||
|
||||
Recommended test cases:
|
||||
|
||||
- Basic CRUD operations
|
||||
- Term search functionality
|
||||
- Difficulty level filtering
|
||||
- Related terms validation
|
||||
- Language-specific queries
|
||||
|
Reference in New Issue
Block a user