update
This commit is contained in:
parent
620dec2036
commit
db5ca9806c
@ -24,6 +24,10 @@ func main() {
|
|||||||
db.Connect()
|
db.Connect()
|
||||||
db.RegisterCallback()
|
db.RegisterCallback()
|
||||||
|
|
||||||
|
// tables := "basic_pricing"
|
||||||
|
// migrations.GenerateModel(&tables, db.Get("master"))
|
||||||
|
// os.Exit(0)
|
||||||
|
|
||||||
//redis
|
//redis
|
||||||
redisDB := database.NewRedis(AppConfig, DBLogger)
|
redisDB := database.NewRedis(AppConfig, DBLogger)
|
||||||
redisDB.Connect()
|
redisDB.Connect()
|
||||||
|
|||||||
@ -12,8 +12,8 @@ const TableNameBasicPricing = "basic_pricing"
|
|||||||
|
|
||||||
// BasicPricing mapped from table <basic_pricing>
|
// BasicPricing mapped from table <basic_pricing>
|
||||||
type BasicPricing struct {
|
type BasicPricing struct {
|
||||||
Name *string `gorm:"column:name;type:character varying(255)" json:"name"`
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
||||||
|
Name *string `gorm:"column:name;type:character varying(255)" json:"name"`
|
||||||
ProvinceSourceID *string `gorm:"column:province_source_id;type:character(26);index:basic_pricing_province_source_id_idx,priority:1" json:"province_source_id"`
|
ProvinceSourceID *string `gorm:"column:province_source_id;type:character(26);index:basic_pricing_province_source_id_idx,priority:1" json:"province_source_id"`
|
||||||
CitySourceID *string `gorm:"column:city_source_id;type:character(26);index:basic_pricing_city_source_id_idx,priority:1" json:"city_source_id"`
|
CitySourceID *string `gorm:"column:city_source_id;type:character(26);index:basic_pricing_city_source_id_idx,priority:1" json:"city_source_id"`
|
||||||
DistrictSourceID *string `gorm:"column:district_source_id;type:character(26);index:basic_pricing_district_source_id_idx,priority:1" json:"district_source_id"`
|
DistrictSourceID *string `gorm:"column:district_source_id;type:character(26);index:basic_pricing_district_source_id_idx,priority:1" json:"district_source_id"`
|
||||||
@ -31,20 +31,22 @@ type BasicPricing struct {
|
|||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
||||||
PackageTypeID *string `gorm:"column:package_type_id;type:character(26);index:basic_pricing_package_type_id_idx,priority:1" json:"package_type_id"`
|
PackageTypeID *string `gorm:"column:package_type_id;type:character(26);index:basic_pricing_package_type_id_idx,priority:1" json:"package_type_id"`
|
||||||
ModaID *string `gorm:"column:moda_id;type:character(26);index:basic_pricing_moda_id_idx,priority:1" json:"moda_id"`
|
ModaID *string `gorm:"column:moda_id;type:character(26);index:basic_pricing_moda_id_idx,priority:1" json:"moda_id"`
|
||||||
CityDestination_Relation *City `gorm:"foreignKey:city_destination_id;references:id" json:"city_destination_relation"`
|
LeadTime *string `gorm:"column:lead_time;type:character varying(10)" json:"lead_time"`
|
||||||
CitySource_Relation *City `gorm:"foreignKey:city_source_id;references:id" json:"city_source_relation"`
|
MinimumWeight *float32 `gorm:"column:minimum_weight;type:real" json:"minimum_weight"`
|
||||||
DistrictDestination_Relation *District `gorm:"foreignKey:district_destination_id;references:id" json:"district_destination_relation"`
|
CityDestination_Relation City `gorm:"foreignKey:city_destination_id;references:id" json:"city_destination_relation"`
|
||||||
DistrictSource_Relation *District `gorm:"foreignKey:district_source_id;references:id" json:"district_source_relation"`
|
CitySource_Relation City `gorm:"foreignKey:city_source_id;references:id" json:"city_source_relation"`
|
||||||
Merchant_Relation *Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
DistrictDestination_Relation District `gorm:"foreignKey:district_destination_id;references:id" json:"district_destination_relation"`
|
||||||
Moda_Relation *Moda `gorm:"foreignKey:moda_id;references:id" json:"moda_relation"`
|
DistrictSource_Relation District `gorm:"foreignKey:district_source_id;references:id" json:"district_source_relation"`
|
||||||
PackageType_Relation *PackageType `gorm:"foreignKey:package_type_id;references:id" json:"package_type_relation"`
|
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
||||||
PostalCodeDestination_Relation *PostalCode `gorm:"foreignKey:postal_code_destination_id;references:id" json:"postal_code_destination_relation"`
|
Moda_Relation Moda `gorm:"foreignKey:moda_id;references:id" json:"moda_relation"`
|
||||||
PostalCodeSource_Relation *PostalCode `gorm:"foreignKey:postal_code_source_id;references:id" json:"postal_code_source_relation"`
|
PackageType_Relation PackageType `gorm:"foreignKey:id;references:id" json:"package_type_relation"`
|
||||||
ProvinceDestination_Relation *Province `gorm:"foreignKey:province_destination_id;references:id" json:"province_destination_relation"`
|
PostalCodeDestination_Relation PostalCode `gorm:"foreignKey:postal_code_destination_id;references:id" json:"postal_code_destination_relation"`
|
||||||
ProvinceSource_Relation *Province `gorm:"foreignKey:province_source_id;references:id" json:"province_source_relation"`
|
PostalCodeSource_Relation PostalCode `gorm:"foreignKey:postal_code_source_id;references:id" json:"postal_code_source_relation"`
|
||||||
SubdistrictDestination_Relation *Subdistrict `gorm:"foreignKey:subdistrict_destination_id;references:id" json:"subdistrict_destination_relation"`
|
ProvinceDestination_Relation Province `gorm:"foreignKey:province_destination_id;references:id" json:"province_destination_relation"`
|
||||||
SubdistrictSource_Relation *Subdistrict `gorm:"foreignKey:subdistrict_source_id;references:id" json:"subdistrict_source_relation"`
|
ProvinceSource_Relation Province `gorm:"foreignKey:province_source_id;references:id" json:"province_source_relation"`
|
||||||
Users_Relation *User `gorm:"foreignKey:created_by;references:id" json:"users_relation"`
|
SubdistrictDestination_Relation Subdistrict `gorm:"foreignKey:subdistrict_destination_id;references:id" json:"subdistrict_destination_relation"`
|
||||||
|
SubdistrictSource_Relation Subdistrict `gorm:"foreignKey:subdistrict_source_id;references:id" json:"subdistrict_source_relation"`
|
||||||
|
Users_Relation User `gorm:"foreignKey:created_by;references:id" json:"users_relation"`
|
||||||
BasicPricingComponent_ByBasicPricing_Relation []BasicPricingComponent `gorm:"foreignKey:basic_pricing_id;references:id" json:"basic_pricing_component_by_basic_pricing_relation"`
|
BasicPricingComponent_ByBasicPricing_Relation []BasicPricingComponent `gorm:"foreignKey:basic_pricing_id;references:id" json:"basic_pricing_component_by_basic_pricing_relation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,6 +51,7 @@ func (u *BasicPricingUsecase) loadComponents(pricingIDs []string) (map[string][]
|
|||||||
func (u *BasicPricingUsecase) toResponse(pricing domain.BasicPricing, components []domain.BasicPricingComponent) dto.CreateBasicPricingResponse {
|
func (u *BasicPricingUsecase) toResponse(pricing domain.BasicPricing, components []domain.BasicPricingComponent) dto.CreateBasicPricingResponse {
|
||||||
resp := dto.CreateBasicPricingResponse{
|
resp := dto.CreateBasicPricingResponse{
|
||||||
ID: pricing.ID,
|
ID: pricing.ID,
|
||||||
|
Name: pricing.Name,
|
||||||
ProvinceSourceID: pricing.ProvinceSourceID,
|
ProvinceSourceID: pricing.ProvinceSourceID,
|
||||||
CitySourceID: pricing.CitySourceID,
|
CitySourceID: pricing.CitySourceID,
|
||||||
DistrictSourceID: pricing.DistrictSourceID,
|
DistrictSourceID: pricing.DistrictSourceID,
|
||||||
@ -83,7 +84,7 @@ func (u *BasicPricingUsecase) GetAll(filter dto.BasicPricingFilterAllRequest) ([
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&pricings)
|
tx := db.Model(&pricings)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -91,7 +92,7 @@ func (u *BasicPricingUsecase) GetAll(filter dto.BasicPricingFilterAllRequest) ([
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.BasicPricing{}).Count(&total)
|
tx.Model(&domain.BasicPricing{}).Count(&total)
|
||||||
@ -165,24 +166,24 @@ func (u *BasicPricingUsecase) Create(req dto.CreateBasicPricingRequest, createdB
|
|||||||
|
|
||||||
err := db.Transaction(func(tx *gorm.DB) error {
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
pricing = domain.BasicPricing{
|
pricing = domain.BasicPricing{
|
||||||
Name: &req.Name,
|
Name: &req.Name,
|
||||||
ProvinceSourceID: strPtr(req.ProvinceSourceID),
|
ProvinceSourceID: strPtr(req.ProvinceSourceID),
|
||||||
CitySourceID: strPtr(req.CitySourceID),
|
CitySourceID: strPtr(req.CitySourceID),
|
||||||
DistrictSourceID: strPtr(req.DistrictSourceID),
|
DistrictSourceID: strPtr(req.DistrictSourceID),
|
||||||
SubdistrictSourceID: strPtr(req.SubdistrictSourceID),
|
SubdistrictSourceID: strPtr(req.SubdistrictSourceID),
|
||||||
PostalCodeSourceID: strPtr(req.PostalCodeSourceID),
|
PostalCodeSourceID: strPtr(req.PostalCodeSourceID),
|
||||||
ProvinceDestinationID: strPtr(req.ProvinceDestinationID),
|
ProvinceDestinationID: strPtr(req.ProvinceDestinationID),
|
||||||
CityDestinationID: strPtr(req.CityDestinationID),
|
CityDestinationID: strPtr(req.CityDestinationID),
|
||||||
DistrictDestinationID: strPtr(req.DistrictDestinationID),
|
DistrictDestinationID: strPtr(req.DistrictDestinationID),
|
||||||
SubdistrictDestinationID: strPtr(req.SubdistrictDestinationID),
|
SubdistrictDestinationID: strPtr(req.SubdistrictDestinationID),
|
||||||
PostalCodeDestinationID: strPtr(req.PostalCodeDestinationID),
|
PostalCodeDestinationID: strPtr(req.PostalCodeDestinationID),
|
||||||
PackageTypeID: strPtr(req.PackageTypeID),
|
PackageTypeID: strPtr(req.PackageTypeID),
|
||||||
ModaID: strPtr(req.ModaID),
|
ModaID: strPtr(req.ModaID),
|
||||||
MerchantID: merchantid,
|
MerchantID: merchantid,
|
||||||
CreatedBy: &createdBy,
|
CreatedBy: &createdBy,
|
||||||
CreatedOn: &now,
|
CreatedOn: &now,
|
||||||
UpdatedBy: &createdBy,
|
UpdatedBy: &createdBy,
|
||||||
UpdatedOn: &now,
|
UpdatedOn: &now,
|
||||||
}
|
}
|
||||||
if err := tx.Create(&pricing).Error; err != nil {
|
if err := tx.Create(&pricing).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (u *CityUsecase) GetAll(filter dto.CityFilterAllRequest) ([]domain.City, in
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&cities)
|
tx := db.Model(&cities)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -45,7 +45,7 @@ func (u *CityUsecase) GetAll(filter dto.CityFilterAllRequest) ([]domain.City, in
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.City{}).Count(&total)
|
tx.Model(&domain.City{}).Count(&total)
|
||||||
@ -150,7 +150,7 @@ func (u *CityUsecase) Update(id string, name string, provinceID string, port str
|
|||||||
func (u *CityUsecase) Delete(id string) error {
|
func (u *CityUsecase) Delete(id string) error {
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
db = db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Delete(&domain.City{}, "id = ?", id).Error; err != nil {
|
if err := db.Delete(&domain.City{}, "id = ?", id).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func (u *CostComponentUsecase) GetAll(filter dto.CostComponentFilterAllRequest)
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&components)
|
tx := db.Model(&components)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -47,7 +47,7 @@ func (u *CostComponentUsecase) GetAll(filter dto.CostComponentFilterAllRequest)
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.CostComponent{}).Count(&total)
|
tx.Model(&domain.CostComponent{}).Count(&total)
|
||||||
@ -173,7 +173,7 @@ func (u *CostComponentUsecase) Update(id string, name string, code string, value
|
|||||||
func (u *CostComponentUsecase) Delete(id string) error {
|
func (u *CostComponentUsecase) Delete(id string) error {
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
db = db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Delete(&domain.CostComponent{}, "id = ?", id).Error; err != nil {
|
if err := db.Delete(&domain.CostComponent{}, "id = ?", id).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (u *DistrictUsecase) GetAll(filter dto.DistrictFilterAllRequest) ([]domain.
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&districts)
|
tx := db.Model(&districts)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -45,7 +45,7 @@ func (u *DistrictUsecase) GetAll(filter dto.DistrictFilterAllRequest) ([]domain.
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.District{}).Count(&total)
|
tx.Model(&domain.District{}).Count(&total)
|
||||||
@ -159,7 +159,7 @@ func (u *DistrictUsecase) Update(id string, name string, provinceID string, city
|
|||||||
func (u *DistrictUsecase) Delete(id string) error {
|
func (u *DistrictUsecase) Delete(id string) error {
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
db = db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Delete(&domain.District{}, "id = ?", id).Error; err != nil {
|
if err := db.Delete(&domain.District{}, "id = ?", id).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (u *PostalCodeUsecase) GetAll(filter dto.PostalCodeFilterAllRequest) ([]dom
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&postalCodes)
|
tx := db.Model(&postalCodes)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -45,7 +45,7 @@ func (u *PostalCodeUsecase) GetAll(filter dto.PostalCodeFilterAllRequest) ([]dom
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.PostalCode{}).Count(&total)
|
tx.Model(&domain.PostalCode{}).Count(&total)
|
||||||
@ -181,7 +181,7 @@ func (u *PostalCodeUsecase) Update(id string, postalCode string, provinceID stri
|
|||||||
func (u *PostalCodeUsecase) Delete(id string) error {
|
func (u *PostalCodeUsecase) Delete(id string) error {
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
db = db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Delete(&domain.PostalCode{}, "id = ?", id).Error; err != nil {
|
if err := db.Delete(&domain.PostalCode{}, "id = ?", id).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (u *ProvinceUsecase) GetAll(filter dto.ProvinceFilterAllRequest) ([]domain.
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&provinces)
|
tx := db.Model(&provinces)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -45,7 +45,7 @@ func (u *ProvinceUsecase) GetAll(filter dto.ProvinceFilterAllRequest) ([]domain.
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.Province{}).Count(&total)
|
tx.Model(&domain.Province{}).Count(&total)
|
||||||
@ -144,7 +144,7 @@ func (u *ProvinceUsecase) Update(id string, name string, updatedBy string) (doma
|
|||||||
func (u *ProvinceUsecase) Delete(id string) error {
|
func (u *ProvinceUsecase) Delete(id string) error {
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
db = db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Delete(&domain.Province{}, "id = ?", id).Error; err != nil {
|
if err := db.Delete(&domain.Province{}, "id = ?", id).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (u *SubdistrictUsecase) GetAll(filter dto.SubdistrictFilterAllRequest) ([]d
|
|||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Model(&subdistricts)
|
tx := db.Model(&subdistricts)
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
tx = tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
}
|
}
|
||||||
v := reflect.ValueOf(filter)
|
v := reflect.ValueOf(filter)
|
||||||
t := reflect.TypeOf(filter)
|
t := reflect.TypeOf(filter)
|
||||||
@ -45,7 +45,7 @@ func (u *SubdistrictUsecase) GetAll(filter dto.SubdistrictFilterAllRequest) ([]d
|
|||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
if v.Field(i).String() != "" {
|
if v.Field(i).String() != "" {
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
tx = tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.Subdistrict{}).Count(&total)
|
tx.Model(&domain.Subdistrict{}).Count(&total)
|
||||||
@ -170,7 +170,7 @@ func (u *SubdistrictUsecase) Update(id string, name string, provinceID string, c
|
|||||||
func (u *SubdistrictUsecase) Delete(id string) error {
|
func (u *SubdistrictUsecase) Delete(id string) error {
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation == nil || u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
db = db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Delete(&domain.Subdistrict{}, "id = ?", id).Error; err != nil {
|
if err := db.Delete(&domain.Subdistrict{}, "id = ?", id).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -107,8 +107,20 @@ func GenerateModel(table *string, db *gorm.DB) {
|
|||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// Get tables
|
// Get tables
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
qInfo := ""
|
||||||
rows, err := sqlDB.Query(`
|
if table != nil {
|
||||||
|
qInfo = fmt.Sprintf(`
|
||||||
|
SELECT
|
||||||
|
table_name
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE
|
||||||
|
table_schema = 'public'
|
||||||
|
AND table_type = 'BASE TABLE'
|
||||||
|
AND table_name = '%v'
|
||||||
|
ORDER BY table_name
|
||||||
|
`, table)
|
||||||
|
} else {
|
||||||
|
qInfo = fmt.Sprintf(`
|
||||||
SELECT
|
SELECT
|
||||||
table_name
|
table_name
|
||||||
FROM information_schema.tables
|
FROM information_schema.tables
|
||||||
@ -116,7 +128,9 @@ func GenerateModel(table *string, db *gorm.DB) {
|
|||||||
table_schema = 'public'
|
table_schema = 'public'
|
||||||
AND table_type = 'BASE TABLE'
|
AND table_type = 'BASE TABLE'
|
||||||
ORDER BY table_name
|
ORDER BY table_name
|
||||||
`)
|
`, table)
|
||||||
|
}
|
||||||
|
rows, err := sqlDB.Query(qInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf(
|
log.Fatalf(
|
||||||
"Gagal mengambil daftar tabel: %v",
|
"Gagal mengambil daftar tabel: %v",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user