/
dao.go
87 lines (75 loc) · 1.72 KB
/
dao.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
package forum
import (
"errors"
"fmt"
"github.com/itimofeev/hustledb/components/util"
"gopkg.in/mgutz/dat.v1/sqlx-runner"
"strings"
)
func NewDao(db *runner.DB) ForumDao {
return &ForumDaoImpl{
db: db,
}
}
type ForumDao interface {
FindJudgeIdByTitle(title string) int64
FindCompetitionId(compUrl string) int64
}
type ForumDaoImpl struct {
db *runner.DB
}
func (f *ForumDaoImpl) FindCompetitionId(compUrl string) int64 {
var compIds []int64
err := f.db.SQL(`
SELECT
c.id
FROM
competition c
WHERE
c.site = $1
`, compUrl).
QuerySlice(&compIds)
util.CheckErr(err, fmt.Sprintf("Not found judge by title: %s", compUrl))
if len(compIds) != 1 {
util.CheckErr(errors.New("WTF"), compUrl)
}
return compIds[0]
}
func (f *ForumDaoImpl) FindJudgeIdByTitle(title string) int64 {
switch title {
case "Лебедев Сергей", "Сергей Лебедев":
return 952
case "Кудрявцева Ирина":
return 1008
case "Графова Варвара":
return 1101
case "Потапов Вячеслав":
return 1410
case "Новикова Екатерина":
return 3221
case "Селиванова Алёна":
return 2057
case "Лион Анастасия":
return 534
case "Торшин Артём":
return 2363
case "результаты перетанцовки":
return -11
}
var dancerIds []int64
err := f.db.SQL(`
SELECT
d.id
FROM
dancer d
WHERE
lower(d.surname || ' ' || d.name) = lower($1) OR
lower(d.name || ' ' || d.surname) = lower($1)
`, strings.TrimSpace(title)).
QuerySlice(&dancerIds)
util.CheckErr(err, fmt.Sprintf("Not found judge by title: %s", title))
if len(dancerIds) != 1 {
util.CheckOk(false, dancerIds, title)
}
return dancerIds[0]
}