247 lines
8.1 KiB
Go
247 lines
8.1 KiB
Go
package models
|
|
|
|
import (
|
|
"api-service/internal/models"
|
|
"database/sql"
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
|
|
type MsRegistrationCounter 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"`
|
|
FKRefHealtcareTypeID models.NullableInt32 `json:"fk_ref_healtcare_type_id,omitempty" db:"fk_ref_healtcare_type_id"`
|
|
FKRefServiceTypeID models.NullableInt32 `json:"fk_ref_service_type_id,omitempty" db:"fk_ref_service_type_id"`
|
|
FKSdLocationID sql.NullString `json:"fk_sd_location_id,omitempty" db:"fk_sd_location_id"`
|
|
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:"servicetype"`
|
|
Location sql.NullString `json:"location" db:"location"`
|
|
DisplayLocation sql.NullString `json:"displaylocation" db:"displaylocation"`
|
|
}
|
|
|
|
|
|
func (m MsRegistrationCounterDetail) MarshalJSON() ([]byte, error) {
|
|
type Alias MsRegistrationCounterDetail
|
|
|
|
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"`
|
|
Location *string `json:"location"`
|
|
DisplayLocation *string `json:"displaylocation"`
|
|
*Alias
|
|
}{
|
|
Alias: (*Alias)(&m),
|
|
}
|
|
|
|
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.Location.Valid {
|
|
aux.Location = &m.Location.String
|
|
} else {
|
|
emptyStr := ""
|
|
aux.Location = &emptyStr
|
|
}
|
|
|
|
if m.DisplayLocation.Valid {
|
|
aux.DisplayLocation = &m.DisplayLocation.String
|
|
} else {
|
|
emptyStr := ""
|
|
aux.DisplayLocation = &emptyStr
|
|
}
|
|
|
|
if m.HealthCareType.Valid {
|
|
aux.HealthCareType = &m.HealthCareType.String
|
|
}
|
|
if m.ServiceType.Valid {
|
|
aux.ServiceType = &m.ServiceType.String
|
|
}
|
|
|
|
return json.Marshal(aux)
|
|
}
|
|
|
|
func (r MsRegistrationCounter) MarshalJSON() ([]byte, error) {
|
|
type Alias MsRegistrationCounter
|
|
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"`
|
|
FKRefHealtcareTypeID *int32 `json:"fk_ref_healtcare_type_id,omitempty"`
|
|
FKRefServiceTypeID *int32 `json:"fk_ref_service_type_id,omitempty"`
|
|
FKSdLocationID *string `json:"fk_sd_location_id,omitempty"`
|
|
DsSdLocation *string `json:"ds_sd_location,omitempty"`
|
|
*Alias
|
|
}{
|
|
Alias: (*Alias)(&r),
|
|
}
|
|
|
|
if r.Name.Valid {
|
|
aux.Name = &r.Name.String
|
|
}
|
|
if r.Code.Valid {
|
|
aux.Code = &r.Code.String
|
|
}
|
|
if r.Icon.Valid {
|
|
aux.Icon = &r.Icon.String
|
|
}
|
|
if r.Quota.Valid {
|
|
aux.Quota = &r.Quota.Int16
|
|
}
|
|
if r.Active.Valid {
|
|
aux.Active = &r.Active.Bool
|
|
}
|
|
if r.FKRefHealtcareTypeID.Valid {
|
|
fkrht := int32(r.FKRefHealtcareTypeID.Int32)
|
|
aux.FKRefHealtcareTypeID = &fkrht
|
|
}
|
|
if r.FKRefServiceTypeID.Valid {
|
|
fkrst := int32(r.FKRefServiceTypeID.Int32)
|
|
aux.FKRefServiceTypeID = &fkrst
|
|
}
|
|
if r.FKSdLocationID.Valid {
|
|
aux.FKSdLocationID = &r.FKSdLocationID.String
|
|
}
|
|
if r.DsSdLocation.Valid {
|
|
aux.DsSdLocation = &r.DsSdLocation.String
|
|
}
|
|
|
|
return json.Marshal(aux)
|
|
}
|
|
|
|
|
|
// Helper methods untuk mendapatkan nilai yang aman
|
|
func (r *MsRegistrationCounter) GetName() string {
|
|
if r.Name.Valid {
|
|
return r.Name.String
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (r *MsRegistrationCounter) GetCode() string {
|
|
if r.Code.Valid {
|
|
return r.Code.String
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (r *MsRegistrationCounter) GetIcon() string {
|
|
if r.Icon.Valid {
|
|
return r.Icon.String
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (r *MsRegistrationCounter) GetQuota() int16 {
|
|
if r.Quota.Valid {
|
|
return r.Quota.Int16
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (r *MsRegistrationCounter) GetActive() bool {
|
|
if r.Active.Valid {
|
|
return r.Active.Bool
|
|
}
|
|
return false
|
|
}
|
|
|
|
// type MsRegistrationCounterGetByIDResponse struct {
|
|
// Message string `json:"message"`
|
|
// Data *MsRegistrationCounter `json:"data"`
|
|
// }
|
|
|
|
type MsRegistrationCounterGetByIDResponse struct {
|
|
Message string `json:"message"`
|
|
Data *MsRegistrationCounterDetail `json:"data"`
|
|
}
|
|
|
|
type MsRegistrationCounterGetResponse struct {
|
|
Message string `json:"message"`
|
|
Data []MsRegistrationCounter `json:"data"`
|
|
Meta models.MetaResponse `json:"meta"`
|
|
Summary *models.AggregateData `json:"summary,omitempty"`
|
|
}
|
|
|
|
type MsRegistrationCounterCreateRequest struct {
|
|
Name string `json:"name"`
|
|
Code string `json:"code"`
|
|
Icon string `json:"icon"`
|
|
Quota int16 `json:"quota" validate:"min=0"`
|
|
Active bool `json:"active"`
|
|
FKRefHealtcareTypeID int32 `json:"fk_ref_healtcare_type_id"`
|
|
FKRefServiceTypeID int32 `json:"fk_ref_service_type_id"`
|
|
FKSdLocationID string `json:"fk_sd_location_id"`
|
|
DsSdLocation string `json:"ds_sd_location"`
|
|
}
|
|
|
|
type MsRegistrationCounterCreateResponse struct {
|
|
Message string `json:"message"`
|
|
Data *MsRegistrationCounter `json:"data"`
|
|
}
|
|
|
|
type MsRegistrationCounterUpdateRequest struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Code string `json:"code"`
|
|
Icon string `json:"icon"`
|
|
Quota int16 `json:"quota" validate:"min=0"`
|
|
Active bool `json:"active"`
|
|
FKRefHealtcareTypeID int32 `json:"fk_ref_healtcare_type_id"`
|
|
FKRefServiceTypeID int32 `json:"fk_ref_service_type_id"`
|
|
FKSdLocationID string `json:"fk_sd_location_id"`
|
|
DsSdLocation string `json:"ds_sd_location"`
|
|
}
|
|
|
|
|
|
type MsRegistrationCounterUpdateResponse struct {
|
|
Message string `json:"message"`
|
|
Data *MsRegistrationCounter `json:"data"`
|
|
}
|
|
|
|
|
|
type MsRegistrationCounterDeleteResponse struct {
|
|
Message string `json:"message"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type MsRegistrationCounterFilter struct {
|
|
Status *string `json:"status,omitempty" form:"status"`
|
|
Search *string `json:"search,omitempty" form:"search"`
|
|
DateFrom *time.Time `json:"date_from,omitempty" form:"date_from"`
|
|
DateTo *time.Time `json:"date_to,omitempty" form:"date_to"`
|
|
} |