-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainees.go
65 lines (60 loc) · 1.97 KB
/
trainees.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
package entities
import (
"github.com/kode-magic/eco-bowl-api/core/commons"
"time"
)
type (
Trainee struct {
ID string `json:"id"`
Forename string `json:"forename"`
Surname string `json:"surname"`
Gender commons.Genders `json:"gender"`
BirthDate time.Time `json:"birthDate"`
Phone string `json:"phone"`
Email string `json:"email"`
Qualification string `json:"qualification"`
EventID string `json:"eventId"`
Event Event `json:"event"`
TeamID string `json:"teamId"`
Team Team `json:"team"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
TraineeRepo interface {
Create(trainee *Trainee) (*Trainee, map[string]string)
List(event string) (*[]Trainee, error)
Get(id string) (*Trainee, error)
GetByPhoneEmail(event, phoneEmail string) (*Trainee, error)
GetByEmail(event, email string) (*Trainee, error)
AddToTeam(trainee *Trainee) (*Trainee, error)
}
)
func (trainee *Trainee) Validate() map[string]string {
var date time.Time
var errorMessages = make(map[string]string)
if trainee.EventID == "" {
errorMessages["event"] = "event is required"
}
if trainee.Forename == "" {
errorMessages["forename"] = "forename is required"
}
if trainee.Surname == "" {
errorMessages["surname"] = "surname is required"
}
if trainee.Phone == "" {
errorMessages["phone"] = "phone is required"
}
if trainee.Email == "" {
errorMessages["email"] = "email is required"
}
if trainee.Gender != commons.Male && trainee.Gender != commons.Female {
errorMessages["gender"] = "gender is required and must be a valid gender value"
}
if trainee.BirthDate == date {
errorMessages["birth_date"] = "birth date is required"
}
if trainee.Qualification == "" {
errorMessages["qualification"] = "qualification is required"
}
return errorMessages
}