Requires the role: | superadmin |
GET | /superadmin/incentives/ | Query incentives |
---|
import Foundation
import ServiceStack
// @ValidateRequest(Validator="IsAuthenticated")
// @ApiResponse(Description="You were unauthorized to call this service", StatusCode=401)
public class AdminIncentivesQuery : QueryDb2<Incentive, QueryResponse<AdminIncentiveQueryResponse>>
{
public var id:Int?
public var companyId:String?
public var validFrom:Date?
public var validTo:Date?
public var actionId:Int?
public var active:Bool?
public var includeCriteria:Bool
public var includeCompanies:Bool
public var includeAction:Bool
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case id
case companyId
case validFrom
case validTo
case actionId
case active
case includeCriteria
case includeCompanies
case includeAction
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id)
companyId = try container.decodeIfPresent(String.self, forKey: .companyId)
validFrom = try container.decodeIfPresent(Date.self, forKey: .validFrom)
validTo = try container.decodeIfPresent(Date.self, forKey: .validTo)
actionId = try container.decodeIfPresent(Int.self, forKey: .actionId)
active = try container.decodeIfPresent(Bool.self, forKey: .active)
includeCriteria = try container.decodeIfPresent(Bool.self, forKey: .includeCriteria)
includeCompanies = try container.decodeIfPresent(Bool.self, forKey: .includeCompanies)
includeAction = try container.decodeIfPresent(Bool.self, forKey: .includeAction)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if id != nil { try container.encode(id, forKey: .id) }
if companyId != nil { try container.encode(companyId, forKey: .companyId) }
if validFrom != nil { try container.encode(validFrom, forKey: .validFrom) }
if validTo != nil { try container.encode(validTo, forKey: .validTo) }
if actionId != nil { try container.encode(actionId, forKey: .actionId) }
if active != nil { try container.encode(active, forKey: .active) }
if includeCriteria != nil { try container.encode(includeCriteria, forKey: .includeCriteria) }
if includeCompanies != nil { try container.encode(includeCompanies, forKey: .includeCompanies) }
if includeAction != nil { try container.encode(includeAction, forKey: .includeAction) }
}
}
public class Incentive : BaseModel
{
public var id:Int
public var heading:String
public var storageUrl:String
public var successButtonText:String
public var active:Bool
public var actionId:Int
public var frequency:IncentiveRecurrenceFrequency
public var recurrenceInterval:UInt32
public var initialDelayInSeconds:Int
public var maxDisplayCount:Int?
public var validFrom:Date
public var validTo:Date
public var createdDate:Date
public var modifiedDate:Date?
public var appliesToAllCompanies:Bool
public var payload:String
public var companies:[IncentiveCompanyRelation] = []
public var criteria:[IncentiveCriteria] = []
// @Ignore()
public var action:IncentiveAction
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case id
case heading
case storageUrl
case successButtonText
case active
case actionId
case frequency
case recurrenceInterval
case initialDelayInSeconds
case maxDisplayCount
case validFrom
case validTo
case createdDate
case modifiedDate
case appliesToAllCompanies
case payload
case companies
case criteria
case action
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id)
heading = try container.decodeIfPresent(String.self, forKey: .heading)
storageUrl = try container.decodeIfPresent(String.self, forKey: .storageUrl)
successButtonText = try container.decodeIfPresent(String.self, forKey: .successButtonText)
active = try container.decodeIfPresent(Bool.self, forKey: .active)
actionId = try container.decodeIfPresent(Int.self, forKey: .actionId)
frequency = try container.decodeIfPresent(IncentiveRecurrenceFrequency.self, forKey: .frequency)
recurrenceInterval = try container.decodeIfPresent(UInt32.self, forKey: .recurrenceInterval)
initialDelayInSeconds = try container.decodeIfPresent(Int.self, forKey: .initialDelayInSeconds)
maxDisplayCount = try container.decodeIfPresent(Int.self, forKey: .maxDisplayCount)
validFrom = try container.decodeIfPresent(Date.self, forKey: .validFrom)
validTo = try container.decodeIfPresent(Date.self, forKey: .validTo)
createdDate = try container.decodeIfPresent(Date.self, forKey: .createdDate)
modifiedDate = try container.decodeIfPresent(Date.self, forKey: .modifiedDate)
appliesToAllCompanies = try container.decodeIfPresent(Bool.self, forKey: .appliesToAllCompanies)
payload = try container.decodeIfPresent(String.self, forKey: .payload)
companies = try container.decodeIfPresent([IncentiveCompanyRelation].self, forKey: .companies) ?? []
criteria = try container.decodeIfPresent([IncentiveCriteria].self, forKey: .criteria) ?? []
action = try container.decodeIfPresent(IncentiveAction.self, forKey: .action)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if id != nil { try container.encode(id, forKey: .id) }
if heading != nil { try container.encode(heading, forKey: .heading) }
if storageUrl != nil { try container.encode(storageUrl, forKey: .storageUrl) }
if successButtonText != nil { try container.encode(successButtonText, forKey: .successButtonText) }
if active != nil { try container.encode(active, forKey: .active) }
if actionId != nil { try container.encode(actionId, forKey: .actionId) }
if frequency != nil { try container.encode(frequency, forKey: .frequency) }
if recurrenceInterval != nil { try container.encode(recurrenceInterval, forKey: .recurrenceInterval) }
if initialDelayInSeconds != nil { try container.encode(initialDelayInSeconds, forKey: .initialDelayInSeconds) }
if maxDisplayCount != nil { try container.encode(maxDisplayCount, forKey: .maxDisplayCount) }
if validFrom != nil { try container.encode(validFrom, forKey: .validFrom) }
if validTo != nil { try container.encode(validTo, forKey: .validTo) }
if createdDate != nil { try container.encode(createdDate, forKey: .createdDate) }
if modifiedDate != nil { try container.encode(modifiedDate, forKey: .modifiedDate) }
if appliesToAllCompanies != nil { try container.encode(appliesToAllCompanies, forKey: .appliesToAllCompanies) }
if payload != nil { try container.encode(payload, forKey: .payload) }
if companies.count > 0 { try container.encode(companies, forKey: .companies) }
if criteria.count > 0 { try container.encode(criteria, forKey: .criteria) }
if action != nil { try container.encode(action, forKey: .action) }
}
}
public class BaseModel : Codable
{
required public init(){}
}
public enum IncentiveRecurrenceFrequency : Int, Codable
{
case OneTime = 1
case Weekly = 2
case Monthly = 3
}
public class IncentiveCompanyRelation : BaseModel
{
public var id:Int
public var companyId:String
public var incentiveId:Int
public var createdDate:Date
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case id
case companyId
case incentiveId
case createdDate
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id)
companyId = try container.decodeIfPresent(String.self, forKey: .companyId)
incentiveId = try container.decodeIfPresent(Int.self, forKey: .incentiveId)
createdDate = try container.decodeIfPresent(Date.self, forKey: .createdDate)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if id != nil { try container.encode(id, forKey: .id) }
if companyId != nil { try container.encode(companyId, forKey: .companyId) }
if incentiveId != nil { try container.encode(incentiveId, forKey: .incentiveId) }
if createdDate != nil { try container.encode(createdDate, forKey: .createdDate) }
}
}
public class IncentiveCriteria : BaseModel
{
public var id:Int
public var incentiveId:Int
public var criteriaType:CriteriaType
public var value:String
public var invertCondition:Bool
public var createdDate:Date
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case id
case incentiveId
case criteriaType
case value
case invertCondition
case createdDate
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id)
incentiveId = try container.decodeIfPresent(Int.self, forKey: .incentiveId)
criteriaType = try container.decodeIfPresent(CriteriaType.self, forKey: .criteriaType)
value = try container.decodeIfPresent(String.self, forKey: .value)
invertCondition = try container.decodeIfPresent(Bool.self, forKey: .invertCondition)
createdDate = try container.decodeIfPresent(Date.self, forKey: .createdDate)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if id != nil { try container.encode(id, forKey: .id) }
if incentiveId != nil { try container.encode(incentiveId, forKey: .incentiveId) }
if criteriaType != nil { try container.encode(criteriaType, forKey: .criteriaType) }
if value != nil { try container.encode(value, forKey: .value) }
if invertCondition != nil { try container.encode(invertCondition, forKey: .invertCondition) }
if createdDate != nil { try container.encode(createdDate, forKey: .createdDate) }
}
}
public enum CriteriaType : String, Codable
{
case LicenseAvailability
case SmsActivation
case eAccountingActivation
case CodeLockActivation
case SocialActivation
case OnlinePaymentActivation
case FollowUpMessageActivation
case RatingActivation
}
public class IncentiveAction : BaseModel
{
public var id:Int
public var actionType:IncentiveActionType
public var page:String
public var segment:String
public var element:String
public var licenseTypeId:Int?
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case id
case actionType
case page
case segment
case element
case licenseTypeId
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(Int.self, forKey: .id)
actionType = try container.decodeIfPresent(IncentiveActionType.self, forKey: .actionType)
page = try container.decodeIfPresent(String.self, forKey: .page)
segment = try container.decodeIfPresent(String.self, forKey: .segment)
element = try container.decodeIfPresent(String.self, forKey: .element)
licenseTypeId = try container.decodeIfPresent(Int.self, forKey: .licenseTypeId)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if id != nil { try container.encode(id, forKey: .id) }
if actionType != nil { try container.encode(actionType, forKey: .actionType) }
if page != nil { try container.encode(page, forKey: .page) }
if segment != nil { try container.encode(segment, forKey: .segment) }
if element != nil { try container.encode(element, forKey: .element) }
if licenseTypeId != nil { try container.encode(licenseTypeId, forKey: .licenseTypeId) }
}
}
public enum IncentiveActionType : Int, Codable
{
case Upgrade = 1
case AddOn = 2
case Information = 3
}
public class AccessKeyTypeResponse : Codable
{
public var id:Int
public var keyType:String
public var Description:String
required public init(){}
}
Swift AdminIncentivesQuery DTOs
To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
GET /superadmin/incentives/ HTTP/1.1 Host: testapi.bokamera.se Accept: text/jsv
HTTP/1.1 200 OK Content-Type: text/jsv Content-Length: length { Offset: 0, Total: 0, Results: [ { Offset: 0, Total: 0, Results: [ { Frequency: OneTime, RecurrenceInterval: 0, CreatedDate: 0001-01-01T00:00:00.0000000+00:00, ModifiedDate: 0001-01-01T00:00:00.0000000+00:00, CompanyIds: [ 00000000-0000-0000-0000-000000000000 ], Criteria: [ { Id: 0, IncentiveId: 0, CriteriaType: LicenseAvailability, Value: String, InvertCondition: False, CreatedDate: 0001-01-01T00:00:00.0000000+00:00 } ], ApplyToAllCompanies: False, Id: 0, Heading: String, StorageUrl: String, SuccessButtonText: String, ActionId: 0, InitialDelayInSeconds: 0, MaxDisplayCount: 0, ValidFrom: 0001-01-01T00:00:00.0000000+00:00, ValidTo: 0001-01-01T00:00:00.0000000+00:00, Action: { Id: 0, ActionType: Upgrade, Page: String, Segment: String, Element: String, LicenseTypeId: 0, SuggestedLicenseToUpgrade: { Id: 0, Name: String, Description: String, IsExtraLicenseOption: False, PeriodOfNoticeDays: 0, Items: [ { Id: 0, Name: String, AllowedItems: 0 } ], Prices: [ { LicenseTypeId: 0, CountryId: String, Price: 0, Country: { CurrencyId: String, CurrencyInfo: { Name: String, CurrencySign: String, Active: False, ModifiedDate: 0001-01-01T00:00:00.0000000+00:00, Id: String }, Name: String, Culture: String, TimeZone: String, ModifiedDate: 0001-01-01T00:00:00.0000000+00:00, Id: String }, LicensePlanId: 0 } ] } }, Payload: String } ], Meta: { String: String }, ResponseStatus: { ErrorCode: String, Message: String, StackTrace: String, Errors: [ { ErrorCode: String, FieldName: String, Message: String, Meta: { String: String } } ], Meta: { String: String } } } ], Meta: { String: String }, ResponseStatus: { ErrorCode: String, Message: String, StackTrace: String, Errors: [ { ErrorCode: String, FieldName: String, Message: String, Meta: { String: String } } ], Meta: { String: String } } }