-
Notifications
You must be signed in to change notification settings - Fork 0
/
tatoeba.go
134 lines (107 loc) · 2.81 KB
/
tatoeba.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//go:generate mockery --output mock --name TatoebaSentence
//go:generate mockery --output mock --name TatoebaSentencePair
package service
import (
"errors"
"time"
appD "github.com/kujilabo/cocotola-api/src/app/domain"
libD "github.com/kujilabo/cocotola-api/src/lib/domain"
)
var ErrTatoebaSentenceAlreadyExists = errors.New("tatoebaSentence already exists")
type TatoebaSentence interface {
GetSentenceNumber() int
GetLang2() appD.Lang2
GetText() string
GetAuthor() string
GetUpdatedAt() time.Time
}
type tatoebaSentence struct {
SentenceNumber int
Lang2 appD.Lang2
Text string
Author string
UpdatedAt time.Time
}
func NewTatoebaSentence(sentenceNumber int, lang2 appD.Lang2, text, author string, updatedAt time.Time) (TatoebaSentence, error) {
m := &tatoebaSentence{
SentenceNumber: sentenceNumber,
Lang2: lang2,
Text: text,
Author: author,
UpdatedAt: updatedAt,
}
return m, libD.Validator.Struct(m)
}
func (m *tatoebaSentence) GetSentenceNumber() int {
return m.SentenceNumber
}
func (m *tatoebaSentence) GetLang2() appD.Lang2 {
return m.Lang2
}
func (m *tatoebaSentence) GetText() string {
return m.Text
}
func (m *tatoebaSentence) GetAuthor() string {
return m.Author
}
func (m *tatoebaSentence) GetUpdatedAt() time.Time {
return m.UpdatedAt
}
type TatoebaSentencePair interface {
GetSrc() TatoebaSentence
GetDst() TatoebaSentence
}
type tatoebaSentencePair struct {
Src TatoebaSentence
Dst TatoebaSentence
}
func NewTatoebaSentencePair(src, dst TatoebaSentence) (TatoebaSentencePair, error) {
m := &tatoebaSentencePair{
Src: src,
Dst: dst,
}
return m, libD.Validator.Struct(m)
}
func (m *tatoebaSentencePair) GetSrc() TatoebaSentence {
return m.Src
}
func (m *tatoebaSentencePair) GetDst() TatoebaSentence {
return m.Dst
}
type TatoebaSentenceSearchCondition interface {
GetPageNo() int
GetPageSize() int
GetKeyword() string
IsRandom() bool
}
type tatoebaSentenceSearchCondition struct {
PageNo int `validate:"required,gte=1"`
PageSize int `validate:"required,gte=1,lte=100"`
Keyword string
Random bool
}
func NewTatoebaSentenceSearchCondition(pageNo, pageSize int, keyword string, random bool) (TatoebaSentenceSearchCondition, error) {
m := &tatoebaSentenceSearchCondition{
PageNo: pageNo,
PageSize: pageSize,
Keyword: keyword,
Random: random,
}
return m, libD.Validator.Struct(m)
}
func (c *tatoebaSentenceSearchCondition) GetPageNo() int {
return c.PageNo
}
func (c *tatoebaSentenceSearchCondition) GetPageSize() int {
return c.PageSize
}
func (c *tatoebaSentenceSearchCondition) GetKeyword() string {
return c.Keyword
}
func (c *tatoebaSentenceSearchCondition) IsRandom() bool {
return c.Random
}
type TatoebaSentencePairSearchResult struct {
TotalCount int64
Results []TatoebaSentencePair
}