diff --git a/go.mod b/go.mod index 047fa70a..a6d2f49f 100644 --- a/go.mod +++ b/go.mod @@ -18,11 +18,13 @@ require ( github.com/gin-gonic/gin v1.8.1 github.com/go-redis/redis/v8 v8.11.4 github.com/go-resty/resty/v2 v2.7.0 + github.com/go-sql-driver/mysql v1.6.0 github.com/goccy/go-json v0.9.7 github.com/gofrs/uuid v4.0.0+incompatible github.com/golang-jwt/jwt/v4 v4.4.2 github.com/golang-migrate/migrate/v4 v4.15.2 github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible + github.com/jackc/pgx/v5 v5.2.0 github.com/jmoiron/sqlx v1.3.5 github.com/json-iterator/go v1.1.12 github.com/meilisearch/meilisearch-go v0.21.0 @@ -59,7 +61,6 @@ require ( github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.10.1 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-querystring v1.1.0 // indirect @@ -109,9 +110,9 @@ require ( github.com/ugorji/go/codec v1.2.7 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d // indirect - go.uber.org/atomic v1.9.0 // indirect + go.uber.org/atomic v1.10.0 // indirect golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect - golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect + golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect diff --git a/go.sum b/go.sum index e09346b6..bc0561be 100644 --- a/go.sum +++ b/go.sum @@ -888,6 +888,8 @@ github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1r github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= github.com/jackc/pgx/v4 v4.16.1 h1:JzTglcal01DrghUqt+PmzWsZx/Yh7SC/CTQmSBMTd0Y= github.com/jackc/pgx/v4 v4.16.1/go.mod h1:SIhx0D5hoADaiXZVyv+3gSm3LCIIINTVO0PficsvWGQ= +github.com/jackc/pgx/v5 v5.2.0 h1:NdPpngX0Y6z6XDFKqmFQaE+bCtkqzvQIOt1wvBlAqs8= +github.com/jackc/pgx/v5 v5.2.0/go.mod h1:Ptn7zmohNsWEsdxRawMzk3gaKma2obW+NWTnKa0S4nk= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= @@ -1481,8 +1483,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= -go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= @@ -1534,8 +1536,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM= +golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/internal/conf/db_sqlx.go b/internal/conf/db_sqlx.go index bfdc7a95..24477f12 100644 --- a/internal/conf/db_sqlx.go +++ b/internal/conf/db_sqlx.go @@ -11,6 +11,9 @@ import ( "github.com/alimy/cfg" "github.com/jmoiron/sqlx" "github.com/sirupsen/logrus" + + _ "github.com/go-sql-driver/mysql" + _ "github.com/jackc/pgx/v5/stdlib" ) var ( @@ -32,7 +35,7 @@ func newSqlxDB() (db *sqlx.DB, err error) { if cfg.If("MySQL") { db, err = sqlx.Open("mysql", MysqlSetting.Dsn()) } else if cfg.If("PostgreSQL") || cfg.If("Postgres") { - db, err = sqlx.Open("postgres", PostgresSetting.Dsn()) + db, err = sqlx.Open("pgx", PostgresSetting.Dsn()) } else if cfg.If("Sqlite3") { var ( driver string diff --git a/internal/dao/dao.go b/internal/dao/dao.go index d0b05c9c..9d448bb3 100644 --- a/internal/dao/dao.go +++ b/internal/dao/dao.go @@ -30,9 +30,9 @@ func DataService() core.DataService { var v core.VersionInfo if cfg.If("Gorm") { ds, v = jinzhu.NewDataService() - } else if cfg.If("Sqlx") && cfg.If("MySQL") { + } else if cfg.If("Sqlx") { ds, v = sakila.NewDataService() - } else if cfg.If("Sqlx") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) { + } else if cfg.If("Sqlc") && (cfg.If("Postgres") || cfg.If("PostgreSQL")) { ds, v = slonik.NewDataService() } else { // default use gorm as orm for sql database diff --git a/internal/dao/jinzhu/messages.go b/internal/dao/jinzhu/messages.go index 32edaac2..25b429f6 100644 --- a/internal/dao/jinzhu/messages.go +++ b/internal/dao/jinzhu/messages.go @@ -24,32 +24,32 @@ func newMessageService(db *gorm.DB) core.MessageService { } } -func (d *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) { - return msg.Create(d.db) +func (s *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) { + return msg.Create(s.db) } -func (d *messageServant) GetUnreadCount(userID int64) (int64, error) { - return (&dbr.Message{}).Count(d.db, &dbr.ConditionsT{ +func (s *messageServant) GetUnreadCount(userID int64) (int64, error) { + return (&dbr.Message{}).Count(s.db, &dbr.ConditionsT{ "receiver_user_id": userID, "is_read": dbr.MsgStatusUnread, }) } -func (d *messageServant) GetMessageByID(id int64) (*core.Message, error) { +func (s *messageServant) GetMessageByID(id int64) (*core.Message, error) { return (&dbr.Message{ Model: &dbr.Model{ ID: id, }, - }).Get(d.db) + }).Get(s.db) } -func (d *messageServant) ReadMessage(message *core.Message) error { +func (s *messageServant) ReadMessage(message *core.Message) error { message.IsRead = 1 - return message.Update(d.db) + return message.Update(s.db) } -func (d *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { - messages, err := (&dbr.Message{}).List(d.db, conditions, offset, limit) +func (s *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { + messages, err := (&dbr.Message{}).List(s.db, conditions, offset, limit) if err != nil { return nil, err } @@ -63,6 +63,6 @@ func (d *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit return mfs, nil } -func (d *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) { - return (&dbr.Message{}).Count(d.db, conditions) +func (s *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) { + return (&dbr.Message{}).Count(s.db, conditions) } diff --git a/internal/dao/jinzhu/wallet.go b/internal/dao/jinzhu/wallet.go index 7b2023d7..e74710c6 100644 --- a/internal/dao/jinzhu/wallet.go +++ b/internal/dao/jinzhu/wallet.go @@ -25,49 +25,49 @@ func newWalletService(db *gorm.DB) core.WalletService { } } -func (d *walletServant) GetRechargeByID(id int64) (*core.WalletRecharge, error) { +func (s *walletServant) GetRechargeByID(id int64) (*core.WalletRecharge, error) { recharge := &dbr.WalletRecharge{ Model: &dbr.Model{ ID: id, }, } - return recharge.Get(d.db) + return recharge.Get(s.db) } -func (d *walletServant) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { +func (s *walletServant) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { recharge := &dbr.WalletRecharge{ UserID: userId, Amount: amount, } - return recharge.Create(d.db) + return recharge.Create(s.db) } -func (d *walletServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *walletServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { statement := &dbr.WalletStatement{ UserID: userID, } - return statement.List(d.db, &dbr.ConditionsT{ + return statement.List(s.db, &dbr.ConditionsT{ "ORDER": "id DESC", }, offset, limit) } -func (d *walletServant) GetUserWalletBillCount(userID int64) (int64, error) { +func (s *walletServant) GetUserWalletBillCount(userID int64) (int64, error) { statement := &dbr.WalletStatement{ UserID: userID, } - return statement.Count(d.db, &dbr.ConditionsT{}) + return statement.Count(s.db, &dbr.ConditionsT{}) } -func (d *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { +func (s *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { user, _ := (&dbr.User{ Model: &dbr.Model{ ID: recharge.UserID, }, - }).Get(d.db) + }).Get(s.db) - return d.db.Transaction(func(tx *gorm.DB) error { + return s.db.Transaction(func(tx *gorm.DB) error { // 扣除金额 if err := tx.Model(user).Update("balance", gorm.Expr("balance + ?", recharge.Amount)).Error; err != nil { // 返回任何错误都会回滚事务 @@ -97,8 +97,8 @@ func (d *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tra }) } -func (d *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.User) error { - return d.db.Transaction(func(tx *gorm.DB) error { +func (s *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.User) error { + return s.db.Transaction(func(tx *gorm.DB) error { // 扣除金额 if err := tx.Model(user).Update("balance", gorm.Expr("balance - ?", post.AttachmentPrice)).Error; err != nil { // 返回任何错误都会回滚事务 @@ -133,7 +133,7 @@ func (d *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.U ID: post.UserID, }, } - master, _ = master.Get(d.db) + master, _ = master.Get(s.db) if err := tx.Model(master).Update("balance", gorm.Expr("balance + ?", income)).Error; err != nil { // 返回任何错误都会回滚事务 diff --git a/internal/dao/sakila/authority.go b/internal/dao/sakila/authority.go new file mode 100644 index 00000000..8e2e0fb2 --- /dev/null +++ b/internal/dao/sakila/authority.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/pkg/debug" +) + +var ( + _ core.AuthorizationManageService = (*authorizationManageServant)(nil) +) + +type authorizationManageServant struct { + db *sqlx.DB + stmtIdx *sqlx.Stmt + stmtUpdateFriend *sqlx.Stmt +} + +func (s *authorizationManageServant) IsAllow(user *core.User, action *core.Action) bool { + // TODO + debug.NotImplemented() + return false +} + +func (s *authorizationManageServant) MyFriendSet(userId int64) core.FriendSet { + // TODO + debug.NotImplemented() + return nil +} + +func (s *authorizationManageServant) BeFriendFilter(userId int64) core.FriendFilter { + // TODO + debug.NotImplemented() + return nil +} + +func (s *authorizationManageServant) BeFriendIds(userId int64) ([]int64, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *authorizationManageServant) isFriend(userId int64, friendId int64) bool { + // TODO + debug.NotImplemented() + return false +} + +func newAuthorizationManageService(db *sqlx.DB) core.AuthorizationManageService { + return &authorizationManageServant{ + db: db, + stmtIdx: c(`SELECT * FROM @person WHERE first_name=?`), + stmtUpdateFriend: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go new file mode 100644 index 00000000..c4a25eac --- /dev/null +++ b/internal/dao/sakila/comments.go @@ -0,0 +1,110 @@ +// 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/pkg/debug" +) + +var ( + _ core.CommentService = (*commentServant)(nil) + _ core.CommentManageService = (*commentManageServant)(nil) +) + +type commentServant struct { + db *sqlx.DB + stmtGetComments *sqlx.Stmt + stmtGetReply *sqlx.Stmt +} + +type commentManageServant struct { + db *sqlx.DB + stmtDelComments *sqlx.Stmt + stmtAddComents *sqlx.Stmt +} + +func (s *commentServant) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentServant) GetCommentByID(id int64) (*core.Comment, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentServant) GetCommentReplyByID(id int64) (*core.CommentReply, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentServant) GetCommentCount(conditions *core.ConditionsT) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *commentServant) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentServant) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentManageServant) DeleteComment(comment *core.Comment) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *commentManageServant) CreateComment(comment *core.Comment) (*core.Comment, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentManageServant) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *commentManageServant) DeleteCommentReply(reply *core.CommentReply) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *commentManageServant) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func newCommentService(db *sqlx.DB) core.CommentService { + return &commentServant{ + db: db, + stmtGetComments: c(`SELECT * FROM @person WHERE first_name=?`), + stmtGetReply: c(`SELECT * FROM @person WHERE first_name=?`), + } +} + +func newCommentManageService(db *sqlx.DB) core.CommentManageService { + return &commentManageServant{ + db: db, + stmtAddComents: c(`SELECT * FROM @person WHERE first_name=?`), + stmtDelComments: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go new file mode 100644 index 00000000..b7b8eba2 --- /dev/null +++ b/internal/dao/sakila/contacts.go @@ -0,0 +1,65 @@ +// 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/pkg/debug" +) + +var ( + _ core.ContactManageService = (*contactManageServant)(nil) +) + +type contactManageServant struct { + db *sqlx.DB + stmtAddFriend *sqlx.Stmt + stmtDelFriend *sqlx.Stmt +} + +func (s *contactManageServant) RequestingFriend(userId int64, friendId int64, greetings string) (err error) { + // TODO + debug.NotImplemented() + return nil +} + +func (s *contactManageServant) AddFriend(userId int64, friendId int64) (err error) { + // TODO + debug.NotImplemented() + return nil +} + +func (s *contactManageServant) RejectFriend(userId int64, friendId int64) (err error) { + // TODO + debug.NotImplemented() + return nil +} + +func (s *contactManageServant) DeleteFriend(userId int64, friendId int64) (err error) { + // TODO + debug.NotImplemented() + return nil +} + +func (s *contactManageServant) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *contactManageServant) IsFriend(userId int64, friendId int64) bool { + // TODO + debug.NotImplemented() + return false +} + +func newContactManageService(db *sqlx.DB) core.ContactManageService { + return &contactManageServant{ + db: db, + stmtAddFriend: c(`SELECT * FROM @person WHERE first_name=?`), + stmtDelFriend: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/index.go b/internal/dao/sakila/index.go index c382993b..d70ec2ec 100644 --- a/internal/dao/sakila/index.go +++ b/internal/dao/sakila/index.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/pkg/debug" ) var ( @@ -27,29 +28,27 @@ type simpleIndexPostsServant struct { // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; func (s *indexPostsServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { // TODO + debug.NotImplemented() return nil, nil } // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { // TODO + debug.NotImplemented() return nil, nil } func newIndexPostsService(db *sqlx.DB) core.IndexPostsService { return &indexPostsServant{ - db: db, - stmtIndex: c(` - SELECT * FROM @person WHERE first_name=? - `), + db: db, + stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`), } } func newSimpleIndexPostsService(db *sqlx.DB) core.IndexPostsService { return &simpleIndexPostsServant{ - db: db, - stmtIndex: c(` - SELECT * FROM @person WHERE first_name=? - `), + db: db, + stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`), } } diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go new file mode 100644 index 00000000..d0539edf --- /dev/null +++ b/internal/dao/sakila/messages.go @@ -0,0 +1,67 @@ +// 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/pkg/debug" +) + +var ( + _ core.MessageService = (*messageServant)(nil) +) + +type messageServant struct { + db *sqlx.DB + stmtAddMsg *sqlx.Stmt + stmtGetMsg *sqlx.Stmt + stmtReadMsg *sqlx.Stmt +} + +func (s *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *messageServant) GetUnreadCount(userID int64) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *messageServant) GetMessageByID(id int64) (*core.Message, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *messageServant) ReadMessage(message *core.Message) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func newMessageService(db *sqlx.DB) core.MessageService { + return &messageServant{ + db: db, + stmtAddMsg: c(`SELECT * FROM @person WHERE first_name=?`), + stmtGetMsg: c(`SELECT * FROM @person WHERE first_name=?`), + stmtReadMsg: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/sakila.go b/internal/dao/sakila/sakila.go index 228264f0..354b7525 100644 --- a/internal/dao/sakila/sakila.go +++ b/internal/dao/sakila/sakila.go @@ -1,25 +1,86 @@ -// Copyright 2022 ROC. All rights reserved. +// 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. -// Core service implement base sqlx+mysql. All sub-service -// will declare here and provide initial function. - package sakila import ( + "github.com/Masterminds/semver/v3" + "github.com/alimy/cfg" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/dao/cache" + "github.com/rocboss/paopao-ce/internal/dao/security" "github.com/sirupsen/logrus" ) +var ( + _ core.DataService = (*dataServant)(nil) + _ core.VersionInfo = (*dataServant)(nil) +) + +type dataServant struct { + core.IndexPostsService + core.WalletService + core.MessageService + core.TopicService + core.TweetService + core.TweetManageService + core.TweetHelpService + core.CommentService + core.CommentManageService + core.UserManageService + core.ContactManageService + core.SecurityService + core.AttachmentCheckService +} + func NewDataService() (core.DataService, core.VersionInfo) { - logrus.Fatal("not support now") - _ = newIndexPostsService(sqlxDB()) - _ = newSimpleIndexPostsService(sqlxDB()) - return nil, nil + // initialize CacheIndex if needed + var ( + c core.CacheIndexService + v core.VersionInfo + ) + db := sqlxDB() + pvs := security.NewPhoneVerifyService() + + i := newIndexPostsService(db) + if cfg.If("SimpleCacheIndex") { + i = newSimpleIndexPostsService(db) + c, v = cache.NewSimpleCacheIndexService(i) + } else if cfg.If("BigCacheIndex") { + a := newAuthorizationManageService(db) + c, v = cache.NewBigCacheIndexService(i, a) + } else { + c, v = cache.NewNoneCacheIndexService(i) + } + logrus.Infof("use %s as cache index service by version: %s", v.Name(), v.Version()) + + ds := &dataServant{ + IndexPostsService: c, + WalletService: newWalletService(db), + MessageService: newMessageService(db), + TopicService: newTopicService(db), + TweetService: newTweetService(db), + TweetManageService: newTweetManageService(db, c), + TweetHelpService: newTweetHelpService(db), + CommentService: newCommentService(db), + CommentManageService: newCommentManageService(db), + UserManageService: newUserManageService(db), + ContactManageService: newContactManageService(db), + SecurityService: newSecurityService(db, pvs), + AttachmentCheckService: security.NewAttachmentCheckService(), + } + return ds, ds } func NewAuthorizationManageService() core.AuthorizationManageService { - logrus.Fatal("not support now") - return nil + return newAuthorizationManageService(sqlxDB()) +} + +func (s *dataServant) Name() string { + return "Sqlx" +} + +func (s *dataServant) Version() *semver.Version { + return semver.MustParse("v0.1.0") } diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go new file mode 100644 index 00000000..457b407d --- /dev/null +++ b/internal/dao/sakila/security.go @@ -0,0 +1,52 @@ +// 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/pkg/debug" +) + +var ( + _ core.SecurityService = (*securityServant)(nil) +) + +type securityServant struct { + db *sqlx.DB + phoneVerify core.PhoneVerifyService + stmtAddCaptcha *sqlx.Stmt + stmtGetCaptcha *sqlx.Stmt +} + +// GetLatestPhoneCaptcha 获取最新短信验证码 +func (s *securityServant) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +// UsePhoneCaptcha 更新短信验证码 +func (s *securityServant) UsePhoneCaptcha(captcha *core.Captcha) error { + // TODO + debug.NotImplemented() + return nil +} + +// SendPhoneCaptcha 发送短信验证码 +func (s *securityServant) SendPhoneCaptcha(phone string) error { + // TODO + debug.NotImplemented() + return nil +} + +func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.SecurityService { + return &securityServant{ + db: db, + phoneVerify: phoneVerify, + stmtAddCaptcha: c(`SELECT * FROM @person WHERE first_name=?`), + stmtGetCaptcha: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/topics.go b/internal/dao/sakila/topics.go new file mode 100644 index 00000000..7f599509 --- /dev/null +++ b/internal/dao/sakila/topics.go @@ -0,0 +1,55 @@ +// 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/pkg/debug" +) + +var ( + _ core.TopicService = (*topicServant)(nil) +) + +type topicServant struct { + db *sqlx.DB + stmtAddTag *sqlx.Stmt + stmtDelTag *sqlx.Stmt + stmtListTag *sqlx.Stmt +} + +func (s *topicServant) CreateTag(tag *core.Tag) (*core.Tag, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *topicServant) DeleteTag(tag *core.Tag) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *topicServant) GetTags(conditions *core.ConditionsT, offset, limit int) ([]*core.Tag, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *topicServant) GetTagsByKeyword(keyword string) ([]*core.Tag, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func newTopicService(db *sqlx.DB) core.TopicService { + return &topicServant{ + db: db, + stmtAddTag: c(`SELECT * FROM @person WHERE first_name=?`), + stmtDelTag: c(`SELECT * FROM @person WHERE first_name=?`), + stmtListTag: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go new file mode 100644 index 00000000..3d3fa958 --- /dev/null +++ b/internal/dao/sakila/tweets.go @@ -0,0 +1,257 @@ +// 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/dao/jinzhu/dbr" + "github.com/rocboss/paopao-ce/pkg/debug" + "gorm.io/gorm" +) + +var ( + _ core.TweetService = (*tweetServant)(nil) + _ core.TweetManageService = (*tweetManageServant)(nil) + _ core.TweetHelpService = (*tweetHelpServant)(nil) +) + +type tweetServant struct { + db *sqlx.DB + stmtGetTweet *sqlx.Stmt + stmtListTweet *sqlx.Stmt + stmtListStar *sqlx.Stmt +} + +type tweetManageServant struct { + db *sqlx.DB + cacheIndex core.CacheIndexService + stmtAddTweet *sqlx.Stmt + stmtDelTweet *sqlx.Stmt + stmtStickTweet *sqlx.Stmt +} + +type tweetHelpServant struct { + db *sqlx.DB + stmtAddTag *sqlx.Stmt + stmtDelTag *sqlx.Stmt + stmtListTag *sqlx.Stmt +} + +// MergePosts post数据整合 +func (s *tweetHelpServant) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +// RevampPosts post数据整形修复 +func (s *tweetHelpServant) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetHelpServant) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetHelpServant) getUsersByIDs(ids []int64) ([]*dbr.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) DeletePostCollection(p *core.PostCollection) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *tweetManageServant) CreatePostContent(content *core.PostContent) (*core.PostContent, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) CreateAttachment(attachment *core.Attachment) (*core.Attachment, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) CreatePost(post *core.Post) (*core.Post, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) DeletePost(post *core.Post) ([]string, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) deleteCommentByPostId(db *gorm.DB, postId int64) ([]string, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) LockPost(post *core.Post) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *tweetManageServant) StickPost(post *core.Post) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *tweetManageServant) VisiblePost(post *core.Post, visibility core.PostVisibleT) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *tweetManageServant) UpdatePost(post *core.Post) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *tweetManageServant) CreatePostStar(postID, userID int64) (*core.PostStar, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetManageServant) DeletePostStar(p *core.PostStar) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *tweetServant) GetPostByID(id int64) (*core.Post, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetPostCount(conditions *core.ConditionsT) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *tweetServant) GetUserPostStar(postID, userID int64) (*core.PostStar, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetUserPostStarCount(userID int64) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *tweetServant) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetUserPostCollectionCount(userID int64) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *tweetServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetUserWalletBillCount(userID int64) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *tweetServant) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *tweetServant) GetPostContentByID(id int64) (*core.PostContent, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func newTweetService(db *sqlx.DB) core.TweetService { + return &tweetServant{ + db: db, + stmtGetTweet: c(`SELECT * FROM @person WHERE first_name=?`), + stmtListTweet: c(`SELECT * FROM @person WHERE first_name=?`), + stmtListStar: c(`SELECT * FROM @person WHERE first_name=?`), + } +} + +func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageService { + return &tweetManageServant{ + db: db, + cacheIndex: cacheIndex, + stmtAddTweet: c(`SELECT * FROM @person WHERE first_name=?`), + stmtDelTweet: c(`SELECT * FROM @person WHERE first_name=?`), + stmtStickTweet: c(`SELECT * FROM @person WHERE first_name=?`), + } +} + +func newTweetHelpService(db *sqlx.DB) core.TweetHelpService { + return &tweetHelpServant{ + db: db, + stmtAddTag: c(`SELECT * FROM @person WHERE first_name=?`), + stmtDelTag: c(`SELECT * FROM @person WHERE first_name=?`), + stmtListTag: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go new file mode 100644 index 00000000..74c8ec38 --- /dev/null +++ b/internal/dao/sakila/user.go @@ -0,0 +1,79 @@ +// 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/pkg/debug" +) + +var ( + _ core.UserManageService = (*userManageServant)(nil) +) + +type userManageServant struct { + db *sqlx.DB + stmtAddUser *sqlx.Stmt + stmtUpdateUser *sqlx.Stmt + stmtGetUser *sqlx.Stmt +} + +func (s *userManageServant) GetUserByID(id int64) (*core.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) GetUserByUsername(username string) (*core.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) GetUserByPhone(phone string) (*core.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) GetUsersByIDs(ids []int64) ([]*core.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) GetUsersByKeyword(keyword string) ([]*core.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) GetTagsByKeyword(keyword string) ([]*core.Tag, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) CreateUser(user *core.User) (*core.User, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *userManageServant) UpdateUser(user *core.User) error { + // TODO + debug.NotImplemented() + return nil +} + +func newUserManageService(db *sqlx.DB) core.UserManageService { + return &userManageServant{ + db: db, + stmtAddUser: c(`SELECT * FROM @person WHERE first_name=?`), + stmtUpdateUser: c(`SELECT * FROM @person WHERE first_name=?`), + stmtGetUser: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go new file mode 100644 index 00000000..950484d2 --- /dev/null +++ b/internal/dao/sakila/wallet.go @@ -0,0 +1,66 @@ +// 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/pkg/debug" +) + +var ( + _ core.WalletService = (*walletServant)(nil) +) + +type walletServant struct { + db *sqlx.DB + stmtAddRecharge *sqlx.Stmt + stmtGetRecharge *sqlx.Stmt + stmtGetBills *sqlx.Stmt +} + +func (s *walletServant) GetRechargeByID(id int64) (*core.WalletRecharge, error) { + // TODO + debug.NotImplemented() + return nil, nil +} +func (s *walletServant) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *walletServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { + // TODO + debug.NotImplemented() + return nil, nil +} + +func (s *walletServant) GetUserWalletBillCount(userID int64) (int64, error) { + // TODO + debug.NotImplemented() + return 0, nil +} + +func (s *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { + // TODO + debug.NotImplemented() + return nil +} + +func (s *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.User) error { + // TODO + debug.NotImplemented() + return nil +} + +func newWalletService(db *sqlx.DB) core.WalletService { + return &walletServant{ + db: db, + stmtAddRecharge: c(`SELECT * FROM @person WHERE first_name=?`), + stmtGetRecharge: c(`SELECT * FROM @person WHERE first_name=?`), + stmtGetBills: c(`SELECT * FROM @person WHERE first_name=?`), + } +} diff --git a/pkg/debug/annotation.go b/pkg/debug/annotation.go new file mode 100644 index 00000000..227399d0 --- /dev/null +++ b/pkg/debug/annotation.go @@ -0,0 +1,17 @@ +// 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 debug + +import ( + "github.com/sirupsen/logrus" +) + +func TODO() { + logrus.Fatalln("in todo progress") +} + +func NotImplemented() { + logrus.Fatalln("not implemented") +}