| Required role: | super-admin |
| POST | /document-template |
|---|
import Foundation
import ServiceStack
public class CreateOrUpdateTemplateRequest : Codable
{
public var id:Int?
public var documentIds:[Int] = []
public var title:String
public var Description:String
public var isActive:Bool
public var elements:[DocumentElementDto] = []
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(){}
}
public class CreateDocumentTemplateResponse : IResponseRequest, Codable
{
public var insertedId:Int
public var code:Int
public var message:String
required public init(){}
}
Swift CreateOrUpdateTemplateRequest 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.
POST /document-template HTTP/1.1
Host: etc-api.vsmlab.vn
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length
{
id: 0,
documentIds:
[
0
],
title: String,
description: String,
isActive: False,
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
}
]
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length
{
insertedId: 0,
code: 0,
message: String
}