Skip to content

Commit 5e2e1d7

Browse files
committed
answerResponseを共通の方にした
1 parent 1fe3dce commit 5e2e1d7

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

vmdb-api/controller.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@ func (c *Controller) hello(w http.ResponseWriter, r *http.Request) {
2020
w.Write([]byte(GREETING))
2121
}
2222

23+
type answerResponse struct {
24+
ID uuid.UUID `json:"id"`
25+
ProblemID uuid.UUID `json:"problem_id"`
26+
ProblemCode string `json:"problem_code"`
27+
TeamID uuid.UUID `json:"team_id"`
28+
Body string `json:"body"`
29+
CreatedAt time.Time `json:"created_at"`
30+
UpdatedAt time.Time `json:"updated_at"`
31+
}
32+
33+
func newAnswerResponseFrom(answer Answer, problem Problem) answerResponse {
34+
bodies := []string{}
35+
for _, b := range answer.Bodies {
36+
bodies = append(bodies, b...)
37+
}
38+
39+
return answerResponse{
40+
ID: answer.ID,
41+
ProblemID: answer.ProblemID,
42+
ProblemCode: problem.Code,
43+
TeamID: answer.TeamID,
44+
CreatedAt: answer.CreatedAt,
45+
UpdatedAt: answer.UpdatedAt,
46+
Body: strings.Join(bodies, "\n"),
47+
}
48+
}
49+
2350
type listProblemEnvironmentsResponse []ProblemEnvironment
2451

2552
func (c *Controller) listProblemEnvironments(w http.ResponseWriter, r *http.Request) {
@@ -90,17 +117,7 @@ func (c *Controller) getAnswerID(w http.ResponseWriter, r *http.Request) {
90117
}
91118
}
92119

93-
type listLatestUnconfirmedAnswersForLocalProblemResponse []listLatestUnconfirmedAnswersForLocalProblemResponseItem
94-
95-
type listLatestUnconfirmedAnswersForLocalProblemResponseItem struct {
96-
ID uuid.UUID `json:"id"`
97-
ProblemID uuid.UUID `json:"problem_id"`
98-
ProblemCode string `json:"problem_code"`
99-
TeamID uuid.UUID `json:"team_id"`
100-
CreatedAt time.Time `json:"created_at"`
101-
UpdatedAt time.Time `json:"updated_at"`
102-
Body string `json:"body"`
103-
}
120+
type listLatestUnconfirmedAnswersForLocalProblemResponse []answerResponse
104121

105122
func (c *Controller) listLatestUnconfirmedAnswersForLocalProblem(w http.ResponseWriter, r *http.Request) {
106123
ctx := r.Context()

0 commit comments

Comments
 (0)