Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/lib/pq"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
@@ -497,25 +498,65 @@ func UserCreateRoute(db *sql.DB) http.HandlerFunc {
|
||||
|
||||
// ROLES
|
||||
for _, role := range payload.Roles {
|
||||
_, _ = tx.Exec(queries.InsertUserRole, newID, role)
|
||||
role = strings.TrimSpace(role)
|
||||
if role == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := tx.Exec(queries.InsertUserRole, newID, role); err != nil {
|
||||
log.Printf("USER ROLE INSERT ERROR user_id=%d role=%q err=%v", newID, role, err)
|
||||
http.Error(w, "Rol eklenemedi", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// DEPARTMENTS
|
||||
for _, d := range payload.Departments {
|
||||
_, _ = tx.Exec(queries.InsertUserDepartment, newID, d.Code)
|
||||
code := strings.TrimSpace(d.Code)
|
||||
if code == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := tx.Exec(queries.InsertUserDepartment, newID, code); err != nil {
|
||||
log.Printf("USER DEPARTMENT INSERT ERROR user_id=%d department=%q err=%v", newID, code, err)
|
||||
http.Error(w, "Departman eklenemedi", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// PIYASALAR
|
||||
for _, p := range payload.Piyasalar {
|
||||
_, _ = tx.Exec(queries.InsertUserPiyasa, newID, p.Code)
|
||||
code := strings.TrimSpace(p.Code)
|
||||
if code == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := tx.Exec(queries.InsertUserPiyasa, newID, code); err != nil {
|
||||
log.Printf("USER PIYASA INSERT ERROR user_id=%d piyasa=%q err=%v", newID, code, err)
|
||||
http.Error(w, "Piyasa eklenemedi", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// NEBIM
|
||||
for _, n := range payload.NebimUsers {
|
||||
_, _ = tx.Exec(queries.InsertUserNebim, newID, n.Username)
|
||||
username := strings.TrimSpace(n.Username)
|
||||
if username == "" {
|
||||
continue
|
||||
}
|
||||
if _, err := tx.Exec(queries.InsertUserNebim, newID, username); err != nil {
|
||||
log.Printf("USER NEBIM INSERT ERROR user_id=%d username=%q err=%v", newID, username, err)
|
||||
http.Error(w, "Nebim kullanıcısı eklenemedi", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
if pe, ok := err.(*pq.Error); ok {
|
||||
log.Printf(
|
||||
"USER CREATE COMMIT ERROR user_id=%d code=%s detail=%s constraint=%s table=%s err=%v",
|
||||
newID, pe.Code, pe.Detail, pe.Constraint, pe.Table, err,
|
||||
)
|
||||
} else {
|
||||
log.Printf("USER CREATE COMMIT ERROR user_id=%d err=%v", newID, err)
|
||||
}
|
||||
http.Error(w, "Commit başarısız", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user