add createMethod #1
|
@ -2,7 +2,6 @@ package usermngmt
|
|||
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
"fmt"
|
||||
|
||||
"github.com/Selly-Modules/logger"
|
||||
|
@ -12,13 +11,13 @@ import (
|
|||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
||||
|
||||
// CreateOptions ...
|
||||
type CreateOptions struct {
|
||||
Name string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Phone string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Email string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
HashedPassword string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Status string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
RoleID primitive.ObjectID
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Other string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Name string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Phone string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Email string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Password string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Status string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
RoleID primitive.ObjectID
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Other string
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
}
|
||||
|
||||
// Create ...
|
||||
|
@ -29,7 +28,7 @@ func (s Service) Create(payload CreateOptions) error {
|
|||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
||||
)
|
||||
|
||||
// Validate payload
|
||||
err := payload.validate()
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
err := payload.validate(ctx)
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -40,20 +39,10 @@ func (s Service) Create(payload CreateOptions) error {
|
|||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
||||
return err
|
||||
}
|
||||
|
||||
// Find roleID exists or not
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
if !s.isRoleIDAlreadyExisted(ctx, userData.RoleID) {
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
return errors.New("roleID does not exist")
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
}
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
// Find phone number,email exists or not
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
if s.isPhoneNumberOrEmailAlreadyExisted(ctx, userData.Phone, userData.Email) {
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
return errors.New("phone number or email already existed")
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
}
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
// Create device
|
||||
_, err = col.InsertOne(ctx, userData)
|
||||
if err != nil {
|
||||
logger.Error("usermngmt - Create ", logger.LogData{
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
logger.Error("usermngmt - Create", logger.LogData{
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
"doc": userData,
|
||||
"err": err.Error(),
|
||||
})
|
||||
|
@ -70,7 +59,7 @@ func (payload CreateOptions) newUser() (result User, err error) {
|
|||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
||||
Name: payload.Name,
|
||||
Phone: payload.Phone,
|
||||
Email: payload.Email,
|
||||
HashedPassword: payload.HashedPassword,
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
HashedPassword: hashPassword(payload.Password),
|
||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
||||
Status: payload.Status,
|
||||
RoleID: payload.RoleID,
|
||||
Other: payload.Other,
|
||||
|
|
|||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
|
@ -6,4 +6,6 @@ const (
|
|||
tableRole = "roles"
|
||||
|
||||
timezoneHCM = "Asia/Ho_Chi_Minh"
|
||||
|
||||
passwordHashingCost = 14
|
||||
)
|
||||
|
|
34
db.go
|
@ -12,18 +12,23 @@ import (
|
|||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() done done
|
||||
|
||||
// getUserCollection ...
|
||||
func (s Service) getUserCollection() *mongo.Collection {
|
||||
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableUser))
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
if s.TablePrefix != "" {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableUser))
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
}
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
return s.DB.Collection(tableUser)
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
}
|
||||
|
||||
// getRoleCollection ...
|
||||
func (s Service) getRoleCollection() *mongo.Collection {
|
||||
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableRole))
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
if s.TablePrefix != "" {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableRole))
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
}
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
return s.DB.Collection(tableRole)
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
}
|
||||
|
||||
func (s Service) isPhoneNumberOrEmailAlreadyExisted(ctx context.Context, phone, email string) bool {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
func (s Service) isPhoneNumberOrEmailExisted(ctx context.Context, phone, email string) bool {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
var (
|
||||
col = s.getUserCollection()
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
user = User{}
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
col = s.getUserCollection()
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
)
|
||||
|
||||
// Find
|
||||
|
@ -37,32 +42,33 @@ func (s Service) isPhoneNumberOrEmailAlreadyExisted(ctx context.Context, phone,
|
|||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() done done
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := col.FindOne(ctx, cond).Decode(&user); err != nil {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
logger.Error("usermngmt - findByCondition", logger.LogData{
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
total, err := col.CountDocuments(ctx, cond)
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
if err != nil {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
logger.Error("usermngmt - countUserByCondition", logger.LogData{
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
"condition": cond,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return true
|
||||
}
|
||||
return !user.ID.IsZero()
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
return total != 0
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
}
|
||||
|
||||
func (s Service) isRoleIDAlreadyExisted(ctx context.Context, roleID primitive.ObjectID) bool {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
func (s Service) isRoleIDExisted(ctx context.Context, roleID primitive.ObjectID) bool {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
var (
|
||||
col = s.getRoleCollection()
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
role = Role{}
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
col = s.getRoleCollection()
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
)
|
||||
|
||||
// Find
|
||||
cond := bson.M{
|
||||
"_id": roleID,
|
||||
}
|
||||
if err := col.FindOne(ctx, cond).Decode(&role); err != nil {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
logger.Error("usermngmt - findRoleByCondition", logger.LogData{
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
total, err := col.CountDocuments(ctx, cond)
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
if err != nil {
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
logger.Error("usermngmt - countRoleByCondition", logger.LogData{
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
"condition": cond,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return false
|
||||
}
|
||||
return !role.ID.IsZero()
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
return total != 0
|
||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
||||
}
|
||||
|
|
|||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() done done
|
12
helper.go
|
@ -1 +1,13 @@
|
|||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
![]() done done
|
||||
package usermngmt
|
||||
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
import "golang.org/x/crypto/bcrypt"
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
func hashPassword(password string) string {
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), passwordHashingCost)
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
return string(bytes)
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
}
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
func checkPasswordHash(password, hash string) bool {
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
return err == nil
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
}
|
||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
||||
|
|
|||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
![]() done done
|
4
model.go
|
@ -12,9 +12,9 @@ type User struct {
|
|||
![]() HashedPassword HashedPassword
![]() HashedPassword HashedPassword
![]() done done
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]()
`bson:"roleId"`
![]() done done
![]() done done
![]() done done
![]() done done
|
||||
Name string `bson:"name" json:"name"`
|
||||
Phone string `bson:"phone" json:"phone"` // unique
|
||||
Email string `bson:"email" json:"email"` // unique
|
||||
HashedPassword string `bson:"hashedPassword" json:"hashedPassword"`
|
||||
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
|
||||
HashedPassword string `bson:"hashedPassword" json:"-"`
|
||||
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
|
||||
Status string `bson:"status" json:"status"`
|
||||
RoleID primitive.ObjectID `bson:"roleID" json:"roleId"`
|
||||
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
|
||||
RoleID primitive.ObjectID `bson:"roleId" json:"roleId"`
|
||||
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
|
||||
Other string `bson:"other" json:"other"`
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
|
||||
|
|
|||
![]() HashedPassword HashedPassword
![]() HashedPassword HashedPassword
![]() done done
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]()
`bson:"roleId"`
![]() done done
![]() done done
![]() done done
![]() done done
|
|
@ -31,7 +31,7 @@ var s *Service
|
|||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
![]() done done
|
||||
|
||||
// Init ...
|
||||
func Init(config Config) (*Service, error) {
|
||||
if config.MongoDB.Host == "" || config.TablePrefix == "" {
|
||||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
|
||||
if config.MongoDB.Host == "" {
|
||||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
|
||||
return nil, errors.New("please provide all necessary information for init user")
|
||||
}
|
||||
|
||||
|
|
|||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
![]() done done
|
21
validate.go
|
@ -1,12 +1,13 @@
|
|||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
||||
package usermngmt
|
||||
|
||||
import (
|
||||
"context"
|
||||
![]() check plain password check plain password
![]() done done
|
||||
"errors"
|
||||
|
||||
"github.com/Selly-Modules/logger"
|
||||
)
|
||||
|
||||
func (co CreateOptions) validate() error {
|
||||
![]() check plain password check plain password
![]() done done
|
||||
func (co CreateOptions) validate(ctx context.Context) error {
|
||||
![]() check plain password check plain password
![]() done done
|
||||
// Name
|
||||
if co.Name == "" {
|
||||
logger.Error("usermngmt - Create: no Name data", logger.LogData{
|
||||
|
@ -31,12 +32,12 @@ func (co CreateOptions) validate() error {
|
|||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
||||
return errors.New("no email data")
|
||||
}
|
||||
|
||||
// HashedPassword
|
||||
![]() check plain password check plain password
![]() done done
|
||||
if co.HashedPassword == "" {
|
||||
![]() check plain password check plain password
![]() done done
|
||||
logger.Error("usermngmt - Create: no hashedPassword data", logger.LogData{
|
||||
![]() check plain password check plain password
![]() done done
|
||||
// Password
|
||||
![]() check plain password check plain password
![]() done done
|
||||
if co.Password == "" {
|
||||
![]() check plain password check plain password
![]() done done
|
||||
logger.Error("usermngmt - Create: no password data", logger.LogData{
|
||||
![]() check plain password check plain password
![]() done done
|
||||
"payload": co,
|
||||
})
|
||||
return errors.New("no hashedPassword data")
|
||||
![]() check plain password check plain password
![]() done done
|
||||
return errors.New("no password data")
|
||||
![]() check plain password check plain password
![]() done done
|
||||
}
|
||||
|
||||
// Status
|
||||
|
@ -55,5 +56,15 @@ func (co CreateOptions) validate() error {
|
|||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
||||
return errors.New("invalid roleID data")
|
||||
}
|
||||
|
||||
// Find roleID exists or not
|
||||
![]() check plain password check plain password
![]() done done
|
||||
if !s.isRoleIDExisted(ctx, co.RoleID) {
|
||||
![]() check plain password check plain password
![]() done done
|
||||
return errors.New("role id does not exist")
|
||||
![]() check plain password check plain password
![]() done done
|
||||
}
|
||||
![]() check plain password check plain password
![]() done done
|
||||
|
||||
![]() check plain password check plain password
![]() done done
|
||||
// Find phone number,email exists or not
|
||||
![]() check plain password check plain password
![]() done done
|
||||
if s.isPhoneNumberOrEmailExisted(ctx, co.Phone, co.Email) {
|
||||
![]() check plain password check plain password
![]() done done
|
||||
return errors.New("phone number or email already existed")
|
||||
![]() check plain password check plain password
![]() done done
|
||||
}
|
||||
![]() check plain password check plain password
![]() done done
|
||||
|
||||
![]() check plain password check plain password
![]() done done
|
||||
return nil
|
||||
}
|
||||
|
|
|||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
boolean thì:
is
has
trên sửa lại
isNameOrPhoneExisted
boolean thì:
is
has
trên sửa lại
isNameOrPhoneExisted
have name or phone existed -> phone number or email already existed
have name or phone existed -> phone number or email already existed
thiếu check roleId trong db
thiếu check roleId trong db
done
done
done
done
done
done
password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
isRoleIDAlreadyExisted -> isRoleIDExisted
isRoleIDAlreadyExisted -> isRoleIDExisted
roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
func này với func isRoleIDExisted nên đưa vô func
payload.validate()
, gom tất cả validate trước khi xử lý về 1 chỗfunc này với func isRoleIDExisted nên đưa vô func
payload.validate()
, gom tất cả validate trước khi xử lý về 1 chỗbỏ dấu space sau Create
bỏ dấu space sau Create
password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
done
done
done
done
done
done
done
done
done
done
done
done
đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
nên là
string
, nếu client không dùng mongodb thì phải cài thêm thư việnnote: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
nên là
string
, nếu client không dùng mongodb thì phải cài thêm thư việnnote: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
done
done
done
done