GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: update index and index subjects (#234) · gitLibs/server@c1ee878

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • internal
    • cmd/gen/gorm
      • main.go
    • ctrl
      • ctrl.go
      • get_index.go
    • dal
      • dao
        • chii_index.gen.go
        • chii_index_related.gen.go
      • query
        • chii_index.gen.go
        • chii_index_related.gen.go
    • domain
      • error.go
      • index.go
    • index
      • mysql_repository.go
      • mysql_repository_test.go
    • mocks
      • IndexRepo.go
    • model
      • index.go
    • web
      • handler.go
      • handler
        • comments.go
        • fx.go
        • index_test.go
        • index
          • index.go
          • index_test.go
          • new.go
          • subject.go
          • subject_test.go
          • util.go
      • req
        • index.go
      • res
        • index.go
  • openapi
    • v0.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎internal/cmd/gen/gorm/main.go‎

Copy file name to clipboardExpand all lines: internal/cmd/gen/gorm/main.go
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,15 @@ func main() {
215215
gen.FieldTrimPrefix("idx_"),
216216
gen.FieldType("idx_id", "uint32"),
217217
gen.FieldType("idx_uid", userIDTypeString),
218+
gen.FieldType("idx_collects", "uint32"),
219+
// 变量重命名
218220
gen.FieldRename("idx_uid", "CreatorID"),
219-
gen.FieldType("idx_collects", "uint32")))
221+
gen.FieldRename("idx_dateline", "CreatedTime"),
222+
gen.FieldRename("idx_lasttouch", "UpdatedTime"),
223+
gen.FieldRename("idx_replies", "ReplyCount"),
224+
gen.FieldRename("idx_collects", "CollectCount"),
225+
gen.FieldRename("idx_subject_total", "SubjectCount"),
226+
))
220227

221228
modelPersonField := g.GenerateModelAs("chii_person_fields", "PersonField",
222229
gen.FieldTrimPrefix("prsn_"),
@@ -382,6 +389,11 @@ func main() {
382389
gen.FieldRelate(field.BelongsTo, "Subject", modelSubject, &field.RelateConfig{
383390
GORMTag: "foreignKey:idx_rlt_sid;references:subject_id",
384391
}),
392+
// 变量重命名
393+
gen.FieldRename("idx_rlt_rid", "IndexID"),
394+
gen.FieldRename("idx_rlt_sid", "SubjectID"),
395+
gen.FieldRename("idx_rlt_type", "SubjectType"),
396+
gen.FieldRename("idx_rlt_dateline", "CreatedTime"),
385397
))
386398

