get list notification by user
This commit is contained in:
		
							parent
							
								
									b9ce18f0f4
								
							
						
					
					
						commit
						94cd3a171a
					
				
							
								
								
									
										20
									
								
								model.go
								
								
								
								
							
							
						
						
									
										20
									
								
								model.go
								
								
								
								
							| 
						 | 
					@ -50,6 +50,26 @@ type query struct {
 | 
				
			||||||
	Limit    int64  `json:"limit,omitempty"`
 | 
						Limit    int64  `json:"limit,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Notification ...
 | 
				
			||||||
 | 
					type Notification struct {
 | 
				
			||||||
 | 
						ID         string `json:"id"`
 | 
				
			||||||
 | 
						Category   string `json:"category,omitempty"`
 | 
				
			||||||
 | 
						Title      string `json:"title"`
 | 
				
			||||||
 | 
						Body       string `json:"body"`
 | 
				
			||||||
 | 
						IsRead     bool   `json:"isRead"`
 | 
				
			||||||
 | 
						Data       string `json:"data,omitempty"`
 | 
				
			||||||
 | 
						CreatedAt  string `json:"createdAt"`
 | 
				
			||||||
 | 
						LastPushAt string `json:"lastPushAt"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ListNotificationResponse ...
 | 
				
			||||||
 | 
					type ListNotificationResponse struct {
 | 
				
			||||||
 | 
						List  []Notification `json:"list"`
 | 
				
			||||||
 | 
						Total int64          `json:"total"`
 | 
				
			||||||
 | 
						Limit int64          `json:"limit"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Read ...
 | 
				
			||||||
type Read struct {
 | 
					type Read struct {
 | 
				
			||||||
	APIKey string `json:"apiKey"`
 | 
						APIKey string `json:"apiKey"`
 | 
				
			||||||
	ID     string `json:"id"`
 | 
						ID     string `json:"id"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ func NewClient(cfg Config) (*Client, error) {
 | 
				
			||||||
	return c, nil
 | 
						return c, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PushToUsers ...
 | 
					// PushToUsers push notification to list user id
 | 
				
			||||||
func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) {
 | 
					func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error) {
 | 
				
			||||||
	p := pushRequest{
 | 
						p := pushRequest{
 | 
				
			||||||
		APIKey: c.Config.APIKey,
 | 
							APIKey: c.Config.APIKey,
 | 
				
			||||||
| 
						 | 
					@ -73,6 +73,26 @@ func (c *Client) PushToUsers(payload PushRequest) (requestID string, err error)
 | 
				
			||||||
	return res.RequestID, nil
 | 
						return res.RequestID, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Query get list notification by user id
 | 
				
			||||||
 | 
					func (c *Client) Query(q Query) (ListNotificationResponse, error) {
 | 
				
			||||||
 | 
						p := query{
 | 
				
			||||||
 | 
							APIKey:   c.Config.APIKey,
 | 
				
			||||||
 | 
							User:     q.User,
 | 
				
			||||||
 | 
							Category: q.Category,
 | 
				
			||||||
 | 
							Page:     q.Page,
 | 
				
			||||||
 | 
							Limit:    q.Limit,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						msg, err := c.natsServer.Request(SubjectPushNotification, toBytes(p))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ListNotificationResponse{}, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var res ListNotificationResponse
 | 
				
			||||||
 | 
						if err := json.Unmarshal(msg.Data, &res); err != nil {
 | 
				
			||||||
 | 
							return ListNotificationResponse{}, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return res, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func toBytes(data interface{}) []byte {
 | 
					func toBytes(data interface{}) []byte {
 | 
				
			||||||
	b, _ := json.Marshal(data)
 | 
						b, _ := json.Marshal(data)
 | 
				
			||||||
	return b
 | 
						return b
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue