Add User Partner and Product
This commit is contained in:
+37
-35
@@ -14,23 +14,24 @@ type AuthData struct {
|
||||
}
|
||||
|
||||
type UserDB struct {
|
||||
ID int64 `gorm:"primary_key;column:id" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Email string `gorm:"column:email" json:"email"`
|
||||
Password string `gorm:"column:password" json:"-"`
|
||||
Status userstatus.UserStatus `gorm:"column:status" json:"status"`
|
||||
UserType string `gorm:"column:user_type" json:"user_type"`
|
||||
PhoneNumber string `gorm:"column:phone_number" json:"phone_number"`
|
||||
NIK string `gorm:"column:nik" json:"nik"`
|
||||
RoleID int64 `gorm:"column:role_id" json:"role_id"`
|
||||
RoleName string `gorm:"column:role_name" json:"role_name"`
|
||||
BranchID *int64 `gorm:"column:partner_id" json:"partner_id"`
|
||||
BranchName string `gorm:"column:partner_name" json:"partner_name"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
CreatedBy int64 `gorm:"column:created_by" json:"created_by"`
|
||||
UpdatedBy int64 `gorm:"column:updated_by" json:"updated_by"`
|
||||
ID int64 `gorm:"primary_key;column:id" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Email string `gorm:"column:email" json:"email"`
|
||||
Password string `gorm:"column:password" json:"-"`
|
||||
Status userstatus.UserStatus `gorm:"column:status" json:"status"`
|
||||
UserType string `gorm:"column:user_type" json:"user_type"`
|
||||
PhoneNumber string `gorm:"column:phone_number" json:"phone_number"`
|
||||
NIK string `gorm:"column:nik" json:"nik"`
|
||||
RoleID int64 `gorm:"column:role_id" json:"role_id"`
|
||||
RoleName string `gorm:"column:role_name" json:"role_name"`
|
||||
PartnerID *int64 `gorm:"column:partner_id" json:"partner_id"`
|
||||
PartnerName string `gorm:"column:partner_name" json:"partner_name"`
|
||||
PartnerStatus string `gorm:"column:partner_status" json:"partner_status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
|
||||
CreatedBy int64 `gorm:"column:created_by" json:"created_by"`
|
||||
UpdatedBy int64 `gorm:"column:updated_by" json:"updated_by"`
|
||||
}
|
||||
|
||||
func (u *UserDB) ToUser() *User {
|
||||
@@ -39,16 +40,16 @@ func (u *UserDB) ToUser() *User {
|
||||
}
|
||||
|
||||
userEntity := &User{
|
||||
ID: u.ID,
|
||||
Name: u.Name,
|
||||
Email: u.Email,
|
||||
Status: u.Status,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: u.UpdatedAt,
|
||||
RoleID: role.Role(u.RoleID),
|
||||
RoleName: u.RoleName,
|
||||
PartnerID: u.BranchID,
|
||||
BranchName: u.BranchName,
|
||||
ID: u.ID,
|
||||
Name: u.Name,
|
||||
Email: u.Email,
|
||||
Status: u.Status,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: u.UpdatedAt,
|
||||
RoleID: role.Role(u.RoleID),
|
||||
RoleName: u.RoleName,
|
||||
PartnerID: u.PartnerID,
|
||||
PartnerName: u.PartnerName,
|
||||
}
|
||||
|
||||
return userEntity
|
||||
@@ -63,7 +64,7 @@ func (u *UserDB) ToUserRoleDB() *UserRoleDB {
|
||||
ID: 0,
|
||||
UserID: u.ID,
|
||||
RoleID: u.RoleID,
|
||||
PartnerID: u.BranchID,
|
||||
PartnerID: u.PartnerID,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: u.UpdatedAt,
|
||||
}
|
||||
@@ -77,12 +78,13 @@ func (UserDB) TableName() string {
|
||||
|
||||
func (u *UserDB) ToUserAuthenticate(signedToken string) *AuthenticateUser {
|
||||
return &AuthenticateUser{
|
||||
Token: signedToken,
|
||||
Name: u.Name,
|
||||
RoleID: role.Role(u.RoleID),
|
||||
RoleName: u.RoleName,
|
||||
BranchID: u.BranchID,
|
||||
BranchName: u.BranchName,
|
||||
Token: signedToken,
|
||||
Name: u.Name,
|
||||
RoleID: role.Role(u.RoleID),
|
||||
RoleName: u.RoleName,
|
||||
PartnerID: u.PartnerID,
|
||||
PartnerName: u.PartnerName,
|
||||
PartnerStatus: u.PartnerStatus,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ func (u *UserDB) ToUpdatedUser(req User) error {
|
||||
}
|
||||
|
||||
if *req.PartnerID > 0 {
|
||||
u.BranchID = req.PartnerID
|
||||
u.PartnerID = req.PartnerID
|
||||
}
|
||||
|
||||
if req.RoleID > 0 {
|
||||
|
||||
@@ -3,10 +3,10 @@ package entity
|
||||
import "github.com/golang-jwt/jwt"
|
||||
|
||||
type JWTAuthClaims struct {
|
||||
UserID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Role int `json:"role"`
|
||||
BranchID int64 `json:"branch_id"`
|
||||
UserID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Role int `json:"role"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
@@ -1,19 +1,42 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/constants/role"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CreatePartnerRequest struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Address string `json:"address"`
|
||||
Username string `json:"username" validate:"required"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
NIK string `json:"nik"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
BankName string `json:"bank_name"`
|
||||
BankAccountNumber string `json:"bank_account_number"`
|
||||
BankAccountHolderName string `json:"bank_account_holder_name"`
|
||||
}
|
||||
|
||||
type Partner struct {
|
||||
ID int64
|
||||
Name string
|
||||
Status string
|
||||
Address string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
CreatedBy int64
|
||||
UpdatedBy int64
|
||||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||||
Name string `gorm:"type:varchar(255);not null;column:name"`
|
||||
Status string `gorm:"type:varchar(50);column:status"`
|
||||
LicenseExpiredDate *time.Time `gorm:"type:date;column:license_expired_date"`
|
||||
Address string `gorm:"type:varchar(255);column:address"`
|
||||
BankName string `gorm:"type:varchar(255);column:bank_name"`
|
||||
BankAccountNumber string `gorm:"type:varchar(50);column:bank_account_number"`
|
||||
BankAccountHolderName string `gorm:"type:varchar(255);column:bank_account_holder_name"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
||||
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
||||
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
||||
}
|
||||
|
||||
func (Partner) TableName() string {
|
||||
return "partners"
|
||||
}
|
||||
|
||||
type PartnerSearch struct {
|
||||
@@ -80,3 +103,46 @@ func (o *PartnerDB) SetDeleted(updatedBy int64) {
|
||||
o.DeletedAt = ¤tTime
|
||||
o.UpdatedBy = updatedBy
|
||||
}
|
||||
|
||||
func (c *CreatePartnerRequest) ToUserAdmin(partnerID int64) *User {
|
||||
return &User{
|
||||
Name: c.FullName,
|
||||
Password: c.Password,
|
||||
Email: c.Email,
|
||||
NIK: c.NIK,
|
||||
Status: "active",
|
||||
RoleID: role.PartnerAdmin,
|
||||
PartnerID: &partnerID,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *CreatePartnerRequest) ToPartnerDB(createdBy int64) *PartnerDB {
|
||||
twoDays := 48 * time.Hour
|
||||
licenseExpiredDate := time.Now().Add(twoDays)
|
||||
|
||||
return &PartnerDB{
|
||||
Partner: Partner{
|
||||
Name: e.Name,
|
||||
Status: "inactive",
|
||||
Address: e.Address,
|
||||
CreatedBy: createdBy,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
BankAccountHolderName: e.BankAccountHolderName,
|
||||
BankAccountNumber: e.BankAccountNumber,
|
||||
BankName: e.BankName,
|
||||
LicenseExpiredDate: &licenseExpiredDate,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e *CreatePartnerRequest) ToWallet(partnerID int64) *Wallet {
|
||||
return &Wallet{
|
||||
PartnerID: partnerID,
|
||||
Balance: 0,
|
||||
Currency: "IDR",
|
||||
Status: "active",
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
+20
-25
@@ -6,20 +6,25 @@ import (
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
ID int64
|
||||
Name string
|
||||
Type product.ProductType
|
||||
Price float64
|
||||
Status product.ProductStatus
|
||||
Description string
|
||||
Image string
|
||||
BranchID int64
|
||||
StockQty int64
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time
|
||||
CreatedBy int64
|
||||
UpdatedBy int64
|
||||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||||
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
||||
SiteID int64 `gorm:"type:int;column:site_id"`
|
||||
Name string `gorm:"type:varchar(255);not null;column:name"`
|
||||
Type string `gorm:"type:varchar;column:type"`
|
||||
Price float64 `gorm:"type:decimal;column:price"`
|
||||
IsWeekendTicket bool `gorm:"type:bool;column:is_weekend_ticket"`
|
||||
IsSeasonTicket bool `gorm:"type:bool;column:is_season_ticket"`
|
||||
Status string `gorm:"type:varchar;column:status"`
|
||||
Description string `gorm:"type:varchar(255);not null;column:description"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
||||
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
||||
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
||||
}
|
||||
|
||||
func (Product) TableName() string {
|
||||
return "products"
|
||||
}
|
||||
|
||||
type ProductSearch struct {
|
||||
@@ -56,9 +61,7 @@ func (e *ProductDB) ToProduct() *Product {
|
||||
Price: e.Price,
|
||||
Status: e.Status,
|
||||
Description: e.Description,
|
||||
Image: e.Image,
|
||||
BranchID: e.BranchID,
|
||||
StockQty: e.StockQty,
|
||||
PartnerID: e.PartnerID,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
DeletedAt: e.DeletedAt,
|
||||
@@ -97,14 +100,6 @@ func (o *ProductDB) ToUpdatedProduct(updatedby int64, req Product) {
|
||||
if req.Description != "" {
|
||||
o.Description = req.Description
|
||||
}
|
||||
|
||||
if req.Image != "" {
|
||||
o.Image = req.Image
|
||||
}
|
||||
|
||||
if req.StockQty > 0 {
|
||||
o.StockQty = req.StockQty
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ProductDB) SetDeleted(updatedby int64) {
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Site struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||||
Name string `gorm:"type:varchar(255);not null;column:name"`
|
||||
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
||||
Image string `gorm:"type:varchar;column:image"`
|
||||
Address string `gorm:"type:varchar;column:address"`
|
||||
LocationLink string `gorm:"type:varchar;column:location_link"`
|
||||
Description string `gorm:"type:varchar;column:description"`
|
||||
Highlight string `gorm:"type:varchar;column:highlight"`
|
||||
ContactPerson string `gorm:"type:varchar;column:contact_person"`
|
||||
TnC string `gorm:"type:varchar;column:tnc"`
|
||||
AdditionalInfo string `gorm:"type:varchar;column:additional_info"`
|
||||
Status string `gorm:"type:varchar;column:status"`
|
||||
IsSeasonTicket bool `gorm:"type:bool;column:is_season_ticket"`
|
||||
IsDiscountActive bool `gorm:"type:bool;column:is_discount_active"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
||||
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
||||
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
||||
Products []Product `gorm:"foreignKey:SiteID;constraint:OnDelete:CASCADE;"`
|
||||
}
|
||||
|
||||
type SiteSearch struct {
|
||||
Search string
|
||||
Name string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type SiteList []*SiteDB
|
||||
|
||||
type SiteDB struct {
|
||||
Site
|
||||
}
|
||||
|
||||
func (s *Site) ToSiteDB() *SiteDB {
|
||||
return &SiteDB{
|
||||
Site: *s,
|
||||
}
|
||||
}
|
||||
|
||||
func (SiteDB) TableName() string {
|
||||
return "sites"
|
||||
}
|
||||
|
||||
func (e *SiteDB) ToSite() *Site {
|
||||
return &Site{
|
||||
ID: e.ID,
|
||||
Name: e.Name,
|
||||
PartnerID: e.PartnerID,
|
||||
Image: e.Image,
|
||||
Address: e.Address,
|
||||
LocationLink: e.LocationLink,
|
||||
Description: e.Description,
|
||||
Highlight: e.Highlight,
|
||||
ContactPerson: e.ContactPerson,
|
||||
TnC: e.TnC,
|
||||
AdditionalInfo: e.AdditionalInfo,
|
||||
Status: e.Status,
|
||||
IsSeasonTicket: e.IsSeasonTicket,
|
||||
IsDiscountActive: e.IsDiscountActive,
|
||||
CreatedAt: e.CreatedAt,
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
DeletedAt: e.DeletedAt,
|
||||
CreatedBy: e.CreatedBy,
|
||||
UpdatedBy: e.UpdatedBy,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SiteList) ToSiteList() []*Site {
|
||||
var sites []*Site
|
||||
for _, site := range *s {
|
||||
sites = append(sites, site.ToSite())
|
||||
}
|
||||
return sites
|
||||
}
|
||||
|
||||
func (o *SiteDB) ToUpdatedSite(updatedBy int64, req Site) {
|
||||
o.UpdatedBy = updatedBy
|
||||
|
||||
if req.Name != "" {
|
||||
o.Name = req.Name
|
||||
}
|
||||
|
||||
if req.PartnerID != 0 {
|
||||
o.PartnerID = req.PartnerID
|
||||
}
|
||||
|
||||
if req.Image != "" {
|
||||
o.Image = req.Image
|
||||
}
|
||||
|
||||
if req.Address != "" {
|
||||
o.Address = req.Address
|
||||
}
|
||||
|
||||
if req.LocationLink != "" {
|
||||
o.LocationLink = req.LocationLink
|
||||
}
|
||||
|
||||
if req.Description != "" {
|
||||
o.Description = req.Description
|
||||
}
|
||||
|
||||
if req.Highlight != "" {
|
||||
o.Highlight = req.Highlight
|
||||
}
|
||||
|
||||
if req.ContactPerson != "" {
|
||||
o.ContactPerson = req.ContactPerson
|
||||
}
|
||||
|
||||
if req.TnC != "" {
|
||||
o.TnC = req.TnC
|
||||
}
|
||||
|
||||
if req.AdditionalInfo != "" {
|
||||
o.AdditionalInfo = req.AdditionalInfo
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
o.Status = req.Status
|
||||
}
|
||||
|
||||
if req.IsSeasonTicket {
|
||||
o.IsSeasonTicket = req.IsSeasonTicket
|
||||
}
|
||||
|
||||
if req.IsDiscountActive {
|
||||
o.IsDiscountActive = req.IsDiscountActive
|
||||
}
|
||||
}
|
||||
|
||||
func (o *SiteDB) SetDeleted(updatedBy int64) {
|
||||
currentTime := time.Now()
|
||||
o.DeletedAt = ¤tTime
|
||||
o.UpdatedBy = updatedBy
|
||||
}
|
||||
+21
-20
@@ -10,27 +10,28 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID int64
|
||||
Name string
|
||||
Email string
|
||||
Password string
|
||||
Status userstatus.UserStatus
|
||||
NIK string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
RoleID role.Role
|
||||
RoleName string
|
||||
PartnerID *int64
|
||||
BranchName string
|
||||
ID int64
|
||||
Name string
|
||||
Email string
|
||||
Password string
|
||||
Status userstatus.UserStatus
|
||||
NIK string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
RoleID role.Role
|
||||
RoleName string
|
||||
PartnerID *int64
|
||||
PartnerName string
|
||||
}
|
||||
|
||||
type AuthenticateUser struct {
|
||||
Token string
|
||||
Name string
|
||||
RoleID role.Role
|
||||
RoleName string
|
||||
BranchID *int64
|
||||
BranchName string
|
||||
Token string
|
||||
Name string
|
||||
RoleID role.Role
|
||||
RoleName string
|
||||
PartnerID *int64
|
||||
PartnerName string
|
||||
PartnerStatus string
|
||||
}
|
||||
|
||||
type UserRoleDB struct {
|
||||
@@ -53,7 +54,7 @@ func (u *User) ToUserDB(createdBy int64) (*UserDB, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if u.RoleID == role.BranchAdmin && u.PartnerID == nil {
|
||||
if u.RoleID == role.Admin && u.PartnerID == nil {
|
||||
return nil, errors.New("invalid request")
|
||||
}
|
||||
|
||||
@@ -62,7 +63,7 @@ func (u *User) ToUserDB(createdBy int64) (*UserDB, error) {
|
||||
Email: u.Email,
|
||||
Password: hashedPassword,
|
||||
RoleID: int64(u.RoleID),
|
||||
BranchID: u.PartnerID,
|
||||
PartnerID: u.PartnerID,
|
||||
Status: userstatus.Active,
|
||||
CreatedBy: createdBy,
|
||||
}, nil
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type Wallet struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||||
PartnerID int64 `gorm:"type:int;not null;column:partner_id"`
|
||||
Balance float64 `gorm:"type:decimal(18,2);not null;default:0.00;column:balance"`
|
||||
Currency string `gorm:"type:varchar(3);not null;column:currency"`
|
||||
Status string `gorm:"type:varchar(50);column:status"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||
}
|
||||
|
||||
func (Wallet) TableName() string {
|
||||
return "wallets"
|
||||
}
|
||||
Reference in New Issue
Block a user