This commit is contained in:
143
internal/models/kiosk/listkiosk.go
Normal file
143
internal/models/kiosk/listkiosk.go
Normal file
@@ -0,0 +1,143 @@
|
||||
package kiosk
|
||||
|
||||
import (
|
||||
"api-service/internal/models"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Listkiosk represents the data structure for the listkiosk table
|
||||
// with proper null handling and optimized JSON marshaling
|
||||
type Listkiosk struct {
|
||||
ID int64 `json:"id" db:"id"`
|
||||
Name sql.NullString `json:"name,omitempty" db:"name"`
|
||||
Icon sql.NullString `json:"icon,omitempty" db:"icon"`
|
||||
Url sql.NullString `json:"url,omitempty" db:"url"`
|
||||
Active sql.NullBool `json:"active,omitempty" db:"active"`
|
||||
FKRefHealthcareTypeID models.NullableInt32 `json:"fk_ref_healthcare_type_id,omitempty" db:"fk_ref_healthcare_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"`
|
||||
}
|
||||
|
||||
// Custom JSON marshaling untuk Listkiosk agar NULL values tidak muncul di response
|
||||
func (r Listkiosk) MarshalJSON() ([]byte, error) {
|
||||
type Alias Listkiosk
|
||||
aux := &struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
FKRefHealthcareTypeID *int32 `json:"fk_ref_healthcare_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.Icon.Valid {
|
||||
aux.Icon = &r.Icon.String
|
||||
}
|
||||
if r.Url.Valid {
|
||||
aux.Url = &r.Url.String
|
||||
}
|
||||
if r.Active.Valid {
|
||||
aux.Active = &r.Active.Bool
|
||||
}
|
||||
|
||||
if r.FKRefHealthcareTypeID.Valid {
|
||||
fkrht := int32(r.FKRefHealthcareTypeID.Int32)
|
||||
aux.FKRefHealthcareTypeID = &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 *Listkiosk) GetName() string {
|
||||
if r.Name.Valid {
|
||||
return r.Name.String
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Response struct untuk GET by ID
|
||||
type ListkioskGetByIDResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data *Listkiosk `json:"data"`
|
||||
}
|
||||
|
||||
// Enhanced GET response dengan pagination dan aggregation
|
||||
type ListkioskGetResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []Listkiosk `json:"data"`
|
||||
Meta models.MetaResponse `json:"meta"`
|
||||
Summary *models.AggregateData `json:"summary,omitempty"`
|
||||
}
|
||||
|
||||
// Request struct untuk create
|
||||
type ListkioskCreateRequest struct {
|
||||
Name string `json:"name" validate:"min=1,max=20"`
|
||||
Icon string `json:"icon" validate:"min=1,max=20"`
|
||||
Url string `json:"url" validate:"min=1,max=255"`
|
||||
Active bool `json:"active"`
|
||||
FKRefHealthcareTypeID int32 `json:"fk_ref_healthcare_type_id" validate:"min=1"`
|
||||
FKRefServiceTypeID int32 `json:"fk_ref_service_type_id" validate:"min=1"`
|
||||
FKSdLocationID string `json:"fk_sd_location_id"`
|
||||
DsSdLocation string `json:"ds_sd_location" validate:"min=1,max=255"`
|
||||
}
|
||||
|
||||
// Response struct untuk create
|
||||
type ListkioskCreateResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data *Listkiosk `json:"data"`
|
||||
}
|
||||
|
||||
// Update request
|
||||
type ListkioskUpdateRequest struct {
|
||||
ID int `json:"id" validate:"required,min=1"`
|
||||
Name string `json:"name" validate:"min=1,max=20"`
|
||||
Icon string `json:"icon" validate:"min=1,max=20"`
|
||||
Url string `json:"url" validate:"min=1,max=255"`
|
||||
Active bool `json:"active"`
|
||||
FKRefHealthcareTypeID int32 `json:"fk_ref_healthcare_type_id" validate:"min=1"`
|
||||
FKRefServiceTypeID int32 `json:"fk_ref_service_type_id" validate:"min=1"`
|
||||
FKSdLocationID string `json:"fk_sd_location_id" validate:"min=1"`
|
||||
DsSdLocation string `json:"ds_sd_location" validate:"min=1,max=255"`
|
||||
}
|
||||
|
||||
// Response struct untuk update
|
||||
type ListkioskUpdateResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data *Listkiosk `json:"data"`
|
||||
}
|
||||
|
||||
// Response struct untuk delete
|
||||
type ListkioskDeleteResponse struct {
|
||||
Message string `json:"message"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// Filter struct untuk query parameters
|
||||
type ListkioskFilter 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"`
|
||||
}
|
||||
Reference in New Issue
Block a user