bikin fitur crud registrasi counter
Some checks failed
Go-test / build (push) Has been cancelled

This commit is contained in:
2025-12-01 10:43:56 +07:00
parent 61af0740ee
commit 6a985c837f
4 changed files with 1021 additions and 2 deletions

View File

@@ -21,6 +21,63 @@ type MsRegistrationCounter struct {
DsSdLocation sql.NullString `json:"ds_sd_location,omitempty" db:"ds_sd_location"`
}
type MsRegistrationCounterDetail struct {
ID int64 `json:"id" db:"id"`
Name sql.NullString `json:"name,omitempty" db:"name"`
Code sql.NullString `json:"code,omitempty" db:"code"`
Icon sql.NullString `json:"icon,omitempty" db:"icon"`
Quota sql.NullInt16 `json:"quota,omitempty" db:"quota"`
Active sql.NullBool `json:"active,omitempty" db:"active"`
HealthCareType sql.NullString `json:"healthcaretype,omitempty" db:"healthcaretype"`
ServiceType sql.NullString `json:"servicetype,omitempty" db:"fk_ref_service_type_id"`
}
func (m MsRegistrationCounterDetail) MarshalJSON() ([]byte, error) {
// Buat alias untuk menghindari rekursi tak terbatas saat pemanggilan json.Marshal
type Alias MsRegistrationCounterDetail
// Buat struct anonim dengan field pointer untuk menangani nilai NULL
aux := &struct {
Name *string `json:"name,omitempty"`
Code *string `json:"code,omitempty"`
Icon *string `json:"icon,omitempty"`
Quota *int16 `json:"quota,omitempty"`
Active *bool `json:"active,omitempty"`
HealthCareType *string `json:"healthcaretype,omitempty"`
ServiceType *string `json:"servicetype,omitempty"`
// Embed alias untuk menyertakan field non-nullable seperti 'id'
*Alias
}{
Alias: (*Alias)(&m),
}
// Jika field asli valid, isi pointer di struct anonim
if m.Name.Valid {
aux.Name = &m.Name.String
}
if m.Code.Valid {
aux.Code = &m.Code.String
}
if m.Icon.Valid {
aux.Icon = &m.Icon.String
}
if m.Quota.Valid {
aux.Quota = &m.Quota.Int16
}
if m.Active.Valid {
aux.Active = &m.Active.Bool
}
if m.HealthCareType.Valid {
aux.HealthCareType = &m.HealthCareType.String
}
if m.ServiceType.Valid {
aux.ServiceType = &m.ServiceType.String
}
// Marshal struct anonim yang sudah "bersih"
return json.Marshal(aux)
}
func (r MsRegistrationCounter) MarshalJSON() ([]byte, error) {
type Alias MsRegistrationCounter
@@ -72,6 +129,7 @@ func (r MsRegistrationCounter) MarshalJSON() ([]byte, error) {
return json.Marshal(aux)
}
// Helper methods untuk mendapatkan nilai yang aman
func (r *MsRegistrationCounter) GetName() string {
if r.Name.Valid {
@@ -108,9 +166,14 @@ func (r *MsRegistrationCounter) GetActive() bool {
return false
}
// type MsRegistrationCounterGetByIDResponse struct {
// Message string `json:"message"`
// Data *MsRegistrationCounter `json:"data"`
// }
type MsRegistrationCounterGetByIDResponse struct {
Message string `json:"message"`
Data *MsRegistrationCounter `json:"data"`
Data *MsRegistrationCounterDetail `json:"data"`
}
type MsRegistrationCounterGetResponse struct {