-
Notifications
You must be signed in to change notification settings - Fork 4
/
edit.go
76 lines (59 loc) · 1.79 KB
/
edit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package internal
import "github.com/hvxahv/hvx/cockroach"
type Editor interface {
// EditTitle is a method for editing the title of an article.
EditTitle(title string) *Articles
// EditSummary is a method for editing the summary of an article.
EditSummary(summary string) *Articles
// EditArticle is a method for editing the article of an article.
EditArticle(article string) *Articles
// EditTags is a method for editing the tags of an article.
EditTags(tags []string) *Articles
// EditAttachmentType is a method for editing the attachment article.
EditAttachmentType(attachmentType string) *Articles
// EditAttachments is a method for editing the attachments of an article.
EditAttachments(attachments []string) *Articles
// EditNSFW is a method for editing the nsfw of an article.
EditNSFW(nsfw bool) *Articles
// EditVisibility is a method for editing the visibility of an article.
EditVisibility(visibility uint) *Articles
}
func (a *Articles) EditTitle(title string) *Articles {
a.Title = title
return a
}
func (a *Articles) EditSummary(summary string) *Articles {
a.Summary = summary
return a
}
func (a *Articles) EditArticle(article string) *Articles {
a.Article = article
return a
}
func (a *Articles) EditTags(tags []string) *Articles {
a.Tags = tags
return a
}
func (a *Articles) EditAttachments(attachments []string) *Articles {
a.Attachments = attachments
return a
}
func (a *Articles) EditNSFW(nsfw bool) *Articles {
a.NSFW = nsfw
return a
}
func (a *Articles) EditVisibility(visibility int64) *Articles {
a.Visibility = visibility
return a
}
func (a *Articles) Edit() error {
db := cockroach.GetDB()
if err := db.Debug().
Table(ArticleTable).
Where("id = ? AND actor_id = ?", a.ID, a.ActorId).
Updates(a).
Error; err != nil {
return nil
}
return nil
}