387399
g.ApplyBasic(g.GenerateModelAs("chii_rev_text", "RevisionText",
Collapse file

‎internal/ctrl/ctrl.go‎

Copy file name to clipboardExpand all lines: internal/ctrl/ctrl.go
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func New(
3232
person domain.PersonRepo,
3333
character domain.CharacterRepo,
3434
collection domain.CollectionRepo,
35+
index domain.IndexRepo,
3536
timeline domain.TimeLineRepo,
3637
metric tally.Scope,
3738
user domain.UserRepo,
@@ -53,6 +54,7 @@ func New(
5354
episode: episode,
5455
subject: subject,
5556
character: character,
57+
index: index,
5658
collection: collection,
5759
timeline: timeline,
5860

@@ -81,6 +83,7 @@ type Ctrl struct {
8183
subject subject.Repo
8284
character domain.CharacterRepo
8385
collection domain.CollectionRepo
86+
index domain.IndexRepo
8487
timeline domain.TimeLineRepo
8588
metricUserQueryCached tally.Counter
8689
metricUserQueryCount tally.Counter
Collapse file

‎internal/ctrl/get_index.go‎

Copy file name to clipboard
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published
5+
// by the Free Software Foundation, version 3.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
// See the GNU Affero General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU Affero General Public License
13+
// along with this program. If not, see <https://www.gnu.org/licenses/>
14+
15+
package ctrl
16+
17+
import (
18+
"context"
19+
"errors"
20+
"time"
21+
22+
"go.uber.org/zap"
23+
24+
"github.com/bangumi/server/internal/ctrl/internal/cachekey"
25+
"github.com/bangumi/server/internal/domain"
26+
"github.com/bangumi/server/internal/pkg/errgo"
27+
"github.com/bangumi/server/internal/web/res"
28+
)
29+
30+
func (ctl Ctrl) GetIndexWithCache(c context.Context, id uint32) (res.Index, bool, error) {
31+
var key = cachekey.Index(id)
32+
33+
var r res.Index
34+
ok, err := ctl.cache.Get(c, key, &r)
35+
if err != nil {
36+
return r, ok, errgo.Wrap(err, "cache.Get")
37+
}
38+
39+
if ok {
40+
return r, ok, nil
41+
}
42+
43+
i, err := ctl.index.Get(c, id)
44+
if err != nil {
45+
if errors.Is(err, domain.ErrNotFound) {
46+
return res.Index{}, false, nil
47+
}
48+
49+
return res.Index{}, false, errgo.Wrap(err, "Index.Get")
50+
}
51+
52+
u, err := ctl.GetUser(c, i.CreatorID)
53+
if err != nil {
54+
if errors.Is(err, domain.ErrNotFound) {
55+
ctl.log.Error("index missing creator", zap.Uint32("index_id", id), i.CreatorID.Zap())
56+
}
57+
return res.Index{}, false, errgo.Wrap(err, "failed to get creator: user.GetByID")
58+
}
59+
60+
r = res.IndexModelToResponse(&i, u)
61+
62+
if e := ctl.cache.Set(c, key, r, time.Hour); e != nil {
63+
ctl.log.Error("can't set response to cache", zap.Error(e))
64+
}
65+
66+
return r, true, nil
67+
}
Collapse file

‎internal/dal/dao/chii_index.gen.go‎

Copy file name to clipboardExpand all lines: internal/dal/dao/chii_index.gen.go
+5-5Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎internal/dal/dao/chii_index_related.gen.go‎

Copy file name to clipboardExpand all lines: internal/dal/dao/chii_index_related.gen.go
+9-9Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎internal/dal/query/chii_index.gen.go‎

Copy file name to clipboardExpand all lines: internal/dal/query/chii_index.gen.go
+20-20Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎internal/dal/query/chii_index_related.gen.go‎

Copy file name to clipboardExpand all lines: internal/dal/query/chii_index_related.gen.go
+22-22Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎internal/domain/error.go‎

Copy file name to clipboardExpand all lines: internal/domain/error.go
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ var ErrUserNotFound = errgo.MsgNoTrace(ErrNotFound, "user not found")
3131
var ErrSubjectNotCollected = errgo.MsgNoTrace(ErrNotFound, "subject is not collected by user")
3232

3333
var ErrInput = errors.New("input not valid")
34+
35+
var ErrExists = errors.New("item already exists")
Collapse file

‎internal/domain/index.go‎

Copy file name to clipboardExpand all lines: internal/domain/index.go
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ import (
2323

2424
type IndexRepo interface {
2525
Get(ctx context.Context, id model.IndexID) (model.Index, error)
26+
New(ctx context.Context, i *model.Index) error
27+
Update(ctx context.Context, id model.IndexID, title string, desc string) error
28+
Delete(ctx context.Context, id model.IndexID) error
2629

2730
CountSubjects(ctx context.Context, id model.IndexID, subjectType model.SubjectType) (int64, error)
2831
ListSubjects(
2932
ctx context.Context, id model.IndexID, subjectType model.SubjectType, limit, offset int,
3033
) ([]IndexSubject, error)
34+
AddOrUpdateIndexSubject(
35+
ctx context.Context, id model.IndexID, subjectID model.SubjectID, sort uint32, comment string,
36+
) (*IndexSubject, error)
37+
DeleteIndexSubject(
38+
ctx context.Context, id model.IndexID, subjectID model.SubjectID,
39+
) error
3140
}
3241

3342
type IndexSubject struct {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.