tvpl.api

<back to all web services

GetTemplateByIdRequest

Requires Authentication
The following routes are available for this service:
GET/document-template
import Foundation
import ServiceStack

public class GetTemplateByIdRequest : Codable
{
    public var id:Int

    required public init(){}
}

public class DocumentTemplateResponse : Codable
{
    public var template:DocumentTemplateDto
    public var insertedId:Int
    public var code:Int
    public var message:String

    required public init(){}
}

public class DocumentTemplateDto : DocumentTemplate
{
    public var elements:[DocumentElementDto] = []

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

    private enum CodingKeys : String, CodingKey {
        case elements
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        elements = try container.decodeIfPresent([DocumentElementDto].self, forKey: .elements) ?? []
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if elements.count > 0 { try container.encode(elements, forKey: .elements) }
    }
}

public class DocumentTemplate : Codable
{
    public var id:Int
    // @Required()
    public var title:String?

    public var Description:String
    public var isActive:Bool
    public var fileKey:String
    public var fileUrl:String
    public var fileName:String
    public var fileSize:Int?

    required public init(){}
}

public class DocumentElementDto : DocumentElement
{
    public var children:[DocumentElementDto] = []

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

    private enum CodingKeys : String, CodingKey {
        case children
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        children = try container.decodeIfPresent([DocumentElementDto].self, forKey: .children) ?? []
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if children.count > 0 { try container.encode(children, forKey: .children) }
    }
}

public class DocumentElement : Codable
{
    public var id:Int
    public var templateId:Int
    // @Required()
    public var elementKey:String?

    // @Required()
    public var tag:String?

    public var parentId:Int?
    // @Required()
    public var title:String?

    public var Description:String
    // @Required()
    public var dataType:String?

    public var templateType:String
    public var orderIndex:Int
    public var isRequired:Bool?

    required public init(){}
}


Swift GetTemplateByIdRequest DTOs

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

HTTP + JSV

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

GET /document-template HTTP/1.1 
Host: qlcn-api.vsmlab.vn 
Accept: text/jsv
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	template: 
	{
		elements: 
		[
			{
				children: 
				[
					{
						children: 
						[
							{
								id: 0,
								templateId: 0,
								elementKey: String,
								tag: String,
								parentId: 0,
								title: String,
								description: String,
								dataType: String,
								templateType: String,
								orderIndex: 0,
								isRequired: False
							}
						],
						id: 0,
						templateId: 0,
						elementKey: String,
						tag: String,
						parentId: 0,
						title: String,
						description: String,
						dataType: String,
						templateType: String,
						orderIndex: 0,
						isRequired: False
					}
				],
				id: 0,
				templateId: 0,
				elementKey: String,
				tag: String,
				parentId: 0,
				title: String,
				description: String,
				dataType: String,
				templateType: String,
				orderIndex: 0,
				isRequired: False
			}
		],
		id: 0,
		title: String,
		description: String,
		isActive: False,
		fileKey: String,
		fileUrl: String,
		fileName: String,
		fileSize: 0
	},
	insertedId: 0,
	code: 0,
	message: String
}