From 56b8463707ea548f9c66088315130286f51076a0 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Mon, 14 Aug 2023 20:24:00 +0800 Subject: [PATCH] sqlx: add miss method for following --- internal/dao/sakila/following.go | 59 +++++++++++++++++++++++++++ internal/dao/sakila/sakila.go | 2 + internal/dao/sakila/yesql/cc/yesql.go | 20 +++++++++ internal/dao/sakila/yesql/yesql.sql | 8 ++++ 4 files changed, 89 insertions(+) create mode 100644 internal/dao/sakila/following.go diff --git a/internal/dao/sakila/following.go b/internal/dao/sakila/following.go new file mode 100644 index 00000000..8073238b --- /dev/null +++ b/internal/dao/sakila/following.go @@ -0,0 +1,59 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package sakila + +import ( + "github.com/jmoiron/sqlx" + "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" +) + +var ( + _ core.FollowingManageService = (*followingManageSrv)(nil) +) + +type followingManageSrv struct { + *sqlxSrv + q *cc.FollowingManager +} + +func (s *followingManageSrv) FollowUser(userId int64, followId int64) error { + // TODO + return cs.ErrNotImplemented +} + +func (s *followingManageSrv) UnfollowUser(userId int64, followId int64) error { + // TDOO + return cs.ErrNotImplemented +} + +func (s *followingManageSrv) ListFollows(userId int64, limit, offset int) (*ms.ContactList, error) { + // TODO + return nil, cs.ErrNotImplemented +} + +func (s *followingManageSrv) ListFollowings(userId int64, limit, offset int) (*ms.ContactList, error) { + // TODO + return nil, cs.ErrNotImplemented +} + +func (s *followingManageSrv) GetFollowCount(userId int64) (int64, int64, error) { + // TODO + return 0, 0, cs.ErrNotImplemented +} + +func (s *followingManageSrv) IsFollow(userId int64, followId int64) bool { + // TODO + return false +} + +func newFollowingManageService(db *sqlx.DB) core.FollowingManageService { + return &followingManageSrv{ + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildFollowingManager), + } +} diff --git a/internal/dao/sakila/sakila.go b/internal/dao/sakila/sakila.go index a232424b..678dc677 100644 --- a/internal/dao/sakila/sakila.go +++ b/internal/dao/sakila/sakila.go @@ -38,6 +38,7 @@ type dataSrv struct { core.CommentManageService core.UserManageService core.ContactManageService + core.FollowingManageService core.SecurityService core.AttachmentCheckService } @@ -105,6 +106,7 @@ func NewDataService() (core.DataService, core.VersionInfo) { CommentManageService: newCommentManageService(_db), UserManageService: newUserManageService(_db), ContactManageService: newContactManageService(_db), + FollowingManageService: newFollowingManageService(_db), SecurityService: newSecurityService(_db, pvs), AttachmentCheckService: security.NewAttachmentCheckService(), } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 87941a71..0c114d0a 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -52,6 +52,7 @@ const ( _ContactManager_TotalFriendsById = `SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0` _FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _FollowingManager_CreateFollowing = `INSERT INTO @following (user_id, follow_id, created_on) VALUES (?, ?, ?)` _FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _FriendIndex_UserInfo = `SELECT * FROM @user WHERE username=?` _LightIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` @@ -214,6 +215,11 @@ type FollowIndexA struct { UserInfo *sqlx.Stmt `yesql:"user_info"` } +type FollowingManager struct { + yesql.Namespace `yesql:"following_manager"` + CreateFollowing *sqlx.Stmt `yesql:"create_following"` +} + type FriendIndex struct { yesql.Namespace `yesql:"friend_index"` UserInfo *sqlx.Stmt `yesql:"user_info"` @@ -564,6 +570,20 @@ func BuildFollowIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fo return } +func BuildFollowingManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FollowingManager, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &FollowingManager{} + if obj.CreateFollowing, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FollowingManager_CreateFollowing))); err != nil { + return + } + return +} + func BuildFriendIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *FriendIndex, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index fed99627..2cdac69e 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -141,6 +141,14 @@ UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0; +-------------------------------------------------------------------------------- +-- following_manager sql dml +-------------------------------------------------------------------------------- + +-- name: create_following@following_manager +-- prepare: stmt +INSERT INTO @following (user_id, follow_id, created_on) VALUES (?, ?, ?); + -------------------------------------------------------------------------------- -- contact_manager sql dml --------------------------------------------------------------------------------