Files
honoka-chan/internal/handler/api/achievement/initialaccomplishedlist.go
T
2026-06-13 06:54:32 +08:00

45 lines
1.1 KiB
Go

package achievement
import (
achievementapischema "honoka-chan/internal/schema/api/achievement"
"honoka-chan/internal/session"
"time"
"github.com/gin-gonic/gin"
)
func initialAccomplishedList(ctx *gin.Context) (res any, err error) {
ss := session.Get(ctx)
grouped, err := ListVisibleAccomplishedAchievements(ss)
if err != nil {
return nil, err
}
listData := make([]achievementapischema.UnaccomplishListData, 0, len(achievementFilterCategoryList))
for _, filterCategoryID := range achievementFilterCategoryList {
achievementItems := grouped[filterCategoryID]
if achievementItems == nil {
achievementItems = []achievementapischema.AchievementListItem{}
} else {
if len(achievementItems) > 5 {
achievementItems = achievementItems[:5]
}
}
listData = append(listData, achievementapischema.UnaccomplishListData{
FilterCategoryID: filterCategoryID,
AchievementList: achievementItems,
Count: len(grouped[filterCategoryID]),
IsLast: true,
})
}
return achievementapischema.UnaccomplishListResp{
Result: listData,
Status: 200,
CommandNum: false,
TimeStamp: time.Now().Unix(),
}, nil
}