From f67e767d2d1e2aefbe014da5633ad7b231d055d0 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Tue, 14 May 2024 14:29:11 +0000 Subject: [PATCH 1/4] feat(collection): new api DeleteSubjectCollection --- internal/collections/domain.go | 4 ++ internal/collections/infra/mysql_repo.go | 11 ++++ internal/collections/infra/mysql_repo_test.go | 33 ++++++++++++ internal/mocks/CollectionRepo.go | 48 +++++++++++++++++ openapi/v0.yaml | 34 ++++++++++++ web/handler/user/delete_subject_collection.go | 53 +++++++++++++++++++ .../user/delete_subject_collection_test.go | 50 +++++++++++++++++ web/routes.go | 1 + 8 files changed, 234 insertions(+) create mode 100644 web/handler/user/delete_subject_collection.go create mode 100644 web/handler/user/delete_subject_collection_test.go diff --git a/internal/collections/domain.go b/internal/collections/domain.go index a3ccbb5cd..cad4d91a5 100644 --- a/internal/collections/domain.go +++ b/internal/collections/domain.go @@ -64,6 +64,10 @@ type Repo interface { update func(ctx context.Context, s *collection.Subject) (*collection.Subject, error), ) error + DeleteSubjectCollection( + ctx context.Context, userID model.UserID, subjectID model.SubjectID, + ) error + UpdateEpisodeCollection( ctx context.Context, userID model.UserID, subjectID model.SubjectID, diff --git a/internal/collections/infra/mysql_repo.go b/internal/collections/infra/mysql_repo.go index a42e46dec..f2eb6c362 100644 --- a/internal/collections/infra/mysql_repo.go +++ b/internal/collections/infra/mysql_repo.go @@ -117,6 +117,17 @@ func (r mysqlRepo) UpdateOrCreateSubjectCollection( return r.updateOrCreateSubjectCollection(ctx, userID, subject, at, ip, update, s) } +func (r mysqlRepo) DeleteSubjectCollection( + ctx context.Context, + userID model.UserID, + subjectID model.SubjectID, +) error { + _, err := r.q.SubjectCollection.WithContext(ctx). + Where(r.q.SubjectCollection.UserID.Eq(userID), r.q.SubjectCollection.SubjectID.Eq(subjectID)). + Delete() + return err +} + func (r mysqlRepo) updateOrCreateSubjectCollection( ctx context.Context, userID model.UserID, diff --git a/internal/collections/infra/mysql_repo_test.go b/internal/collections/infra/mysql_repo_test.go index c38945548..57887082c 100644 --- a/internal/collections/infra/mysql_repo_test.go +++ b/internal/collections/infra/mysql_repo_test.go @@ -23,6 +23,7 @@ import ( "github.com/trim21/go-phpserialize" "go.uber.org/zap" "gorm.io/gen/field" + "gorm.io/gorm" "github.com/bangumi/server/dal/dao" "github.com/bangumi/server/dal/query" @@ -415,6 +416,38 @@ func TestMysqlRepo_UpdateSubjectCollectionType(t *testing.T) { require.Zero(t, r.DoneTime) require.Zero(t, r.OnHoldTime) } + +func TestMysqlRepo_DeleteSubjectCollection(t *testing.T) { + t.Parallel() + test.RequireEnv(t, test.EnvMysql) + + const id model.UserID = 30000 + const subjectID model.SubjectID = 10000 + + repo, q := getRepo(t) + + test.RunAndCleanup(t, func() { + _, err := q.WithContext(context.Background()).SubjectCollection. + Where(q.SubjectCollection.SubjectID.Eq(subjectID), q.SubjectCollection.UserID.Eq(id)).Delete() + require.NoError(t, err) + }) + + err := q.WithContext(context.Background()).SubjectCollection.Create(&dao.SubjectCollection{ + UserID: id, + SubjectID: subjectID, + Rate: 2, + }) + require.NoError(t, err) + + err = repo.DeleteSubjectCollection(context.Background(), id, subjectID) + require.NoError(t, err) + + r, err := q.WithContext(context.Background()).SubjectCollection. + Where(q.SubjectCollection.SubjectID.Eq(subjectID), q.SubjectCollection.UserID.Eq(id)).Take() + require.ErrorIs(t, err, gorm.ErrRecordNotFound) + require.Nil(t, r) +} + func TestMysqlRepo_UpdateEpisodeCollection(t *testing.T) { test.RequireEnv(t, test.EnvMysql) t.Parallel() diff --git a/internal/mocks/CollectionRepo.go b/internal/mocks/CollectionRepo.go index 811b211b2..8bbf921d5 100644 --- a/internal/mocks/CollectionRepo.go +++ b/internal/mocks/CollectionRepo.go @@ -90,6 +90,54 @@ func (_c *CollectionRepo_CountSubjectCollections_Call) RunAndReturn(run func(con return _c } +// DeleteSubjectCollection provides a mock function with given fields: ctx, userID, subjectID +func (_m *CollectionRepo) DeleteSubjectCollection(ctx context.Context, userID uint32, subjectID uint32) error { + ret := _m.Called(ctx, userID, subjectID) + + if len(ret) == 0 { + panic("no return value specified for DeleteSubjectCollection") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uint32, uint32) error); ok { + r0 = rf(ctx, userID, subjectID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CollectionRepo_DeleteSubjectCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteSubjectCollection' +type CollectionRepo_DeleteSubjectCollection_Call struct { + *mock.Call +} + +// DeleteSubjectCollection is a helper method to define mock.On call +// - ctx context.Context +// - userID uint32 +// - subjectID uint32 +func (_e *CollectionRepo_Expecter) DeleteSubjectCollection(ctx interface{}, userID interface{}, subjectID interface{}) *CollectionRepo_DeleteSubjectCollection_Call { + return &CollectionRepo_DeleteSubjectCollection_Call{Call: _e.mock.On("DeleteSubjectCollection", ctx, userID, subjectID)} +} + +func (_c *CollectionRepo_DeleteSubjectCollection_Call) Run(run func(ctx context.Context, userID uint32, subjectID uint32)) *CollectionRepo_DeleteSubjectCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uint32), args[2].(uint32)) + }) + return _c +} + +func (_c *CollectionRepo_DeleteSubjectCollection_Call) Return(_a0 error) *CollectionRepo_DeleteSubjectCollection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *CollectionRepo_DeleteSubjectCollection_Call) RunAndReturn(run func(context.Context, uint32, uint32) error) *CollectionRepo_DeleteSubjectCollection_Call { + _c.Call.Return(run) + return _c +} + // GetSubjectCollection provides a mock function with given fields: ctx, userID, subjectID func (_m *CollectionRepo) GetSubjectCollection(ctx context.Context, userID uint32, subjectID uint32) (collection.UserSubjectCollection, error) { ret := _m.Called(ctx, userID, subjectID) diff --git a/openapi/v0.yaml b/openapi/v0.yaml index 10d03ec39..8cc637044 100644 --- a/openapi/v0.yaml +++ b/openapi/v0.yaml @@ -957,6 +957,40 @@ paths: "$ref": "#/components/schemas/ErrorDetail" security: - OptionalHTTPBearer: [] + delete: + tags: + - 收藏 + summary: 删除用户单个收藏 + description: | + 删除条目收藏状态 + + 会删除当前填写的评分、tags 和吐槽,不会影响章节进度 + operationId: deleteUserCollection + parameters: + - $ref: "#/components/parameters/path_subject_id" + responses: + "204": + description: Successful Response + "400": + description: Validation Error + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "401": + description: Unauthorized + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 用户不存在或者条目未收藏 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + security: + - OptionalHTTPBearer: [] "/v0/users/-/collections/{subject_id}/episodes": get: diff --git a/web/handler/user/delete_subject_collection.go b/web/handler/user/delete_subject_collection.go new file mode 100644 index 000000000..0bf766588 --- /dev/null +++ b/web/handler/user/delete_subject_collection.go @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see + +package user + +import ( + "errors" + "net/http" + + "github.com/labstack/echo/v4" + + "github.com/bangumi/server/domain/gerr" + "github.com/bangumi/server/internal/model" + "github.com/bangumi/server/web/accessor" + "github.com/bangumi/server/web/req" + "github.com/bangumi/server/web/res" +) + +func (h User) DeleteSubjectCollection(c echo.Context) error { + subjectID, err := req.ParseID(c.Param("subject_id")) + if err != nil { + return err + } + + return h.deleteSubjectCollection(c, subjectID) +} + +func (h User) deleteSubjectCollection(c echo.Context, subjectID model.SubjectID) error { + u := accessor.GetFromCtx(c) + + err := h.collect.DeleteSubjectCollection(c.Request().Context(), u.ID, subjectID) + if err != nil { + switch { + case errors.Is(err, gerr.ErrSubjectNotCollected): + return res.JSONError(c, err) + default: + return err + } + } + + return c.NoContent(http.StatusNoContent) +} diff --git a/web/handler/user/delete_subject_collection_test.go b/web/handler/user/delete_subject_collection_test.go new file mode 100644 index 000000000..9aef126d7 --- /dev/null +++ b/web/handler/user/delete_subject_collection_test.go @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see + +package user_test + +import ( + "fmt" + "net/http" + "testing" + + "github.com/labstack/echo/v4" + "github.com/stretchr/testify/mock" + "github.com/trim21/htest" + + "github.com/bangumi/server/internal/auth" + "github.com/bangumi/server/internal/mocks" + "github.com/bangumi/server/internal/model" + "github.com/bangumi/server/internal/pkg/test" +) + +func TestUser_DeleteSubjectCollection(t *testing.T) { + t.Parallel() + const uid model.UserID = 1 + const sid model.SubjectID = 8 + + a := mocks.NewAuthService(t) + a.EXPECT().GetByToken(mock.Anything, mock.Anything).Return(auth.Auth{ID: uid}, nil) + + c := mocks.NewCollectionRepo(t) + c.EXPECT().DeleteSubjectCollection(mock.Anything, uid, sid). + Return(nil) + + app := test.GetWebApp(t, test.Mock{CollectionRepo: c, AuthService: a}) + + htest.New(t, app). + Header(echo.HeaderAuthorization, "Bearer t"). + Delete(fmt.Sprintf("/v0/users/-/collections/%d", sid)). + ExpectCode(http.StatusNoContent) +} diff --git a/web/routes.go b/web/routes.go index dc071617c..d68263fee 100644 --- a/web/routes.go +++ b/web/routes.go @@ -83,6 +83,7 @@ func AddRouters( v0.GET("/users/-/collections/:subject_id/episodes", userHandler.GetSubjectEpisodeCollection, mw.NeedLogin) v0.PATCH("/users/-/collections/:subject_id", userHandler.PatchSubjectCollection, req.JSON, mw.NeedLogin) v0.POST("/users/-/collections/:subject_id", userHandler.PostSubjectCollection, req.JSON, mw.NeedLogin) + v0.DELETE("/users/-/collections/:subject_id", userHandler.DeleteSubjectCollection, mw.NeedLogin) v0.PATCH("/users/-/collections/:subject_id/episodes", userHandler.PatchEpisodeCollectionBatch, req.JSON, mw.NeedLogin) From b1a0c71469c3dc6f114b4703cf7796962a3ab0e1 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 10 Dec 2024 23:20:57 +0800 Subject: [PATCH 2/4] revert proto change --- generated/proto/go/api/v1/timeline.pb.go | 218 +++++++---------------- proto | 2 +- 2 files changed, 64 insertions(+), 156 deletions(-) diff --git a/generated/proto/go/api/v1/timeline.pb.go b/generated/proto/go/api/v1/timeline.pb.go index 2728da773..de176aca5 100644 --- a/generated/proto/go/api/v1/timeline.pb.go +++ b/generated/proto/go/api/v1/timeline.pb.go @@ -262,16 +262,8 @@ type Subject struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - NameCn string `protobuf:"bytes,4,opt,name=name_cn,json=nameCn,proto3" json:"name_cn,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - Image string `protobuf:"bytes,5,opt,name=image,proto3" json:"image,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - Series bool `protobuf:"varint,6,opt,name=series,proto3" json:"series,omitempty"` + Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` VolsTotal uint32 `protobuf:"varint,7,opt,name=vols_total,json=volsTotal,proto3" json:"vols_total,omitempty"` EpsTotal uint32 `protobuf:"varint,8,opt,name=eps_total,json=epsTotal,proto3" json:"eps_total,omitempty"` } @@ -322,38 +314,6 @@ func (x *Subject) GetType() uint32 { return 0 } -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Subject) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Subject) GetNameCn() string { - if x != nil { - return x.NameCn - } - return "" -} - -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Subject) GetImage() string { - if x != nil { - return x.Image - } - return "" -} - -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Subject) GetSeries() bool { - if x != nil { - return x.Series - } - return false -} - func (x *Subject) GetVolsTotal() uint32 { if x != nil { return x.VolsTotal @@ -374,14 +334,6 @@ type Episode struct { unknownFields protoimpl.UnknownFields Id uint32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - NameCn string `protobuf:"bytes,4,opt,name=name_cn,json=nameCn,proto3" json:"name_cn,omitempty"` - // Deprecated: Marked as deprecated in api/v1/timeline.proto. - Sort float64 `protobuf:"fixed64,5,opt,name=sort,proto3" json:"sort,omitempty"` } func (x *Episode) Reset() { @@ -423,38 +375,6 @@ func (x *Episode) GetId() uint32 { return 0 } -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Episode) GetType() uint32 { - if x != nil { - return x.Type - } - return 0 -} - -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Episode) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Episode) GetNameCn() string { - if x != nil { - return x.NameCn - } - return "" -} - -// Deprecated: Marked as deprecated in api/v1/timeline.proto. -func (x *Episode) GetSort() float64 { - if x != nil { - return x.Sort - } - return 0 -} - // The request message containing the user's name. type SubjectCollectRequest struct { state protoimpl.MessageState @@ -695,83 +615,71 @@ var file_api_v1_timeline_proto_rawDesc = []byte{ 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x22, 0x28, 0x0a, 0x16, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, - 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x22, 0xd4, 0x01, - 0x0a, 0x07, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x07, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x63, 0x6e, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, 0x06, 0x6e, 0x61, 0x6d, 0x65, - 0x43, 0x6e, 0x12, 0x18, 0x0a, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x06, - 0x73, 0x65, 0x72, 0x69, 0x65, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x42, 0x02, 0x18, 0x01, - 0x52, 0x06, 0x73, 0x65, 0x72, 0x69, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x76, 0x6f, 0x6c, 0x73, - 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x76, 0x6f, - 0x6c, 0x73, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x70, 0x73, 0x5f, 0x74, - 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x65, 0x70, 0x73, 0x54, - 0x6f, 0x74, 0x61, 0x6c, 0x22, 0x7e, 0x0a, 0x07, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x12, - 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, - 0x16, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x42, 0x02, 0x18, - 0x01, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x1b, 0x0a, 0x07, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x63, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x02, 0x18, 0x01, 0x52, 0x06, 0x6e, 0x61, 0x6d, 0x65, 0x43, 0x6e, 0x12, 0x16, 0x0a, 0x04, - 0x73, 0x6f, 0x72, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x42, 0x02, 0x18, 0x01, 0x52, 0x04, - 0x73, 0x6f, 0x72, 0x74, 0x22, 0xce, 0x01, 0x0a, 0x15, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, + 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x22, 0x6f, 0x0a, + 0x07, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x0a, + 0x76, 0x6f, 0x6c, 0x73, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x09, 0x76, 0x6f, 0x6c, 0x73, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x12, 0x1b, 0x0a, 0x09, 0x65, + 0x70, 0x73, 0x5f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, + 0x65, 0x70, 0x73, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x4a, 0x04, 0x08, 0x03, 0x10, 0x07, 0x22, 0x1f, + 0x0a, 0x07, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x4a, 0x04, 0x08, 0x02, 0x10, 0x06, 0x22, + 0xce, 0x01, 0x0a, 0x15, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, + 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, + 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, + 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, + 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x1e, 0x0a, + 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, + 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x61, 0x74, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x61, 0x74, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, + 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x0c, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, + 0x22, 0x80, 0x01, 0x0a, 0x15, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6c, 0x6c, + 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, + 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, + 0x72, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x04, 0x6c, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x70, 0x69, 0x73, 0x6f, + 0x64, 0x65, 0x52, 0x04, 0x6c, 0x61, 0x73, 0x74, 0x12, 0x29, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x22, 0x9c, 0x01, 0x0a, 0x16, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, + 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, - 0x72, 0x61, 0x74, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x61, 0x74, 0x65, - 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, - 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0c, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x80, 0x01, 0x0a, 0x15, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, - 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x04, 0x6c, 0x61, 0x73, 0x74, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, - 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x6c, 0x61, 0x73, 0x74, 0x12, 0x29, 0x0a, - 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, - 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x9c, 0x01, 0x0a, 0x16, 0x53, 0x75, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x29, 0x0a, 0x07, - 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, - 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x70, 0x73, 0x5f, 0x75, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x65, 0x70, 0x73, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x76, 0x6f, 0x6c, 0x73, 0x5f, 0x75, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x76, 0x6f, 0x6c, - 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x32, 0xc5, 0x02, 0x0a, 0x0f, 0x54, 0x69, 0x6d, 0x65, - 0x4c, 0x69, 0x6e, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x36, 0x0a, 0x05, 0x48, - 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, - 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6f, - 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x12, 0x1d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, - 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x54, 0x0a, 0x0f, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0e, - 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x12, 0x1d, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, - 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, 0x6f, - 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, - 0x1f, 0x5a, 0x1d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, - 0x6e, 0x67, 0x75, 0x6d, 0x69, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x70, 0x73, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x65, 0x70, 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x76, 0x6f, 0x6c, 0x73, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x76, 0x6f, 0x6c, 0x73, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x32, 0xc5, 0x02, 0x0a, 0x0f, 0x54, 0x69, 0x6d, 0x65, 0x4c, 0x69, 0x6e, 0x65, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x36, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, + 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x48, + 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, + 0x0a, 0x0e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, + 0x12, 0x1d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, + 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, + 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x54, 0x0a, 0x0f, 0x53, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x72, 0x6f, 0x67, + 0x72, 0x65, 0x73, 0x73, 0x12, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0e, 0x45, 0x70, 0x69, 0x73, 0x6f, + 0x64, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x12, 0x1d, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x76, 0x31, 0x2e, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x31, 0x2e, 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x1f, 0x5a, 0x1d, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x6e, 0x67, 0x75, 0x6d, 0x69, + 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/proto b/proto index 134977239..7475c4b23 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 134977239d0a241d32ae029076c31b55b070650f +Subproject commit 7475c4b237d2541de47d726ded88560405f17013 From 809b852ce4b3d34009ba7b29bca12fb377ec481e Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 10 Dec 2024 23:25:05 +0800 Subject: [PATCH 3/4] set type to 0 on delete --- internal/collections/infra/mysql_repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/collections/infra/mysql_repo.go b/internal/collections/infra/mysql_repo.go index 204920c42..ac09d6f0d 100644 --- a/internal/collections/infra/mysql_repo.go +++ b/internal/collections/infra/mysql_repo.go @@ -128,7 +128,7 @@ func (r mysqlRepo) DeleteSubjectCollection( ) error { _, err := r.q.SubjectCollection.WithContext(ctx). Where(r.q.SubjectCollection.UserID.Eq(userID), r.q.SubjectCollection.SubjectID.Eq(subjectID)). - Delete() + UpdateSimple(r.q.SubjectCollection.Type.Value(0)) return err } From 0f76d740c3b33f9db505e9fa5278dca0c1ca170b Mon Sep 17 00:00:00 2001 From: Trim21 Date: Tue, 10 Dec 2024 23:33:07 +0800 Subject: [PATCH 4/4] use raw sql --- dal/query/export_db.go | 2 +- internal/auth/mysql_repository_test.go | 2 +- internal/collections/infra/mysql_repo.go | 25 ++++++++++++++----- internal/collections/infra/mysql_repo_test.go | 4 +-- internal/tag/mysql_repo_test.go | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/dal/query/export_db.go b/dal/query/export_db.go index bac903af6..46ca5d6c3 100644 --- a/dal/query/export_db.go +++ b/dal/query/export_db.go @@ -18,6 +18,6 @@ import ( "gorm.io/gorm" ) -func (q *Query) DB() *gorm.DB { +func (q *Query) RawDB() *gorm.DB { return q.db } diff --git a/internal/auth/mysql_repository_test.go b/internal/auth/mysql_repository_test.go index 0320de7ac..6c7907127 100644 --- a/internal/auth/mysql_repository_test.go +++ b/internal/auth/mysql_repository_test.go @@ -37,7 +37,7 @@ import ( func getRepo(t *testing.T) (auth.Repo, *query.Query) { t.Helper() q := query.Use(test.GetGorm(t)) - repo := auth.NewMysqlRepo(q, zap.NewNop(), sqlx.NewDb(lo.Must(q.DB().DB()), "mysql")) + repo := auth.NewMysqlRepo(q, zap.NewNop(), sqlx.NewDb(lo.Must(q.RawDB().DB()), "mysql")) return repo, q } diff --git a/internal/collections/infra/mysql_repo.go b/internal/collections/infra/mysql_repo.go index ac09d6f0d..438b184c1 100644 --- a/internal/collections/infra/mysql_repo.go +++ b/internal/collections/infra/mysql_repo.go @@ -126,9 +126,22 @@ func (r mysqlRepo) DeleteSubjectCollection( userID model.UserID, subjectID model.SubjectID, ) error { - _, err := r.q.SubjectCollection.WithContext(ctx). - Where(r.q.SubjectCollection.UserID.Eq(userID), r.q.SubjectCollection.SubjectID.Eq(subjectID)). - UpdateSimple(r.q.SubjectCollection.Type.Value(0)) + err := r.q.RawDB().Exec(` + UPDATE chii_subject_interests set interest_type = 0, + interest_rate = 0, + interest_comment = 0, + interest_has_comment = 0, + interest_tag = '', + interest_ep_status = 0, + interest_vol_status = 0, + interest_wish_dateline = 0, + interest_doing_dateline = 0, + interest_collect_dateline = 0, + interest_on_hold_dateline = 0, + interest_dropped_dateline = 0 + where interest_uid = ? and interest_subject_id = ? +`, userID, subjectID).Error + return err } @@ -319,7 +332,7 @@ func (r mysqlRepo) reCountSubjectTags(ctx context.Context, tx *query.Query, return true }) - db := tx.DB().WithContext(ctx) + db := tx.RawDB().WithContext(ctx) err = db.Exec(` update chii_tag_neue_index as ti @@ -565,7 +578,7 @@ func (r mysqlRepo) reCountSubjectCollection(ctx context.Context, subjectID model } return r.q.Transaction(func(tx *query.Query) error { - err := tx.DB().WithContext(ctx).Raw(` + err := tx.RawDB().WithContext(ctx).Raw(` select interest_type as type, count(interest_type) as total from chii_subject_interests where interest_subject_id = ? group by interest_type @@ -614,7 +627,7 @@ func (r mysqlRepo) reCountSubjectRate(ctx context.Context, subjectID model.Subje for _, rate := range []uint8{before, after} { var count uint32 if rate != 0 { - err := tx.DB().WithContext(ctx).Raw(` + err := tx.RawDB().WithContext(ctx).Raw(` select count(*) from chii_subject_interests where interest_subject_id = ? and interest_private = 0 and interest_rate = ? `, subjectID, rate).Scan(&count).Error diff --git a/internal/collections/infra/mysql_repo_test.go b/internal/collections/infra/mysql_repo_test.go index 6a1c42950..d2836bcd6 100644 --- a/internal/collections/infra/mysql_repo_test.go +++ b/internal/collections/infra/mysql_repo_test.go @@ -242,7 +242,7 @@ func TestMysqlRepo_UpdateOrCreateSubjectCollection(t *testing.T) { now := time.Now() - // DB 里没有数据 + // RawDB 里没有数据 _, err = table.WithContext(context.TODO()).Where(table.SubjectID.Eq(sid), table.UserID.Eq(uid)).Take() require.Error(t, err) @@ -253,7 +253,7 @@ func TestMysqlRepo_UpdateOrCreateSubjectCollection(t *testing.T) { }) require.NoError(t, err) - // DB 里有数据 + // RawDB 里有数据 _, err = table.WithContext(context.TODO()).Where(table.SubjectID.Eq(sid), table.UserID.Eq(uid)).Take() require.NoError(t, err) diff --git a/internal/tag/mysql_repo_test.go b/internal/tag/mysql_repo_test.go index 31cc1585d..e1cf92d14 100644 --- a/internal/tag/mysql_repo_test.go +++ b/internal/tag/mysql_repo_test.go @@ -32,7 +32,7 @@ import ( func getRepo(t *testing.T) tag.Repo { t.Helper() q := query.Use(test.GetGorm(t)) - repo, err := tag.NewMysqlRepo(q, zap.NewNop(), sqlx.NewDb(lo.Must(q.DB().DB()), "mysql")) + repo, err := tag.NewMysqlRepo(q, zap.NewNop(), sqlx.NewDb(lo.Must(q.RawDB().DB()), "mysql")) require.NoError(t, err) return repo