/
types.go
146 lines (132 loc) · 5.08 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
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
135
136
137
138
139
140
141
142
143
144
145
146
// Code generated by goa v3.16.1, DO NOT EDIT.
//
// resume HTTP server types
//
// Command:
// $ goa gen goa.design/examples/multipart/design
package server
import (
resume "goa.design/examples/multipart/gen/resume"
resumeviews "goa.design/examples/multipart/gen/resume/views"
goa "goa.design/goa/v3/pkg"
)
// StoredResumeResponseCollection is the type of the "resume" service "list"
// endpoint HTTP response body.
type StoredResumeResponseCollection []*StoredResumeResponse
// StoredResumeResponse is used to define fields on response body types.
type StoredResumeResponse struct {
// ID of the resume
ID int `form:"id" json:"id" xml:"id"`
// Name in the resume
Name string `form:"name" json:"name" xml:"name"`
// Experience section in the resume
Experience []*ExperienceResponse `form:"experience" json:"experience" xml:"experience"`
// Education section in the resume
Education []*EducationResponse `form:"education" json:"education" xml:"education"`
// Time when resume was created
CreatedAt string `form:"created_at" json:"created_at" xml:"created_at"`
}
// ExperienceResponse is used to define fields on response body types.
type ExperienceResponse struct {
// Name of the company
Company string `form:"company" json:"company" xml:"company"`
// Name of the role in the company
Role string `form:"role" json:"role" xml:"role"`
// Duration (in years) in the company
Duration int `form:"duration" json:"duration" xml:"duration"`
}
// EducationResponse is used to define fields on response body types.
type EducationResponse struct {
// Name of the institution
Institution string `form:"institution" json:"institution" xml:"institution"`
// Major name
Major string `form:"major" json:"major" xml:"major"`
}
// ResumeRequestBody is used to define fields on request body types.
type ResumeRequestBody struct {
// Name in the resume
Name *string `form:"name,omitempty" json:"name,omitempty" xml:"name,omitempty"`
// Experience section in the resume
Experience []*ExperienceRequestBody `form:"experience,omitempty" json:"experience,omitempty" xml:"experience,omitempty"`
// Education section in the resume
Education []*EducationRequestBody `form:"education,omitempty" json:"education,omitempty" xml:"education,omitempty"`
}
// ExperienceRequestBody is used to define fields on request body types.
type ExperienceRequestBody struct {
// Name of the company
Company *string `form:"company,omitempty" json:"company,omitempty" xml:"company,omitempty"`
// Name of the role in the company
Role *string `form:"role,omitempty" json:"role,omitempty" xml:"role,omitempty"`
// Duration (in years) in the company
Duration *int `form:"duration,omitempty" json:"duration,omitempty" xml:"duration,omitempty"`
}
// EducationRequestBody is used to define fields on request body types.
type EducationRequestBody struct {
// Name of the institution
Institution *string `form:"institution,omitempty" json:"institution,omitempty" xml:"institution,omitempty"`
// Major name
Major *string `form:"major,omitempty" json:"major,omitempty" xml:"major,omitempty"`
}
// NewStoredResumeResponseCollection builds the HTTP response body from the
// result of the "list" endpoint of the "resume" service.
func NewStoredResumeResponseCollection(res resumeviews.StoredResumeCollectionView) StoredResumeResponseCollection {
body := make([]*StoredResumeResponse, len(res))
for i, val := range res {
body[i] = marshalResumeviewsStoredResumeViewToStoredResumeResponse(val)
}
return body
}
// NewAddResume builds a resume service add endpoint payload.
func NewAddResume(body []*ResumeRequestBody) []*resume.Resume {
v := make([]*resume.Resume, len(body))
for i, val := range body {
v[i] = unmarshalResumeRequestBodyToResumeResume(val)
}
return v
}
// ValidateResumeRequestBody runs the validations defined on ResumeRequestBody
func ValidateResumeRequestBody(body *ResumeRequestBody) (err error) {
if body.Name == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("name", "body"))
}
for _, e := range body.Experience {
if e != nil {
if err2 := ValidateExperienceRequestBody(e); err2 != nil {
err = goa.MergeErrors(err, err2)
}
}
}
for _, e := range body.Education {
if e != nil {
if err2 := ValidateEducationRequestBody(e); err2 != nil {
err = goa.MergeErrors(err, err2)
}
}
}
return
}
// ValidateExperienceRequestBody runs the validations defined on
// ExperienceRequestBody
func ValidateExperienceRequestBody(body *ExperienceRequestBody) (err error) {
if body.Company == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("company", "body"))
}
if body.Role == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("role", "body"))
}
if body.Duration == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("duration", "body"))
}
return
}
// ValidateEducationRequestBody runs the validations defined on
// EducationRequestBody
func ValidateEducationRequestBody(body *EducationRequestBody) (err error) {
if body.Institution == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("institution", "body"))
}
if body.Major == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("major", "body"))
}
return
}