Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 2795724

Browse files
committed
added bulk create and increase db functions
1 parent 6ac0fb6 commit 2795724

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

db.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ func Create(token, repo string, body interface{}, v interface{}) error {
1212
return Post(token, fmt.Sprintf("/db/%s", repo), body, v)
1313
}
1414

15+
func CreateBulk(token, repo string, body interface{}) (bool, error) {
16+
var status bool
17+
if err := Post(token, fmt.Sprintf("/db/%s?bulk=1", repo), body, &status); err != nil {
18+
return false, err
19+
}
20+
return status, nil
21+
}
22+
1523
// ListParams are used to page results and sort.
1624
type ListParams struct {
1725
Page int
@@ -196,3 +204,16 @@ func SudoListRepositories(token string) ([]string, error) {
196204

197205
return names, nil
198206
}
207+
208+
// Increase increases or decreases a field in a document based on n signed
209+
func Increase(token, repo, id, field string, n int) error {
210+
var body = new(struct {
211+
Field string `json:"field"`
212+
Range int `json:"range"`
213+
})
214+
body.Field = field
215+
body.Range = n
216+
217+
var status bool
218+
return Put(token, fmt.Sprintf("/inc/%s/%s", repo, id), body, &status)
219+
}

sendmail.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ package backend
22

33
// EmailData used to request the send email process
44
type EmailData struct {
5-
From string `json:"from"`
6-
To string `json:"to"`
7-
Subject string `json:"subject"`
8-
Body string `json:"body"`
9-
ReplyTo string `json:"replyTo"`
5+
FromName string `json:"fromName"`
6+
From string `json:"from"`
7+
To string `json:"to"`
8+
Subject string `json:"subject"`
9+
Body string `json:"body"`
10+
ReplyTo string `json:"replyTo"`
1011
}
1112

12-
func SendMail(token, from, to, subject, body, replyTo string) (ok bool, err error) {
13+
func SendMail(token, from, fromName, to, subject, body, replyTo string) (ok bool, err error) {
1314
data := EmailData{
14-
From: from,
15-
To: to,
16-
Subject: subject,
17-
Body: body,
18-
ReplyTo: replyTo,
15+
FromName: fromName,
16+
From: from,
17+
To: to,
18+
Subject: subject,
19+
Body: body,
20+
ReplyTo: replyTo,
1921
}
2022
err = Post(token, "/sudo/sendmail", data, &ok)
2123
return

0 commit comments

Comments
 (0)