feat(showcase): 去掉 Bento 灵感类型,只保留 hero / work
后端校验、分组、后台列表,以及后台页面与首页取图都只认 hero 和 work;启动时清掉遗留的 bento 记录。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -72,6 +72,10 @@ func NewApp(ctx context.Context) (*App, error) {
|
||||
if err := db.WithContext(ctx).Exec(`ALTER TABLE model_configs DROP COLUMN IF EXISTS enabled`).Error; err != nil {
|
||||
return nil, fmt.Errorf("drop model_configs.enabled: %w", err)
|
||||
}
|
||||
// 首页展示位不再支持 bento,清掉遗留记录。
|
||||
if err := db.WithContext(ctx).Exec(`DELETE FROM showcase_items WHERE kind = 'bento'`).Error; err != nil {
|
||||
return nil, fmt.Errorf("purge bento showcase: %w", err)
|
||||
}
|
||||
if err := seedDefaults(ctx, db); err != nil {
|
||||
return nil, fmt.Errorf("seed defaults: %w", err)
|
||||
}
|
||||
|
||||
@@ -46,16 +46,16 @@ func (h *ShowcaseHandler) List(c *gin.Context) {
|
||||
|
||||
// AdminList is the paginated flat view for the admin 首页内容 page — the public
|
||||
// List keeps its grouped shape for the home page, this one adds kind filter +
|
||||
// limit/offset/total. Order mirrors the old client flattening: hero → bento → work.
|
||||
// limit/offset/total. Order mirrors the old client flattening: hero → work.
|
||||
func (h *ShowcaseHandler) AdminList(c *gin.Context) {
|
||||
grouped, err := h.showcase.Grouped(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load showcase"})
|
||||
return
|
||||
}
|
||||
kindFilter := c.Query("kind") // "" | hero | bento | work
|
||||
kindFilter := c.Query("kind") // "" | hero | work
|
||||
flat := make([]gin.H, 0, 16)
|
||||
for _, kind := range []string{"hero", "bento", "work"} {
|
||||
for _, kind := range []string{"hero", "work"} {
|
||||
if kindFilter != "" && kind != kindFilter {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -62,9 +62,8 @@ func (r *ShowcaseRepository) Grouped(ctx context.Context) (map[string][]model.Sh
|
||||
}
|
||||
|
||||
grouped := map[string][]model.ShowcaseItem{
|
||||
"hero": {},
|
||||
"bento": {},
|
||||
"work": {},
|
||||
"hero": {},
|
||||
"work": {},
|
||||
}
|
||||
for _, item := range items {
|
||||
grouped[item.Kind] = append(grouped[item.Kind], item)
|
||||
|
||||
@@ -292,7 +292,7 @@ func (s *AdminWriteService) DeleteUserAPIKey(ctx context.Context, userID, keyID
|
||||
func (s *AdminWriteService) CreateShowcase(ctx context.Context, body map[string]any) (*model.ShowcaseItem, error) {
|
||||
kind := normalizedShowcaseKind(stringValue(body["kind"]))
|
||||
if kind == "" {
|
||||
return nil, errors.New("kind must be hero, bento or work")
|
||||
return nil, errors.New("kind must be hero or work")
|
||||
}
|
||||
image := strings.TrimSpace(stringValue(body["image"]))
|
||||
if image == "" {
|
||||
@@ -333,7 +333,7 @@ func (s *AdminWriteService) UpdateShowcase(ctx context.Context, entryID string,
|
||||
if _, ok := body["kind"]; ok {
|
||||
kind := normalizedShowcaseKind(stringValue(body["kind"]))
|
||||
if kind == "" {
|
||||
return nil, errors.New("kind must be hero, bento or work")
|
||||
return nil, errors.New("kind must be hero or work")
|
||||
}
|
||||
patch["kind"] = kind
|
||||
}
|
||||
@@ -581,7 +581,7 @@ func normalizedStatus(status string) string {
|
||||
|
||||
func normalizedShowcaseKind(kind string) string {
|
||||
switch strings.TrimSpace(kind) {
|
||||
case "hero", "bento", "work":
|
||||
case "hero", "work":
|
||||
return strings.TrimSpace(kind)
|
||||
default:
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user