From d94a14d5b42ec8ce5edbb3cac7d53af0dc038193 Mon Sep 17 00:00:00 2001 From: Mostafa Date: Fri, 3 Jan 2025 21:48:48 +0800 Subject: [PATCH] chore: fix linting issues --- go.mod | 1 - go.sum | 20 ------ internal/engine/command/crowdfund/create.go | 5 +- .../engine/command/crowdfund/crowdfund.go | 17 ++--- .../command/crowdfund/crowdfund_test.go | 71 +++++++++---------- internal/entity/faucet.go | 2 +- internal/entity/voucher.go | 2 +- 7 files changed, 50 insertions(+), 68 deletions(-) diff --git a/go.mod b/go.mod index 21bf0d44..1d0bf3f6 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/telebot.v3 v3.3.8 gopkg.in/yaml.v3 v3.0.1 - gorm.io/datatypes v1.2.5 gorm.io/driver/mysql v1.5.7 gorm.io/driver/sqlite v1.4.3 gorm.io/gorm v1.25.12 diff --git a/go.sum b/go.sum index b29f92bb..15f5ec2c 100644 --- a/go.sum +++ b/go.sum @@ -188,10 +188,6 @@ github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= -github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= -github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= -github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -350,14 +346,6 @@ github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E= github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ= -github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= -github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= -github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk= @@ -467,8 +455,6 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA= -github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ= @@ -1216,16 +1202,10 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/datatypes v1.2.5 h1:9UogU3jkydFVW1bIVVeoYsTpLRgwDVW3rHfJG6/Ek9I= -gorm.io/datatypes v1.2.5/go.mod h1:I5FUdlKpLb5PMqeMQhm30CQ6jXP8Rj89xkTeCSAaAD4= gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= -gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U= -gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A= gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU= gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI= -gorm.io/driver/sqlserver v1.5.4 h1:xA+Y1KDNspv79q43bPyjDMUgHoYHLhXYmdFcYPobg8g= -gorm.io/driver/sqlserver v1.5.4/go.mod h1:+frZ/qYmuna11zHPlh5oc2O6ZA/lS88Keb0XSH1Zh/g= gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= diff --git a/internal/engine/command/crowdfund/create.go b/internal/engine/command/crowdfund/create.go index 7b399db8..dfaf9b9f 100644 --- a/internal/engine/command/crowdfund/create.go +++ b/internal/engine/command/crowdfund/create.go @@ -35,7 +35,10 @@ func (c *CrowdfundCmd) createHandler( Desc: desc, Packages: packages, } - c.db.AddCrowdfundCampaign(campaign) + err = c.db.AddCrowdfundCampaign(campaign) + if err != nil { + return cmd.FailedResult(err.Error()) + } return cmd.SuccessfulResultF( "Crowdfund campaign '%s' created successfully with %d packages", diff --git a/internal/engine/command/crowdfund/crowdfund.go b/internal/engine/command/crowdfund/crowdfund.go index 8eb96c57..aab900b3 100644 --- a/internal/engine/command/crowdfund/crowdfund.go +++ b/internal/engine/command/crowdfund/crowdfund.go @@ -20,7 +20,8 @@ type CrowdfundCmd struct { func NewCrowdfundCmd(ctx context.Context, db *repository.Database, wallet wallet.IWallet, - nowPayments nowpayments.INowpayments) *CrowdfundCmd { + nowPayments nowpayments.INowpayments, +) *CrowdfundCmd { return &CrowdfundCmd{ ctx: ctx, db: db, @@ -29,7 +30,7 @@ func NewCrowdfundCmd(ctx context.Context, } } -func (n *CrowdfundCmd) GetCommand() *command.Command { +func (c *CrowdfundCmd) GetCommand() *command.Command { subCmdCreate := &command.Command{ Name: "create", Help: "Create a new crowdfunding campaign", @@ -55,7 +56,7 @@ func (n *CrowdfundCmd) GetCommand() *command.Command { }, SubCommands: nil, AppIDs: entity.AllAppIDs(), - Handler: n.createHandler, + Handler: c.createHandler, TargetFlag: command.TargetMaskAll, } subCmdDisable := &command.Command{ @@ -64,7 +65,7 @@ func (n *CrowdfundCmd) GetCommand() *command.Command { Args: []command.Args{}, SubCommands: nil, AppIDs: entity.AllAppIDs(), - Handler: n.disableHandler, + Handler: c.disableHandler, TargetFlag: command.TargetMaskAll, } subCmdReport := &command.Command{ @@ -73,7 +74,7 @@ func (n *CrowdfundCmd) GetCommand() *command.Command { Args: []command.Args{}, SubCommands: nil, AppIDs: entity.AllAppIDs(), - Handler: n.reportHandler, + Handler: c.reportHandler, TargetFlag: command.TargetMaskAll, } subCmdInfo := &command.Command{ @@ -82,7 +83,7 @@ func (n *CrowdfundCmd) GetCommand() *command.Command { Args: []command.Args{}, SubCommands: nil, AppIDs: entity.AllAppIDs(), - Handler: n.infoHandler, + Handler: c.infoHandler, TargetFlag: command.TargetMaskAll, } subCmdPurchase := &command.Command{ @@ -91,7 +92,7 @@ func (n *CrowdfundCmd) GetCommand() *command.Command { Args: []command.Args{}, SubCommands: nil, AppIDs: entity.AllAppIDs(), - Handler: n.purchaseHandler, + Handler: c.purchaseHandler, TargetFlag: command.TargetMaskAll, } subCmdClaim := &command.Command{ @@ -100,7 +101,7 @@ func (n *CrowdfundCmd) GetCommand() *command.Command { Args: []command.Args{}, SubCommands: nil, AppIDs: entity.AllAppIDs(), - Handler: n.claimHandler, + Handler: c.claimHandler, TargetFlag: command.TargetMaskAll, } diff --git a/internal/engine/command/crowdfund/crowdfund_test.go b/internal/engine/command/crowdfund/crowdfund_test.go index c02ed290..14958a93 100644 --- a/internal/engine/command/crowdfund/crowdfund_test.go +++ b/internal/engine/command/crowdfund/crowdfund_test.go @@ -9,7 +9,6 @@ import ( "github.com/pagu-project/pagu/internal/testsuite" "github.com/pagu-project/pagu/pkg/nowpayments" "github.com/pagu-project/pagu/pkg/wallet" - "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" ) @@ -58,38 +57,38 @@ func WithPackages(packages []entity.Package) CampaignOption { } } -func (td *testData) createTestCampaign(t *testing.T, opts ...CampaignOption) *entity.CrowdfundCampaign { - t.Helper() - - campaign := &entity.CrowdfundCampaign{ - Title: td.RandString(16), - Desc: td.RandString(128), - Packages: []entity.Package{ - entity.Package{ - Name: td.RandString(16), - USDAmount: td.RandInt(1000), - PACAmount: td.RandInt(1000), - }, - entity.Package{ - Name: td.RandString(16), - USDAmount: td.RandInt(1000), - PACAmount: td.RandInt(1000), - }, - entity.Package{ - Name: td.RandString(16), - USDAmount: td.RandInt(1000), - PACAmount: td.RandInt(1000), - }, - }, - } - - // Apply options - for _, opt := range opts { - opt(campaign) - } - - err := td.database.AddCrowdfundCampaign(campaign) - require.NoError(t, err) - - return campaign -} +// func (td *testData) createTestCampaign(t *testing.T, opts ...CampaignOption) *entity.CrowdfundCampaign { +// t.Helper() + +// campaign := &entity.CrowdfundCampaign{ +// Title: td.RandString(16), +// Desc: td.RandString(128), +// Packages: []entity.Package{ +// { +// Name: td.RandString(16), +// USDAmount: td.RandInt(1000), +// PACAmount: td.RandInt(1000), +// }, +// { +// Name: td.RandString(16), +// USDAmount: td.RandInt(1000), +// PACAmount: td.RandInt(1000), +// }, +// { +// Name: td.RandString(16), +// USDAmount: td.RandInt(1000), +// PACAmount: td.RandInt(1000), +// }, +// }, +// } + +// // Apply options +// for _, opt := range opts { +// opt(campaign) +// } + +// err := td.database.AddCrowdfundCampaign(campaign) +// require.NoError(t, err) + +// return campaign +// } diff --git a/internal/entity/faucet.go b/internal/entity/faucet.go index d23727e5..50409d63 100644 --- a/internal/entity/faucet.go +++ b/internal/entity/faucet.go @@ -15,8 +15,8 @@ type PhoenixFaucet struct { TxHash string `gorm:"type:char(64);unique;not null"` } -// TODO: rename me to "faucet" (just remove this function is enough) func (*PhoenixFaucet) TableName() string { + // TODO: rename me to "faucets" (just remove this function is enough). return "phoenix_faucet" } diff --git a/internal/entity/voucher.go b/internal/entity/voucher.go index 1015df13..d714006f 100644 --- a/internal/entity/voucher.go +++ b/internal/entity/voucher.go @@ -18,8 +18,8 @@ type Voucher struct { ClaimedBy uint } -// TODO: rename me to "voucher" (just remove this function is enough) func (Voucher) TableName() string { + // TODO: rename me to "vouchers" (just remove this function is enough). return "voucher" }