fix(publish): 后台详情与品牌列表改读基表,修复未发布内容在后台不可达

This commit is contained in:
toom1996
2026-09-23 10:16:09 +08:00
parent f5144038ab
commit 4169ebe1ed
9 changed files with 287 additions and 52 deletions

View File

@ -50,6 +50,11 @@ type fakeBrand struct{}
func (f *fakeBrand) List(ctx context.Context, q dto.BrandQuery) ([]dto.PublicBrand, int64, error) {
return []dto.PublicBrand{{UID: "001DESke", NameEn: "Acne Studios", NameCn: "艾克妮"}}, 1, nil
}
// AdminList 后台品牌列表:假实现里与 List 同源(本假实现不区分走秀发布态)。
func (f *fakeBrand) AdminList(ctx context.Context, q dto.BrandQuery) ([]dto.PublicBrand, int64, error) {
return f.List(ctx, q)
}
func (f *fakeBrand) Hot(ctx context.Context, limit int, locale string) ([]dto.PublicBrand, error) {
return nil, nil
}
@ -104,11 +109,19 @@ func (f *fakeArticle) AdminList(ctx context.Context, q dto.ArticleQuery) ([]dto.
ImageCount: 12,
}}, 1, nil
}
// Detail 公开详情。本 fake 代表一条「待审」内容:公开路径读视图,读不到,
// 故固定返回 not found;后台详情只有走 DetailAdmin(读基表)才渲染得出来。
func (f *fakeArticle) Detail(ctx context.Context, id, locale string) (*dto.PublicArticleDetail, error) {
return nil, service.ErrArticleNotFound
}
// DetailAdmin 后台详情:读基表,待审内容也能渲染(Title 带「待审」标记便于断言)。
func (f *fakeArticle) DetailAdmin(ctx context.Context, id, locale string) (*dto.PublicArticleDetail, error) {
return &dto.PublicArticleDetail{
UID: id,
BrandUID: "001DESke",
Title: "Acne Studios Spring 2024",
Title: "Acne Studios Spring 2024(待审)",
BrandName: "Acne Studios",
Images: []dto.PublicArticleImage{
{ID: "i1", Image: "/uploads/runway/1.jpg", Name: "Look 1"},
@ -149,10 +162,17 @@ func (f *fakeStreet) AdminList(ctx context.Context, q dto.StreetSnapQuery) ([]dt
return f.List(ctx, q)
}
// Detail 公开详情。本 fake 代表一条「待审」街拍:公开路径读视图,读不到,
// 故固定返回 not found;后台详情只有走 DetailAdmin(读基表)才渲染得出来。
func (f *fakeStreet) Detail(ctx context.Context, id string) (*dto.PublicStreetSnapDetail, error) {
return nil, service.ErrStreetSnapNotFound
}
// DetailAdmin 后台详情:读基表,待审内容也能渲染(Title 带「待审」标记便于断言)。
func (f *fakeStreet) DetailAdmin(ctx context.Context, id string) (*dto.PublicStreetSnapDetail, error) {
return &dto.PublicStreetSnapDetail{
UID: id,
Title: "Paris Fashion Week Street",
Title: "Paris Fashion Week Street(待审)",
Images: []dto.PublicArticleImage{
{ID: "j1", Image: "/uploads/snap/1.jpg", Name: "Snap 1"},
},
@ -270,13 +290,15 @@ func TestBackstage(t *testing.T) {
t.Fatalf("走秀列表异常: %d %s", w.Code, w.Body.String())
}
// 7) 走秀详情渲染图集
// 7) 后台走秀详情渲染图集。
// fakeArticle.Detail(公开路径)对这条「待审」内容固定返回 not found,
// 这里仍 200 且渲染出「待审」标记,即证明后台详情走的是 DetailAdmin(读基表)。
w = httptest.NewRecorder()
req = httptest.NewRequest(http.MethodGet, "/admin/runways/r001DESke", nil)
req.AddCookie(&http.Cookie{Name: adminCookie, Value: token})
r.ServeHTTP(w, req)
if w.Code != 200 || !strings.Contains(w.Body.String(), "Look 1") {
t.Fatalf("走秀详情异常: %d %s", w.Code, w.Body.String())
if w.Code != 200 || !strings.Contains(w.Body.String(), "Look 1") || !strings.Contains(w.Body.String(), "(待审)") {
t.Fatalf("后台应能渲染待审走秀详情(走 DetailAdmin): %d %s", w.Code, w.Body.String())
}
// 8) 街拍列表渲染
@ -288,13 +310,14 @@ func TestBackstage(t *testing.T) {
t.Fatalf("街拍列表异常: %d %s", w.Code, w.Body.String())
}
// 9) 街拍详情渲染图集
// 9) 后台街拍详情渲染图集。
// 同 7):fakeStreet.Detail(公开路径)返回 not found,此处 200 且渲染待审标记即证明走 DetailAdmin。
w = httptest.NewRecorder()
req = httptest.NewRequest(http.MethodGet, "/admin/street-snaps/s001DESke", nil)
req.AddCookie(&http.Cookie{Name: adminCookie, Value: token})
r.ServeHTTP(w, req)
if w.Code != 200 || !strings.Contains(w.Body.String(), "Snap 1") {
t.Fatalf("街拍详情异常: %d %s", w.Code, w.Body.String())
if w.Code != 200 || !strings.Contains(w.Body.String(), "Snap 1") || !strings.Contains(w.Body.String(), "(待审)") {
t.Fatalf("后台应能渲染待审街拍详情(走 DetailAdmin): %d %s", w.Code, w.Body.String())
}
}