| GET | /audits |
|---|
import Foundation
import ServiceStack
public class AuditLogRequest : PagingRequest
{
public var userName:String
public var userId:Int
public var documentId:Int
public var action:String
public var Description:String
public var ipAddress:String
public var startDate:Date
public var endDate:Date
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case userName
case userId
case documentId
case action
case Description
case ipAddress
case startDate
case endDate
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
userName = try container.decodeIfPresent(String.self, forKey: .userName)
userId = try container.decodeIfPresent(Int.self, forKey: .userId)
documentId = try container.decodeIfPresent(Int.self, forKey: .documentId)
action = try container.decodeIfPresent(String.self, forKey: .action)
Description = try container.decodeIfPresent(String.self, forKey: .Description)
ipAddress = try container.decodeIfPresent(String.self, forKey: .ipAddress)
startDate = try container.decodeIfPresent(Date.self, forKey: .startDate)
endDate = try container.decodeIfPresent(Date.self, forKey: .endDate)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if userName != nil { try container.encode(userName, forKey: .userName) }
if userId != nil { try container.encode(userId, forKey: .userId) }
if documentId != nil { try container.encode(documentId, forKey: .documentId) }
if action != nil { try container.encode(action, forKey: .action) }
if Description != nil { try container.encode(Description, forKey: .Description) }
if ipAddress != nil { try container.encode(ipAddress, forKey: .ipAddress) }
if startDate != nil { try container.encode(startDate, forKey: .startDate) }
if endDate != nil { try container.encode(endDate, forKey: .endDate) }
}
}
public class PagingRequest : Codable
{
public var page:Int
public var limit:Int
required public init(){}
}
public class PageResponse<AuditLog : Codable> : IResponseRequest, Codable
{
public var code:Int
public var message:String
public var data:[AuditLog] = []
public var pagination:Pagination
required public init(){}
}
public class AuditLog : MongoObject, IEntityId, ICreated, IUpdate
{
public var userName:String
public var userId:Int?
public var documentId:Int
public var action:String
public var Description:String
public var createdDate:Date
public var updatedDate:Date
public var ipAddress:String
public var userAgent:String
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case userName
case userId
case documentId
case action
case Description
case createdDate
case updatedDate
case ipAddress
case userAgent
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
userName = try container.decodeIfPresent(String.self, forKey: .userName)
userId = try container.decodeIfPresent(Int.self, forKey: .userId)
documentId = try container.decodeIfPresent(Int.self, forKey: .documentId)
action = try container.decodeIfPresent(String.self, forKey: .action)
Description = try container.decodeIfPresent(String.self, forKey: .Description)
createdDate = try container.decodeIfPresent(Date.self, forKey: .createdDate)
updatedDate = try container.decodeIfPresent(Date.self, forKey: .updatedDate)
ipAddress = try container.decodeIfPresent(String.self, forKey: .ipAddress)
userAgent = try container.decodeIfPresent(String.self, forKey: .userAgent)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if userName != nil { try container.encode(userName, forKey: .userName) }
if userId != nil { try container.encode(userId, forKey: .userId) }
if documentId != nil { try container.encode(documentId, forKey: .documentId) }
if action != nil { try container.encode(action, forKey: .action) }
if Description != nil { try container.encode(Description, forKey: .Description) }
if createdDate != nil { try container.encode(createdDate, forKey: .createdDate) }
if updatedDate != nil { try container.encode(updatedDate, forKey: .updatedDate) }
if ipAddress != nil { try container.encode(ipAddress, forKey: .ipAddress) }
if userAgent != nil { try container.encode(userAgent, forKey: .userAgent) }
}
}
public class MongoObject : IMongoModel, Codable
{
public var id:String
required public init(){}
}
public class Pagination : Codable
{
public var total:Int
public var pages:Int
public var offset:Int
public var limit:Int
public var currentPage:Int
required public init(){}
}
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 /audits HTTP/1.1 Host: etc-api.vsmlab.vn Accept: text/jsv
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length
{
code: 0,
message: String,
data:
[
{
userName: String,
userId: 0,
documentId: 0,
action: String,
description: String,
ipAddress: String,
userAgent: String,
id: 000000000000000000000000
}
]
}