Просмотр исходного кода

fix: sort list by id in decreasing order

RegMs If 3 лет назад
Родитель
Сommit
7a29a6447d
4 измененных файлов с 7 добавлено и 7 удалено
  1. 5 0
      controller/dicts.go
  2. 0 5
      controller/words.go
  3. 1 1
      model/dicts.go
  4. 1 1
      model/words.go

+ 5 - 0
controller/dicts.go

@@ -34,6 +34,11 @@ type GetDictRequest struct {
 	DictID uint `form:"id" binding:"required"`
 	DictID uint `form:"id" binding:"required"`
 }
 }
 
 
+type ListWordsResponse struct {
+	Total uint               `json:"total"`
+	List  []model.WordResult `json:"list"`
+}
+
 type GetDictResponse struct {
 type GetDictResponse struct {
 	*model.DictResult `json:"dict"`
 	*model.DictResult `json:"dict"`
 	Words             ListWordsResponse `json:"words"`
 	Words             ListWordsResponse `json:"words"`

+ 0 - 5
controller/words.go

@@ -9,11 +9,6 @@ import (
 	"gorm.io/gorm"
 	"gorm.io/gorm"
 )
 )
 
 
-type ListWordsResponse struct {
-	Total uint               `json:"total"`
-	List  []model.WordResult `json:"list"`
-}
-
 type CreateWordRequest struct {
 type CreateWordRequest struct {
 	Value   string `form:"value" binding:"required"`
 	Value   string `form:"value" binding:"required"`
 	Meaning string `form:"meaning" binding:"required"`
 	Meaning string `form:"meaning" binding:"required"`

+ 1 - 1
model/dicts.go

@@ -47,7 +47,7 @@ type DictResult struct {
 // 列出所有词库
 // 列出所有词库
 func ListDicts(dict *Dict) ([]DictResult, error) {
 func ListDicts(dict *Dict) ([]DictResult, error) {
 	result := []DictResult{}
 	result := []DictResult{}
-	if err := global.DB.Model(&Dict{}).Select("*, (?) AS word_count", global.DB.Model(&Word{}).Select("COUNT()").Where("dict_id = dicts.id")).Find(&result, dict, "user_id").Error; err != nil {
+	if err := global.DB.Model(&Dict{}).Select("*, (?) AS word_count", global.DB.Model(&Word{}).Select("COUNT()").Where("dict_id = dicts.id")).Order("id desc").Find(&result, dict, "user_id").Error; err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 	return result, nil
 	return result, nil

+ 1 - 1
model/words.go

@@ -44,7 +44,7 @@ type WordResult struct {
 // 列出所有单词
 // 列出所有单词
 func ListWords(word *Word) ([]WordResult, error) {
 func ListWords(word *Word) ([]WordResult, error) {
 	result := []WordResult{}
 	result := []WordResult{}
-	if err := global.DB.Model(&Word{}).Find(&result, word, "dict_id").Error; err != nil {
+	if err := global.DB.Model(&Word{}).Order("id desc").Find(&result, word, "dict_id").Error; err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 	return result, nil
 	return result, nil