This commit is contained in:
parent
dc28c6f6fc
commit
43bb3e1dd0
@ -1,28 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameCity = "city"
|
|
||||||
|
|
||||||
// City mapped from table <city>
|
|
||||||
type City struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:city_name_idx,priority:1" json:"name"`
|
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:city_province_id_idx,priority:1" json:"province_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:city_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName City's table name
|
|
||||||
func (*City) TableName() string {
|
|
||||||
return TableNameCity
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameCostComponent = "cost_component"
|
|
||||||
|
|
||||||
// CostComponent mapped from table <cost_component>
|
|
||||||
type CostComponent struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:cost_component_name_idx,priority:1" json:"name"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:cost_component_merchant_id_idx,priority:1" json:"merchant_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:cost_component_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
|
||||||
Inc *int32 `gorm:"column:inc;type:integer" json:"inc"`
|
|
||||||
Code *string `gorm:"column:code;type:character varying(100)" json:"code"`
|
|
||||||
Value *string `gorm:"column:value;type:character varying(255)" json:"value"`
|
|
||||||
CostComponentGroupID *string `gorm:"column:cost_component_group_id;type:character(26);index:cost_component_cost_component_group_id_idx,priority:1" json:"cost_component_group_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName CostComponent's table name
|
|
||||||
func (*CostComponent) TableName() string {
|
|
||||||
return TableNameCostComponent
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameCostComponentGroup = "cost_component_group"
|
|
||||||
|
|
||||||
// CostComponentGroup mapped from table <cost_component_group>
|
|
||||||
type CostComponentGroup struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255)" json:"name"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
Code *string `gorm:"column:code;type:character varying(100)" json:"code"`
|
|
||||||
Inc *int32 `gorm:"column:inc;type:integer" json:"inc"`
|
|
||||||
Value *string `gorm:"column:value;type:character varying(255)" json:"value"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName CostComponentGroup's table name
|
|
||||||
func (*CostComponentGroup) TableName() string {
|
|
||||||
return TableNameCostComponentGroup
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameDistrict = "district"
|
|
||||||
|
|
||||||
// District mapped from table <district>
|
|
||||||
type District struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:district_name_idx,priority:1" json:"name"`
|
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:district_province_id_idx,priority:1" json:"province_id"`
|
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:district_city_id_idx,priority:1" json:"city_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:district_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName District's table name
|
|
||||||
func (*District) TableName() string {
|
|
||||||
return TableNameDistrict
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameMerchant = "merchant"
|
|
||||||
|
|
||||||
// Merchant mapped from table <merchant>
|
|
||||||
type Merchant struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:merchant_name_idx,priority:3" json:"name"`
|
|
||||||
Address *string `gorm:"column:address;type:character varying(500);index:merchant_name_idx,priority:1" json:"address"`
|
|
||||||
Email *string `gorm:"column:email;type:character varying(200);index:merchant_name_idx,priority:2" json:"email"`
|
|
||||||
Telp *string `gorm:"column:telp;type:character varying(50);index:merchant_name_idx,priority:4" json:"telp"`
|
|
||||||
AdditionalInformation *string `gorm:"column:additional_information;type:jsonb;index:merchant_additional_information_idx,priority:1;default:{}" json:"additional_information"`
|
|
||||||
Active *bool `gorm:"column:active;type:boolean;default:true" json:"active"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:merchant_province_id_idx,priority:1" json:"province_id"`
|
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:merchant_city_id_idx,priority:1" json:"city_id"`
|
|
||||||
DistrictID *string `gorm:"column:district_id;type:character(26);index:merchant_district_id_idx,priority:1" json:"district_id"`
|
|
||||||
SubdistrictID *string `gorm:"column:subdistrict_id;type:character(26);index:merchant_subdistrict_id_idx,priority:1" json:"subdistrict_id"`
|
|
||||||
PostalCode *string `gorm:"column:postal_code;type:character(26);index:merchant_postal_code_idx,priority:1" json:"postal_code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName Merchant's table name
|
|
||||||
func (*Merchant) TableName() string {
|
|
||||||
return TableNameMerchant
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameModa = "moda"
|
|
||||||
|
|
||||||
// Moda mapped from table <moda>
|
|
||||||
type Moda struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:moda_name_idx,priority:1" json:"name"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:moda_merchant_id_idx,priority:1" json:"merchant_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:moda_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName Moda's table name
|
|
||||||
func (*Moda) TableName() string {
|
|
||||||
return TableNameModa
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNamePackageType = "package_type"
|
|
||||||
|
|
||||||
// PackageType mapped from table <package_type>
|
|
||||||
type PackageType struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:package_type_name_idx,priority:1" json:"name"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:package_type_merchant_id_idx,priority:1" json:"merchant_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName PackageType's table name
|
|
||||||
func (*PackageType) TableName() string {
|
|
||||||
return TableNamePackageType
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNamePostalCode = "postal_code"
|
|
||||||
|
|
||||||
// PostalCode mapped from table <postal_code>
|
|
||||||
type PostalCode struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
PostalCode *string `gorm:"column:postal_code;type:character varying(255);index:postal_code_postal_code_idx,priority:1" json:"postal_code"`
|
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:postal_code_province_id_idx,priority:1" json:"province_id"`
|
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:postal_code_city_id_idx,priority:1" json:"city_id"`
|
|
||||||
DistrictID *string `gorm:"column:district_id;type:character(26);index:postal_code_district_id_idx,priority:1" json:"district_id"`
|
|
||||||
SubdistrictID *string `gorm:"column:subdistrict_id;type:character(26);index:postal_code_subdistrict_id_idx,priority:1" json:"subdistrict_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:postal_code_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *string `gorm:"column:updated_on;type:character varying" json:"updated_on"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName PostalCode's table name
|
|
||||||
func (*PostalCode) TableName() string {
|
|
||||||
return TableNamePostalCode
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameProvince = "province"
|
|
||||||
|
|
||||||
// Province mapped from table <province>
|
|
||||||
type Province struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:province_name_idx,priority:1" json:"name"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:province_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName Province's table name
|
|
||||||
func (*Province) TableName() string {
|
|
||||||
return TableNameProvince
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameSubdistrict = "subdistrict"
|
|
||||||
|
|
||||||
// Subdistrict mapped from table <subdistrict>
|
|
||||||
type Subdistrict struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255);index:subdistrit_name_idx,priority:1" json:"name"`
|
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:subdistrit_province_id_idx,priority:1" json:"province_id"`
|
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:subdistrit_city_id_idx,priority:1" json:"city_id"`
|
|
||||||
DistrictID *string `gorm:"column:district_id;type:character(26);index:subdistrit_district_id_idx,priority:1" json:"district_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:subdistrit_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName Subdistrict's table name
|
|
||||||
func (*Subdistrict) TableName() string {
|
|
||||||
return TableNameSubdistrict
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameUser = "users"
|
|
||||||
|
|
||||||
// User mapped from table <users>
|
|
||||||
type User struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:users_merchant_id_idx,priority:1" json:"merchant_id"`
|
|
||||||
NickName *string `gorm:"column:nick_name;type:character varying(100);index:users_nick_name_idx,priority:2" json:"nick_name"`
|
|
||||||
Email *string `gorm:"column:email;type:character varying(200);index:users_nick_name_idx,priority:1" json:"email"`
|
|
||||||
Password *string `gorm:"column:password;type:character varying(300)" json:"password"`
|
|
||||||
IsActive *bool `gorm:"column:is_active;type:boolean;default:true" json:"is_active"`
|
|
||||||
UsersRoleID *string `gorm:"column:users_role_id;type:character(26)" json:"users_role_id"`
|
|
||||||
Blocked *bool `gorm:"column:blocked;type:boolean" json:"blocked"`
|
|
||||||
BlockedNotes *string `gorm:"column:blocked_notes;type:character varying(500)" json:"blocked_notes"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:users_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName User's table name
|
|
||||||
func (*User) TableName() string {
|
|
||||||
return TableNameUser
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameUsersRole = "users_roles"
|
|
||||||
|
|
||||||
// UsersRole mapped from table <users_roles>
|
|
||||||
type UsersRole struct {
|
|
||||||
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"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone;default:now()" json:"updated_on"`
|
|
||||||
RoleKey string `gorm:"column:role_key;type:character varying(20);not null" json:"role_key"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName UsersRole's table name
|
|
||||||
func (*UsersRole) TableName() string {
|
|
||||||
return TableNameUsersRole
|
|
||||||
}
|
|
||||||
31
internal/domain/basic_pricing.go
Normal file
31
internal/domain/basic_pricing.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const TableNameBasicPricing = "basic_pricing"
|
||||||
|
|
||||||
|
type BasicPricing struct {
|
||||||
|
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"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"`
|
||||||
|
DistrictSourceID *string `gorm:"column:district_source_id;type:character(26);index:basic_pricing_district_source_id_idx,priority:1" json:"district_source_id"`
|
||||||
|
SubdistrictSourceID *string `gorm:"column:subdistrict_source_id;type:character(26);index:basic_pricing_subdistrict_source_id_idx,priority:1" json:"subdistrict_source_id"`
|
||||||
|
PostalCodeSourceID *string `gorm:"column:postal_code_source_id;type:character(26);index:basic_pricing_postal_code_source_id_idx,priority:1" json:"postal_code_source_id"`
|
||||||
|
ProvinceDestinationID *string `gorm:"column:province_destination_id;type:character(26);index:basic_pricing_province_destination_id_idx,priority:1" json:"province_destination_id"`
|
||||||
|
CityDestinationID *string `gorm:"column:city_destination_id;type:character(26);index:basic_pricing_city_destination_id_idx,priority:1" json:"city_destination_id"`
|
||||||
|
DistrictDestinationID *string `gorm:"column:district_destination_id;type:character(26);index:basic_pricing_district_destination_id_idx,priority:1" json:"district_destination_id"`
|
||||||
|
SubdistrictDestinationID *string `gorm:"column:subdistrict_destination_id;type:character(26)" json:"subdistrict_destination_id"`
|
||||||
|
PostalCodeDestinationID *string `gorm:"column:postal_code_destination_id;type:character(26);index:basic_pricing_postal_code_destination_id_idx,priority:1" json:"postal_code_destination_id"`
|
||||||
|
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:basic_pricing_merchant_id_idx,priority:1" json:"merchant_id"`
|
||||||
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:basic_pricing_created_by_idx,priority:1" json:"created_by"`
|
||||||
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
||||||
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
|
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"`
|
||||||
|
ModaID *string `gorm:"column:moda_id;type:character(26);index:basic_pricing_moda_id_idx,priority:1" json:"moda_id"`
|
||||||
|
Name *string `gorm:"column:name;type:character varying(255);index:basic_pricing_name_idx,priority:1" json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*BasicPricing) TableName() string {
|
||||||
|
return TableNameBasicPricing
|
||||||
|
}
|
||||||
14
internal/domain/basic_pricing_component.go
Normal file
14
internal/domain/basic_pricing_component.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
const TableNameBasicPricingComponent = "basic_pricing_component"
|
||||||
|
|
||||||
|
type BasicPricingComponent struct {
|
||||||
|
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
||||||
|
CostComponentID *string `gorm:"column:cost_component_id;type:character(26);index:basic_pricing_component_cost_component_id_idx,priority:1" json:"cost_component_id"`
|
||||||
|
Value *float32 `gorm:"column:value;type:real" json:"value"`
|
||||||
|
BasicPricingID *string `gorm:"column:basic_pricing_id;type:character(26);index:basic_pricing_component_basic_pricing_id_idx,priority:1" json:"basic_pricing_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*BasicPricingComponent) TableName() string {
|
||||||
|
return TableNameBasicPricingComponent
|
||||||
|
}
|
||||||
@ -1,35 +1,21 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameCity = "city"
|
const TableNameCity = "city"
|
||||||
|
|
||||||
// City mapped from table <city>
|
|
||||||
type City struct {
|
type City struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:city_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:city_name_idx,priority:1" json:"name"`
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:city_province_id_idx,priority:1" json:"province_id"`
|
ProvinceID *string `gorm:"column:province_id;type:character(26);index:city_province_id_idx,priority:1" json:"province_id"`
|
||||||
|
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
||||||
|
Port *string `gorm:"column:port;type:character varying(255)" json:"port"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:city_created_by_idx,priority:1" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:city_created_by_idx,priority:1" json:"created_by"`
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
PostalCodes_Relation []PostalCode `gorm:"foreignKey:city_id;references:id" json:"postal_codes_relation"`
|
|
||||||
Subdistricts_Relation []Subdistrict `gorm:"foreignKey:city_id;references:id" json:"subdistricts_relation"`
|
|
||||||
Districts_Relation []District `gorm:"foreignKey:city_id;references:id" json:"districts_relation"`
|
|
||||||
Province_Relation Province `gorm:"foreignKey:province_id;references:id" json:"province_relation"`
|
|
||||||
Merchants_Relation []Merchant `gorm:"foreignKey:city_id;references:id" json:"merchants_relation"`
|
|
||||||
CreatedBy_Relation User `gorm:"foreignKey:created_by;references:id" json:"created_by_relation"`
|
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName City's table name
|
|
||||||
func (*City) TableName() string {
|
func (*City) TableName() string {
|
||||||
return TableNameCity
|
return TableNameCity
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,9 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameCostComponent = "cost_component"
|
const TableNameCostComponent = "cost_component"
|
||||||
|
|
||||||
// CostComponent mapped from table <cost_component>
|
|
||||||
type CostComponent struct {
|
type CostComponent struct {
|
||||||
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);index:cost_component_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:cost_component_name_idx,priority:1" json:"name"`
|
||||||
@ -22,10 +15,9 @@ type CostComponent struct {
|
|||||||
Inc *int32 `gorm:"column:inc;type:integer" json:"inc"`
|
Inc *int32 `gorm:"column:inc;type:integer" json:"inc"`
|
||||||
Code *string `gorm:"column:code;type:character varying(100)" json:"code"`
|
Code *string `gorm:"column:code;type:character varying(100)" json:"code"`
|
||||||
Value *string `gorm:"column:value;type:character varying(255)" json:"value"`
|
Value *string `gorm:"column:value;type:character varying(255)" json:"value"`
|
||||||
CostComponentGroupID *string `gorm:"column:cost_component_group_id;type:character(26);index:cost_component_cost_component_group_id_idx,priority:1" json:"cost_component_group_id"`
|
ComponentType *int32 `gorm:"column:component_type;type:integer;comment:0.Input 1.Formula" json:"component_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName CostComponent's table name
|
|
||||||
func (*CostComponent) TableName() string {
|
func (*CostComponent) TableName() string {
|
||||||
return TableNameCostComponent
|
return TableNameCostComponent
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameCostComponentGroup = "cost_component_group"
|
|
||||||
|
|
||||||
// CostComponentGroup mapped from table <cost_component_group>
|
|
||||||
type CostComponentGroup struct {
|
|
||||||
ID string `gorm:"column:id;type:character(26);not null" json:"id"`
|
|
||||||
Name *string `gorm:"column:name;type:character varying(255)" json:"name"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
Code *string `gorm:"column:code;type:character varying(100)" json:"code"`
|
|
||||||
Inc *int32 `gorm:"column:inc;type:integer" json:"inc"`
|
|
||||||
Value *string `gorm:"column:value;type:character varying(255)" json:"value"`
|
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName CostComponentGroup's table name
|
|
||||||
func (*CostComponentGroup) TableName() string {
|
|
||||||
return TableNameCostComponentGroup
|
|
||||||
}
|
|
||||||
@ -1,36 +1,21 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameDistrict = "district"
|
const TableNameDistrict = "district"
|
||||||
|
|
||||||
// District mapped from table <district>
|
|
||||||
type District struct {
|
type District struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:district_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:district_name_idx,priority:1" json:"name"`
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:district_province_id_idx,priority:1" json:"province_id"`
|
ProvinceID *string `gorm:"column:province_id;type:character(26);index:district_province_id_idx,priority:1" json:"province_id"`
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:district_city_id_idx,priority:1" json:"city_id"`
|
CityID *string `gorm:"column:city_id;type:character(26);index:district_city_id_idx,priority:1" json:"city_id"`
|
||||||
|
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:district_created_by_idx,priority:1" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:district_created_by_idx,priority:1" json:"created_by"`
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
PostalCodes_Relation []PostalCode `gorm:"foreignKey:district_id;references:id" json:"postal_codes_relation"`
|
|
||||||
Subdistricts_Relation []Subdistrict `gorm:"foreignKey:district_id;references:id" json:"subdistricts_relation"`
|
|
||||||
Province_Relation Province `gorm:"foreignKey:province_id;references:id" json:"province_relation"`
|
|
||||||
City_Relation City `gorm:"foreignKey:city_id;references:id" json:"city_relation"`
|
|
||||||
Merchants_Relation []Merchant `gorm:"foreignKey:district_id;references:id" json:"merchants_relation"`
|
|
||||||
CreatedBy_Relation User `gorm:"foreignKey:created_by;references:id" json:"created_by_relation"`
|
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName District's table name
|
|
||||||
func (*District) TableName() string {
|
func (*District) TableName() string {
|
||||||
return TableNameDistrict
|
return TableNameDistrict
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,11 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameMerchant = "merchant"
|
const TableNameMerchant = "merchant"
|
||||||
|
|
||||||
// Merchant mapped from table <merchant>
|
|
||||||
type Merchant struct {
|
type Merchant struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:merchant_name_idx,priority:3" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:merchant_name_idx,priority:3" json:"name"`
|
||||||
Address *string `gorm:"column:address;type:character varying(500);index:merchant_name_idx,priority:1" json:"address"`
|
Address *string `gorm:"column:address;type:character varying(500);index:merchant_name_idx,priority:1" json:"address"`
|
||||||
Email *string `gorm:"column:email;type:character varying(200);index:merchant_name_idx,priority:2" json:"email"`
|
Email *string `gorm:"column:email;type:character varying(200);index:merchant_name_idx,priority:2" json:"email"`
|
||||||
@ -28,23 +21,8 @@ type Merchant struct {
|
|||||||
DistrictID *string `gorm:"column:district_id;type:character(26);index:merchant_district_id_idx,priority:1" json:"district_id"`
|
DistrictID *string `gorm:"column:district_id;type:character(26);index:merchant_district_id_idx,priority:1" json:"district_id"`
|
||||||
SubdistrictID *string `gorm:"column:subdistrict_id;type:character(26);index:merchant_subdistrict_id_idx,priority:1" json:"subdistrict_id"`
|
SubdistrictID *string `gorm:"column:subdistrict_id;type:character(26);index:merchant_subdistrict_id_idx,priority:1" json:"subdistrict_id"`
|
||||||
PostalCode *string `gorm:"column:postal_code;type:character(26);index:merchant_postal_code_idx,priority:1" json:"postal_code"`
|
PostalCode *string `gorm:"column:postal_code;type:character(26);index:merchant_postal_code_idx,priority:1" json:"postal_code"`
|
||||||
Province_Relation *Province `gorm:"foreignKey:province_id;references:id" json:"province_relation"`
|
|
||||||
City_Relation *City `gorm:"foreignKey:city_id;references:id" json:"city_relation"`
|
|
||||||
District_Relation *District `gorm:"foreignKey:district_id;references:id" json:"district_relation"`
|
|
||||||
Subdistrict_Relation *Subdistrict `gorm:"foreignKey:subdistrict_id;references:id" json:"subdistrict_relation"`
|
|
||||||
UsersRoless_Relation []*UsersRole `gorm:"foreignKey:merchant_id;references:id" json:"users_roless_relation"`
|
|
||||||
Modas_Relation []*Moda `gorm:"foreignKey:merchant_id;references:id" json:"modas_relation"`
|
|
||||||
PackageTypes_Relation []*PackageType `gorm:"foreignKey:merchant_id;references:id" json:"package_types_relation"`
|
|
||||||
Userss_Relation []*User `gorm:"foreignKey:merchant_id;references:id" json:"userss_relation"`
|
|
||||||
CreatedBy_Relation *User `gorm:"foreignKey:created_by;references:id" json:"created_by_relation"`
|
|
||||||
Provinces_Relation []*Province `gorm:"foreignKey:merchant_id;references:id" json:"provinces_relation"`
|
|
||||||
Citys_Relation []*City `gorm:"foreignKey:merchant_id;references:id" json:"citys_relation"`
|
|
||||||
Districts_Relation []*District `gorm:"foreignKey:merchant_id;references:id" json:"districts_relation"`
|
|
||||||
Subdistricts_Relation []*Subdistrict `gorm:"foreignKey:merchant_id;references:id" json:"subdistricts_relation"`
|
|
||||||
PostalCodes_Relation []*PostalCode `gorm:"foreignKey:merchant_id;references:id" json:"postal_codes_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName Merchant's table name
|
|
||||||
func (*Merchant) TableName() string {
|
func (*Merchant) TableName() string {
|
||||||
return TableNameMerchant
|
return TableNameMerchant
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,19 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameModa = "moda"
|
const TableNameModa = "moda"
|
||||||
|
|
||||||
// Moda mapped from table <moda>
|
|
||||||
type Moda struct {
|
type Moda struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:moda_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:moda_name_idx,priority:1" json:"name"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:moda_merchant_id_idx,priority:1" json:"merchant_id"`
|
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:moda_merchant_id_idx,priority:1" json:"merchant_id"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:moda_created_by_idx,priority:1" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:moda_created_by_idx,priority:1" json:"created_by"`
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
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"`
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName Moda's table name
|
|
||||||
func (*Moda) TableName() string {
|
func (*Moda) TableName() string {
|
||||||
return TableNameModa
|
return TableNameModa
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,19 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNamePackageType = "package_type"
|
const TableNamePackageType = "package_type"
|
||||||
|
|
||||||
// PackageType mapped from table <package_type>
|
|
||||||
type PackageType struct {
|
type PackageType struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:package_type_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:package_type_name_idx,priority:1" json:"name"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:package_type_merchant_id_idx,priority:1" json:"merchant_id"`
|
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:package_type_merchant_id_idx,priority:1" json:"merchant_id"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName PackageType's table name
|
|
||||||
func (*PackageType) TableName() string {
|
func (*PackageType) TableName() string {
|
||||||
return TableNamePackageType
|
return TableNamePackageType
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,23 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNamePostalCode = "postal_code"
|
const TableNamePostalCode = "postal_code"
|
||||||
|
|
||||||
// PostalCode mapped from table <postal_code>
|
|
||||||
type PostalCode struct {
|
type PostalCode struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;default:generate_ulid()" json:"id"`
|
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
||||||
PostalCode *string `gorm:"column:postal_code;type:character varying(255);index:postal_code_postal_code_idx,priority:1" json:"postal_code"`
|
PostalCode *string `gorm:"column:postal_code;type:character varying(255);index:postal_code_postal_code_idx,priority:1" json:"postal_code"`
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:postal_code_province_id_idx,priority:1" json:"province_id"`
|
ProvinceID *string `gorm:"column:province_id;type:character(26);index:postal_code_province_id_idx,priority:1" json:"province_id"`
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:postal_code_city_id_idx,priority:1" json:"city_id"`
|
CityID *string `gorm:"column:city_id;type:character(26);index:postal_code_city_id_idx,priority:1" json:"city_id"`
|
||||||
DistrictID *string `gorm:"column:district_id;type:character(26);index:postal_code_district_id_idx,priority:1" json:"district_id"`
|
DistrictID *string `gorm:"column:district_id;type:character(26);index:postal_code_district_id_idx,priority:1" json:"district_id"`
|
||||||
SubdistrictID *string `gorm:"column:subdistrict_id;type:character(26);index:postal_code_subdistrict_id_idx,priority:1" json:"subdistrict_id"`
|
SubdistrictID *string `gorm:"column:subdistrict_id;type:character(26);index:postal_code_subdistrict_id_idx,priority:1" json:"subdistrict_id"`
|
||||||
|
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:postal_code_created_by_idx,priority:1" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:postal_code_created_by_idx,priority:1" json:"created_by"`
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
UpdatedOn *string `gorm:"column:updated_on;type:character varying" json:"updated_on"`
|
UpdatedOn *string `gorm:"column:updated_on;type:character varying" json:"updated_on"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
Province_Relation Province `gorm:"foreignKey:province_id;references:id" json:"province_relation"`
|
|
||||||
City_Relation City `gorm:"foreignKey:city_id;references:id" json:"city_relation"`
|
|
||||||
District_Relation District `gorm:"foreignKey:district_id;references:id" json:"district_relation"`
|
|
||||||
Subdistrict_Relation Subdistrict `gorm:"foreignKey:subdistrict_id;references:id" json:"subdistrict_relation"`
|
|
||||||
CreatedBy_Relation User `gorm:"foreignKey:created_by;references:id" json:"created_by_relation"`
|
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName PostalCode's table name
|
|
||||||
func (*PostalCode) TableName() string {
|
func (*PostalCode) TableName() string {
|
||||||
return TableNamePostalCode
|
return TableNamePostalCode
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +1,19 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameProvince = "province"
|
const TableNameProvince = "province"
|
||||||
|
|
||||||
// Province mapped from table <province>
|
|
||||||
type Province struct {
|
type Province struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:province_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:province_name_idx,priority:1" json:"name"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:province_created_by_idx,priority:1" json:"created_by"`
|
|
||||||
CreatedOn *time.Time `gorm:"autoCreateTime;column:created_on;type:timestamp without time zone" json:"created_on"`
|
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
|
||||||
UpdatedOn *time.Time `gorm:"autoUpdateTime;column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
||||||
PostalCodes_Relation []PostalCode `gorm:"foreignKey:province_id;references:id" json:"postal_codes_relation"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:province_created_by_idx,priority:1" json:"created_by"`
|
||||||
Subdistricts_Relation []Subdistrict `gorm:"foreignKey:province_id;references:id" json:"subdistricts_relation"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
||||||
Districts_Relation []District `gorm:"foreignKey:province_id;references:id" json:"districts_relation"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
Citys_Relation []City `gorm:"foreignKey:province_id;references:id" json:"citys_relation"`
|
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
||||||
Merchants_Relation []Merchant `gorm:"foreignKey:province_id;references:id" json:"merchants_relation"`
|
|
||||||
CreatedBy_Relation User `gorm:"foreignKey:created_by;references:id" json:"created_by_relation"`
|
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName Province's table name
|
|
||||||
func (*Province) TableName() string {
|
func (*Province) TableName() string {
|
||||||
return TableNameProvince
|
return TableNameProvince
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,22 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameSubdistrict = "subdistrict"
|
const TableNameSubdistrict = "subdistrict"
|
||||||
|
|
||||||
// Subdistrict mapped from table <subdistrict>
|
|
||||||
type Subdistrict struct {
|
type Subdistrict struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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);index:subdistrit_name_idx,priority:1" json:"name"`
|
Name *string `gorm:"column:name;type:character varying(255);index:subdistrit_name_idx,priority:1" json:"name"`
|
||||||
ProvinceID *string `gorm:"column:province_id;type:character(26);index:subdistrit_province_id_idx,priority:1" json:"province_id"`
|
ProvinceID *string `gorm:"column:province_id;type:character(26);index:subdistrit_province_id_idx,priority:1" json:"province_id"`
|
||||||
CityID *string `gorm:"column:city_id;type:character(26);index:subdistrit_city_id_idx,priority:1" json:"city_id"`
|
CityID *string `gorm:"column:city_id;type:character(26);index:subdistrit_city_id_idx,priority:1" json:"city_id"`
|
||||||
DistrictID *string `gorm:"column:district_id;type:character(26);index:subdistrit_district_id_idx,priority:1" json:"district_id"`
|
DistrictID *string `gorm:"column:district_id;type:character(26);index:subdistrit_district_id_idx,priority:1" json:"district_id"`
|
||||||
|
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26);index:subdistrit_created_by_idx,priority:1" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26);index:subdistrit_created_by_idx,priority:1" json:"created_by"`
|
||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
UpdatedOn *time.Time `gorm:"column:updated_on;type:timestamp without time zone" json:"updated_on"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
|
||||||
PostalCodes_Relation []PostalCode `gorm:"foreignKey:subdistrict_id;references:id" json:"postal_codes_relation"`
|
|
||||||
Province_Relation Province `gorm:"foreignKey:province_id;references:id" json:"province_relation"`
|
|
||||||
City_Relation City `gorm:"foreignKey:city_id;references:id" json:"city_relation"`
|
|
||||||
District_Relation District `gorm:"foreignKey:district_id;references:id" json:"district_relation"`
|
|
||||||
Merchants_Relation []Merchant `gorm:"foreignKey:subdistrict_id;references:id" json:"merchants_relation"`
|
|
||||||
CreatedBy_Relation User `gorm:"foreignKey:created_by;references:id" json:"created_by_relation"`
|
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName Subdistrict's table name
|
|
||||||
func (*Subdistrict) TableName() string {
|
func (*Subdistrict) TableName() string {
|
||||||
return TableNameSubdistrict
|
return TableNameSubdistrict
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,11 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameUser = "users"
|
const TableNameUser = "users"
|
||||||
|
|
||||||
// User mapped from table <users>
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;default:generate_ulid()" json:"id"`
|
ID string `gorm:"column:id;type:character(26);not null;default:generate_ulid()" json:"id"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:users_merchant_id_idx,priority:1" json:"merchant_id"`
|
MerchantID *string `gorm:"column:merchant_id;type:character(26);index:users_merchant_id_idx,priority:1" json:"merchant_id"`
|
||||||
NickName *string `gorm:"column:nick_name;type:character varying(100);index:users_nick_name_idx,priority:2" json:"nick_name"`
|
NickName *string `gorm:"column:nick_name;type:character varying(100);index:users_nick_name_idx,priority:2" json:"nick_name"`
|
||||||
Email *string `gorm:"column:email;type:character varying(200);index:users_nick_name_idx,priority:1" json:"email"`
|
Email *string `gorm:"column:email;type:character varying(200);index:users_nick_name_idx,priority:1" json:"email"`
|
||||||
@ -25,17 +18,9 @@ type User struct {
|
|||||||
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
CreatedOn *time.Time `gorm:"column:created_on;type:timestamp without time zone;default:now()" json:"created_on"`
|
||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
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"`
|
||||||
Merchant_Relation *Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
UsersRole_Relation UsersRole `gorm:"foreignKey:UsersRoleID;references:ID" json:"users_role_relation"`
|
||||||
UsersRole_Relation UsersRole `gorm:"foreignKey:users_role_id;references:id" json:"users_role_relation"`
|
|
||||||
Merchants_Relation []Merchant `gorm:"foreignKey:created_by;references:id" json:"merchants_relation"`
|
|
||||||
Provinces_Relation []Province `gorm:"foreignKey:created_by;references:id" json:"provinces_relation"`
|
|
||||||
Citys_Relation []City `gorm:"foreignKey:created_by;references:id" json:"citys_relation"`
|
|
||||||
Districts_Relation []District `gorm:"foreignKey:created_by;references:id" json:"districts_relation"`
|
|
||||||
Subdistricts_Relation []Subdistrict `gorm:"foreignKey:created_by;references:id" json:"subdistricts_relation"`
|
|
||||||
PostalCodes_Relation []PostalCode `gorm:"foreignKey:created_by;references:id" json:"postal_codes_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName User's table name
|
|
||||||
func (*User) TableName() string {
|
func (*User) TableName() string {
|
||||||
return TableNameUser
|
return TableNameUser
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,11 @@
|
|||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
import (
|
import "time"
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const TableNameUsersRole = "users_roles"
|
const TableNameUsersRole = "users_roles"
|
||||||
|
|
||||||
// UsersRole mapped from table <users_roles>
|
|
||||||
type UsersRole struct {
|
type UsersRole struct {
|
||||||
ID string `gorm:"column:id;type:character(26);primaryKey;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"`
|
Name *string `gorm:"column:name;type:character varying(255)" json:"name"`
|
||||||
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
MerchantID *string `gorm:"column:merchant_id;type:character(26)" json:"merchant_id"`
|
||||||
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
CreatedBy *string `gorm:"column:created_by;type:character(26)" json:"created_by"`
|
||||||
@ -20,11 +13,8 @@ type UsersRole struct {
|
|||||||
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
UpdatedBy *string `gorm:"column:updated_by;type:character(26)" json:"updated_by"`
|
||||||
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"`
|
||||||
RoleKey string `gorm:"column:role_key;type:character varying(20);not null" json:"role_key"`
|
RoleKey string `gorm:"column:role_key;type:character varying(20);not null" json:"role_key"`
|
||||||
Merchant_Relation Merchant `gorm:"foreignKey:merchant_id;references:id" json:"merchant_relation"`
|
|
||||||
Userss_Relation []User `gorm:"foreignKey:users_role_id;references:id" json:"userss_relation"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName UsersRole's table name
|
|
||||||
func (*UsersRole) TableName() string {
|
func (*UsersRole) TableName() string {
|
||||||
return TableNameUsersRole
|
return TableNameUsersRole
|
||||||
}
|
}
|
||||||
|
|||||||
66
internal/handlers/dto/basic_pricing.go
Normal file
66
internal/handlers/dto/basic_pricing.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
type BasicPricingComponentRequest struct {
|
||||||
|
CostComponentID string `json:"cost_component_id" binding:"required"`
|
||||||
|
Value float32 `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BasicPricingComponentResponse struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
CostComponentID *string `json:"cost_component_id"`
|
||||||
|
Value *float32 `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateBasicPricingRequest struct {
|
||||||
|
Name string `json:"name" binding:"required,min=2"`
|
||||||
|
ProvinceSourceID string `json:"province_source_id"`
|
||||||
|
CitySourceID string `json:"city_source_id"`
|
||||||
|
DistrictSourceID string `json:"district_source_id"`
|
||||||
|
SubdistrictSourceID string `json:"subdistrict_source_id"`
|
||||||
|
PostalCodeSourceID string `json:"postal_code_source_id"`
|
||||||
|
ProvinceDestinationID string `json:"province_destination_id"`
|
||||||
|
CityDestinationID string `json:"city_destination_id"`
|
||||||
|
DistrictDestinationID string `json:"district_destination_id"`
|
||||||
|
SubdistrictDestinationID string `json:"subdistrict_destination_id"`
|
||||||
|
PostalCodeDestinationID string `json:"postal_code_destination_id"`
|
||||||
|
PackageTypeID string `json:"package_type_id"`
|
||||||
|
ModaID string `json:"moda_id"`
|
||||||
|
Components []BasicPricingComponentRequest `json:"components"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateBasicPricingResponse struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name *string `json:"name"`
|
||||||
|
ProvinceSourceID *string `json:"province_source_id"`
|
||||||
|
CitySourceID *string `json:"city_source_id"`
|
||||||
|
DistrictSourceID *string `json:"district_source_id"`
|
||||||
|
SubdistrictSourceID *string `json:"subdistrict_source_id"`
|
||||||
|
PostalCodeSourceID *string `json:"postal_code_source_id"`
|
||||||
|
ProvinceDestinationID *string `json:"province_destination_id"`
|
||||||
|
CityDestinationID *string `json:"city_destination_id"`
|
||||||
|
DistrictDestinationID *string `json:"district_destination_id"`
|
||||||
|
SubdistrictDestinationID *string `json:"subdistrict_destination_id"`
|
||||||
|
PostalCodeDestinationID *string `json:"postal_code_destination_id"`
|
||||||
|
PackageTypeID *string `json:"package_type_id"`
|
||||||
|
ModaID *string `json:"moda_id"`
|
||||||
|
MerchantID *string `json:"merchant_id"`
|
||||||
|
Components []BasicPricingComponentResponse `json:"components"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BasicPricingFilterAllRequest struct {
|
||||||
|
ID string `json:"id" form:"id"`
|
||||||
|
Name string `json:"name" form:"name"`
|
||||||
|
ProvinceSourceID string `json:"province_source_id" form:"province_source_id"`
|
||||||
|
CitySourceID string `json:"city_source_id" form:"city_source_id"`
|
||||||
|
DistrictSourceID string `json:"district_source_id" form:"district_source_id"`
|
||||||
|
SubdistrictSourceID string `json:"subdistrict_source_id" form:"subdistrict_source_id"`
|
||||||
|
PostalCodeSourceID string `json:"postal_code_source_id" form:"postal_code_source_id"`
|
||||||
|
ProvinceDestinationID string `json:"province_destination_id" form:"province_destination_id"`
|
||||||
|
CityDestinationID string `json:"city_destination_id" form:"city_destination_id"`
|
||||||
|
DistrictDestinationID string `json:"district_destination_id" form:"district_destination_id"`
|
||||||
|
SubdistrictDestinationID string `json:"subdistrict_destination_id" form:"subdistrict_destination_id"`
|
||||||
|
PostalCodeDestinationID string `json:"postal_code_destination_id" form:"postal_code_destination_id"`
|
||||||
|
PackageTypeID string `json:"package_type_id" form:"package_type_id"`
|
||||||
|
ModaID string `json:"moda_id" form:"moda_id"`
|
||||||
|
MerchantID string `json:"merchant_id" form:"merchant_id"`
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ package dto
|
|||||||
type CreateCityRequest struct {
|
type CreateCityRequest struct {
|
||||||
Name string `json:"name" binding:"required,min=2"`
|
Name string `json:"name" binding:"required,min=2"`
|
||||||
ProvinceID string `json:"province_id" binding:"required"`
|
ProvinceID string `json:"province_id" binding:"required"`
|
||||||
|
Port string `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateCityResponse struct {
|
type CreateCityResponse struct {
|
||||||
@ -10,6 +11,7 @@ type CreateCityResponse struct {
|
|||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
ProvinceID *string `json:"province_id"`
|
ProvinceID *string `json:"province_id"`
|
||||||
MerchantID *string `json:"merchant_id"`
|
MerchantID *string `json:"merchant_id"`
|
||||||
|
Port *string `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CityFilterAllRequest struct {
|
type CityFilterAllRequest struct {
|
||||||
@ -17,11 +19,13 @@ type CityFilterAllRequest struct {
|
|||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
ProvinceID string `json:"province_id" form:"province_id"`
|
ProvinceID string `json:"province_id" form:"province_id"`
|
||||||
MerchantID string `json:"merchant_id" form:"merchant_id"`
|
MerchantID string `json:"merchant_id" form:"merchant_id"`
|
||||||
|
Port string `json:"port" form:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCityRequest struct {
|
type UpdateCityRequest struct {
|
||||||
Name string `json:"name" binding:"required,min=2"`
|
Name string `json:"name" binding:"required,min=2"`
|
||||||
ProvinceID string `json:"province_id" binding:"required"`
|
ProvinceID string `json:"province_id" binding:"required"`
|
||||||
|
Port string `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImportCityResponse struct {
|
type ImportCityResponse struct {
|
||||||
|
|||||||
@ -3,9 +3,8 @@ package dto
|
|||||||
type CreateCostComponentRequest struct {
|
type CreateCostComponentRequest struct {
|
||||||
Name string `json:"name" binding:"required,min=2"`
|
Name string `json:"name" binding:"required,min=2"`
|
||||||
Code string `json:"code" binding:"required"`
|
Code string `json:"code" binding:"required"`
|
||||||
Inc int32 `json:"inc"`
|
Value string `json:"value" binding:"required"`
|
||||||
Value string `json:"value"`
|
ComponentType int32 `json:"component_type"`
|
||||||
CostComponentGroupID string `json:"cost_component_group_id" binding:"required"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateCostComponentResponse struct {
|
type CreateCostComponentResponse struct {
|
||||||
@ -14,7 +13,7 @@ type CreateCostComponentResponse struct {
|
|||||||
Code *string `json:"code"`
|
Code *string `json:"code"`
|
||||||
Inc *int32 `json:"inc"`
|
Inc *int32 `json:"inc"`
|
||||||
Value *string `json:"value"`
|
Value *string `json:"value"`
|
||||||
CostComponentGroupID *string `json:"cost_component_group_id"`
|
ComponentType *int32 `json:"component_type"`
|
||||||
MerchantID *string `json:"merchant_id"`
|
MerchantID *string `json:"merchant_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,25 +21,17 @@ type CostComponentFilterAllRequest struct {
|
|||||||
ID string `json:"id" form:"id"`
|
ID string `json:"id" form:"id"`
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Code string `json:"code" form:"code"`
|
Code string `json:"code" form:"code"`
|
||||||
CostComponentGroupID string `json:"cost_component_group_id" form:"cost_component_group_id"`
|
ComponentType string `json:"component_type" form:"component_type"`
|
||||||
MerchantID string `json:"merchant_id" form:"merchant_id"`
|
MerchantID string `json:"merchant_id" form:"merchant_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCostComponentRequest struct {
|
type UpdateCostComponentRequest struct {
|
||||||
Name string `json:"name" binding:"required,min=2"`
|
Name string `json:"name" binding:"required,min=2"`
|
||||||
Code string `json:"code" binding:"required"`
|
Code string `json:"code" binding:"required"`
|
||||||
Inc int32 `json:"inc"`
|
Value string `json:"value" binding:"required"`
|
||||||
Value string `json:"value"`
|
ComponentType int32 `json:"component_type"`
|
||||||
CostComponentGroupID string `json:"cost_component_group_id" binding:"required"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImportCostComponentResponse struct {
|
type MatchCostComponentRequest struct {
|
||||||
JobID string `json:"job_id,omitempty"`
|
ID string `json:"id" form:"id" binding:"required,len=26"`
|
||||||
TotalRows int `json:"total_rows"`
|
|
||||||
Imported int `json:"imported"`
|
|
||||||
Skipped int `json:"skipped"`
|
|
||||||
Logs []ImportLog `json:"logs"`
|
|
||||||
Errors []string `json:"errors"`
|
|
||||||
IsAsync bool `json:"is_async"`
|
|
||||||
Message string `json:"message,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
package dto
|
|
||||||
|
|
||||||
type CreateCostComponentGroupRequest struct {
|
|
||||||
Name string `json:"name" binding:"required,min=2"`
|
|
||||||
Code string `json:"code" binding:"required"`
|
|
||||||
Inc int32 `json:"inc"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateCostComponentGroupResponse struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Name *string `json:"name"`
|
|
||||||
Code *string `json:"code"`
|
|
||||||
Inc *int32 `json:"inc"`
|
|
||||||
Value *string `json:"value"`
|
|
||||||
MerchantID *string `json:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CostComponentGroupFilterAllRequest struct {
|
|
||||||
ID string `json:"id" form:"id"`
|
|
||||||
Name string `json:"name" form:"name"`
|
|
||||||
Code string `json:"code" form:"code"`
|
|
||||||
MerchantID string `json:"merchant_id" form:"merchant_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateCostComponentGroupRequest struct {
|
|
||||||
Name string `json:"name" binding:"required,min=2"`
|
|
||||||
Code string `json:"code" binding:"required"`
|
|
||||||
Inc int32 `json:"inc"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ImportCostComponentGroupResponse struct {
|
|
||||||
JobID string `json:"job_id,omitempty"`
|
|
||||||
TotalRows int `json:"total_rows"`
|
|
||||||
Imported int `json:"imported"`
|
|
||||||
Skipped int `json:"skipped"`
|
|
||||||
Logs []ImportLog `json:"logs"`
|
|
||||||
Errors []string `json:"errors"`
|
|
||||||
IsAsync bool `json:"is_async"`
|
|
||||||
Message string `json:"message,omitempty"`
|
|
||||||
}
|
|
||||||
@ -2,9 +2,9 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cargo-erp-backend/internal/handlers/router/auth"
|
"cargo-erp-backend/internal/handlers/router/auth"
|
||||||
|
"cargo-erp-backend/internal/handlers/router/basic_pricing"
|
||||||
"cargo-erp-backend/internal/handlers/router/city"
|
"cargo-erp-backend/internal/handlers/router/city"
|
||||||
"cargo-erp-backend/internal/handlers/router/cost_component"
|
"cargo-erp-backend/internal/handlers/router/cost_component"
|
||||||
"cargo-erp-backend/internal/handlers/router/cost_component_group"
|
|
||||||
"cargo-erp-backend/internal/handlers/router/district"
|
"cargo-erp-backend/internal/handlers/router/district"
|
||||||
"cargo-erp-backend/internal/handlers/router/postal_code"
|
"cargo-erp-backend/internal/handlers/router/postal_code"
|
||||||
"cargo-erp-backend/internal/handlers/router/province"
|
"cargo-erp-backend/internal/handlers/router/province"
|
||||||
@ -115,10 +115,14 @@ func (h *Handlers) Run() {
|
|||||||
district.NewDistrictHandler(h.Helper, masterdata).Router()
|
district.NewDistrictHandler(h.Helper, masterdata).Router()
|
||||||
subdistrict.NewSubdistrictHandler(h.Helper, masterdata).Router()
|
subdistrict.NewSubdistrictHandler(h.Helper, masterdata).Router()
|
||||||
postal_code.NewPostalCodeHandler(h.Helper, masterdata).Router()
|
postal_code.NewPostalCodeHandler(h.Helper, masterdata).Router()
|
||||||
cost_component_group.NewCostComponentGroupHandler(h.Helper, masterdata).Router()
|
|
||||||
cost_component.NewCostComponentHandler(h.Helper, masterdata).Router()
|
cost_component.NewCostComponentHandler(h.Helper, masterdata).Router()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//basic-pricing
|
||||||
|
basicPricingGroup := r.Group("basic-pricings")
|
||||||
|
basicPricingGroup.Use(middleware.NewAuthMiddleware(h.Helper).Check())
|
||||||
|
basic_pricing.NewBasicPricingHandler(h.Helper, basicPricingGroup).Router()
|
||||||
|
|
||||||
h.Helper.Log().Info("Starting Apps")
|
h.Helper.Log().Info("Starting Apps")
|
||||||
r.Run(fmt.Sprintf("%v:%v", host, port))
|
r.Run(fmt.Sprintf("%v:%v", host, port))
|
||||||
}
|
}
|
||||||
|
|||||||
162
internal/handlers/router/basic_pricing/basic_pricing.go
Normal file
162
internal/handlers/router/basic_pricing/basic_pricing.go
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
package basic_pricing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cargo-erp-backend/internal/handlers/dto"
|
||||||
|
"cargo-erp-backend/internal/usecases"
|
||||||
|
"cargo-erp-backend/pkg/helpers"
|
||||||
|
"cargo-erp-backend/pkg/response"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BasicPricingHandlerInterface interface {
|
||||||
|
Router()
|
||||||
|
}
|
||||||
|
|
||||||
|
type BasicPricingHandler struct {
|
||||||
|
Helper helpers.HelperInterface
|
||||||
|
Group *gin.RouterGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBasicPricingHandler(helper helpers.HelperInterface, g *gin.RouterGroup) BasicPricingHandlerInterface {
|
||||||
|
return &BasicPricingHandler{Helper: helper, Group: g}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) Router() {
|
||||||
|
r := h.Group
|
||||||
|
{
|
||||||
|
r.GET("/", h.GetAll)
|
||||||
|
r.POST("/list", h.GetList)
|
||||||
|
r.GET("/:id", h.GetByID)
|
||||||
|
r.POST("/", h.Create)
|
||||||
|
r.PUT("/:id", h.Update)
|
||||||
|
r.DELETE("/:id", h.Delete)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) GetAll(c *gin.Context) {
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req dto.BasicPricingFilterAllRequest
|
||||||
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := usecases.NewBasicPricingUsecase(h.Helper, *userid)
|
||||||
|
pricings, _, err := u.GetAll(req)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, pricings)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) GetList(c *gin.Context) {
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req dto.DataTableRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.Error(c, http.StatusBadRequest, "Request Format request invalid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
u := usecases.NewBasicPricingUsecase(h.Helper, *userid)
|
||||||
|
res, err := u.GetList(req)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, res)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) GetByID(c *gin.Context) {
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id := c.Param("id")
|
||||||
|
|
||||||
|
u := usecases.NewBasicPricingUsecase(h.Helper, *userid)
|
||||||
|
pricing, err := u.GetByID(id)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusNotFound, "basic pricing not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, pricing)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) Create(c *gin.Context) {
|
||||||
|
var req dto.CreateBasicPricingRequest
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
response.Error(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var merchantid *string = nil
|
||||||
|
if userid.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
merchantid = userid.MerchantID
|
||||||
|
}
|
||||||
|
createdBy := userid.ID
|
||||||
|
|
||||||
|
u := usecases.NewBasicPricingUsecase(h.Helper, *userid)
|
||||||
|
pricing, err := u.Create(req, createdBy, merchantid)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Created(c, pricing)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) Update(c *gin.Context) {
|
||||||
|
id := c.Param("id")
|
||||||
|
|
||||||
|
var req dto.CreateBasicPricingRequest
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
response.Error(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
updatedBy := userid.ID
|
||||||
|
|
||||||
|
u := usecases.NewBasicPricingUsecase(h.Helper, *userid)
|
||||||
|
pricing, err := u.Update(id, req, updatedBy)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, pricing)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *BasicPricingHandler) Delete(c *gin.Context) {
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id := c.Param("id")
|
||||||
|
u := usecases.NewBasicPricingUsecase(h.Helper, *userid)
|
||||||
|
if err := u.Delete(id); err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, map[string]interface{}{"message": "basic pricing deleted"})
|
||||||
|
}
|
||||||
@ -125,7 +125,7 @@ func (h *CityHandler) Create(c *gin.Context) {
|
|||||||
createdBy := userid.ID
|
createdBy := userid.ID
|
||||||
|
|
||||||
u := usecases.NewCityUsecase(h.Helper, *userid)
|
u := usecases.NewCityUsecase(h.Helper, *userid)
|
||||||
city, err := u.Create(req.Name, req.ProvinceID, createdBy, merchantid)
|
city, err := u.Create(req.Name, req.ProvinceID, req.Port, createdBy, merchantid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -151,7 +151,7 @@ func (h *CityHandler) Update(c *gin.Context) {
|
|||||||
updatedBy := userid.ID
|
updatedBy := userid.ID
|
||||||
|
|
||||||
u := usecases.NewCityUsecase(h.Helper, *userid)
|
u := usecases.NewCityUsecase(h.Helper, *userid)
|
||||||
city, err := u.Update(id, req.Name, req.ProvinceID, updatedBy)
|
city, err := u.Update(id, req.Name, req.ProvinceID, req.Port, updatedBy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@ -2,10 +2,8 @@ package cost_component
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cargo-erp-backend/internal/handlers/dto"
|
"cargo-erp-backend/internal/handlers/dto"
|
||||||
cost_componentimporter "cargo-erp-backend/internal/importers/cost_component"
|
|
||||||
"cargo-erp-backend/internal/usecases"
|
"cargo-erp-backend/internal/usecases"
|
||||||
"cargo-erp-backend/pkg/helpers"
|
"cargo-erp-backend/pkg/helpers"
|
||||||
"cargo-erp-backend/pkg/importer"
|
|
||||||
"cargo-erp-backend/pkg/response"
|
"cargo-erp-backend/pkg/response"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -34,10 +32,8 @@ func (h *CostComponentHandler) Router() {
|
|||||||
r.POST("/", h.Create)
|
r.POST("/", h.Create)
|
||||||
r.PUT("/:id", h.Update)
|
r.PUT("/:id", h.Update)
|
||||||
r.DELETE("/:id", h.Delete)
|
r.DELETE("/:id", h.Delete)
|
||||||
r.GET("/template", h.Template)
|
r.POST("/sortup", h.SortUp)
|
||||||
r.POST("/import", h.Import)
|
r.POST("/sortdown", h.SortDown)
|
||||||
r.POST("/import/stop", h.ImportStop)
|
|
||||||
r.GET("/import/status/:jobId", h.ImportStatus)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +121,7 @@ func (h *CostComponentHandler) Create(c *gin.Context) {
|
|||||||
createdBy := userid.ID
|
createdBy := userid.ID
|
||||||
|
|
||||||
u := usecases.NewCostComponentUsecase(h.Helper, *userid)
|
u := usecases.NewCostComponentUsecase(h.Helper, *userid)
|
||||||
component, err := u.Create(req.Name, req.Code, req.Inc, req.Value, req.CostComponentGroupID, createdBy, merchantid)
|
component, err := u.Create(req.Name, req.Code, req.Value, req.ComponentType, createdBy, merchantid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -151,7 +147,7 @@ func (h *CostComponentHandler) Update(c *gin.Context) {
|
|||||||
updatedBy := userid.ID
|
updatedBy := userid.ID
|
||||||
|
|
||||||
u := usecases.NewCostComponentUsecase(h.Helper, *userid)
|
u := usecases.NewCostComponentUsecase(h.Helper, *userid)
|
||||||
component, err := u.Update(id, req.Name, req.Code, req.Inc, req.Value, req.CostComponentGroupID, updatedBy)
|
component, err := u.Update(id, req.Name, req.Code, req.Value, req.ComponentType, updatedBy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
@ -177,105 +173,42 @@ func (h *CostComponentHandler) Delete(c *gin.Context) {
|
|||||||
response.Success(c, map[string]interface{}{"message": "cost component deleted"})
|
response.Success(c, map[string]interface{}{"message": "cost component deleted"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CostComponentHandler) Template(c *gin.Context) {
|
func (h *CostComponentHandler) SortUp(c *gin.Context) {
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handler := cost_componentimporter.NewCostComponentImportHandler(*userid, h.Helper)
|
var req dto.MatchCostComponentRequest
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
imp.ServeTemplate(c.Writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentHandler) Import(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
file, header, err := c.Request.FormFile("file")
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, "File is required")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
handler := cost_componentimporter.NewCostComponentImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
|
|
||||||
result, err := imp.Process(file, userid.ID, header.Filename)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var importLogs []dto.ImportLog
|
|
||||||
for _, l := range result.Logs {
|
|
||||||
importLogs = append(importLogs, dto.ImportLog{
|
|
||||||
Row: l.Row,
|
|
||||||
Status: l.Status,
|
|
||||||
Data: l.Data,
|
|
||||||
Message: l.Message,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, dto.ImportCostComponentResponse{
|
|
||||||
JobID: result.JobID,
|
|
||||||
TotalRows: result.TotalRows,
|
|
||||||
Imported: result.Imported,
|
|
||||||
Skipped: result.Skipped,
|
|
||||||
Logs: importLogs,
|
|
||||||
Errors: result.Errors,
|
|
||||||
IsAsync: result.IsAsync,
|
|
||||||
Message: result.Message,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentHandler) ImportStatus(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jobId := c.Param("jobId")
|
|
||||||
|
|
||||||
handler := cost_componentimporter.NewCostComponentImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
|
|
||||||
job, logs, err := imp.GetJobStatus(jobId)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusNotFound, "Job not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, map[string]interface{}{
|
|
||||||
"job": job,
|
|
||||||
"logs": logs,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentHandler) ImportStop(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req dto.StopImportRequest
|
|
||||||
if err := c.BindJSON(&req); err != nil {
|
if err := c.BindJSON(&req); err != nil {
|
||||||
response.Error(c, http.StatusBadRequest, "job_id is required")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
handler := cost_componentimporter.NewCostComponentImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
|
|
||||||
if err := imp.StopJob(req.JobID); err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, err.Error())
|
response.Error(c, http.StatusBadRequest, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
sortUp := usecases.NewCostComponentUsecase(h.Helper, *userid)
|
||||||
|
|
||||||
response.Success(c, map[string]interface{}{"message": "Job stopped"})
|
if err := sortUp.SortUp(req.ID); err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, map[string]interface{}{"message": "Sorting Up Success"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *CostComponentHandler) SortDown(c *gin.Context) {
|
||||||
|
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, http.StatusUnauthorized, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req dto.MatchCostComponentRequest
|
||||||
|
if err := c.BindJSON(&req); err != nil {
|
||||||
|
response.Error(c, http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sortUp := usecases.NewCostComponentUsecase(h.Helper, *userid)
|
||||||
|
|
||||||
|
if err := sortUp.SortDown(req.ID); err != nil {
|
||||||
|
response.Error(c, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Success(c, map[string]interface{}{"message": "Sorting Down Success"})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,281 +0,0 @@
|
|||||||
package cost_component_group
|
|
||||||
|
|
||||||
import (
|
|
||||||
"cargo-erp-backend/internal/handlers/dto"
|
|
||||||
cost_component_groupimporter "cargo-erp-backend/internal/importers/cost_component_group"
|
|
||||||
"cargo-erp-backend/internal/usecases"
|
|
||||||
"cargo-erp-backend/pkg/helpers"
|
|
||||||
"cargo-erp-backend/pkg/importer"
|
|
||||||
"cargo-erp-backend/pkg/response"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CostComponentGroupHandlerInterface interface {
|
|
||||||
Router()
|
|
||||||
}
|
|
||||||
|
|
||||||
type CostComponentGroupHandler struct {
|
|
||||||
Helper helpers.HelperInterface
|
|
||||||
Group *gin.RouterGroup
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCostComponentGroupHandler(helper helpers.HelperInterface, g *gin.RouterGroup) CostComponentGroupHandlerInterface {
|
|
||||||
return &CostComponentGroupHandler{Helper: helper, Group: g}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) Router() {
|
|
||||||
r := h.Group.Group("cost-component-groups")
|
|
||||||
{
|
|
||||||
r.GET("/", h.GetAll)
|
|
||||||
r.POST("/list", h.GetList)
|
|
||||||
r.GET("/:id", h.GetByID)
|
|
||||||
r.POST("/", h.Create)
|
|
||||||
r.PUT("/:id", h.Update)
|
|
||||||
r.DELETE("/:id", h.Delete)
|
|
||||||
r.GET("/template", h.Template)
|
|
||||||
r.POST("/import", h.Import)
|
|
||||||
r.POST("/import/stop", h.ImportStop)
|
|
||||||
r.GET("/import/status/:jobId", h.ImportStatus)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) GetAll(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var req dto.CostComponentGroupFilterAllRequest
|
|
||||||
if err := c.ShouldBindQuery(&req); err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
u := usecases.NewCostComponentGroupUsecase(h.Helper, *userid)
|
|
||||||
groups, _, err := u.GetAll(req)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var responseDTO = make([]dto.CreateCostComponentGroupResponse, 0)
|
|
||||||
for _, v := range groups {
|
|
||||||
var DTO dto.CreateCostComponentGroupResponse
|
|
||||||
h.Helper.MapStructToStruct(v, "json", &DTO, "json")
|
|
||||||
responseDTO = append(responseDTO, DTO)
|
|
||||||
}
|
|
||||||
response.Success(c, responseDTO)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) GetList(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req dto.DataTableRequest
|
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, "Request Format request invalid")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
u := usecases.NewCostComponentGroupUsecase(h.Helper, *userid)
|
|
||||||
res, err := u.GetList(req)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
response.Success(c, res)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) GetByID(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
id := c.Param("id")
|
|
||||||
|
|
||||||
u := usecases.NewCostComponentGroupUsecase(h.Helper, *userid)
|
|
||||||
group, err := u.GetByID(id)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusNotFound, "cost component group not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, group)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) Create(c *gin.Context) {
|
|
||||||
var req dto.CreateCostComponentGroupRequest
|
|
||||||
if err := c.BindJSON(&req); err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var merchantid *string = nil
|
|
||||||
if userid.UsersRole_Relation.RoleKey != "SPM" {
|
|
||||||
merchantid = userid.MerchantID
|
|
||||||
}
|
|
||||||
createdBy := userid.ID
|
|
||||||
|
|
||||||
u := usecases.NewCostComponentGroupUsecase(h.Helper, *userid)
|
|
||||||
group, err := u.Create(req.Name, req.Code, req.Inc, req.Value, createdBy, merchantid)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var responseDTO dto.CreateCostComponentGroupResponse
|
|
||||||
h.Helper.MapStructToStruct(group, "json", &responseDTO, "json")
|
|
||||||
response.Created(c, responseDTO)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) Update(c *gin.Context) {
|
|
||||||
id := c.Param("id")
|
|
||||||
|
|
||||||
var req dto.UpdateCostComponentGroupRequest
|
|
||||||
if err := c.BindJSON(&req); err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
updatedBy := userid.ID
|
|
||||||
|
|
||||||
u := usecases.NewCostComponentGroupUsecase(h.Helper, *userid)
|
|
||||||
group, err := u.Update(id, req.Name, req.Code, req.Inc, req.Value, updatedBy)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var responseDTO dto.CreateCostComponentGroupResponse
|
|
||||||
h.Helper.MapStructToStruct(group, "json", &responseDTO, "json")
|
|
||||||
response.Success(c, responseDTO)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) Delete(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
id := c.Param("id")
|
|
||||||
u := usecases.NewCostComponentGroupUsecase(h.Helper, *userid)
|
|
||||||
if err := u.Delete(id); err != nil {
|
|
||||||
response.Error(c, http.StatusInternalServerError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, map[string]interface{}{"message": "cost component group deleted"})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) Template(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
handler := cost_component_groupimporter.NewCostComponentGroupImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
imp.ServeTemplate(c.Writer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) Import(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
file, header, err := c.Request.FormFile("file")
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, "File is required")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
handler := cost_component_groupimporter.NewCostComponentGroupImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
|
|
||||||
result, err := imp.Process(file, userid.ID, header.Filename)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var importLogs []dto.ImportLog
|
|
||||||
for _, l := range result.Logs {
|
|
||||||
importLogs = append(importLogs, dto.ImportLog{
|
|
||||||
Row: l.Row,
|
|
||||||
Status: l.Status,
|
|
||||||
Data: l.Data,
|
|
||||||
Message: l.Message,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, dto.ImportCostComponentGroupResponse{
|
|
||||||
JobID: result.JobID,
|
|
||||||
TotalRows: result.TotalRows,
|
|
||||||
Imported: result.Imported,
|
|
||||||
Skipped: result.Skipped,
|
|
||||||
Logs: importLogs,
|
|
||||||
Errors: result.Errors,
|
|
||||||
IsAsync: result.IsAsync,
|
|
||||||
Message: result.Message,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) ImportStatus(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jobId := c.Param("jobId")
|
|
||||||
|
|
||||||
handler := cost_component_groupimporter.NewCostComponentGroupImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
|
|
||||||
job, logs, err := imp.GetJobStatus(jobId)
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusNotFound, "Job not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, map[string]interface{}{
|
|
||||||
"job": job,
|
|
||||||
"logs": logs,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupHandler) ImportStop(c *gin.Context) {
|
|
||||||
userid, err := h.Helper.GetAuthInfo(c.GetString("auth"))
|
|
||||||
if err != nil {
|
|
||||||
response.Error(c, http.StatusUnauthorized, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req dto.StopImportRequest
|
|
||||||
if err := c.BindJSON(&req); err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, "job_id is required")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
handler := cost_component_groupimporter.NewCostComponentGroupImportHandler(*userid, h.Helper)
|
|
||||||
imp := importer.NewImporter(h.Helper, handler)
|
|
||||||
|
|
||||||
if err := imp.StopJob(req.JobID); err != nil {
|
|
||||||
response.Error(c, http.StatusBadRequest, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
response.Success(c, map[string]interface{}{"message": "Job stopped"})
|
|
||||||
}
|
|
||||||
@ -28,7 +28,7 @@ func (h *CityImportHandler) ValidateRow(row []string, rowNumber int) (importer.R
|
|||||||
var errors []error
|
var errors []error
|
||||||
|
|
||||||
if len(row) < 2 {
|
if len(row) < 2 {
|
||||||
errors = append(errors, fmt.Errorf("row must have 2 columns: name, province_name"))
|
errors = append(errors, fmt.Errorf("row must have at least 2 columns: name, province_name"))
|
||||||
return nil, errors
|
return nil, errors
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +46,11 @@ func (h *CityImportHandler) ValidateRow(row []string, rowNumber int) (importer.R
|
|||||||
errors = append(errors, fmt.Errorf("province_name is required"))
|
errors = append(errors, fmt.Errorf("province_name is required"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var port string
|
||||||
|
if len(row) >= 3 {
|
||||||
|
port = strings.TrimSpace(row[2])
|
||||||
|
}
|
||||||
|
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
return nil, errors
|
return nil, errors
|
||||||
}
|
}
|
||||||
@ -64,6 +69,7 @@ func (h *CityImportHandler) ValidateRow(row []string, rowNumber int) (importer.R
|
|||||||
city := &domain.City{
|
city := &domain.City{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
ProvinceID: &provinceID,
|
ProvinceID: &provinceID,
|
||||||
|
Port: &port,
|
||||||
MerchantID: h.UserData.MerchantID,
|
MerchantID: h.UserData.MerchantID,
|
||||||
CreatedBy: &h.UserData.ID,
|
CreatedBy: &h.UserData.ID,
|
||||||
CreatedOn: &now,
|
CreatedOn: &now,
|
||||||
@ -95,14 +101,14 @@ func (h *CityImportHandler) IsDuplicate(db *gorm.DB, data importer.RowData) bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *CityImportHandler) GetTemplateHeaders() []string {
|
func (h *CityImportHandler) GetTemplateHeaders() []string {
|
||||||
return []string{"name", "province_name"}
|
return []string{"name", "province_name", "port"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CityImportHandler) GetTemplateRows() [][]string {
|
func (h *CityImportHandler) GetTemplateRows() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
{"Jakarta Pusat", "DKI Jakarta"},
|
{"Jakarta Pusat", "DKI Jakarta", ""},
|
||||||
{"Bandung", "Jawa Barat"},
|
{"Bandung", "Jawa Barat", ""},
|
||||||
{"Surabaya", "Jawa Timur"},
|
{"Surabaya", "Jawa Timur", ""},
|
||||||
{"Semarang", "Jawa Tengah"},
|
{"Semarang", "Jawa Tengah", ""},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,132 +0,0 @@
|
|||||||
package cost_component
|
|
||||||
|
|
||||||
import (
|
|
||||||
"cargo-erp-backend/internal/domain"
|
|
||||||
"cargo-erp-backend/pkg/helpers"
|
|
||||||
"cargo-erp-backend/pkg/importer"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CostComponentImportHandler struct {
|
|
||||||
UserData domain.User
|
|
||||||
Helper helpers.HelperInterface
|
|
||||||
lastGroupName string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCostComponentImportHandler(userData domain.User, helper helpers.HelperInterface) importer.ImportHandler {
|
|
||||||
return &CostComponentImportHandler{
|
|
||||||
UserData: userData,
|
|
||||||
Helper: helper,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentImportHandler) ValidateRow(row []string, rowNumber int) (importer.RowData, []error) {
|
|
||||||
var errors []error
|
|
||||||
|
|
||||||
if len(row) < 5 {
|
|
||||||
errors = append(errors, fmt.Errorf("row must have 5 columns: name, code, inc, value, cost_component_group_name"))
|
|
||||||
return nil, errors
|
|
||||||
}
|
|
||||||
|
|
||||||
name := strings.TrimSpace(row[0])
|
|
||||||
if name == "" {
|
|
||||||
errors = append(errors, fmt.Errorf("name is required"))
|
|
||||||
} else if len(name) < 2 {
|
|
||||||
errors = append(errors, fmt.Errorf("name must be at least 2 characters"))
|
|
||||||
} else if len(name) > 255 {
|
|
||||||
errors = append(errors, fmt.Errorf("name must be at most 255 characters"))
|
|
||||||
}
|
|
||||||
|
|
||||||
code := strings.TrimSpace(row[1])
|
|
||||||
if code == "" {
|
|
||||||
errors = append(errors, fmt.Errorf("code is required"))
|
|
||||||
}
|
|
||||||
|
|
||||||
incStr := strings.TrimSpace(row[2])
|
|
||||||
var inc int32
|
|
||||||
if incStr != "" {
|
|
||||||
parsed, err := strconv.ParseInt(incStr, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
errors = append(errors, fmt.Errorf("inc must be a valid integer"))
|
|
||||||
} else {
|
|
||||||
inc = int32(parsed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
value := strings.TrimSpace(row[3])
|
|
||||||
|
|
||||||
groupName := strings.TrimSpace(row[4])
|
|
||||||
if groupName == "" {
|
|
||||||
errors = append(errors, fmt.Errorf("cost_component_group_name is required"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(errors) > 0 {
|
|
||||||
return nil, errors
|
|
||||||
}
|
|
||||||
|
|
||||||
var group domain.CostComponentGroup
|
|
||||||
db := h.Helper.GetDB("slave")
|
|
||||||
if err := db.Where("UPPER(name) = ?", strings.ToUpper(groupName)).First(&group).Error; err != nil {
|
|
||||||
errors = append(errors, fmt.Errorf("cost_component_group '%s' not found", groupName))
|
|
||||||
return nil, errors
|
|
||||||
}
|
|
||||||
|
|
||||||
h.lastGroupName = groupName
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
component := &domain.CostComponent{
|
|
||||||
Name: &name,
|
|
||||||
Code: &code,
|
|
||||||
Inc: &inc,
|
|
||||||
Value: &value,
|
|
||||||
CostComponentGroupID: &group.ID,
|
|
||||||
MerchantID: h.UserData.MerchantID,
|
|
||||||
CreatedBy: &h.UserData.ID,
|
|
||||||
CreatedOn: &now,
|
|
||||||
UpdatedBy: &h.UserData.ID,
|
|
||||||
UpdatedOn: &now,
|
|
||||||
}
|
|
||||||
|
|
||||||
return component, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentImportHandler) GetDataString(data importer.RowData) string {
|
|
||||||
component := data.(*domain.CostComponent)
|
|
||||||
name := ""
|
|
||||||
if component.Name != nil {
|
|
||||||
name = *component.Name
|
|
||||||
}
|
|
||||||
code := ""
|
|
||||||
if component.Code != nil {
|
|
||||||
code = *component.Code
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s, %s, %s", name, code, h.lastGroupName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentImportHandler) IsDuplicate(db *gorm.DB, data importer.RowData) bool {
|
|
||||||
component := data.(*domain.CostComponent)
|
|
||||||
var count int64
|
|
||||||
db.Model(&domain.CostComponent{}).
|
|
||||||
Joins("JOIN cost_component_group ON cost_component.cost_component_group_id = cost_component_group.id").
|
|
||||||
Where("UPPER(cost_component.name) = ? AND UPPER(cost_component.code) = ? AND UPPER(cost_component_group.name) = ?",
|
|
||||||
strings.ToUpper(*component.Name), strings.ToUpper(*component.Code), strings.ToUpper(h.lastGroupName)).
|
|
||||||
Count(&count)
|
|
||||||
return count > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentImportHandler) GetTemplateHeaders() []string {
|
|
||||||
return []string{"name", "code", "inc", "value", "cost_component_group_name"}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentImportHandler) GetTemplateRows() [][]string {
|
|
||||||
return [][]string{
|
|
||||||
{"Component A", "CA", "1", "10000", "Group 1"},
|
|
||||||
{"Component B", "CB", "2", "20000", "Group 2"},
|
|
||||||
{"Component C", "CC", "3", "30000", "Group 1"},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,118 +0,0 @@
|
|||||||
package cost_component_group
|
|
||||||
|
|
||||||
import (
|
|
||||||
"cargo-erp-backend/internal/domain"
|
|
||||||
"cargo-erp-backend/pkg/helpers"
|
|
||||||
"cargo-erp-backend/pkg/importer"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/oklog/ulid/v2"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CostComponentGroupImportHandler struct {
|
|
||||||
UserData domain.User
|
|
||||||
Helper helpers.HelperInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCostComponentGroupImportHandler(userData domain.User, helper helpers.HelperInterface) importer.ImportHandler {
|
|
||||||
return &CostComponentGroupImportHandler{
|
|
||||||
UserData: userData,
|
|
||||||
Helper: helper,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupImportHandler) ValidateRow(row []string, rowNumber int) (importer.RowData, []error) {
|
|
||||||
var errors []error
|
|
||||||
|
|
||||||
if len(row) < 4 {
|
|
||||||
errors = append(errors, fmt.Errorf("row must have 4 columns: name, code, inc, value"))
|
|
||||||
return nil, errors
|
|
||||||
}
|
|
||||||
|
|
||||||
name := strings.TrimSpace(row[0])
|
|
||||||
if name == "" {
|
|
||||||
errors = append(errors, fmt.Errorf("name is required"))
|
|
||||||
} else if len(name) < 2 {
|
|
||||||
errors = append(errors, fmt.Errorf("name must be at least 2 characters"))
|
|
||||||
} else if len(name) > 255 {
|
|
||||||
errors = append(errors, fmt.Errorf("name must be at most 255 characters"))
|
|
||||||
}
|
|
||||||
|
|
||||||
code := strings.TrimSpace(row[1])
|
|
||||||
if code == "" {
|
|
||||||
errors = append(errors, fmt.Errorf("code is required"))
|
|
||||||
}
|
|
||||||
|
|
||||||
incStr := strings.TrimSpace(row[2])
|
|
||||||
var inc int32
|
|
||||||
if incStr != "" {
|
|
||||||
parsed, err := strconv.ParseInt(incStr, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
errors = append(errors, fmt.Errorf("inc must be a valid integer"))
|
|
||||||
} else {
|
|
||||||
inc = int32(parsed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
value := strings.TrimSpace(row[3])
|
|
||||||
|
|
||||||
if len(errors) > 0 {
|
|
||||||
return nil, errors
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
id := ulid.Make().String()
|
|
||||||
group := &domain.CostComponentGroup{
|
|
||||||
ID: id,
|
|
||||||
Name: &name,
|
|
||||||
Code: &code,
|
|
||||||
Inc: &inc,
|
|
||||||
Value: &value,
|
|
||||||
MerchantID: h.UserData.MerchantID,
|
|
||||||
CreatedBy: &h.UserData.ID,
|
|
||||||
CreatedOn: &now,
|
|
||||||
UpdatedBy: &h.UserData.ID,
|
|
||||||
UpdatedOn: &now,
|
|
||||||
}
|
|
||||||
|
|
||||||
return group, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupImportHandler) GetDataString(data importer.RowData) string {
|
|
||||||
group := data.(*domain.CostComponentGroup)
|
|
||||||
name := ""
|
|
||||||
if group.Name != nil {
|
|
||||||
name = *group.Name
|
|
||||||
}
|
|
||||||
code := ""
|
|
||||||
if group.Code != nil {
|
|
||||||
code = *group.Code
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s, %s", name, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupImportHandler) IsDuplicate(db *gorm.DB, data importer.RowData) bool {
|
|
||||||
group := data.(*domain.CostComponentGroup)
|
|
||||||
var count int64
|
|
||||||
db.Model(&domain.CostComponentGroup{}).
|
|
||||||
Where("UPPER(name) = ? AND UPPER(code) = ?",
|
|
||||||
strings.ToUpper(*group.Name), strings.ToUpper(*group.Code)).
|
|
||||||
Count(&count)
|
|
||||||
return count > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupImportHandler) GetTemplateHeaders() []string {
|
|
||||||
return []string{"name", "code", "inc", "value"}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *CostComponentGroupImportHandler) GetTemplateRows() [][]string {
|
|
||||||
return [][]string{
|
|
||||||
{"Component A", "CA", "1", "10000"},
|
|
||||||
{"Component B", "CB", "2", "20000"},
|
|
||||||
{"Component C", "CC", "3", "30000"},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
294
internal/usecases/basic_pricing.go
Normal file
294
internal/usecases/basic_pricing.go
Normal file
@ -0,0 +1,294 @@
|
|||||||
|
package usecases
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cargo-erp-backend/internal/domain"
|
||||||
|
"cargo-erp-backend/internal/handlers/dto"
|
||||||
|
"cargo-erp-backend/pkg/datatable"
|
||||||
|
"cargo-erp-backend/pkg/helpers"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BasicPricingUsecaseInterface interface {
|
||||||
|
GetAll(filter dto.BasicPricingFilterAllRequest) ([]dto.CreateBasicPricingResponse, int64, error)
|
||||||
|
GetList(dto.DataTableRequest) (dto.DataTableResponse, error)
|
||||||
|
GetByID(id string) (dto.CreateBasicPricingResponse, error)
|
||||||
|
Create(req dto.CreateBasicPricingRequest, createdBy string, merchantid *string) (dto.CreateBasicPricingResponse, error)
|
||||||
|
Update(id string, req dto.CreateBasicPricingRequest, updatedBy string) (dto.CreateBasicPricingResponse, error)
|
||||||
|
Delete(id string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type BasicPricingUsecase struct {
|
||||||
|
Helper helpers.HelperInterface
|
||||||
|
AuthUser domain.User
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBasicPricingUsecase(helper helpers.HelperInterface, authUser domain.User) BasicPricingUsecaseInterface {
|
||||||
|
return &BasicPricingUsecase{Helper: helper, AuthUser: authUser}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) loadComponents(pricingIDs []string) (map[string][]domain.BasicPricingComponent, error) {
|
||||||
|
if len(pricingIDs) == 0 {
|
||||||
|
return make(map[string][]domain.BasicPricingComponent), nil
|
||||||
|
}
|
||||||
|
var components []domain.BasicPricingComponent
|
||||||
|
db := u.Helper.GetDB("slave")
|
||||||
|
if err := db.Where("basic_pricing_id IN ?", pricingIDs).Find(&components).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
componentsMap := make(map[string][]domain.BasicPricingComponent)
|
||||||
|
for _, c := range components {
|
||||||
|
if c.BasicPricingID != nil {
|
||||||
|
componentsMap[*c.BasicPricingID] = append(componentsMap[*c.BasicPricingID], c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return componentsMap, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) toResponse(pricing domain.BasicPricing, components []domain.BasicPricingComponent) dto.CreateBasicPricingResponse {
|
||||||
|
resp := dto.CreateBasicPricingResponse{
|
||||||
|
ID: pricing.ID,
|
||||||
|
Name: pricing.Name,
|
||||||
|
ProvinceSourceID: pricing.ProvinceSourceID,
|
||||||
|
CitySourceID: pricing.CitySourceID,
|
||||||
|
DistrictSourceID: pricing.DistrictSourceID,
|
||||||
|
SubdistrictSourceID: pricing.SubdistrictSourceID,
|
||||||
|
PostalCodeSourceID: pricing.PostalCodeSourceID,
|
||||||
|
ProvinceDestinationID: pricing.ProvinceDestinationID,
|
||||||
|
CityDestinationID: pricing.CityDestinationID,
|
||||||
|
DistrictDestinationID: pricing.DistrictDestinationID,
|
||||||
|
SubdistrictDestinationID: pricing.SubdistrictDestinationID,
|
||||||
|
PostalCodeDestinationID: pricing.PostalCodeDestinationID,
|
||||||
|
PackageTypeID: pricing.PackageTypeID,
|
||||||
|
ModaID: pricing.ModaID,
|
||||||
|
MerchantID: pricing.MerchantID,
|
||||||
|
}
|
||||||
|
resp.Components = make([]dto.BasicPricingComponentResponse, 0, len(components))
|
||||||
|
for _, c := range components {
|
||||||
|
resp.Components = append(resp.Components, dto.BasicPricingComponentResponse{
|
||||||
|
ID: c.ID,
|
||||||
|
CostComponentID: c.CostComponentID,
|
||||||
|
Value: c.Value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) GetAll(filter dto.BasicPricingFilterAllRequest) ([]dto.CreateBasicPricingResponse, int64, error) {
|
||||||
|
var pricings []domain.BasicPricing
|
||||||
|
var total int64
|
||||||
|
|
||||||
|
db := u.Helper.GetDB("slave")
|
||||||
|
tx := db.Model(&pricings)
|
||||||
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
||||||
|
}
|
||||||
|
v := reflect.ValueOf(filter)
|
||||||
|
t := reflect.TypeOf(filter)
|
||||||
|
|
||||||
|
for i := 0; i < v.NumField(); i++ {
|
||||||
|
if v.Field(i).String() != "" {
|
||||||
|
tagKey := t.Field(i).Tag.Get("form")
|
||||||
|
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tx.Model(&domain.BasicPricing{}).Count(&total)
|
||||||
|
tx.Order("name ASC")
|
||||||
|
if err := tx.Find(&pricings).Error; err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pricingIDs := make([]string, 0, len(pricings))
|
||||||
|
for _, p := range pricings {
|
||||||
|
pricingIDs = append(pricingIDs, p.ID)
|
||||||
|
}
|
||||||
|
componentsMap, err := u.loadComponents(pricingIDs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
responses := make([]dto.CreateBasicPricingResponse, 0, len(pricings))
|
||||||
|
for _, p := range pricings {
|
||||||
|
components := componentsMap[p.ID]
|
||||||
|
responses = append(responses, u.toResponse(p, components))
|
||||||
|
}
|
||||||
|
return responses, total, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) GetList(req dto.DataTableRequest) (dto.DataTableResponse, error) {
|
||||||
|
var response dto.DataTableResponse
|
||||||
|
db := u.Helper.GetDB("slave")
|
||||||
|
tx := db.Table("basic_pricing").
|
||||||
|
Joins("LEFT JOIN province AS ps ON basic_pricing.province_source_id=ps.id").
|
||||||
|
Joins("LEFT JOIN city AS cs ON basic_pricing.city_source_id=cs.id").
|
||||||
|
Joins("LEFT JOIN province AS pd ON basic_pricing.province_destination_id=pd.id").
|
||||||
|
Joins("LEFT JOIN city AS cd ON basic_pricing.city_destination_id=cd.id").
|
||||||
|
Joins("LEFT JOIN merchant ON basic_pricing.merchant_id=merchant.id")
|
||||||
|
dt := datatable.NewDatatable(tx, req)
|
||||||
|
coldef := make([]dto.DataTableColDef, 0)
|
||||||
|
coldef = append(coldef, dto.DataTableColDef{
|
||||||
|
Field: "basic_pricing.name",
|
||||||
|
Alias: "name",
|
||||||
|
})
|
||||||
|
coldef = append(coldef, dto.DataTableColDef{
|
||||||
|
Field: "basic_pricing.id",
|
||||||
|
Alias: "id",
|
||||||
|
})
|
||||||
|
|
||||||
|
response = dt.Render(coldef)
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) GetByID(id string) (dto.CreateBasicPricingResponse, error) {
|
||||||
|
var pricing domain.BasicPricing
|
||||||
|
db := u.Helper.GetDB("slave")
|
||||||
|
if err := db.Where("id = ?", id).First(&pricing).Error; err != nil {
|
||||||
|
return dto.CreateBasicPricingResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var components []domain.BasicPricingComponent
|
||||||
|
if err := db.Where("basic_pricing_id = ?", id).Find(&components).Error; err != nil {
|
||||||
|
return dto.CreateBasicPricingResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return u.toResponse(pricing, components), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) Create(req dto.CreateBasicPricingRequest, createdBy string, merchantid *string) (dto.CreateBasicPricingResponse, error) {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var pricing domain.BasicPricing
|
||||||
|
var savedComponents []domain.BasicPricingComponent
|
||||||
|
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
pricing = domain.BasicPricing{
|
||||||
|
Name: &req.Name,
|
||||||
|
ProvinceSourceID: strPtr(req.ProvinceSourceID),
|
||||||
|
CitySourceID: strPtr(req.CitySourceID),
|
||||||
|
DistrictSourceID: strPtr(req.DistrictSourceID),
|
||||||
|
SubdistrictSourceID: strPtr(req.SubdistrictSourceID),
|
||||||
|
PostalCodeSourceID: strPtr(req.PostalCodeSourceID),
|
||||||
|
ProvinceDestinationID: strPtr(req.ProvinceDestinationID),
|
||||||
|
CityDestinationID: strPtr(req.CityDestinationID),
|
||||||
|
DistrictDestinationID: strPtr(req.DistrictDestinationID),
|
||||||
|
SubdistrictDestinationID: strPtr(req.SubdistrictDestinationID),
|
||||||
|
PostalCodeDestinationID: strPtr(req.PostalCodeDestinationID),
|
||||||
|
PackageTypeID: strPtr(req.PackageTypeID),
|
||||||
|
ModaID: strPtr(req.ModaID),
|
||||||
|
MerchantID: merchantid,
|
||||||
|
CreatedBy: &createdBy,
|
||||||
|
CreatedOn: &now,
|
||||||
|
UpdatedBy: &createdBy,
|
||||||
|
UpdatedOn: &now,
|
||||||
|
}
|
||||||
|
if err := tx.Create(&pricing).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, comp := range req.Components {
|
||||||
|
c := domain.BasicPricingComponent{
|
||||||
|
BasicPricingID: &pricing.ID,
|
||||||
|
CostComponentID: &comp.CostComponentID,
|
||||||
|
Value: &comp.Value,
|
||||||
|
}
|
||||||
|
if err := tx.Create(&c).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
savedComponents = append(savedComponents, c)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return dto.CreateBasicPricingResponse{}, err
|
||||||
|
}
|
||||||
|
return u.toResponse(pricing, savedComponents), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) Update(id string, req dto.CreateBasicPricingRequest, updatedBy string) (dto.CreateBasicPricingResponse, error) {
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var pricing domain.BasicPricing
|
||||||
|
var savedComponents []domain.BasicPricingComponent
|
||||||
|
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
|
}
|
||||||
|
if err := q.Where("id = ?", id).First(&pricing).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
now := time.Now()
|
||||||
|
pricing.Name = &req.Name
|
||||||
|
pricing.ProvinceSourceID = strPtr(req.ProvinceSourceID)
|
||||||
|
pricing.CitySourceID = strPtr(req.CitySourceID)
|
||||||
|
pricing.DistrictSourceID = strPtr(req.DistrictSourceID)
|
||||||
|
pricing.SubdistrictSourceID = strPtr(req.SubdistrictSourceID)
|
||||||
|
pricing.PostalCodeSourceID = strPtr(req.PostalCodeSourceID)
|
||||||
|
pricing.ProvinceDestinationID = strPtr(req.ProvinceDestinationID)
|
||||||
|
pricing.CityDestinationID = strPtr(req.CityDestinationID)
|
||||||
|
pricing.DistrictDestinationID = strPtr(req.DistrictDestinationID)
|
||||||
|
pricing.SubdistrictDestinationID = strPtr(req.SubdistrictDestinationID)
|
||||||
|
pricing.PostalCodeDestinationID = strPtr(req.PostalCodeDestinationID)
|
||||||
|
pricing.PackageTypeID = strPtr(req.PackageTypeID)
|
||||||
|
pricing.ModaID = strPtr(req.ModaID)
|
||||||
|
pricing.UpdatedBy = &updatedBy
|
||||||
|
pricing.UpdatedOn = &now
|
||||||
|
|
||||||
|
if err := tx.Save(&pricing).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tx.Where("basic_pricing_id = ?", id).Delete(&domain.BasicPricingComponent{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, comp := range req.Components {
|
||||||
|
c := domain.BasicPricingComponent{
|
||||||
|
BasicPricingID: &pricing.ID,
|
||||||
|
CostComponentID: &comp.CostComponentID,
|
||||||
|
Value: &comp.Value,
|
||||||
|
}
|
||||||
|
if err := tx.Create(&c).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
savedComponents = append(savedComponents, c)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return dto.CreateBasicPricingResponse{}, err
|
||||||
|
}
|
||||||
|
return u.toResponse(pricing, savedComponents), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *BasicPricingUsecase) Delete(id string) error {
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
|
}
|
||||||
|
var pricing domain.BasicPricing
|
||||||
|
if err := q.Where("id = ?", id).First(&pricing).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Where("basic_pricing_id = ?", id).Delete(&domain.BasicPricingComponent{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Delete(&pricing).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func strPtr(s string) *string {
|
||||||
|
if s == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &s
|
||||||
|
}
|
||||||
@ -8,14 +8,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CityUsecaseInterface interface {
|
type CityUsecaseInterface interface {
|
||||||
GetAll(filter dto.CityFilterAllRequest) ([]domain.City, int64, error)
|
GetAll(filter dto.CityFilterAllRequest) ([]domain.City, int64, error)
|
||||||
GetList(dto.DataTableRequest) (dto.DataTableResponse, error)
|
GetList(dto.DataTableRequest) (dto.DataTableResponse, error)
|
||||||
GetByID(id string) (domain.City, error)
|
GetByID(id string) (domain.City, error)
|
||||||
Create(name string, provinceID string, createdBy string, merchantid *string) (domain.City, error)
|
Create(name string, provinceID string, port string, createdBy string, merchantid *string) (domain.City, error)
|
||||||
Update(id string, name string, provinceID string, updatedBy string) (domain.City, error)
|
Update(id string, name string, provinceID string, port string, updatedBy string) (domain.City, error)
|
||||||
Delete(id string) error
|
Delete(id string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,42 +98,50 @@ func (u *CityUsecase) GetByID(id string) (domain.City, error) {
|
|||||||
return city, nil
|
return city, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *CityUsecase) Create(name string, provinceID string, createdBy string, merchantid *string) (domain.City, error) {
|
func (u *CityUsecase) Create(name string, provinceID string, port string, createdBy string, merchantid *string) (domain.City, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
city := domain.City{
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var city domain.City
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
city = domain.City{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
ProvinceID: &provinceID,
|
ProvinceID: &provinceID,
|
||||||
|
Port: &port,
|
||||||
MerchantID: merchantid,
|
MerchantID: merchantid,
|
||||||
CreatedBy: &createdBy,
|
CreatedBy: &createdBy,
|
||||||
CreatedOn: &now,
|
CreatedOn: &now,
|
||||||
UpdatedBy: &createdBy,
|
UpdatedBy: &createdBy,
|
||||||
UpdatedOn: &now,
|
UpdatedOn: &now,
|
||||||
}
|
}
|
||||||
|
return tx.Create(&city).Error
|
||||||
db := u.Helper.GetDB("master")
|
})
|
||||||
if err := db.Create(&city).Error; err != nil {
|
if err != nil {
|
||||||
return domain.City{}, err
|
return domain.City{}, err
|
||||||
}
|
}
|
||||||
return city, nil
|
return city, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *CityUsecase) Update(id string, name string, provinceID string, updatedBy string) (domain.City, error) {
|
func (u *CityUsecase) Update(id string, name string, provinceID string, port string, updatedBy string) (domain.City, error) {
|
||||||
var city domain.City
|
var city domain.City
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Where("id = ?", id).First(&city).Error; err != nil {
|
if err := q.Where("id = ?", id).First(&city).Error; err != nil {
|
||||||
return domain.City{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
city.Name = &name
|
city.Name = &name
|
||||||
city.ProvinceID = &provinceID
|
city.ProvinceID = &provinceID
|
||||||
|
city.Port = &port
|
||||||
city.UpdatedBy = &updatedBy
|
city.UpdatedBy = &updatedBy
|
||||||
city.UpdatedOn = &now
|
city.UpdatedOn = &now
|
||||||
|
return tx.Save(&city).Error
|
||||||
if err := db.Save(&city).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.City{}, err
|
return domain.City{}, err
|
||||||
}
|
}
|
||||||
return city, nil
|
return city, nil
|
||||||
|
|||||||
@ -8,15 +8,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CostComponentUsecaseInterface interface {
|
type CostComponentUsecaseInterface interface {
|
||||||
GetAll(filter dto.CostComponentFilterAllRequest) ([]domain.CostComponent, int64, error)
|
GetAll(filter dto.CostComponentFilterAllRequest) ([]domain.CostComponent, int64, error)
|
||||||
GetList(dto.DataTableRequest) (dto.DataTableResponse, error)
|
GetList(dto.DataTableRequest) (dto.DataTableResponse, error)
|
||||||
GetByID(id string) (domain.CostComponent, error)
|
GetByID(id string) (domain.CostComponent, error)
|
||||||
Create(name string, code string, inc int32, value string, costComponentGroupID string, createdBy string, merchantid *string) (domain.CostComponent, error)
|
Create(name string, code string, value string, componentType int32, createdBy string, merchantid *string) (domain.CostComponent, error)
|
||||||
Update(id string, name string, code string, inc int32, value string, costComponentGroupID string, updatedBy string) (domain.CostComponent, error)
|
Update(id string, name string, code string, value string, componentType int32, updatedBy string) (domain.CostComponent, error)
|
||||||
Delete(id string) error
|
Delete(id string) error
|
||||||
|
SortDown(id string) error
|
||||||
|
SortUp(id string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type CostComponentUsecase struct {
|
type CostComponentUsecase struct {
|
||||||
@ -47,7 +51,7 @@ func (u *CostComponentUsecase) GetAll(filter dto.CostComponentFilterAllRequest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.Model(&domain.CostComponent{}).Count(&total)
|
tx.Model(&domain.CostComponent{}).Count(&total)
|
||||||
tx.Order("name ASC")
|
tx.Order("inc ASC, name ASC")
|
||||||
if err := tx.Find(&components).Error; err != nil {
|
if err := tx.Find(&components).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
@ -58,7 +62,6 @@ func (u *CostComponentUsecase) GetList(req dto.DataTableRequest) (dto.DataTableR
|
|||||||
var response dto.DataTableResponse
|
var response dto.DataTableResponse
|
||||||
db := u.Helper.GetDB("slave")
|
db := u.Helper.GetDB("slave")
|
||||||
tx := db.Table("cost_component").
|
tx := db.Table("cost_component").
|
||||||
Joins("LEFT JOIN cost_component_group ON cost_component.cost_component_group_id=cost_component_group.id").
|
|
||||||
Joins("LEFT JOIN merchant ON cost_component.merchant_id=merchant.id")
|
Joins("LEFT JOIN merchant ON cost_component.merchant_id=merchant.id")
|
||||||
dt := datatable.NewDatatable(tx, req)
|
dt := datatable.NewDatatable(tx, req)
|
||||||
coldef := make([]dto.DataTableColDef, 0)
|
coldef := make([]dto.DataTableColDef, 0)
|
||||||
@ -79,12 +82,8 @@ func (u *CostComponentUsecase) GetList(req dto.DataTableRequest) (dto.DataTableR
|
|||||||
Alias: "value",
|
Alias: "value",
|
||||||
})
|
})
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
coldef = append(coldef, dto.DataTableColDef{
|
||||||
Field: "cost_component_group.name",
|
Field: "cost_component.component_type",
|
||||||
Alias: "cost_component_group_name",
|
Alias: "component_type",
|
||||||
})
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "cost_component.cost_component_group_id",
|
|
||||||
Alias: "cost_component_group_id",
|
|
||||||
})
|
})
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
coldef = append(coldef, dto.DataTableColDef{
|
||||||
Field: "merchant.id",
|
Field: "merchant.id",
|
||||||
@ -108,14 +107,28 @@ func (u *CostComponentUsecase) GetByID(id string) (domain.CostComponent, error)
|
|||||||
return component, nil
|
return component, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *CostComponentUsecase) Create(name string, code string, inc int32, value string, costComponentGroupID string, createdBy string, merchantid *string) (domain.CostComponent, error) {
|
func (u *CostComponentUsecase) Create(name string, code string, value string, componentType int32, createdBy string, merchantid *string) (domain.CostComponent, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
component := domain.CostComponent{
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
|
||||||
|
var component domain.CostComponent
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
var maxInc int64
|
||||||
|
q := tx.Model(&domain.CostComponent{})
|
||||||
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
q = q.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
|
}
|
||||||
|
q.Select("COALESCE(MAX(inc),0)").Row().Scan(&maxInc)
|
||||||
|
|
||||||
|
inc := int32(maxInc + 1)
|
||||||
|
|
||||||
|
component = domain.CostComponent{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
Code: &code,
|
Code: &code,
|
||||||
Inc: &inc,
|
Inc: &inc,
|
||||||
Value: &value,
|
Value: &value,
|
||||||
CostComponentGroupID: &costComponentGroupID,
|
ComponentType: &componentType,
|
||||||
MerchantID: merchantid,
|
MerchantID: merchantid,
|
||||||
CreatedBy: &createdBy,
|
CreatedBy: &createdBy,
|
||||||
CreatedOn: &now,
|
CreatedOn: &now,
|
||||||
@ -123,33 +136,35 @@ func (u *CostComponentUsecase) Create(name string, code string, inc int32, value
|
|||||||
UpdatedOn: &now,
|
UpdatedOn: &now,
|
||||||
}
|
}
|
||||||
|
|
||||||
db := u.Helper.GetDB("master")
|
return tx.Create(&component).Error
|
||||||
if err := db.Create(&component).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.CostComponent{}, err
|
return domain.CostComponent{}, err
|
||||||
}
|
}
|
||||||
return component, nil
|
return component, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *CostComponentUsecase) Update(id string, name string, code string, inc int32, value string, costComponentGroupID string, updatedBy string) (domain.CostComponent, error) {
|
func (u *CostComponentUsecase) Update(id string, name string, code string, value string, componentType int32, updatedBy string) (domain.CostComponent, error) {
|
||||||
var component domain.CostComponent
|
var component domain.CostComponent
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Where("id = ?", id).First(&component).Error; err != nil {
|
if err := q.Where("id = ?", id).First(&component).Error; err != nil {
|
||||||
return domain.CostComponent{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
component.Name = &name
|
component.Name = &name
|
||||||
component.Code = &code
|
component.Code = &code
|
||||||
component.Inc = &inc
|
|
||||||
component.Value = &value
|
component.Value = &value
|
||||||
component.CostComponentGroupID = &costComponentGroupID
|
component.ComponentType = &componentType
|
||||||
component.UpdatedBy = &updatedBy
|
component.UpdatedBy = &updatedBy
|
||||||
component.UpdatedOn = &now
|
component.UpdatedOn = &now
|
||||||
|
return tx.Save(&component).Error
|
||||||
if err := db.Save(&component).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.CostComponent{}, err
|
return domain.CostComponent{}, err
|
||||||
}
|
}
|
||||||
return component, nil
|
return component, nil
|
||||||
@ -165,3 +180,117 @@ func (u *CostComponentUsecase) Delete(id string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *CostComponentUsecase) SortDown(id string) error {
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
|
||||||
|
var olData domain.CostComponent
|
||||||
|
err := db.Model(&olData).Where("id=?", id).Where("merchant_id=?", u.AuthUser.MerchantID).First(&olData).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if olData.ID != "" {
|
||||||
|
var newData domain.CostComponent
|
||||||
|
db.Model(&newData).Where("merchant_id=?", u.AuthUser.MerchantID).Where("inc<?", olData.Inc).Order("inc DESC").First(&newData)
|
||||||
|
if newData.ID != "" {
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
err := tx.Model(&olData).Where("id=?", olData.ID).UpdateColumn("inc", newData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tx.Model(&newData).Where("id=?", newData.ID).UpdateColumn("inc", olData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var olData domain.CostComponent
|
||||||
|
err := db.Model(&olData).Where("id=?", id).First(&olData).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if olData.ID != "" {
|
||||||
|
merchant_id := olData.MerchantID
|
||||||
|
var newData domain.CostComponent
|
||||||
|
db.Model(&newData).Where("merchant_id=?", merchant_id).Where("inc<?", olData.Inc).Order("inc DESC").First(&newData)
|
||||||
|
if newData.ID != "" {
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
err := tx.Model(&olData).Where("id=?", olData.ID).UpdateColumn("inc", newData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tx.Model(&newData).Where("id=?", newData.ID).UpdateColumn("inc", olData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *CostComponentUsecase) SortUp(id string) error {
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
|
|
||||||
|
var olData domain.CostComponent
|
||||||
|
err := db.Model(&olData).Where("id=?", id).Where("merchant_id=?", u.AuthUser.MerchantID).First(&olData).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if olData.ID != "" {
|
||||||
|
var newData domain.CostComponent
|
||||||
|
db.Model(&newData).Where("merchant_id=?", u.AuthUser.MerchantID).Where("inc>?", olData.Inc).Order("inc ASC").Limit(1).First(&newData)
|
||||||
|
if newData.ID != "" {
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
err := tx.Model(&olData).Where("id=?", olData.ID).UpdateColumn("inc", newData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tx.Model(&newData).Where("id=?", newData.ID).UpdateColumn("inc", olData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var olData domain.CostComponent
|
||||||
|
err := db.Model(&olData).Where("id=?", id).First(&olData).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if olData.ID != "" {
|
||||||
|
merchant_id := olData.MerchantID
|
||||||
|
var newData domain.CostComponent
|
||||||
|
db.Model(&newData).Where("merchant_id=?", merchant_id).Where("inc>?", olData.Inc).Order("inc ASC").Limit(1).First(&newData)
|
||||||
|
if newData.ID != "" {
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
err := tx.Model(&olData).Where("id=?", olData.ID).UpdateColumn("inc", newData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tx.Model(&newData).Where("id=?", newData.ID).UpdateColumn("inc", olData.Inc).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -1,160 +0,0 @@
|
|||||||
package usecases
|
|
||||||
|
|
||||||
import (
|
|
||||||
"cargo-erp-backend/internal/domain"
|
|
||||||
"cargo-erp-backend/internal/handlers/dto"
|
|
||||||
"cargo-erp-backend/pkg/datatable"
|
|
||||||
"cargo-erp-backend/pkg/helpers"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/oklog/ulid/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CostComponentGroupUsecaseInterface interface {
|
|
||||||
GetAll(filter dto.CostComponentGroupFilterAllRequest) ([]domain.CostComponentGroup, int64, error)
|
|
||||||
GetList(dto.DataTableRequest) (dto.DataTableResponse, error)
|
|
||||||
GetByID(id string) (domain.CostComponentGroup, error)
|
|
||||||
Create(name string, code string, inc int32, value string, createdBy string, merchantid *string) (domain.CostComponentGroup, error)
|
|
||||||
Update(id string, name string, code string, inc int32, value string, updatedBy string) (domain.CostComponentGroup, error)
|
|
||||||
Delete(id string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type CostComponentGroupUsecase struct {
|
|
||||||
Helper helpers.HelperInterface
|
|
||||||
AuthUser domain.User
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCostComponentGroupUsecase(helper helpers.HelperInterface, authUser domain.User) CostComponentGroupUsecaseInterface {
|
|
||||||
return &CostComponentGroupUsecase{Helper: helper, AuthUser: authUser}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *CostComponentGroupUsecase) GetAll(filter dto.CostComponentGroupFilterAllRequest) ([]domain.CostComponentGroup, int64, error) {
|
|
||||||
var groups []domain.CostComponentGroup
|
|
||||||
var total int64
|
|
||||||
|
|
||||||
db := u.Helper.GetDB("slave")
|
|
||||||
tx := db.Model(&groups)
|
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
|
||||||
tx.Where(db.Where("merchant_id IS NULL").Or("merchant_id=?", u.AuthUser.MerchantID))
|
|
||||||
}
|
|
||||||
v := reflect.ValueOf(filter)
|
|
||||||
t := reflect.TypeOf(filter)
|
|
||||||
|
|
||||||
for i := 0; i < v.NumField(); i++ {
|
|
||||||
if v.Field(i).String() != "" {
|
|
||||||
tagKey := t.Field(i).Tag.Get("form")
|
|
||||||
tx.Where(fmt.Sprintf("%v=?", tagKey), v.Field(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tx.Model(&domain.CostComponentGroup{}).Count(&total)
|
|
||||||
tx.Order("name ASC")
|
|
||||||
if err := tx.Find(&groups).Error; err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
return groups, total, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *CostComponentGroupUsecase) GetList(req dto.DataTableRequest) (dto.DataTableResponse, error) {
|
|
||||||
var response dto.DataTableResponse
|
|
||||||
db := u.Helper.GetDB("slave")
|
|
||||||
tx := db.Table("cost_component_group").
|
|
||||||
Joins("LEFT JOIN merchant ON cost_component_group.merchant_id=merchant.id")
|
|
||||||
dt := datatable.NewDatatable(tx, req)
|
|
||||||
coldef := make([]dto.DataTableColDef, 0)
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "cost_component_group.name",
|
|
||||||
Alias: "name",
|
|
||||||
})
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "cost_component_group.code",
|
|
||||||
Alias: "code",
|
|
||||||
})
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "cost_component_group.inc",
|
|
||||||
Alias: "inc",
|
|
||||||
})
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "cost_component_group.value",
|
|
||||||
Alias: "value",
|
|
||||||
})
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "merchant.id",
|
|
||||||
Alias: "merchant_id",
|
|
||||||
})
|
|
||||||
coldef = append(coldef, dto.DataTableColDef{
|
|
||||||
Field: "cost_component_group.id",
|
|
||||||
Alias: "id",
|
|
||||||
})
|
|
||||||
|
|
||||||
response = dt.Render(coldef)
|
|
||||||
return response, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *CostComponentGroupUsecase) GetByID(id string) (domain.CostComponentGroup, error) {
|
|
||||||
var group domain.CostComponentGroup
|
|
||||||
db := u.Helper.GetDB("slave")
|
|
||||||
if err := db.Where("id = ?", id).First(&group).Error; err != nil {
|
|
||||||
return domain.CostComponentGroup{}, err
|
|
||||||
}
|
|
||||||
return group, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *CostComponentGroupUsecase) Create(name string, code string, inc int32, value string, createdBy string, merchantid *string) (domain.CostComponentGroup, error) {
|
|
||||||
now := time.Now()
|
|
||||||
id := ulid.Make().String()
|
|
||||||
group := domain.CostComponentGroup{
|
|
||||||
ID: id,
|
|
||||||
Name: &name,
|
|
||||||
Code: &code,
|
|
||||||
Inc: &inc,
|
|
||||||
Value: &value,
|
|
||||||
MerchantID: merchantid,
|
|
||||||
CreatedBy: &createdBy,
|
|
||||||
CreatedOn: &now,
|
|
||||||
UpdatedBy: &createdBy,
|
|
||||||
UpdatedOn: &now,
|
|
||||||
}
|
|
||||||
|
|
||||||
db := u.Helper.GetDB("master")
|
|
||||||
if err := db.Create(&group).Error; err != nil {
|
|
||||||
return domain.CostComponentGroup{}, err
|
|
||||||
}
|
|
||||||
return group, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *CostComponentGroupUsecase) Update(id string, name string, code string, inc int32, value string, updatedBy string) (domain.CostComponentGroup, error) {
|
|
||||||
var group domain.CostComponentGroup
|
|
||||||
db := u.Helper.GetDB("master")
|
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
|
||||||
}
|
|
||||||
if err := db.Where("id = ?", id).First(&group).Error; err != nil {
|
|
||||||
return domain.CostComponentGroup{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
group.Name = &name
|
|
||||||
group.Code = &code
|
|
||||||
group.Inc = &inc
|
|
||||||
group.Value = &value
|
|
||||||
group.UpdatedBy = &updatedBy
|
|
||||||
group.UpdatedOn = &now
|
|
||||||
|
|
||||||
if err := db.Save(&group).Error; err != nil {
|
|
||||||
return domain.CostComponentGroup{}, err
|
|
||||||
}
|
|
||||||
return group, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *CostComponentGroupUsecase) Delete(id string) error {
|
|
||||||
db := u.Helper.GetDB("master")
|
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
|
||||||
}
|
|
||||||
if err := db.Delete(&domain.CostComponentGroup{}, "id = ?", id).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@ -8,6 +8,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DistrictUsecaseInterface interface {
|
type DistrictUsecaseInterface interface {
|
||||||
@ -107,7 +109,11 @@ func (u *DistrictUsecase) GetByID(id string) (domain.District, error) {
|
|||||||
|
|
||||||
func (u *DistrictUsecase) Create(name string, provinceID string, cityID string, createdBy string, merchantid *string) (domain.District, error) {
|
func (u *DistrictUsecase) Create(name string, provinceID string, cityID string, createdBy string, merchantid *string) (domain.District, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
district := domain.District{
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var district domain.District
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
district = domain.District{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
ProvinceID: &provinceID,
|
ProvinceID: &provinceID,
|
||||||
CityID: &cityID,
|
CityID: &cityID,
|
||||||
@ -117,9 +123,9 @@ func (u *DistrictUsecase) Create(name string, provinceID string, cityID string,
|
|||||||
UpdatedBy: &createdBy,
|
UpdatedBy: &createdBy,
|
||||||
UpdatedOn: &now,
|
UpdatedOn: &now,
|
||||||
}
|
}
|
||||||
|
return tx.Create(&district).Error
|
||||||
db := u.Helper.GetDB("master")
|
})
|
||||||
if err := db.Create(&district).Error; err != nil {
|
if err != nil {
|
||||||
return domain.District{}, err
|
return domain.District{}, err
|
||||||
}
|
}
|
||||||
return district, nil
|
return district, nil
|
||||||
@ -128,21 +134,23 @@ func (u *DistrictUsecase) Create(name string, provinceID string, cityID string,
|
|||||||
func (u *DistrictUsecase) Update(id string, name string, provinceID string, cityID string, updatedBy string) (domain.District, error) {
|
func (u *DistrictUsecase) Update(id string, name string, provinceID string, cityID string, updatedBy string) (domain.District, error) {
|
||||||
var district domain.District
|
var district domain.District
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Where("id = ?", id).First(&district).Error; err != nil {
|
if err := q.Where("id = ?", id).First(&district).Error; err != nil {
|
||||||
return domain.District{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
district.Name = &name
|
district.Name = &name
|
||||||
district.ProvinceID = &provinceID
|
district.ProvinceID = &provinceID
|
||||||
district.CityID = &cityID
|
district.CityID = &cityID
|
||||||
district.UpdatedBy = &updatedBy
|
district.UpdatedBy = &updatedBy
|
||||||
district.UpdatedOn = &now
|
district.UpdatedOn = &now
|
||||||
|
return tx.Save(&district).Error
|
||||||
if err := db.Save(&district).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.District{}, err
|
return domain.District{}, err
|
||||||
}
|
}
|
||||||
return district, nil
|
return district, nil
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PostalCodeUsecaseInterface interface {
|
type PostalCodeUsecaseInterface interface {
|
||||||
@ -126,7 +128,11 @@ func (u *PostalCodeUsecase) GetByID(id string) (domain.PostalCode, error) {
|
|||||||
func (u *PostalCodeUsecase) Create(postalCode string, provinceID string, cityID string, districtID string, subdistrictID string, createdBy string, merchantid *string) (domain.PostalCode, error) {
|
func (u *PostalCodeUsecase) Create(postalCode string, provinceID string, cityID string, districtID string, subdistrictID string, createdBy string, merchantid *string) (domain.PostalCode, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
nowStr := now.Format("2006-01-02 15:04:05")
|
nowStr := now.Format("2006-01-02 15:04:05")
|
||||||
pc := domain.PostalCode{
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var pc domain.PostalCode
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
pc = domain.PostalCode{
|
||||||
PostalCode: &postalCode,
|
PostalCode: &postalCode,
|
||||||
ProvinceID: &provinceID,
|
ProvinceID: &provinceID,
|
||||||
CityID: &cityID,
|
CityID: &cityID,
|
||||||
@ -138,9 +144,9 @@ func (u *PostalCodeUsecase) Create(postalCode string, provinceID string, cityID
|
|||||||
UpdatedBy: &createdBy,
|
UpdatedBy: &createdBy,
|
||||||
UpdatedOn: &nowStr,
|
UpdatedOn: &nowStr,
|
||||||
}
|
}
|
||||||
|
return tx.Create(&pc).Error
|
||||||
db := u.Helper.GetDB("master")
|
})
|
||||||
if err := db.Create(&pc).Error; err != nil {
|
if err != nil {
|
||||||
return domain.PostalCode{}, err
|
return domain.PostalCode{}, err
|
||||||
}
|
}
|
||||||
return pc, nil
|
return pc, nil
|
||||||
@ -149,13 +155,14 @@ func (u *PostalCodeUsecase) Create(postalCode string, provinceID string, cityID
|
|||||||
func (u *PostalCodeUsecase) Update(id string, postalCode string, provinceID string, cityID string, districtID string, subdistrictID string, updatedBy string) (domain.PostalCode, error) {
|
func (u *PostalCodeUsecase) Update(id string, postalCode string, provinceID string, cityID string, districtID string, subdistrictID string, updatedBy string) (domain.PostalCode, error) {
|
||||||
var pc domain.PostalCode
|
var pc domain.PostalCode
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Where("id = ?", id).First(&pc).Error; err != nil {
|
if err := q.Where("id = ?", id).First(&pc).Error; err != nil {
|
||||||
return domain.PostalCode{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
nowStr := now.Format("2006-01-02 15:04:05")
|
nowStr := now.Format("2006-01-02 15:04:05")
|
||||||
pc.PostalCode = &postalCode
|
pc.PostalCode = &postalCode
|
||||||
@ -165,8 +172,9 @@ func (u *PostalCodeUsecase) Update(id string, postalCode string, provinceID stri
|
|||||||
pc.SubdistrictID = &subdistrictID
|
pc.SubdistrictID = &subdistrictID
|
||||||
pc.UpdatedBy = &updatedBy
|
pc.UpdatedBy = &updatedBy
|
||||||
pc.UpdatedOn = &nowStr
|
pc.UpdatedOn = &nowStr
|
||||||
|
return tx.Save(&pc).Error
|
||||||
if err := db.Save(&pc).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.PostalCode{}, err
|
return domain.PostalCode{}, err
|
||||||
}
|
}
|
||||||
return pc, nil
|
return pc, nil
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProvinceUsecaseInterface interface {
|
type ProvinceUsecaseInterface interface {
|
||||||
@ -96,7 +98,11 @@ func (u *ProvinceUsecase) GetByID(id string) (domain.Province, error) {
|
|||||||
|
|
||||||
func (u *ProvinceUsecase) Create(name string, createdBy string, merchantid *string) (domain.Province, error) {
|
func (u *ProvinceUsecase) Create(name string, createdBy string, merchantid *string) (domain.Province, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
province := domain.Province{
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var province domain.Province
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
province = domain.Province{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
MerchantID: merchantid,
|
MerchantID: merchantid,
|
||||||
CreatedBy: &createdBy,
|
CreatedBy: &createdBy,
|
||||||
@ -104,36 +110,34 @@ func (u *ProvinceUsecase) Create(name string, createdBy string, merchantid *stri
|
|||||||
UpdatedBy: &createdBy,
|
UpdatedBy: &createdBy,
|
||||||
UpdatedOn: &now,
|
UpdatedOn: &now,
|
||||||
}
|
}
|
||||||
|
return tx.Create(&province).Error
|
||||||
db := u.Helper.GetDB("master")
|
})
|
||||||
|
if err != nil {
|
||||||
if err := db.Create(&province).Error; err != nil {
|
|
||||||
return domain.Province{}, err
|
return domain.Province{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return province, nil
|
return province, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *ProvinceUsecase) Update(id string, name string, updatedBy string) (domain.Province, error) {
|
func (u *ProvinceUsecase) Update(id string, name string, updatedBy string) (domain.Province, error) {
|
||||||
var province domain.Province
|
var province domain.Province
|
||||||
|
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Where("id = ?", id).First(&province).Error; err != nil {
|
if err := q.Where("id = ?", id).First(&province).Error; err != nil {
|
||||||
return domain.Province{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
province.Name = &name
|
province.Name = &name
|
||||||
province.UpdatedBy = &updatedBy
|
province.UpdatedBy = &updatedBy
|
||||||
province.UpdatedOn = &now
|
province.UpdatedOn = &now
|
||||||
|
return tx.Save(&province).Error
|
||||||
if err := db.Save(&province).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.Province{}, err
|
return domain.Province{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return province, nil
|
return province, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubdistrictUsecaseInterface interface {
|
type SubdistrictUsecaseInterface interface {
|
||||||
@ -116,7 +118,11 @@ func (u *SubdistrictUsecase) GetByID(id string) (domain.Subdistrict, error) {
|
|||||||
|
|
||||||
func (u *SubdistrictUsecase) Create(name string, provinceID string, cityID string, districtID string, createdBy string, merchantid *string) (domain.Subdistrict, error) {
|
func (u *SubdistrictUsecase) Create(name string, provinceID string, cityID string, districtID string, createdBy string, merchantid *string) (domain.Subdistrict, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
subdistrict := domain.Subdistrict{
|
|
||||||
|
db := u.Helper.GetDB("master")
|
||||||
|
var subdistrict domain.Subdistrict
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
subdistrict = domain.Subdistrict{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
ProvinceID: &provinceID,
|
ProvinceID: &provinceID,
|
||||||
CityID: &cityID,
|
CityID: &cityID,
|
||||||
@ -127,9 +133,9 @@ func (u *SubdistrictUsecase) Create(name string, provinceID string, cityID strin
|
|||||||
UpdatedBy: &createdBy,
|
UpdatedBy: &createdBy,
|
||||||
UpdatedOn: &now,
|
UpdatedOn: &now,
|
||||||
}
|
}
|
||||||
|
return tx.Create(&subdistrict).Error
|
||||||
db := u.Helper.GetDB("master")
|
})
|
||||||
if err := db.Create(&subdistrict).Error; err != nil {
|
if err != nil {
|
||||||
return domain.Subdistrict{}, err
|
return domain.Subdistrict{}, err
|
||||||
}
|
}
|
||||||
return subdistrict, nil
|
return subdistrict, nil
|
||||||
@ -138,13 +144,14 @@ func (u *SubdistrictUsecase) Create(name string, provinceID string, cityID strin
|
|||||||
func (u *SubdistrictUsecase) Update(id string, name string, provinceID string, cityID string, districtID string, updatedBy string) (domain.Subdistrict, error) {
|
func (u *SubdistrictUsecase) Update(id string, name string, provinceID string, cityID string, districtID string, updatedBy string) (domain.Subdistrict, error) {
|
||||||
var subdistrict domain.Subdistrict
|
var subdistrict domain.Subdistrict
|
||||||
db := u.Helper.GetDB("master")
|
db := u.Helper.GetDB("master")
|
||||||
|
err := db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
q := tx
|
||||||
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
if u.AuthUser.UsersRole_Relation.RoleKey != "SPM" {
|
||||||
db.Where("merchant_id=?", u.AuthUser.MerchantID)
|
q = tx.Where("merchant_id=?", u.AuthUser.MerchantID)
|
||||||
}
|
}
|
||||||
if err := db.Where("id = ?", id).First(&subdistrict).Error; err != nil {
|
if err := q.Where("id = ?", id).First(&subdistrict).Error; err != nil {
|
||||||
return domain.Subdistrict{}, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
subdistrict.Name = &name
|
subdistrict.Name = &name
|
||||||
subdistrict.ProvinceID = &provinceID
|
subdistrict.ProvinceID = &provinceID
|
||||||
@ -152,8 +159,9 @@ func (u *SubdistrictUsecase) Update(id string, name string, provinceID string, c
|
|||||||
subdistrict.DistrictID = &districtID
|
subdistrict.DistrictID = &districtID
|
||||||
subdistrict.UpdatedBy = &updatedBy
|
subdistrict.UpdatedBy = &updatedBy
|
||||||
subdistrict.UpdatedOn = &now
|
subdistrict.UpdatedOn = &now
|
||||||
|
return tx.Save(&subdistrict).Error
|
||||||
if err := db.Save(&subdistrict).Error; err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return domain.Subdistrict{}, err
|
return domain.Subdistrict{}, err
|
||||||
}
|
}
|
||||||
return subdistrict, nil
|
return subdistrict, nil
|
||||||
|
|||||||
@ -75,7 +75,6 @@ func GenerateModel(table *string, db *gorm.DB) {
|
|||||||
// Isi opsi relasi berdasarkan foreign key yang terdeteksi
|
// Isi opsi relasi berdasarkan foreign key yang terdeteksi
|
||||||
for _, tName := range tableNames {
|
for _, tName := range tableNames {
|
||||||
var relationOptions []gen.ModelOpt
|
var relationOptions []gen.ModelOpt
|
||||||
|
|
||||||
for _, fk := range fkMetas {
|
for _, fk := range fkMetas {
|
||||||
// A. Relasi BELONGS TO
|
// A. Relasi BELONGS TO
|
||||||
if fk.TableName == tName {
|
if fk.TableName == tName {
|
||||||
@ -185,15 +184,19 @@ func fetchForeignKeys(db *sql.DB) []ForeignKeyMeta {
|
|||||||
kcu.column_name AS column_name,
|
kcu.column_name AS column_name,
|
||||||
ccu.table_name AS referenced_table_name,
|
ccu.table_name AS referenced_table_name,
|
||||||
ccu.column_name AS referenced_column_name
|
ccu.column_name AS referenced_column_name
|
||||||
FROM
|
FROM
|
||||||
information_schema.table_constraints AS tc
|
information_schema.table_constraints AS tc
|
||||||
JOIN information_schema.key_column_usage AS kcu
|
JOIN information_schema.key_column_usage AS kcu
|
||||||
ON tc.constraint_name = kcu.constraint_name
|
ON tc.constraint_name = kcu.constraint_name
|
||||||
AND tc.table_schema = kcu.table_schema
|
AND tc.table_schema = kcu.table_schema
|
||||||
JOIN information_schema.constraint_column_usage AS ccu
|
JOIN information_schema.referential_constraints AS rc
|
||||||
ON ccu.constraint_name = tc.constraint_name
|
ON tc.constraint_name = rc.constraint_name
|
||||||
AND ccu.table_schema = tc.table_schema
|
AND tc.table_schema = rc.constraint_schema
|
||||||
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_schema = 'public';
|
JOIN information_schema.key_column_usage AS ccu
|
||||||
|
ON rc.unique_constraint_name = ccu.constraint_name
|
||||||
|
AND rc.unique_constraint_schema = ccu.table_schema
|
||||||
|
AND kcu.ordinal_position = ccu.ordinal_position
|
||||||
|
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_schema = 'public';
|
||||||
`
|
`
|
||||||
rows, err := db.Query(query)
|
rows, err := db.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -951,3 +951,39 @@
|
|||||||
{"level":"info","ts":"2026-08-22T11:07:37.901+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
{"level":"info","ts":"2026-08-22T11:07:37.901+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
{"level":"info","ts":"2026-08-22T11:07:37.901+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
{"level":"info","ts":"2026-08-22T11:07:37.901+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
{"level":"info","ts":"2026-08-22T11:07:38.241+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
{"level":"info","ts":"2026-08-22T11:07:38.241+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:33:17.459+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:33:17.910+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:33:17.910+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:33:18.417+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:51:34.537+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:51:35.019+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:51:35.019+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:51:35.424+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:52:35.395+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:52:35.907+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:52:35.907+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:52:36.353+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:54:10.923+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:54:11.350+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:54:11.350+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:54:11.838+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:02.321+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:02.783+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:02.784+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:03.261+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:54.007+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:54.407+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:54.407+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T13:58:54.815+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:35.708+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:36.147+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:36.148+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:36.537+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:49.985+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:50.416+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:50.416+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:08:50.873+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:10:17.232+0700","caller":"database/database.go:53","msg":"Connect To Master DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:10:17.638+0700","caller":"database/database.go:63","msg":"DB Master Connected"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:10:17.639+0700","caller":"database/database.go:76","msg":"Connect To Slave DB"}
|
||||||
|
{"level":"info","ts":"2026-08-22T14:10:18.026+0700","caller":"database/database.go:86","msg":"DB Connection Done"}
|
||||||
|
|||||||
2109
storage/logs/db.log
2109
storage/logs/db.log
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user