/
types.go
99 lines (82 loc) · 2.37 KB
/
types.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package query
import (
"time"
)
type TranslationViewRepository interface {
GetView(id, authorID string) (TranslationView, error)
GetLastViewsByTags(authorID, langID string, pageSize, page int, tagIds []string) (LastTranslationViews, error)
GetRandomViews(authorID, langID string, tagIds []string, limit int) (RandomViews, error)
GetLastViewsBySourcePart(authorID, langID, sourcePart string, pageSize, page int) (LastTranslationViews, error)
GetLastViewsByTargetPart(authorID, langID, targetPart string, pageSize, page int) (LastTranslationViews, error)
}
type LastTranslationViews struct {
Views []TranslationView
TotalRecords int
}
type RandomViews struct {
Views []TranslationView
}
type TagViewRepository interface {
GetAllViews(authorID string) ([]TagView, error)
GetView(id, authorID string) (TagView, error)
GetViews(ids []string, authorID string) ([]TagView, error)
}
type LangViewRepository interface {
GetAllViews(authorID string) ([]LangView, error)
GetView(id, authorID string) (LangView, error)
}
type UserViewRepository interface {
GetAllViews() ([]UserView, error)
GetView(id string) (UserView, error)
}
type TranslationView struct {
ID string
Source string
Transcription string
Target string
Example string
Tags []TagView
CreatedAd time.Time
Lang LangView
}
type RoleView struct {
ID int
Name string
IsAdmin bool
}
func (v *TranslationView) sanitize(strictSntz *strictSanitizer, reachSntz *richTextSanitizer) {
v.Source = reachSntz.SanitizeAndEscape(v.Source)
v.Transcription = reachSntz.SanitizeAndEscape(v.Transcription)
v.Target = reachSntz.Sanitize(v.Target)
v.Example = reachSntz.Sanitize(v.Example)
v.Lang.sanitize(strictSntz)
for i := range v.Tags {
v.Tags[i].sanitize(strictSntz)
}
}
type TagView struct {
ID string
Name string
}
func (v *TagView) sanitize(sanitizer *strictSanitizer) {
v.Name = sanitizer.Sanitize(v.Name)
}
type LangView struct {
ID string
Name string
}
func (v *LangView) sanitize(sanitizer *strictSanitizer) {
v.Name = sanitizer.Sanitize(v.Name)
}
type UserView struct {
ID string
Name string
Email string
Role RoleView
DefaultLang LangView
}
func (v *UserView) sanitize(sanitizer *strictSanitizer) {
v.Name = sanitizer.Sanitize(v.Name)
v.Email = sanitizer.Sanitize(v.Email)
v.DefaultLang.sanitize(sanitizer)
}