This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
63 lines (46 loc) · 1.41 KB
/
level.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
package v1
import (
"fmt"
"net/http"
"github.com/competencies-ru/competency-constructor/internal/core/entity/education"
openapiTypes "github.com/deepmap/oapi-codegen/pkg/types"
"github.com/competencies-ru/competency-constructor/internal/core/adapter/driver/rest"
"github.com/competencies-ru/competency-constructor/internal/core/app/service"
"github.com/pkg/errors"
)
func (h handler) GetLevels(w http.ResponseWriter, r *http.Request) {
models, err := h.app.Queries.FindLevels.Handle(r.Context())
if err == nil {
renderLevelResponse(w, r, models)
return
}
rest.InternalServerError(string(UnexpectedError), err, w, r)
}
func (h handler) CreateLevel(w http.ResponseWriter, r *http.Request) {
cmd, ok := decodeCreateLevelCommand(w, r)
if !ok {
return
}
id, err := h.app.Commands.CreateLevel.Handle(r.Context(), cmd)
if err == nil {
w.Header().Set(
"Location",
fmt.Sprintf("/levels/%s", id),
)
w.WriteHeader(http.StatusCreated)
return
}
if errors.Is(err, service.AlreadyExistsEntity) {
rest.NotFound(string(BadRequest), err, w, r)
return
}
if education.IsInvalidLevelParametersError(err) {
rest.UnprocessableEntity(string(InvalidLevelParameters), err, w, r)
return
}
rest.InternalServerError(string(UnexpectedError), err, w, r)
}
func (h handler) GetSpecificLevel(w http.ResponseWriter, r *http.Request, levelID openapiTypes.UUID) {
// TODO implement me
panic("implement me")
}