Pecuario.Backend

<back to all web services

GetDashboard

The following routes are available for this service:
GET/api/v1/dashboard
import Foundation
import ServiceStack

public class GetDashboard : IGet, Codable
{
    public var countryId:Int?
    public var maxAnimals:Int?
    public var maxLands:Int?

    required public init(){}
}

public class GetDashboardResponse : BaseResponse
{
    public var animalCategories:[AnimalCategory] = []
    public var animalsByCategory:[Int:[DashboardAnimal]] = [:]
    public var lands:[DashboardLand] = []
    public var greeting:String
    public var farmsCount:Int

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case animalCategories
        case animalsByCategory
        case lands
        case greeting
        case farmsCount
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        animalCategories = try container.decodeIfPresent([AnimalCategory].self, forKey: .animalCategories) ?? []
        animalsByCategory = try container.decodeIfPresent([Int:[DashboardAnimal]].self, forKey: .animalsByCategory) ?? [:]
        lands = try container.decodeIfPresent([DashboardLand].self, forKey: .lands) ?? []
        greeting = try container.decodeIfPresent(String.self, forKey: .greeting)
        farmsCount = try container.decodeIfPresent(Int.self, forKey: .farmsCount)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if animalCategories.count > 0 { try container.encode(animalCategories, forKey: .animalCategories) }
        if animalsByCategory.count > 0 { try container.encode(animalsByCategory, forKey: .animalsByCategory) }
        if lands.count > 0 { try container.encode(lands, forKey: .lands) }
        if greeting != nil { try container.encode(greeting, forKey: .greeting) }
        if farmsCount != nil { try container.encode(farmsCount, forKey: .farmsCount) }
    }
}

public class BaseResponse : Codable
{
    public var status:Status

    required public init(){}
}

public class Status : Codable
{
    public var message:String
    public var statusCode:Int

    required public init(){}
}

public class AnimalCategory : Codable
{
    public var id:Int
    // @Required()
    // @StringLength(50)
    public var name:String?

    public var alias:String
    public var order:Int
    public var enabled:Bool

    required public init(){}
}

public class DashboardLand : Codable
{
    public var id:String
    public var Description:String
    public var image:String
    public var type:String
    public var price:String
    public var cityRegionName:String
    public var priceType:String

    required public init(){}
}


Swift GetDashboard DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

GET /api/v1/dashboard HTTP/1.1 
Host: pecuario-backend.develsystems.com 
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"animalCategories":[{"id":0,"name":"String","alias":"String","order":0,"enabled":false}],"animalsByCategory":{"0":[{"id":"String","description":"String","image":"String","type":"String","price":"String","cityRegionName":"String","priceType":"String"}]},"lands":[{"id":"String","description":"String","image":"String","type":"String","price":"String","cityRegionName":"String","priceType":"String"}],"greeting":"String","farmsCount":0}