Skip to content

Commit 1ece4ca

Browse files
authored
feat(tem): update tem list emails endpoint (#1695)
1 parent adea168 commit 1ece4ca

File tree

1 file changed

+82
-19
lines changed

1 file changed

+82
-19
lines changed

api/tem/v1alpha1/tem_sdk.go

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,46 @@ func (enum *EmailStatus) UnmarshalJSON(data []byte) error {
152152
return nil
153153
}
154154

155+
type ListEmailsRequestOrderBy string
156+
157+
const (
158+
ListEmailsRequestOrderByCreatedAtDesc = ListEmailsRequestOrderBy("created_at_desc")
159+
ListEmailsRequestOrderByCreatedAtAsc = ListEmailsRequestOrderBy("created_at_asc")
160+
ListEmailsRequestOrderByUpdatedAtDesc = ListEmailsRequestOrderBy("updated_at_desc")
161+
ListEmailsRequestOrderByUpdatedAtAsc = ListEmailsRequestOrderBy("updated_at_asc")
162+
ListEmailsRequestOrderByStatusDesc = ListEmailsRequestOrderBy("status_desc")
163+
ListEmailsRequestOrderByStatusAsc = ListEmailsRequestOrderBy("status_asc")
164+
ListEmailsRequestOrderByMailFromDesc = ListEmailsRequestOrderBy("mail_from_desc")
165+
ListEmailsRequestOrderByMailFromAsc = ListEmailsRequestOrderBy("mail_from_asc")
166+
ListEmailsRequestOrderByMailRcptDesc = ListEmailsRequestOrderBy("mail_rcpt_desc")
167+
ListEmailsRequestOrderByMailRcptAsc = ListEmailsRequestOrderBy("mail_rcpt_asc")
168+
ListEmailsRequestOrderBySubjectDesc = ListEmailsRequestOrderBy("subject_desc")
169+
ListEmailsRequestOrderBySubjectAsc = ListEmailsRequestOrderBy("subject_asc")
170+
)
171+
172+
func (enum ListEmailsRequestOrderBy) String() string {
173+
if enum == "" {
174+
// return default value if empty
175+
return "created_at_desc"
176+
}
177+
return string(enum)
178+
}
179+
180+
func (enum ListEmailsRequestOrderBy) MarshalJSON() ([]byte, error) {
181+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
182+
}
183+
184+
func (enum *ListEmailsRequestOrderBy) UnmarshalJSON(data []byte) error {
185+
tmp := ""
186+
187+
if err := json.Unmarshal(data, &tmp); err != nil {
188+
return err
189+
}
190+
191+
*enum = ListEmailsRequestOrderBy(ListEmailsRequestOrderBy(tmp).String())
192+
return nil
193+
}
194+
155195
// CreateEmailRequestAddress: create email request. address.
156196
type CreateEmailRequestAddress struct {
157197
// Email: email address.
@@ -229,8 +269,10 @@ type Email struct {
229269
ProjectID string `json:"project_id"`
230270
// MailFrom: email address of the sender.
231271
MailFrom string `json:"mail_from"`
232-
// RcptTo: email address of the recipient.
233-
RcptTo string `json:"rcpt_to"`
272+
// Deprecated: RcptTo: (Deprecated) Email address of the recipient.
273+
RcptTo *string `json:"rcpt_to,omitempty"`
274+
// MailRcpt: email address of the recipient.
275+
MailRcpt string `json:"mail_rcpt"`
234276
// RcptType: type of recipient.
235277
// Default value: unknown_rcpt_type
236278
RcptType EmailRcptType `json:"rcpt_type"`
@@ -273,7 +315,7 @@ type ListDomainsResponse struct {
273315

274316
// ListEmailsResponse: list emails response.
275317
type ListEmailsResponse struct {
276-
// TotalCount: count of all emails matching the requested criteria.
318+
// TotalCount: number of emails matching the requested criteria.
277319
TotalCount uint32 `json:"total_count"`
278320
// Emails: single page of emails matching the requested criteria.
279321
Emails []*Email `json:"emails"`
@@ -413,28 +455,47 @@ type ListEmailsRequest struct {
413455
Page *int32 `json:"-"`
414456

415457
PageSize *uint32 `json:"-"`
416-
// ProjectID: ID of the Project in which to list the emails (optional).
458+
// ProjectID: (Optional) ID of the Project in which to list the emails.
417459
ProjectID *string `json:"-"`
418-
// DomainID: ID of the domain for which to list the emails (optional).
460+
// DomainID: (Optional) ID of the domain for which to list the emails.
419461
DomainID *string `json:"-"`
420-
// MessageID: ID of the message for which to list the emails (optional).
462+
// MessageID: (Optional) ID of the message for which to list the emails.
421463
MessageID *string `json:"-"`
422-
// Subject: subject of the email.
423-
Subject *string `json:"-"`
424-
// Since: list emails created after this date (optional).
464+
// Since: (Optional) List emails created after this date.
425465
Since *time.Time `json:"-"`
426-
// Until: list emails created before this date (optional).
466+
// Until: (Optional) List emails created before this date.
427467
Until *time.Time `json:"-"`
428-
// MailFrom: list emails sent with this `mail_from` sender's address (optional).
468+
// MailFrom: (Optional) List emails sent with this sender's email address.
429469
MailFrom *string `json:"-"`
430-
// MailTo: list emails sent with this `mail_to` recipient's address (optional).
470+
// Deprecated: MailTo: (Deprecated) List emails sent to this recipient's email address.
431471
MailTo *string `json:"-"`
432-
// Statuses: list emails having any of this status (optional).
472+
// MailRcpt: (Optional) List emails sent to this recipient's email address.
473+
MailRcpt *string `json:"-"`
474+
// Statuses: (Optional) List emails with any of these statuses.
433475
Statuses []EmailStatus `json:"-"`
476+
// Subject: (Optional) List emails with this subject.
477+
Subject *string `json:"-"`
478+
// OrderBy: (Optional) List emails corresponding to specific criteria.
479+
// You can filter your emails in ascending or descending order using:
480+
// - created_at
481+
// - updated_at
482+
// - status
483+
// - mail_from
484+
// - mail_rcpt
485+
// - subject.
486+
// Default value: created_at_desc
487+
OrderBy ListEmailsRequestOrderBy `json:"-"`
434488
}
435489

436490
// ListEmails: list emails.
437491
// Retrieve the list of emails sent from a specific domain or for a specific Project or Organization. You must specify the `region`.
492+
// You can filter your emails in ascending or descending order using:
493+
// - created_at
494+
// - updated_at
495+
// - status
496+
// - mail_from
497+
// - mail_rcpt
498+
// - subject.
438499
func (s *API) ListEmails(req *ListEmailsRequest, opts ...scw.RequestOption) (*ListEmailsResponse, error) {
439500
var err error
440501

@@ -454,12 +515,14 @@ func (s *API) ListEmails(req *ListEmailsRequest, opts ...scw.RequestOption) (*Li
454515
parameter.AddToQuery(query, "project_id", req.ProjectID)
455516
parameter.AddToQuery(query, "domain_id", req.DomainID)
456517
parameter.AddToQuery(query, "message_id", req.MessageID)
457-
parameter.AddToQuery(query, "subject", req.Subject)
458518
parameter.AddToQuery(query, "since", req.Since)
459519
parameter.AddToQuery(query, "until", req.Until)
460520
parameter.AddToQuery(query, "mail_from", req.MailFrom)
461521
parameter.AddToQuery(query, "mail_to", req.MailTo)
522+
parameter.AddToQuery(query, "mail_rcpt", req.MailRcpt)
462523
parameter.AddToQuery(query, "statuses", req.Statuses)
524+
parameter.AddToQuery(query, "subject", req.Subject)
525+
parameter.AddToQuery(query, "order_by", req.OrderBy)
463526

464527
if fmt.Sprint(req.Region) == "" {
465528
return nil, errors.New("field Region cannot be empty in request")
@@ -484,15 +547,15 @@ func (s *API) ListEmails(req *ListEmailsRequest, opts ...scw.RequestOption) (*Li
484547
type GetStatisticsRequest struct {
485548
// Region: region to target. If none is passed will use default region from the config.
486549
Region scw.Region `json:"-"`
487-
// ProjectID: number of emails for this Project (optional).
550+
// ProjectID: (Optional) Number of emails for this Project.
488551
ProjectID *string `json:"-"`
489-
// DomainID: number of emails sent from this domain (must be coherent with the `project_id` and the `organization_id`) (optional).
552+
// DomainID: (Optional) Number of emails sent from this domain (must be coherent with the `project_id` and the `organization_id`).
490553
DomainID *string `json:"-"`
491-
// Since: number of emails created after this date (optional).
554+
// Since: (Optional) Number of emails created after this date.
492555
Since *time.Time `json:"-"`
493-
// Until: number of emails created before this date (optional).
556+
// Until: (Optional) Number of emails created before this date.
494557
Until *time.Time `json:"-"`
495-
// MailFrom: number of emails sent with this `mail_from` sender's address (optional).
558+
// MailFrom: (Optional) Number of emails sent with this sender's email address.
496559
MailFrom *string `json:"-"`
497560
}
498561

0 commit comments

Comments
 (0)