-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue-75, handlers and service layers created, bugs fixed, new SQL sсripts created #97
Conversation
request.Email = keyVal["email"] | ||
request.Password = keyVal["password"] | ||
|
||
err = r.Body.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it is better to close the body right after ReadAll call?
} | ||
|
||
keyVal := make(map[string]string) | ||
err = json.Unmarshal(body, &keyVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unmarshal it directly in SignupRequest
return | ||
} | ||
|
||
keyVal := make(map[string]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this map please it is not needed
err = postgresql.ErrNoSymbols | ||
handleError(err, w) | ||
return | ||
} else if len(keyVal["password"]) > 256 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a separate package for all your validations functions.
} | ||
|
||
if keyVal["password"] == "" { | ||
err = postgresql.ErrNoSymbols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is PostgreSQL error?
var str string | ||
|
||
for _, val := range u.Roles { | ||
str = str + val + "," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use TextArray instead of this
return | ||
} | ||
|
||
err = validation.Data(&request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make an issue to refactor validate function to make it reusable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #100
if err != nil { | ||
handleError(err, w) | ||
return | ||
} else if result == true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if result is not true?
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ToUser(u) | ||
} | ||
|
||
func ToUser(privatUser user) (*models.Users, error) { | ||
// CheckEmail returns email if it exists in DB or empty string | ||
func (ur *UsersRepository) CheckEmail (email string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is not needed, just use GetUserByEmail
func (ur *UsersRepository) GetEmailByToken (token *models.EmailVerificationTokens) (string, error) { | ||
var email string | ||
|
||
err := ur.DB.Get(&email, "SELECT (SELECT email FROM users WHERE id = email_verification_tokens.id) FROM email_verification_tokens WHERE verification_token = $1", token.VerificationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make an issue to simplify this query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #101
pkg/ims/service/service.go
Outdated
return err | ||
} | ||
|
||
err = service.SignUpRepo.InsertUser(&user) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to start a transaction before making your first request to DB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand enough what do you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem was solved at the zoom conference
return | ||
} | ||
|
||
// Send Email Verification Token function must be here! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function should be added in service layer
} | ||
} | ||
|
||
func (h *SignUpHandler)EmailVerificationToken(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe EmailVerificationToken
should be named CheckEmailVerificationToken
Email string `json:"email" db:"email"` | ||
MobilePhone string `json:"mobile_phone" db:"mobile_phone"` | ||
CreatedAt time.Time `json:"created_at" db:"created_at"` | ||
ModifiedAt time.Time `json:"modified_at" db:"modified_at"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make an issue to make this field pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #110
@@ -7,26 +7,18 @@ import ( | |||
) | |||
|
|||
type CredRepository struct { | |||
db *sqlx.DB | |||
DB sqlx.Ext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can make it unexportable?
pkg/ims/service/service.go
Outdated
var exist bool | ||
var err error | ||
|
||
tx, err := service.db.Beginx() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit transaction is not needed here.
…ripts created `signup_handlers.go`: handlers layer, handle errors function declared `models.go`: added struct `SignupRepository`, corrected mistakes (`ID` type string -> int), db tags added, columns `UpdatedAt`, `CreatedAt`, `GeneratedAt` were changed from type string to type time.Time `type.go`: db tags added, columns `UpdatedAt`, `CreatedAt` were changed from type string to type time.Time `router.go`: inits routers `credentials_repository.go`: updated `signup_repository.go`: updated, modified with TextArray, `InsertUser` was moved from `signup_repository.go` into `users_repository.go` `users_repository.go`: updated, `InsertUser` was moved from `signup_repository.go` into `users_repository.go` `000005_re-creation_role.down.sql`: fixed bugs `000005_re-creation_role.up.sql`: fixed bugs `000006_change_id.up.sql`: drops unique `mobile_phone` constraint, `id` type in tables `credentials` and `email_verification_tokens` changed into integer `000006_change_id.down.sql`: rolls back `service.go`: service layer, added transactions `data.go`: validates user's entered data `email.go`: validates user's entered email `errors.go`: contains validation errors `ims-api.yaml`: updated
signup_handlers.go
: handlers layer, handle errors function declaredmodels.go
: added structSignupRepository
, corrected mistakes (ID
type string -> int)router.go
: inits routerscredentials_repository.go
: updatedsignup_repository.go
: updated, modified with TextArrayusers_repository.go
: updated000005_re-creation_role.down.sql
: fixed bugs000005_re-creation_role.up.sql
: fixed bugs000006_change_id.up.sql
: drops uniquemobile_phone
constraint,id
type in tables
credentials
andemail_verification_tokens
changed into integer000006_change_id.down.sql
service.go
: service layerdata.go
: validates user's entered dataemail.go
: validates user's entered emailerrors.go
: contains validation errorsims-api.yaml
: updatedAdded function that handles errors.
Added error handlers to
signup_handlers.go
,signup_repository.go
,users_repository.go
,credentials_repository.go
,service.go
.Closes #75