2025-09-17 23:55:11 +07:00
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
2025-09-18 17:21:58 +07:00
|
|
|
"apskel-pos-be/internal/entities"
|
|
|
|
|
|
2025-09-17 23:55:11 +07:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CreateCampaignRequest struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
Name string `json:"name" binding:"required,min=1,max=150"`
|
|
|
|
|
Description *string `json:"description,omitempty"`
|
|
|
|
|
Type string `json:"type" binding:"required,oneof=REWARD POINTS TOKENS MIXED"`
|
|
|
|
|
StartDate time.Time `json:"start_date" binding:"required"`
|
|
|
|
|
EndDate time.Time `json:"end_date" binding:"required"`
|
|
|
|
|
IsActive bool `json:"is_active"`
|
|
|
|
|
ShowOnApp bool `json:"show_on_app"`
|
|
|
|
|
Position int `json:"position" binding:"min=0"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
|
|
|
|
Rules []CampaignRuleStruct `json:"rules" binding:"required,min=1"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UpdateCampaignRequest struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
ID uuid.UUID `json:"id" binding:"required"`
|
|
|
|
|
Name string `json:"name" binding:"required,min=1,max=150"`
|
|
|
|
|
Description *string `json:"description,omitempty"`
|
|
|
|
|
Type string `json:"type" binding:"required,oneof=REWARD POINTS TOKENS MIXED"`
|
|
|
|
|
StartDate time.Time `json:"start_date" binding:"required"`
|
|
|
|
|
EndDate time.Time `json:"end_date" binding:"required"`
|
|
|
|
|
IsActive bool `json:"is_active"`
|
|
|
|
|
ShowOnApp bool `json:"show_on_app"`
|
|
|
|
|
Position int `json:"position" binding:"min=0"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
|
|
|
|
Rules []CampaignRuleStruct `json:"rules" binding:"required,min=1"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ListCampaignsRequest struct {
|
|
|
|
|
Page int `form:"page" binding:"min=1"`
|
|
|
|
|
Limit int `form:"limit" binding:"min=1,max=100"`
|
|
|
|
|
Search string `form:"search"`
|
|
|
|
|
Type string `form:"type"`
|
|
|
|
|
IsActive *bool `form:"is_active"`
|
|
|
|
|
ShowOnApp *bool `form:"show_on_app"`
|
|
|
|
|
StartDate *time.Time `form:"start_date"`
|
|
|
|
|
EndDate *time.Time `form:"end_date"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CampaignResponse struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Description *string `json:"description,omitempty"`
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
StartDate time.Time `json:"start_date"`
|
|
|
|
|
EndDate time.Time `json:"end_date"`
|
|
|
|
|
IsActive bool `json:"is_active"`
|
|
|
|
|
ShowOnApp bool `json:"show_on_app"`
|
|
|
|
|
Position int `json:"position"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
|
|
|
|
Rules []CampaignRuleResponse `json:"rules,omitempty"`
|
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CampaignRuleResponse struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
|
CampaignID uuid.UUID `json:"campaign_id"`
|
|
|
|
|
RuleType string `json:"rule_type"`
|
|
|
|
|
ConditionValue *string `json:"condition_value,omitempty"`
|
|
|
|
|
RewardType string `json:"reward_type"`
|
|
|
|
|
RewardValue *int64 `json:"reward_value,omitempty"`
|
|
|
|
|
RewardSubtype *string `json:"reward_subtype,omitempty"`
|
|
|
|
|
RewardRefID *uuid.UUID `json:"reward_ref_id,omitempty"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
|
|
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ListCampaignsResponse struct {
|
|
|
|
|
Campaigns []CampaignResponse `json:"campaigns"`
|
|
|
|
|
Total int64 `json:"total"`
|
|
|
|
|
Page int `json:"page"`
|
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Campaign Rule Models
|
|
|
|
|
type CreateCampaignRuleRequest struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
CampaignID uuid.UUID `json:"campaign_id" binding:"required"`
|
|
|
|
|
RuleType string `json:"rule_type" binding:"required,oneof=TIER SPEND PRODUCT CATEGORY DAY LOCATION"`
|
|
|
|
|
ConditionValue *string `json:"condition_value,omitempty"`
|
|
|
|
|
RewardType string `json:"reward_type" binding:"required,oneof=POINTS TOKENS REWARD"`
|
|
|
|
|
RewardValue *int64 `json:"reward_value,omitempty"`
|
|
|
|
|
RewardSubtype *string `json:"reward_subtype,omitempty"`
|
|
|
|
|
RewardRefID *uuid.UUID `json:"reward_ref_id,omitempty"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UpdateCampaignRuleRequest struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
ID uuid.UUID `json:"id" binding:"required"`
|
|
|
|
|
CampaignID uuid.UUID `json:"campaign_id" binding:"required"`
|
|
|
|
|
RuleType string `json:"rule_type" binding:"required,oneof=TIER SPEND PRODUCT CATEGORY DAY LOCATION"`
|
|
|
|
|
ConditionValue *string `json:"condition_value,omitempty"`
|
|
|
|
|
RewardType string `json:"reward_type" binding:"required,oneof=POINTS TOKENS REWARD"`
|
|
|
|
|
RewardValue *int64 `json:"reward_value,omitempty"`
|
|
|
|
|
RewardSubtype *string `json:"reward_subtype,omitempty"`
|
|
|
|
|
RewardRefID *uuid.UUID `json:"reward_ref_id,omitempty"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ListCampaignRulesRequest struct {
|
|
|
|
|
Page int `form:"page" binding:"min=1"`
|
|
|
|
|
Limit int `form:"limit" binding:"min=1,max=100"`
|
|
|
|
|
CampaignID string `form:"campaign_id"`
|
|
|
|
|
RuleType string `form:"rule_type"`
|
|
|
|
|
RewardType string `form:"reward_type"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ListCampaignRulesResponse struct {
|
|
|
|
|
Rules []CampaignRuleResponse `json:"rules"`
|
|
|
|
|
Total int64 `json:"total"`
|
|
|
|
|
Page int `json:"page"`
|
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper structs
|
|
|
|
|
type CampaignRuleStruct struct {
|
2025-09-18 17:21:58 +07:00
|
|
|
RuleType string `json:"rule_type" binding:"required,oneof=TIER SPEND PRODUCT CATEGORY DAY LOCATION"`
|
|
|
|
|
ConditionValue *string `json:"condition_value,omitempty"`
|
|
|
|
|
RewardType string `json:"reward_type" binding:"required,oneof=POINTS TOKENS REWARD"`
|
|
|
|
|
RewardValue *int64 `json:"reward_value,omitempty"`
|
|
|
|
|
RewardSubtype *string `json:"reward_subtype,omitempty"`
|
|
|
|
|
RewardRefID *uuid.UUID `json:"reward_ref_id,omitempty"`
|
|
|
|
|
Metadata *entities.Metadata `json:"metadata,omitempty"`
|
2025-09-17 23:55:11 +07:00
|
|
|
}
|