reworking
This commit is contained in:
parent
3d0814f7ad
commit
1a2f21b671
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"amocrm/internal/initialize"
|
||||
"context"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@ -26,7 +27,7 @@ func main() {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
var config app.Config
|
||||
var config initialize.Config
|
||||
|
||||
err = env.Parse(config)
|
||||
if err != nil {
|
||||
|
11
go.mod
11
go.mod
@ -5,20 +5,31 @@ go 1.21.6
|
||||
require (
|
||||
github.com/caarlos0/env/v8 v8.0.0
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
go.mongodb.org/mongo-driver v1.14.0
|
||||
go.uber.org/zap v1.27.0
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
github.com/klauspost/compress v1.17.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.51.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
)
|
||||
|
71
go.sum
71
go.sum
@ -2,21 +2,92 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0=
|
||||
github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
|
||||
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
|
||||
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
|
||||
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
||||
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
||||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
|
||||
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
|
@ -2,19 +2,19 @@ package app
|
||||
|
||||
import (
|
||||
"amocrm/internal/controllers"
|
||||
"amocrm/internal/initialize"
|
||||
"amocrm/internal/repository"
|
||||
"amocrm/internal/server/http"
|
||||
"amocrm/internal/service"
|
||||
"amocrm/pkg/closer"
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppName string `env:"APP_NAME"`
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, config Config, logger *zap.Logger) error {
|
||||
func Run(ctx context.Context, config initialize.Config, logger *zap.Logger) error {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Error("Recovered from a panic", zap.Any("error", r))
|
||||
@ -26,51 +26,59 @@ func Run(ctx context.Context, config Config, logger *zap.Logger) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// Инициализация репозиториев
|
||||
shutdownGroup := closer.NewCloserGroup()
|
||||
|
||||
accountRepository := repository.NewAccountRepository()
|
||||
mdb, err := initialize.MongoDB(ctx, config)
|
||||
if err != nil {
|
||||
logger.Error("failed initialize mongo")
|
||||
return err
|
||||
}
|
||||
|
||||
differentRepository := repository.NewDifferentRepository()
|
||||
repo := repository.NewRepository(repository.Deps{
|
||||
MdbUser: mdb.Collection("amoUsers"),
|
||||
})
|
||||
|
||||
// Инициализация сервисов
|
||||
svc := service.NewService(service.Deps{
|
||||
Repository: repo,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
accountService := service.NewAccountService(accountRepository)
|
||||
controller := controllers.NewController(controllers.Deps{
|
||||
Service: svc,
|
||||
Logger: logger,
|
||||
})
|
||||
|
||||
differentService := service.NewDifferentService(differentRepository)
|
||||
|
||||
// Инициализация контроллеров
|
||||
|
||||
accountController := controllers.NewAccountController(accountService)
|
||||
|
||||
differentController := controllers.NewDifferentController(differentService)
|
||||
|
||||
// Создание сервера
|
||||
server := http.NewServer(http.ServerConfig{
|
||||
Controllers: []http.Controller{
|
||||
|
||||
accountController,
|
||||
|
||||
differentController,
|
||||
controller,
|
||||
},
|
||||
})
|
||||
|
||||
go func() {
|
||||
err := server.Start("Host + : + Port")
|
||||
if err != nil {
|
||||
if err := server.Start(config.HTTPHost + ":" + config.HTTPPort); err != nil {
|
||||
logger.Error("Server startup error", zap.Error(err))
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
|
||||
// Вывод маршрутов
|
||||
server.ListRoutes()
|
||||
|
||||
shutdownGroup.Add(closer.CloserFunc(server.Shutdown))
|
||||
shutdownGroup.Add(closer.CloserFunc(mdb.Client().Disconnect))
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
logger.Info("App shutting down gracefully")
|
||||
|
||||
//TODO
|
||||
// Остановка сервера
|
||||
timeoutCtx, timeoutCancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer timeoutCancel()
|
||||
if err := shutdownGroup.Call(timeoutCtx); err != nil {
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
logger.Error("Shutdown timed out", zap.Error(err))
|
||||
} else {
|
||||
logger.Error("Failed to shutdown services gracefully", zap.Error(err))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("Application has stopped")
|
||||
return nil
|
||||
}
|
||||
|
@ -1,139 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type AccountController struct {
|
||||
AccountService *service.AccountService
|
||||
}
|
||||
|
||||
func NewAccountController(service *service.AccountService) *AccountController {
|
||||
return &AccountController{
|
||||
AccountService: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *AccountController) Register(router fiber.Router) {
|
||||
router.Patch("/users", c.UpdateListUsers)
|
||||
router.Get("/users", c.GettingUserFromCash)
|
||||
router.Delete("/utms/:quizID", c.DeletingUserUtm)
|
||||
router.Post("/utms/:quizID", c.SavingUserUtm)
|
||||
router.Get("/utms/:quizID", c.GettingUserUtm)
|
||||
router.Delete("/account", c.SoftDeleteAccount)
|
||||
router.Get("/account", c.GetCurrentAccount)
|
||||
router.Post("/account", c.ConnectAccount)
|
||||
}
|
||||
|
||||
func (c *AccountController) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *AccountController) UpdateListUsers(ctx *fiber.Ctx) error {
|
||||
err := c.AccountService.UpdateListUsers(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *AccountController) GettingUserFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.AccountService.GettingUserFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *AccountController) DeletingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.ListDeleteUTMIDsReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.AccountService.DeletingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *AccountController) SavingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.SaveUserListUTMReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
response, err := c.AccountService.SavingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *AccountController) GettingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.AccountService.GettingUserUtm(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *AccountController) SoftDeleteAccount(ctx *fiber.Ctx) error {
|
||||
err := c.AccountService.SoftDeleteAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *AccountController) GetCurrentAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.AccountService.GetCurrentAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *AccountController) ConnectAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.AccountService.ConnectAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
320
internal/controllers/controller.go
Normal file
320
internal/controllers/controller.go
Normal file
@ -0,0 +1,320 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Service *service.Service
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
service *service.Service
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewController(deps Deps) *Controller {
|
||||
return &Controller{
|
||||
service: deps.Service,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) Register(router fiber.Router) {
|
||||
router.Patch("/users", c.UpdateListUsers)
|
||||
router.Get("/users", c.GettingUserFromCash)
|
||||
router.Delete("/utms/:quizID", c.DeletingUserUtm)
|
||||
router.Post("/utms/:quizID", c.SavingUserUtm)
|
||||
router.Get("/utms/:quizID", c.GettingUserUtm)
|
||||
router.Delete("/account", c.SoftDeleteAccount)
|
||||
router.Get("/account", c.GetCurrentAccount)
|
||||
router.Post("/account", c.ConnectAccount)
|
||||
router.Get("/steps", c.GettingStepsFromCash)
|
||||
router.Patch("/steps", c.UpdateListSteps)
|
||||
router.Get("/webhook/create", c.WebhookCreate)
|
||||
router.Get("/webhook/delete", c.WebhookDelete)
|
||||
router.Patch("/pipelines", c.UpdateListPipelines)
|
||||
router.Get("/pipelines", c.GettingPipelinesFromCash)
|
||||
router.Patch("/rules/:quizID", c.ChangeQuizSettings)
|
||||
router.Post("/rules/:quizID", c.SetQuizSettings)
|
||||
router.Get("/rules/:quizID", c.GettingQuizRules)
|
||||
router.Get("/tags", c.GettingTagsFromCash)
|
||||
router.Patch("/tags", c.UpdateListTags)
|
||||
router.Get("/fields", c.GettingFieldsFromCash)
|
||||
router.Patch("/fields", c.UpdateListCustom)
|
||||
}
|
||||
|
||||
func (c *Controller) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListUsers(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListUsers(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingUserFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingUserFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) DeletingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.ListDeleteUTMIDsReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.DeletingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) SavingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.SaveUserListUTMReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
response, err := c.service.SavingUserUtm(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingUserUtm(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingUserUtm(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) SoftDeleteAccount(ctx *fiber.Ctx) error {
|
||||
err := c.service.SoftDeleteAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GetCurrentAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.service.GetCurrentAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
|
||||
response, err := c.service.ConnectAccount(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingStepsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingStepsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListSteps(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListSteps(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) WebhookCreate(ctx *fiber.Ctx) error {
|
||||
err := c.service.WebhookCreate(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) WebhookDelete(ctx *fiber.Ctx) error {
|
||||
err := c.service.WebhookDelete(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListPipelines(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListPipelines(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingPipelinesFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.ChangeQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.SetQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
response, err := c.service.GettingQuizRules(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingTagsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingTagsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListTags(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingFieldsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GettingFieldsFromCash(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListCustom(ctx *fiber.Ctx) error {
|
||||
err := c.service.UpdateListCustom(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
@ -1,197 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type DifferentController struct {
|
||||
DifferentService *service.DifferentService
|
||||
}
|
||||
|
||||
func NewDifferentController(service *service.DifferentService) *DifferentController {
|
||||
return &DifferentController{
|
||||
DifferentService: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DifferentController) Register(router fiber.Router) {
|
||||
router.Get("/steps", c.GettingStepsFromCash)
|
||||
router.Patch("/steps", c.UpdateListSteps)
|
||||
router.Get("/webhook/create", c.WebhookCreate)
|
||||
router.Get("/webhook/delete", c.WebhookDelete)
|
||||
router.Patch("/pipelines", c.UpdateListPipelines)
|
||||
router.Get("/pipelines", c.GettingPipelinesFromCash)
|
||||
router.Patch("/rules/:quizID", c.ChangeQuizSettings)
|
||||
router.Post("/rules/:quizID", c.SetQuizSettings)
|
||||
router.Get("/rules/:quizID", c.GettingQuizRules)
|
||||
router.Get("/tags", c.GettingTagsFromCash)
|
||||
router.Patch("/tags", c.UpdateListTags)
|
||||
router.Get("/fields", c.GettingFieldsFromCash)
|
||||
router.Patch("/fields", c.UpdateListCustom)
|
||||
}
|
||||
|
||||
func (c *DifferentController) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *DifferentController) GettingStepsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.DifferentService.GettingStepsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *DifferentController) UpdateListSteps(ctx *fiber.Ctx) error {
|
||||
err := c.DifferentService.UpdateListSteps(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) WebhookCreate(ctx *fiber.Ctx) error {
|
||||
err := c.DifferentService.WebhookCreate(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) WebhookDelete(ctx *fiber.Ctx) error {
|
||||
err := c.DifferentService.WebhookDelete(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) UpdateListPipelines(ctx *fiber.Ctx) error {
|
||||
err := c.DifferentService.UpdateListPipelines(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) GettingPipelinesFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.DifferentService.GettingPipelinesFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *DifferentController) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.DifferentService.ChangeQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
var request models.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.DifferentService.SetQuizSettings(ctx.Context(), &request)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
response, err := c.DifferentService.GettingQuizRules(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *DifferentController) GettingTagsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.DifferentService.GettingTagsFromCash(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *DifferentController) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
err := c.DifferentService.UpdateListTags(ctx.Context())
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (c *DifferentController) GettingFieldsFromCash(ctx *fiber.Ctx) error {
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.DifferentService.GettingFieldsFromCash(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *DifferentController) UpdateListCustom(ctx *fiber.Ctx) error {
|
||||
err := c.DifferentService.UpdateListCustom(ctx.Context())
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
13
internal/initialize/config.go
Normal file
13
internal/initialize/config.go
Normal file
@ -0,0 +1,13 @@
|
||||
package initialize
|
||||
|
||||
type Config struct {
|
||||
AppName string `env:"APP_NAME" envDefault:"amocrm"`
|
||||
HTTPHost string `env:"HTTP_HOST" envDefault:"localhost"`
|
||||
HTTPPort string `env:"HTTP_PORT" envDefault:"3000"`
|
||||
MongoHost string `env:"MONGO_HOST" envDefault:"127.0.0.1"`
|
||||
MongoPort string `env:"MONGO_PORT" envDefault:"27020"`
|
||||
MongoUser string `env:"MONGO_USER" envDefault:"test"`
|
||||
MongoPassword string `env:"MONGO_PASSWORD" envDefault:"test"`
|
||||
MongoDatabase string `env:"MONGO_DB" envDefault:"admin"`
|
||||
MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"`
|
||||
}
|
39
internal/initialize/mongo.go
Normal file
39
internal/initialize/mongo.go
Normal file
@ -0,0 +1,39 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
mdb "penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MongoDB(ctx context.Context, cfg Config) (*mongo.Database, error) {
|
||||
dbConfig := &mdb.Configuration{
|
||||
Host: cfg.MongoHost,
|
||||
Port: cfg.MongoPort,
|
||||
User: cfg.MongoUser,
|
||||
Password: cfg.MongoPassword,
|
||||
DatabaseName: cfg.MongoDatabase,
|
||||
Auth: cfg.MongoAuth,
|
||||
}
|
||||
|
||||
newCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
mongoDeps := &mdb.ConnectDeps{
|
||||
Configuration: dbConfig,
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
db, err := mdb.Connect(newCtx, mongoDeps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = db.Client().Ping(newCtx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
type AccountRepository struct {
|
||||
}
|
||||
|
||||
func NewAccountRepository() *AccountRepository {
|
||||
return &AccountRepository{}
|
||||
}
|
||||
|
||||
func (r *AccountRepository) UpdateListUsers(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *AccountRepository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListResp{}, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ListSavedIDUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetListUserUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) SoftDeleteAccount(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *AccountRepository) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetCurrentAccountResp{}, nil
|
||||
}
|
||||
|
||||
func (r *AccountRepository) ConnectAccount(ctx context.Context) (*models.ConnectAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ConnectAccountResp{}, nil
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
)
|
||||
|
||||
type DifferentRepository struct {
|
||||
}
|
||||
|
||||
func NewDifferentRepository() *DifferentRepository {
|
||||
return &DifferentRepository{}
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListStepsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) UpdateListSteps(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) WebhookCreate(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) WebhookDelete(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) UpdateListPipelines(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListPipelinesResp{}, nil
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.Rule{}, nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListTagsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) UpdateListTags(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListFieldsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *DifferentRepository) UpdateListCustom(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
162
internal/repository/repository.go
Normal file
162
internal/repository/repository.go
Normal file
@ -0,0 +1,162 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
MdbUser *mongo.Collection
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
mdbUser *mongo.Collection
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewRepository(deps Deps) *Repository {
|
||||
return &Repository{
|
||||
mdbUser: deps.MdbUser,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListUsers(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ListSavedIDUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetListUserUTMResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) SoftDeleteAccount(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.GetCurrentAccountResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) ConnectAccount(ctx context.Context) (*models.ConnectAccountResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.ConnectAccountResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListStepsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListSteps(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) WebhookCreate(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) WebhookDelete(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListPipelines(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListPipelinesResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.Rule{}, nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListTagsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListTags(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *Repository) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return &models.UserListFieldsResp{}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListCustom(ctx context.Context) error {
|
||||
//TODO:IMPLEMENT ME
|
||||
|
||||
return nil
|
||||
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/repository"
|
||||
"context"
|
||||
)
|
||||
|
||||
type AccountService struct {
|
||||
AccountRepository *repository.AccountRepository
|
||||
}
|
||||
|
||||
func NewAccountService(repository *repository.AccountRepository) *AccountService {
|
||||
return &AccountService{
|
||||
AccountRepository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AccountService) UpdateListUsers(ctx context.Context) error {
|
||||
|
||||
err := s.AccountRepository.UpdateListUsers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *AccountService) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.GettingUserFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *AccountService) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
|
||||
err := s.AccountRepository.DeletingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *AccountService) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.SavingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *AccountService) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.GettingUserUtm(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *AccountService) SoftDeleteAccount(ctx context.Context) error {
|
||||
|
||||
err := s.AccountRepository.SoftDeleteAccount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *AccountService) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.GetCurrentAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *AccountService) ConnectAccount(ctx context.Context) (*models.ConnectAccountResp, error) {
|
||||
|
||||
response, err := s.AccountRepository.ConnectAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/repository"
|
||||
"context"
|
||||
)
|
||||
|
||||
type DifferentService struct {
|
||||
DifferentRepository *repository.DifferentRepository
|
||||
}
|
||||
|
||||
func NewDifferentService(repository *repository.DifferentRepository) *DifferentService {
|
||||
return &DifferentService{
|
||||
DifferentRepository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DifferentService) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
|
||||
response, err := s.DifferentRepository.GettingStepsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) UpdateListSteps(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.UpdateListSteps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) WebhookCreate(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.WebhookCreate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) WebhookDelete(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.WebhookDelete(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) UpdateListPipelines(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.UpdateListPipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
|
||||
response, err := s.DifferentRepository.GettingPipelinesFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.DifferentRepository.ChangeQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.DifferentRepository.SetQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
|
||||
response, err := s.DifferentRepository.GettingQuizRules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
|
||||
response, err := s.DifferentRepository.GettingTagsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) UpdateListTags(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.UpdateListTags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
|
||||
response, err := s.DifferentRepository.GettingFieldsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *DifferentService) UpdateListCustom(ctx context.Context) error {
|
||||
|
||||
err := s.DifferentRepository.UpdateListCustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
214
internal/service/service.go
Normal file
214
internal/service/service.go
Normal file
@ -0,0 +1,214 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/repository"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Deps struct {
|
||||
Repository *repository.Repository
|
||||
Logger *zap.Logger
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
repository *repository.Repository
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func NewService(deps Deps) *Service {
|
||||
return &Service{
|
||||
repository: deps.Repository,
|
||||
logger: deps.Logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListUsers(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListUsers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
||||
|
||||
response, err := s.repository.GettingUserFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) DeletingUserUtm(ctx context.Context, request *models.ListDeleteUTMIDsReq) error {
|
||||
|
||||
err := s.repository.DeletingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SavingUserUtm(ctx context.Context, request *models.SaveUserListUTMReq) (*models.ListSavedIDUTMResp, error) {
|
||||
|
||||
response, err := s.repository.SavingUserUtm(ctx, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingUserUtm(ctx context.Context) (*models.GetListUserUTMResp, error) {
|
||||
|
||||
response, err := s.repository.GettingUserUtm(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) SoftDeleteAccount(ctx context.Context) error {
|
||||
|
||||
err := s.repository.SoftDeleteAccount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
||||
|
||||
response, err := s.repository.GetCurrentAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) ConnectAccount(ctx context.Context) (*models.ConnectAccountResp, error) {
|
||||
|
||||
response, err := s.repository.ConnectAccount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingStepsFromCash(ctx context.Context) (*models.UserListStepsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingStepsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListSteps(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListSteps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) WebhookCreate(ctx context.Context) error {
|
||||
|
||||
err := s.repository.WebhookCreate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) WebhookDelete(ctx context.Context) error {
|
||||
|
||||
err := s.repository.WebhookDelete(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListPipelines(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListPipelines(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingPipelinesFromCash(ctx context.Context) (*models.UserListPipelinesResp, error) {
|
||||
|
||||
response, err := s.repository.GettingPipelinesFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.repository.ChangeQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *models.RulesReq) error {
|
||||
|
||||
err := s.repository.SetQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingQuizRules(ctx context.Context) (*models.Rule, error) {
|
||||
|
||||
response, err := s.repository.GettingQuizRules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingTagsFromCash(ctx context.Context) (*models.UserListTagsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingTagsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListTags(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListTags(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingFieldsFromCash(ctx context.Context) (*models.UserListFieldsResp, error) {
|
||||
|
||||
response, err := s.repository.GettingFieldsFromCash(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListCustom(ctx context.Context) error {
|
||||
|
||||
err := s.repository.UpdateListCustom(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
37
pkg/closer/closer.go
Normal file
37
pkg/closer/closer.go
Normal file
@ -0,0 +1,37 @@
|
||||
package closer
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Closer interface {
|
||||
Close(ctx context.Context) error
|
||||
}
|
||||
|
||||
type CloserFunc func(ctx context.Context) error
|
||||
|
||||
func (cf CloserFunc) Close(ctx context.Context) error {
|
||||
return cf(ctx)
|
||||
}
|
||||
|
||||
type CloserGroup struct {
|
||||
closers []Closer
|
||||
}
|
||||
|
||||
func NewCloserGroup() *CloserGroup {
|
||||
return &CloserGroup{}
|
||||
}
|
||||
|
||||
func (cg *CloserGroup) Add(c Closer) {
|
||||
cg.closers = append(cg.closers, c)
|
||||
}
|
||||
|
||||
func (cg *CloserGroup) Call(ctx context.Context) error {
|
||||
var closeErr error
|
||||
for i := len(cg.closers) - 1; i >= 0; i-- {
|
||||
if err := cg.closers[i].Close(ctx); err != nil && closeErr == nil {
|
||||
closeErr = err
|
||||
}
|
||||
}
|
||||
return closeErr
|
||||
}
|
Loading…
Reference in New Issue
Block a user