新增语言学习后台服务
- 分类管理:支持分类的增删改查 - 单词管理:支持单词的增删改查,包含音标、释义、例句等字段 - 更新 README 项目说明 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// Category represents a word category, such as "农场动物" or "颜色".
|
||||
type Category struct {
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CreateCategoryRequest is the payload for creating a category.
|
||||
type CreateCategoryRequest struct {
|
||||
Name string `json:"name"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
}
|
||||
|
||||
// UpdateCategoryRequest is the payload for updating a category.
|
||||
type UpdateCategoryRequest struct {
|
||||
Name string `json:"name"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
}
|
||||
|
||||
// Word represents a vocabulary word.
|
||||
type Word struct {
|
||||
ID int32 `json:"id"`
|
||||
CategoryID int32 `json:"category_id"`
|
||||
Word string `json:"word"`
|
||||
Translation string `json:"translation"`
|
||||
Phonetic *string `json:"phonetic,omitempty"`
|
||||
ExampleSentence *string `json:"example_sentence,omitempty"`
|
||||
AudioURL *string `json:"audio_url,omitempty"`
|
||||
ImageURL *string `json:"image_url,omitempty"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CreateWordRequest is the payload for creating a word.
|
||||
type CreateWordRequest struct {
|
||||
CategoryID int32 `json:"category_id"`
|
||||
Word string `json:"word"`
|
||||
Translation string `json:"translation"`
|
||||
Phonetic *string `json:"phonetic,omitempty"`
|
||||
ExampleSentence *string `json:"example_sentence,omitempty"`
|
||||
AudioURL *string `json:"audio_url,omitempty"`
|
||||
ImageURL *string `json:"image_url,omitempty"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
}
|
||||
|
||||
// UpdateWordRequest is the payload for updating a word.
|
||||
type UpdateWordRequest struct {
|
||||
CategoryID int32 `json:"category_id"`
|
||||
Word string `json:"word"`
|
||||
Translation string `json:"translation"`
|
||||
Phonetic *string `json:"phonetic,omitempty"`
|
||||
ExampleSentence *string `json:"example_sentence,omitempty"`
|
||||
AudioURL *string `json:"audio_url,omitempty"`
|
||||
ImageURL *string `json:"image_url,omitempty"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
}
|
||||
|
||||
// ListWordsRequest holds query parameters for listing words.
|
||||
type ListWordsRequest struct {
|
||||
CategoryID *int32 `json:"category_id,omitempty"`
|
||||
Keyword string `json:"keyword,omitempty"`
|
||||
Page int32 `json:"page,omitempty"`
|
||||
PageSize int32 `json:"page_size,omitempty"`
|
||||
}
|
||||
|
||||
// ListWordsResponse is the paginated response for word listing.
|
||||
type ListWordsResponse struct {
|
||||
Words []Word `json:"words"`
|
||||
Total int64 `json:"total"`
|
||||
Page int32 `json:"page"`
|
||||
PageSize int32 `json:"page_size"`
|
||||
TotalPages int32 `json:"total_pages"`
|
||||
}
|
||||
|
||||
// APIResponse is the common JSON envelope for all API responses.
|
||||
type APIResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
Reference in New Issue
Block a user