ilk
This commit is contained in:
88
svc/models/user_detail.go
Normal file
88
svc/models/user_detail.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package models
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// ======================================================
|
||||
// 👤 USER DETAIL — GET RESPONSE
|
||||
// UserDetail.vue formuna birebir
|
||||
// ======================================================
|
||||
type UserDetail struct {
|
||||
ID int64 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
IsActive bool `json:"is_active"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
Mobile string `json:"mobile"`
|
||||
Address string `json:"address"`
|
||||
|
||||
HasPassword bool `json:"has_password"` // 🔐 SADECE DURUM
|
||||
|
||||
// ===== İLİŞKİLER =====
|
||||
Roles []string `json:"roles"`
|
||||
Departments []DeptOption `json:"departments"`
|
||||
Piyasalar []DeptOption `json:"piyasalar"`
|
||||
NebimUsers []NebimOption `json:"nebim_users"`
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// ✍️ USER WRITE — PUT PAYLOAD
|
||||
// ======================================================
|
||||
type UserWrite struct {
|
||||
Code string `json:"code"`
|
||||
IsActive bool `json:"is_active"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
Mobile string `json:"mobile"`
|
||||
Address string `json:"address"`
|
||||
|
||||
Roles []string `json:"roles"`
|
||||
Departments []DeptOption `json:"departments"`
|
||||
Piyasalar []DeptOption `json:"piyasalar"`
|
||||
NebimUsers []NebimOption `json:"nebim_users"`
|
||||
}
|
||||
|
||||
// ======================================================
|
||||
// 🔹 COMMON OPTION MODELS
|
||||
// ======================================================
|
||||
type DeptOption struct {
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
// Flexible JSON decode
|
||||
func (d *DeptOption) UnmarshalJSON(data []byte) error {
|
||||
|
||||
var raw struct {
|
||||
Code any `json:"code"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Title = raw.Title
|
||||
|
||||
switch v := raw.Code.(type) {
|
||||
|
||||
case string:
|
||||
d.Code = v
|
||||
|
||||
case []any:
|
||||
if len(v) > 0 {
|
||||
if s, ok := v[0].(string); ok {
|
||||
d.Code = s
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
d.Code = ""
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type NebimOption struct {
|
||||
Username string `json:"username"`
|
||||
UserGroupCode string `json:"user_group_code"`
|
||||
}
|
||||
Reference in New Issue
Block a user