prepair to using go concurrent
This commit is contained in:
1 parent
ce0508294c
commit
47816debd3
10 files changed
+222
-139
No files matched your search
+27
-8
@@ -2,28 +2,47 @@ package routes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/gorilla/mux"
|
||||
"linhdevtran99/rest-api/models"
|
||||
"linhdevtran99/rest-api/rest-api/services"
|
||||
"linhdevtran99/rest-api/utils"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RegisterNewAccount(w http.ResponseWriter, r *http.Request) error {
|
||||
client := utils.MongoDB
|
||||
if r.Method == http.MethodPost {
|
||||
var registerInfo models.CreateUser
|
||||
|
||||
_ = json.NewDecoder(r.Body).Decode(®isterInfo)
|
||||
//call function check info user type in
|
||||
validRegisterInfo := services.CheckAndValidRegisterFiled(®isterInfo, w)
|
||||
//call function check data user use in past or not
|
||||
isValidData := services.CheckAccountExist(client, registerInfo.Username, registerInfo.Email, w)
|
||||
|
||||
if isValidData == false || validRegisterInfo == false {
|
||||
return errors.New("USER DON'T HAVE VALID INFO FOR REGISTER ACCOUNT")
|
||||
validRegisterInfo, responseAPI := services.CheckAndValidRegisterFiled(®isterInfo)
|
||||
if responseAPI != nil {
|
||||
return utils.WriteJSON(w, responseAPI.Code, responseAPI.Err.Error())
|
||||
}
|
||||
//call function check data user use in past or not
|
||||
isValidData, responseAPI := services.CheckAccountExist(utils.MongoDB, registerInfo.Username, registerInfo.Email)
|
||||
if responseAPI != nil {
|
||||
return utils.WriteJSON(w, responseAPI.Code, responseAPI.Err.Error())
|
||||
}
|
||||
|
||||
preUserData := &models.PreusersMongo{
|
||||
Username: registerInfo.Username,
|
||||
Email: registerInfo.Email,
|
||||
PhoneNumber: registerInfo.PhoneNumber,
|
||||
HashPassword: registerInfo.Password,
|
||||
CreatedDate: time.Now(),
|
||||
UpdateDate: time.Now(),
|
||||
VerifySentCount: 1,
|
||||
}
|
||||
|
||||
services.CheckAndWritePreuser(preUserData)
|
||||
|
||||
//debug
|
||||
if isValidData == true || validRegisterInfo == true {
|
||||
return utils.WriteJSON(w, http.StatusOK, "USER HAVE VALID INFO FOR REGISTER ACCOUNT")
|
||||
}
|
||||
//debug
|
||||
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user