sqlx: add all stub interface implement for core.DataService in sqlx feature

pull/351/head
Michael Li 2 years ago
parent 1ce877fb59
commit 060840030e
No known key found for this signature in database

@ -18,11 +18,13 @@ require (
github.com/gin-gonic/gin v1.8.1 github.com/gin-gonic/gin v1.8.1
github.com/go-redis/redis/v8 v8.11.4 github.com/go-redis/redis/v8 v8.11.4
github.com/go-resty/resty/v2 v2.7.0 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/goccy/go-json v0.9.7
github.com/gofrs/uuid v4.0.0+incompatible github.com/gofrs/uuid v4.0.0+incompatible
github.com/golang-jwt/jwt/v4 v4.4.2 github.com/golang-jwt/jwt/v4 v4.4.2
github.com/golang-migrate/migrate/v4 v4.15.2 github.com/golang-migrate/migrate/v4 v4.15.2
github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible 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/jmoiron/sqlx v1.3.5
github.com/json-iterator/go v1.1.12 github.com/json-iterator/go v1.1.12
github.com/meilisearch/meilisearch-go v0.21.0 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/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.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-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/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.1.0 // 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/ugorji/go/codec v1.2.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d // 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/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/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect

@ -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.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 h1:JzTglcal01DrghUqt+PmzWsZx/Yh7SC/CTQmSBMTd0Y=
github.com/jackc/pgx/v4 v4.16.1/go.mod h1:SIhx0D5hoADaiXZVyv+3gSm3LCIIINTVO0PficsvWGQ= 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-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 v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.0/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.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.6.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.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 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.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 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-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-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-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-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 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-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-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

@ -11,6 +11,9 @@ import (
"github.com/alimy/cfg" "github.com/alimy/cfg"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
_ "github.com/go-sql-driver/mysql"
_ "github.com/jackc/pgx/v5/stdlib"
) )
var ( var (
@ -32,7 +35,7 @@ func newSqlxDB() (db *sqlx.DB, err error) {
if cfg.If("MySQL") { if cfg.If("MySQL") {
db, err = sqlx.Open("mysql", MysqlSetting.Dsn()) db, err = sqlx.Open("mysql", MysqlSetting.Dsn())
} else if cfg.If("PostgreSQL") || cfg.If("Postgres") { } 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") { } else if cfg.If("Sqlite3") {
var ( var (
driver string driver string

@ -30,9 +30,9 @@ func DataService() core.DataService {
var v core.VersionInfo var v core.VersionInfo
if cfg.If("Gorm") { if cfg.If("Gorm") {
ds, v = jinzhu.NewDataService() ds, v = jinzhu.NewDataService()
} else if cfg.If("Sqlx") && cfg.If("MySQL") { } else if cfg.If("Sqlx") {
ds, v = sakila.NewDataService() 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() ds, v = slonik.NewDataService()
} else { } else {
// default use gorm as orm for sql database // default use gorm as orm for sql database

@ -24,32 +24,32 @@ func newMessageService(db *gorm.DB) core.MessageService {
} }
} }
func (d *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) { func (s *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) {
return msg.Create(d.db) return msg.Create(s.db)
} }
func (d *messageServant) GetUnreadCount(userID int64) (int64, error) { func (s *messageServant) GetUnreadCount(userID int64) (int64, error) {
return (&dbr.Message{}).Count(d.db, &dbr.ConditionsT{ return (&dbr.Message{}).Count(s.db, &dbr.ConditionsT{
"receiver_user_id": userID, "receiver_user_id": userID,
"is_read": dbr.MsgStatusUnread, "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{ return (&dbr.Message{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, 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 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) { func (s *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) {
messages, err := (&dbr.Message{}).List(d.db, conditions, offset, limit) messages, err := (&dbr.Message{}).List(s.db, conditions, offset, limit)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -63,6 +63,6 @@ func (d *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit
return mfs, nil return mfs, nil
} }
func (d *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) { func (s *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) {
return (&dbr.Message{}).Count(d.db, conditions) return (&dbr.Message{}).Count(s.db, conditions)
} }

@ -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{ recharge := &dbr.WalletRecharge{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, 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{ recharge := &dbr.WalletRecharge{
UserID: userId, UserID: userId,
Amount: amount, 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{ statement := &dbr.WalletStatement{
UserID: userID, UserID: userID,
} }
return statement.List(d.db, &dbr.ConditionsT{ return statement.List(s.db, &dbr.ConditionsT{
"ORDER": "id DESC", "ORDER": "id DESC",
}, offset, limit) }, offset, limit)
} }
func (d *walletServant) GetUserWalletBillCount(userID int64) (int64, error) { func (s *walletServant) GetUserWalletBillCount(userID int64) (int64, error) {
statement := &dbr.WalletStatement{ statement := &dbr.WalletStatement{
UserID: userID, 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{ user, _ := (&dbr.User{
Model: &dbr.Model{ Model: &dbr.Model{
ID: recharge.UserID, 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 { 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 { func (s *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.User) error {
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 - ?", post.AttachmentPrice)).Error; err != nil { 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, 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 { if err := tx.Model(master).Update("balance", gorm.Expr("balance + ?", income)).Error; err != nil {
// 返回任何错误都会回滚事务 // 返回任何错误都会回滚事务

@ -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=?`),
}
}

@ -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=?`),
}
}

@ -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=?`),
}
}

@ -7,6 +7,7 @@ package sakila
import ( import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
) )
var ( var (
@ -27,29 +28,27 @@ type simpleIndexPostsServant struct {
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的 // IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *indexPostsServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { func (s *indexPostsServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO // TODO
debug.NotImplemented()
return nil, nil return nil, nil
} }
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO // TODO
debug.NotImplemented()
return nil, nil return nil, nil
} }
func newIndexPostsService(db *sqlx.DB) core.IndexPostsService { func newIndexPostsService(db *sqlx.DB) core.IndexPostsService {
return &indexPostsServant{ return &indexPostsServant{
db: db, db: db,
stmtIndex: c(` stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`),
SELECT * FROM @person WHERE first_name=?
`),
} }
} }
func newSimpleIndexPostsService(db *sqlx.DB) core.IndexPostsService { func newSimpleIndexPostsService(db *sqlx.DB) core.IndexPostsService {
return &simpleIndexPostsServant{ return &simpleIndexPostsServant{
db: db, db: db,
stmtIndex: c(` stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`),
SELECT * FROM @person WHERE first_name=?
`),
} }
} }

@ -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=?`),
}
}

@ -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 // Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file. // 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 package sakila
import ( import (
"github.com/Masterminds/semver/v3"
"github.com/alimy/cfg"
"github.com/rocboss/paopao-ce/internal/core" "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" "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) { func NewDataService() (core.DataService, core.VersionInfo) {
logrus.Fatal("not support now") // initialize CacheIndex if needed
_ = newIndexPostsService(sqlxDB()) var (
_ = newSimpleIndexPostsService(sqlxDB()) c core.CacheIndexService
return nil, nil 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 { func NewAuthorizationManageService() core.AuthorizationManageService {
logrus.Fatal("not support now") return newAuthorizationManageService(sqlxDB())
return nil }
func (s *dataServant) Name() string {
return "Sqlx"
}
func (s *dataServant) Version() *semver.Version {
return semver.MustParse("v0.1.0")
} }

@ -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=?`),
}
}

@ -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=?`),
}
}

@ -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=?`),
}
}

@ -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=?`),
}
}

@ -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=?`),
}
}

@ -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")
}
Loading…
Cancel
Save