From 052f062ccad2896b9ec2e3a350877fcbf089a56c Mon Sep 17 00:00:00 2001 From: mohammad mahdi rezaei Date: Thu, 11 Jan 2024 10:43:37 +0330 Subject: [PATCH] fix(niki): linter errors fixed --- Makefile | 3 ++ config.yml | 14 ++++++ .../http_server/admin/kind_box/handler.go | 2 +- .../http_server/admin/kind_box_req/handler.go | 2 +- .../benefactor/kind_box/handler.go | 2 +- .../benefactor/kind_box_req/handler.go | 2 +- docker-compose.yaml | 10 ----- param/admin/admin/get.go | 1 - param/admin/admin/get_all_benefactor.go | 1 - param/admin/admin/get_all_staff.go | 1 - param/admin/admin/get_benefactor.go | 1 - param/admin/admin/get_staff.go | 1 - param/admin/admin/login.go | 1 - param/admin/admin/register_benefactor.go | 1 - param/admin/admin/register_staff.go | 1 - param/admin/admin/update_benefactor.go | 1 - param/admin/admin/update_staff.go | 1 - param/admin/super_admin/get_admin.go | 1 - param/admin/super_admin/get_all_admin.go | 1 - param/admin/super_admin/login.go | 1 - param/admin/super_admin/register_admin.go | 1 - param/admin/super_admin/update_admin.go | 1 - param/benefactor/benefactor/get.go | 7 --- param/benefactor/benefactor/login.go | 7 --- param/benefactor/benefactor/register.go | 9 ---- param/benefactor/benefactor/update.go | 1 - param/staff/staff/get.go | 1 - param/staff/staff/login.go | 1 - service/admin/admin/get.go | 1 - service/admin/admin/get_all_benefactor.go | 1 - service/admin/admin/get_all_staff.go | 1 - service/admin/admin/get_benefactor.go | 1 - service/admin/admin/get_staff.go | 1 - service/admin/admin/login.go | 1 - service/admin/admin/register_benefactor.go | 1 - service/admin/admin/register_staff.go | 1 - service/admin/admin/service.go | 1 - service/admin/admin/update_benefactor.go | 1 - service/admin/admin/update_staff.go | 1 - service/admin/super_admin/get_admin.go | 1 - service/admin/super_admin/get_all_admin.go | 1 - service/admin/super_admin/login.go | 1 - service/admin/super_admin/register_admin.go | 1 - service/admin/super_admin/service.go | 1 - service/admin/super_admin/update_admin.go | 1 - service/auth/admin/login.go | 1 + service/auth/{ => admin}/service.go | 2 +- service/auth/user/login.go | 1 + service/auth/user/register.go | 1 + service/auth/user/service.go | 23 ++++++++++ service/benefactor/benefactor/get.go | 1 - service/benefactor/benefactor/login.go | 45 ------------------- service/benefactor/benefactor/register.go | 36 --------------- service/benefactor/benefactor/service.go | 27 ----------- service/benefactor/benefactor/update.go | 1 - service/staff/staff/get.go | 1 - service/staff/staff/login.go | 45 ------------------- service/staff/staff/service.go | 27 ----------- 58 files changed, 48 insertions(+), 256 deletions(-) delete mode 100644 param/admin/admin/get.go delete mode 100644 param/admin/admin/get_all_benefactor.go delete mode 100644 param/admin/admin/get_all_staff.go delete mode 100644 param/admin/admin/get_benefactor.go delete mode 100644 param/admin/admin/get_staff.go delete mode 100644 param/admin/admin/login.go delete mode 100644 param/admin/admin/register_benefactor.go delete mode 100644 param/admin/admin/register_staff.go delete mode 100644 param/admin/admin/update_benefactor.go delete mode 100644 param/admin/admin/update_staff.go delete mode 100644 param/admin/super_admin/get_admin.go delete mode 100644 param/admin/super_admin/get_all_admin.go delete mode 100644 param/admin/super_admin/login.go delete mode 100644 param/admin/super_admin/register_admin.go delete mode 100644 param/admin/super_admin/update_admin.go delete mode 100644 param/benefactor/benefactor/get.go delete mode 100644 param/benefactor/benefactor/login.go delete mode 100644 param/benefactor/benefactor/register.go delete mode 100644 param/benefactor/benefactor/update.go delete mode 100644 param/staff/staff/get.go delete mode 100644 param/staff/staff/login.go delete mode 100644 service/admin/admin/get.go delete mode 100644 service/admin/admin/get_all_benefactor.go delete mode 100644 service/admin/admin/get_all_staff.go delete mode 100644 service/admin/admin/get_benefactor.go delete mode 100644 service/admin/admin/get_staff.go delete mode 100644 service/admin/admin/login.go delete mode 100644 service/admin/admin/register_benefactor.go delete mode 100644 service/admin/admin/register_staff.go delete mode 100644 service/admin/admin/service.go delete mode 100644 service/admin/admin/update_benefactor.go delete mode 100644 service/admin/admin/update_staff.go delete mode 100644 service/admin/super_admin/get_admin.go delete mode 100644 service/admin/super_admin/get_all_admin.go delete mode 100644 service/admin/super_admin/login.go delete mode 100644 service/admin/super_admin/register_admin.go delete mode 100644 service/admin/super_admin/service.go delete mode 100644 service/admin/super_admin/update_admin.go create mode 100644 service/auth/admin/login.go rename service/auth/{ => admin}/service.go (95%) create mode 100644 service/auth/user/login.go create mode 100644 service/auth/user/register.go create mode 100644 service/auth/user/service.go delete mode 100644 service/benefactor/benefactor/get.go delete mode 100644 service/benefactor/benefactor/login.go delete mode 100644 service/benefactor/benefactor/register.go delete mode 100644 service/benefactor/benefactor/service.go delete mode 100644 service/benefactor/benefactor/update.go delete mode 100644 service/staff/staff/get.go delete mode 100644 service/staff/staff/login.go delete mode 100644 service/staff/staff/service.go diff --git a/Makefile b/Makefile index de2ccd1..4fa0af0 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,6 @@ format: @gci write $(ROOT) @which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0) @golangci-lint run --fix + +build: + go build main.go \ No newline at end of file diff --git a/config.yml b/config.yml index e69de29..c4f61b0 100644 --- a/config.yml +++ b/config.yml @@ -0,0 +1,14 @@ +--- +type: yml +auth: + sign_key: jwt_secret + +http_server: + port: 8080 + +mysql: + port: 3308 + host: localhost + db_name: niki_db + username: niki + password: nikit0lk2o20 diff --git a/delivery/http_server/admin/kind_box/handler.go b/delivery/http_server/admin/kind_box/handler.go index df616d4..bd17359 100644 --- a/delivery/http_server/admin/kind_box/handler.go +++ b/delivery/http_server/admin/kind_box/handler.go @@ -2,7 +2,7 @@ package adminkindboxhandler import ( adminkindboxservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box" - authservice "git.gocasts.ir/ebhomengo/niki/service/auth" + authservice "git.gocasts.ir/ebhomengo/niki/service/auth/user" adminkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box" ) diff --git a/delivery/http_server/admin/kind_box_req/handler.go b/delivery/http_server/admin/kind_box_req/handler.go index cc99b6c..5e0100b 100644 --- a/delivery/http_server/admin/kind_box_req/handler.go +++ b/delivery/http_server/admin/kind_box_req/handler.go @@ -2,7 +2,7 @@ package adminkindboxreqhandler import ( adminkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/admin/kind_box_req" - authservice "git.gocasts.ir/ebhomengo/niki/service/auth" + authservice "git.gocasts.ir/ebhomengo/niki/service/auth/user" adminkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/admin/kind_box_req" ) diff --git a/delivery/http_server/benefactor/kind_box/handler.go b/delivery/http_server/benefactor/kind_box/handler.go index 0808277..66da3f0 100644 --- a/delivery/http_server/benefactor/kind_box/handler.go +++ b/delivery/http_server/benefactor/kind_box/handler.go @@ -1,7 +1,7 @@ package benefactorkindboxhandler import ( - authservice "git.gocasts.ir/ebhomengo/niki/service/auth" + authservice "git.gocasts.ir/ebhomengo/niki/service/auth/user" benefactorkindboxservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box" benefactorkindboxvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box" ) diff --git a/delivery/http_server/benefactor/kind_box_req/handler.go b/delivery/http_server/benefactor/kind_box_req/handler.go index 5b803a6..d5576db 100644 --- a/delivery/http_server/benefactor/kind_box_req/handler.go +++ b/delivery/http_server/benefactor/kind_box_req/handler.go @@ -1,7 +1,7 @@ package benefactorkindboxreqhandler import ( - authservice "git.gocasts.ir/ebhomengo/niki/service/auth" + authservice "git.gocasts.ir/ebhomengo/niki/service/auth/user" benefactorkindboxreqservice "git.gocasts.ir/ebhomengo/niki/service/benefactor/kind_box_req" benefactorkindboxreqvalidator "git.gocasts.ir/ebhomengo/niki/validator/benefactor/kind_box_req" ) diff --git a/docker-compose.yaml b/docker-compose.yaml index d653bdd..56588bc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -18,13 +18,3 @@ services: - MYSQL_DATABASE=niki -#set mysql in ubuntu -#//https://www.tecmint.com/fix-mysql-error-1819-hy000/ -# -# sudo mysql_secure_installation -# sudo systemctl start mysql -# mysql> CREATE USER 'user'@'localhost' IDENTIFIED BY 'g#Y!298mKwz85'; -# mysql> create database orginfo; -# mysql> grant all privileges on orginfo.* to user@localhost; -# mysql> set password for user@localhost = password("g#Y!298mKwz85"); - diff --git a/param/admin/admin/get.go b/param/admin/admin/get.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/get.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/get_all_benefactor.go b/param/admin/admin/get_all_benefactor.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/get_all_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/get_all_staff.go b/param/admin/admin/get_all_staff.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/get_all_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/get_benefactor.go b/param/admin/admin/get_benefactor.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/get_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/get_staff.go b/param/admin/admin/get_staff.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/get_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/login.go b/param/admin/admin/login.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/login.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/register_benefactor.go b/param/admin/admin/register_benefactor.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/register_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/register_staff.go b/param/admin/admin/register_staff.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/register_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/update_benefactor.go b/param/admin/admin/update_benefactor.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/update_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/admin/update_staff.go b/param/admin/admin/update_staff.go deleted file mode 100644 index 1ae4025..0000000 --- a/param/admin/admin/update_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminparam diff --git a/param/admin/super_admin/get_admin.go b/param/admin/super_admin/get_admin.go deleted file mode 100644 index a15243e..0000000 --- a/param/admin/super_admin/get_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminparam diff --git a/param/admin/super_admin/get_all_admin.go b/param/admin/super_admin/get_all_admin.go deleted file mode 100644 index a15243e..0000000 --- a/param/admin/super_admin/get_all_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminparam diff --git a/param/admin/super_admin/login.go b/param/admin/super_admin/login.go deleted file mode 100644 index a15243e..0000000 --- a/param/admin/super_admin/login.go +++ /dev/null @@ -1 +0,0 @@ -package superadminparam diff --git a/param/admin/super_admin/register_admin.go b/param/admin/super_admin/register_admin.go deleted file mode 100644 index a15243e..0000000 --- a/param/admin/super_admin/register_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminparam diff --git a/param/admin/super_admin/update_admin.go b/param/admin/super_admin/update_admin.go deleted file mode 100644 index a15243e..0000000 --- a/param/admin/super_admin/update_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminparam diff --git a/param/benefactor/benefactor/get.go b/param/benefactor/benefactor/get.go deleted file mode 100644 index 9afd5df..0000000 --- a/param/benefactor/benefactor/get.go +++ /dev/null @@ -1,7 +0,0 @@ -package benefactorparam - -type BenefactorProfileRequest struct{} - -type BenefactorProfileResponse struct { - Benefactor entity.Benefactor -} diff --git a/param/benefactor/benefactor/login.go b/param/benefactor/benefactor/login.go deleted file mode 100644 index b483d57..0000000 --- a/param/benefactor/benefactor/login.go +++ /dev/null @@ -1,7 +0,0 @@ -package benefactorparam - -type BenefactorLoginRequest struct{} - -type BenefactorLoginResponse struct { - Benefactor entity.Benefactor -} diff --git a/param/benefactor/benefactor/register.go b/param/benefactor/benefactor/register.go deleted file mode 100644 index 5e60d35..0000000 --- a/param/benefactor/benefactor/register.go +++ /dev/null @@ -1,9 +0,0 @@ -package benefactorparam - -import entity "git.gocasts.ir/ebhomengo/niki/entity" - -type BenefactorRegisterRequest struct{} - -type BenefactorRegisterResponse struct { - Benefactor entity.Benefactor -} diff --git a/param/benefactor/benefactor/update.go b/param/benefactor/benefactor/update.go deleted file mode 100644 index ee3160a..0000000 --- a/param/benefactor/benefactor/update.go +++ /dev/null @@ -1 +0,0 @@ -package benefactorparam diff --git a/param/staff/staff/get.go b/param/staff/staff/get.go deleted file mode 100644 index ee4625b..0000000 --- a/param/staff/staff/get.go +++ /dev/null @@ -1 +0,0 @@ -package staffparam diff --git a/param/staff/staff/login.go b/param/staff/staff/login.go deleted file mode 100644 index ee4625b..0000000 --- a/param/staff/staff/login.go +++ /dev/null @@ -1 +0,0 @@ -package staffparam diff --git a/service/admin/admin/get.go b/service/admin/admin/get.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/get.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/get_all_benefactor.go b/service/admin/admin/get_all_benefactor.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/get_all_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/get_all_staff.go b/service/admin/admin/get_all_staff.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/get_all_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/get_benefactor.go b/service/admin/admin/get_benefactor.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/get_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/get_staff.go b/service/admin/admin/get_staff.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/get_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/login.go b/service/admin/admin/login.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/login.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/register_benefactor.go b/service/admin/admin/register_benefactor.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/register_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/register_staff.go b/service/admin/admin/register_staff.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/register_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/service.go b/service/admin/admin/service.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/service.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/update_benefactor.go b/service/admin/admin/update_benefactor.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/update_benefactor.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/admin/update_staff.go b/service/admin/admin/update_staff.go deleted file mode 100644 index da1256d..0000000 --- a/service/admin/admin/update_staff.go +++ /dev/null @@ -1 +0,0 @@ -package adminservice diff --git a/service/admin/super_admin/get_admin.go b/service/admin/super_admin/get_admin.go deleted file mode 100644 index 5806c01..0000000 --- a/service/admin/super_admin/get_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminservice diff --git a/service/admin/super_admin/get_all_admin.go b/service/admin/super_admin/get_all_admin.go deleted file mode 100644 index 5806c01..0000000 --- a/service/admin/super_admin/get_all_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminservice diff --git a/service/admin/super_admin/login.go b/service/admin/super_admin/login.go deleted file mode 100644 index 5806c01..0000000 --- a/service/admin/super_admin/login.go +++ /dev/null @@ -1 +0,0 @@ -package superadminservice diff --git a/service/admin/super_admin/register_admin.go b/service/admin/super_admin/register_admin.go deleted file mode 100644 index 5806c01..0000000 --- a/service/admin/super_admin/register_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminservice diff --git a/service/admin/super_admin/service.go b/service/admin/super_admin/service.go deleted file mode 100644 index 5806c01..0000000 --- a/service/admin/super_admin/service.go +++ /dev/null @@ -1 +0,0 @@ -package superadminservice diff --git a/service/admin/super_admin/update_admin.go b/service/admin/super_admin/update_admin.go deleted file mode 100644 index 5806c01..0000000 --- a/service/admin/super_admin/update_admin.go +++ /dev/null @@ -1 +0,0 @@ -package superadminservice diff --git a/service/auth/admin/login.go b/service/auth/admin/login.go new file mode 100644 index 0000000..d78da5d --- /dev/null +++ b/service/auth/admin/login.go @@ -0,0 +1 @@ +package admin diff --git a/service/auth/service.go b/service/auth/admin/service.go similarity index 95% rename from service/auth/service.go rename to service/auth/admin/service.go index 9c97a75..bb115be 100644 --- a/service/auth/service.go +++ b/service/auth/admin/service.go @@ -1,4 +1,4 @@ -package authservice +package admin import ( "time" diff --git a/service/auth/user/login.go b/service/auth/user/login.go new file mode 100644 index 0000000..a00006b --- /dev/null +++ b/service/auth/user/login.go @@ -0,0 +1 @@ +package user diff --git a/service/auth/user/register.go b/service/auth/user/register.go new file mode 100644 index 0000000..a00006b --- /dev/null +++ b/service/auth/user/register.go @@ -0,0 +1 @@ +package user diff --git a/service/auth/user/service.go b/service/auth/user/service.go new file mode 100644 index 0000000..349069f --- /dev/null +++ b/service/auth/user/service.go @@ -0,0 +1,23 @@ +package user + +import ( + "time" +) + +type Config struct { + SignKey string `koanf:"sign_key"` + AccessExpirationTime time.Duration `koanf:"access_expiration_time"` + RefreshExpirationTime time.Duration `koanf:"refresh_expiration_time"` + AccessSubject string `koanf:"access_subject"` + RefreshSubject string `koanf:"refresh_subject"` +} + +type Service struct { + config Config +} + +func New(cfg Config) Service { + return Service{ + config: cfg, + } +} diff --git a/service/benefactor/benefactor/get.go b/service/benefactor/benefactor/get.go deleted file mode 100644 index 5673010..0000000 --- a/service/benefactor/benefactor/get.go +++ /dev/null @@ -1 +0,0 @@ -package benefactorservice diff --git a/service/benefactor/benefactor/login.go b/service/benefactor/benefactor/login.go deleted file mode 100644 index 5c293b5..0000000 --- a/service/benefactor/benefactor/login.go +++ /dev/null @@ -1,45 +0,0 @@ -package benefactorservice - -import ( - "fmt" - - "gameapp/param" - "gameapp/pkg/richerror" -) - -func (s Service) Login(req param.LoginRequest) (param.LoginResponse, error) { - const op = "benefactorservice.Login" - - // TODO - it would be better to user two separate method for existence check and getUserByPhoneNumber - user, err := s.repo.GetUserByPhoneNumber(req.PhoneNumber) - if err != nil { - return param.LoginResponse{}, richerror.New(op).WithErr(err). - WithMeta(map[string]interface{}{"phone_number": req.PhoneNumber}) - } - - if user.Password != getMD5Hash(req.Password) { - return param.LoginResponse{}, fmt.Errorf("username or password isn't correct") - } - - accessToken, err := s.auth.CreateAccessToken(user) - if err != nil { - return param.LoginResponse{}, fmt.Errorf("unexpected error: %w", err) - } - - refreshToken, err := s.auth.CreateRefreshToken(user) - if err != nil { - return param.LoginResponse{}, fmt.Errorf("unexpected error: %w", err) - } - - return param.LoginResponse{ - User: param.UserInfo{ - ID: user.ID, - PhoneNumber: user.PhoneNumber, - Name: user.Name, - }, - Tokens: param.Tokens{ - AccessToken: accessToken, - RefreshToken: refreshToken, - }, - }, nil -} diff --git a/service/benefactor/benefactor/register.go b/service/benefactor/benefactor/register.go deleted file mode 100644 index 22b921c..0000000 --- a/service/benefactor/benefactor/register.go +++ /dev/null @@ -1,36 +0,0 @@ -package benefactorservice - -import ( - "fmt" - - entity "git.gocasts.ir/ebhomengo/niki/entity" - param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactor" -) - -// rol -// login(sms)-> {rigester}() -> next -func (s Service) Register(req param.RegisterRequest) (param.RegisterResponse, error) { - // TODO - we should verify phone number by verification code - - // TODO - replace md5 with bcrypt - user := entity.Benefactor{ - ID: 0, - PhoneNumber: req.PhoneNumber, - Name: req.Name, - Password: getMD5Hash(req.Password), - Role: entity.BenefactorRole, - } - - // create new user in storage - createdUser, err := s.repo.Register(user) - if err != nil { - return param.RegisterResponse{}, fmt.Errorf("unexpected error: %w", err) - } - - // return created user - return param.RegisterResponse{User: param.UserInfo{ - ID: createdUser.ID, - PhoneNumber: createdUser.Name, - Name: createdUser.PhoneNumber, - }}, nil -} diff --git a/service/benefactor/benefactor/service.go b/service/benefactor/benefactor/service.go deleted file mode 100644 index a3ec957..0000000 --- a/service/benefactor/benefactor/service.go +++ /dev/null @@ -1,27 +0,0 @@ -package benefactorservice - -import ( - "context" - - "git.gocasts.ir/ebhomengo/niki/entity" -) - -type Repository interface { - Register(benefactor entity.Benefactor) (entity.Benefactor, error) - GetUserByPhoneNumber(phoneNumber string) (entity.Benefactor, error) - GetUserByID(ctx context.Context, userID uint) (entity.Benefactor, error) -} - -type AuthGenerator interface { - CreateAccessToken(benefactor entity.Benefactor) (string, error) - CreateRefreshToken(benefactor entity.Benefactor) (string, error) -} - -type Service struct { - auth AuthGenerator - repo Repository -} - -func New(authGenerator AuthGenerator, repo Repository) Service { - return Service{auth: authGenerator, repo: repo} -} diff --git a/service/benefactor/benefactor/update.go b/service/benefactor/benefactor/update.go deleted file mode 100644 index 5673010..0000000 --- a/service/benefactor/benefactor/update.go +++ /dev/null @@ -1 +0,0 @@ -package benefactorservice diff --git a/service/staff/staff/get.go b/service/staff/staff/get.go deleted file mode 100644 index b246338..0000000 --- a/service/staff/staff/get.go +++ /dev/null @@ -1 +0,0 @@ -package staffservice diff --git a/service/staff/staff/login.go b/service/staff/staff/login.go deleted file mode 100644 index 30388e0..0000000 --- a/service/staff/staff/login.go +++ /dev/null @@ -1,45 +0,0 @@ -package staffservice - -import ( - "fmt" - - "gameapp/param" - "gameapp/pkg/richerror" -) - -func (s Service) Login(req param.LoginRequest) (param.LoginResponse, error) { - const op = "benefactorservice.Login" - - // TODO - it would be better to user two separate method for existence check and getUserByPhoneNumber - user, err := s.repo.GetUserByPhoneNumber(req.PhoneNumber) - if err != nil { - return param.LoginResponse{}, richerror.New(op).WithErr(err). - WithMeta(map[string]interface{}{"phone_number": req.PhoneNumber}) - } - - if user.Password != getMD5Hash(req.Password) { - return param.LoginResponse{}, fmt.Errorf("username or password isn't correct") - } - - accessToken, err := s.auth.CreateAccessToken(user) - if err != nil { - return param.LoginResponse{}, fmt.Errorf("unexpected error: %w", err) - } - - refreshToken, err := s.auth.CreateRefreshToken(user) - if err != nil { - return param.LoginResponse{}, fmt.Errorf("unexpected error: %w", err) - } - - return param.LoginResponse{ - User: param.UserInfo{ - ID: user.ID, - PhoneNumber: user.PhoneNumber, - Name: user.Name, - }, - Tokens: param.Tokens{ - AccessToken: accessToken, - RefreshToken: refreshToken, - }, - }, nil -} diff --git a/service/staff/staff/service.go b/service/staff/staff/service.go deleted file mode 100644 index 9a21f9e..0000000 --- a/service/staff/staff/service.go +++ /dev/null @@ -1,27 +0,0 @@ -package staffservice - -import ( - "context" - - "git.gocasts.ir/ebhomengo/niki/entity" -) - -type Repository interface { - Register(benefactor entity.Benefactor) (entity.Benefactor, error) - GetUserByPhoneNumber(phoneNumber string) (entity.Benefactor, error) - GetUserByID(ctx context.Context, userID uint) (entity.Benefactor, error) -} - -type AuthGenerator interface { - CreateAccessToken(benefactor entity.Benefactor) (string, error) - CreateRefreshToken(benefactor entity.Benefactor) (string, error) -} - -type Service struct { - auth AuthGenerator - repo Repository -} - -func New(authGenerator AuthGenerator, repo Repository) Service { - return Service{auth: authGenerator, repo: repo} -}