| GET | /notifications | Lấy danh sách các Notification mới nhất |
|---|
import Foundation
import ServiceStack
/**
* Lấy danh sách các Notification mới nhất của người dùng hiện tại
*/
public class GetNotificationFilter : PagingRequest, IGet
{
public var filter:NotificationFilter
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case filter
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
filter = try container.decodeIfPresent(NotificationFilter.self, forKey: .filter)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if filter != nil { try container.encode(filter, forKey: .filter) }
}
}
public class PagingRequest : Codable
{
public var page:Int
public var limit:Int
required public init(){}
}
public enum NotificationFilter : String, Codable
{
case Unread
case All
}
public class NotificationResponse : IResponseRequest, Codable
{
public var code:Int
public var message:String
public var notifications:[Notification] = []
public var unreadCount:Int
public var totalCount:Int
required public init(){}
}
public class Notification : IMongoModel, Codable
{
public var id:String
public var accountId:Int
// @Required()
// @StringLength(200)
public var title:String?
public var message:String
public var payload:String
public var createdOn:Date
public var readOn:Date?
public var pushOn:Date?
public var deletedOn:Date?
required public init(){}
}
Swift GetNotificationFilter 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 /notifications 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,
notifications:
[
{
id: String,
accountId: 0,
title: String,
message: String,
payload: String,
readOn: "0001-01-01T00:00:00.0000000+07:06",
pushOn: "0001-01-01T00:00:00.0000000+07:06",
deletedOn: "0001-01-01T00:00:00.0000000+07:06"
}
],
unreadCount: 0,
totalCount: 0
}