1
0
Fork 0

feat(training): add Description field

This commit is contained in:
Vojtěch Mareš 2024-05-05 09:47:50 +02:00
parent bda8bb9e85
commit d55276886b
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
5 changed files with 76 additions and 58 deletions

View file

@ -161,9 +161,12 @@ components:
format: int8 format: int8
minimum: 1 minimum: 1
maximum: 5 maximum: 5
description:
type: string
required: required:
- name - name
- days - days
- description
Training: Training:
allOf: allOf:

View file

@ -33,8 +33,9 @@ type ListTrainingsResponse = []Training
// NewTraining defines model for NewTraining. // NewTraining defines model for NewTraining.
type NewTraining struct { type NewTraining struct {
Days int8 `json:"days"` Days int8 `json:"days"`
Name string `json:"name"` Description string `json:"description"`
Name string `json:"name"`
} }
// ProblemDetails Schema that carries the details of an error in an HTTP response. See https://datatracker.ietf.org/doc/html/rfc7807 for more information. // ProblemDetails Schema that carries the details of an error in an HTTP response. See https://datatracker.ietf.org/doc/html/rfc7807 for more information.
@ -57,9 +58,10 @@ type ProblemDetails struct {
// Training defines model for Training. // Training defines model for Training.
type Training struct { type Training struct {
Days int8 `json:"days"` Days int8 `json:"days"`
Id TrainingID `json:"id"` Description string `json:"description"`
Name string `json:"name"` Id TrainingID `json:"id"`
Name string `json:"name"`
} }
// TrainingID defines model for TrainingID. // TrainingID defines model for TrainingID.
@ -583,27 +585,27 @@ func (sh *strictHandler) UpdateTraining(ctx *fiber.Ctx, trainingID TrainingID) e
// Base64 encoded, gzipped, json marshaled Swagger object // Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{ var swaggerSpec = []string{
"H4sIAAAAAAAC/9RXwXLbNhN+FQz+/1ZalJtkkuGpad0mmkkTN3F6cX2AwCUJhwRgYClbo+GT9NR3ad+r", "H4sIAAAAAAAC/9xYwXLbNhD9FQzaW2lRbpJJhqemdZtoJk3cxOnF9QEClyQcEoCBpWyNhl/SU/+l/a8O",
"A0CkSIl25EYZxyfLILD77beLD7srylWllQSJliYrqplhFSAY/9+ZYUIKmc9O3H8pWG6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kMv7rOUJsP3nG419d9Pp3d0", "Exvq7NqXv5HnpzMa0QUYG+RhOjmeTN1CpUEyLWhCH/lXka9Nz0+8OO6qz7/IwYfmOPRXwSylybBXoFvj",
"p/frSscbh5Hm9CUphUWviB2uJqLPApYxFx3meDiF+LY2COw6UsLKsmc2osgcN+d0Q4FTBa3sCFXDPnM9", "xffT6R198v364/GmZKRNfk5KYdHrZ4erieiTgGXMRYc5Hs5DvsEOcryOlLCy7JmNKDLHzTndUOA0RCs7",
"RoHFH1W6PBhN4713M7yMbmprdnJ1/NVA3J6sbu7k/kjqMvV0v0xtT2eHyHEAThiRcN3l+ZY0N9HwisSr", "QtWwh10PdGDxR5UuD0bT+BTQDI+mmx+bnVwdfzYQtyerm4C535K6TD3eL1Pbc+IhchyAE0YkXHd5viXN",
"zYzchDe2BITdOjjx67066I/pt4jcZstAlS52kvj0jtk+AFpz/PTzTA3HzEPwG0InrOPWdU3+4Ru/SKOS", "TTQ8IvFqM6034UYuAWG3Dk78+14d9H8wuEXkNksGqnSxk8THd/zKEACtOX78caaGA+8h+A2hE9Zx63os",
"05t7Dkze4dRqbDYb1SrsTTQPlJRXgPtnRNcjGRk+3V+elMPL4ngvtJcsTr8aiD1ksfZHvlAWH6iuQrj7", "f02OH6RRyenNVAcm73BqNTb3jWoV9qalB0rKC8D9M6LrkYwMr+5PT8rhZXG8c9pLFqefDcQeslj7LZ8o",
"lpY/64emUDNDQt4ozkqSwgJKpSuQuB6wBi1TEsel21coi8mT6XTqy2ntbNviu7aCLWFzVePgWV93VRt8", "iw9UVyHcfUvL7/UjVqiZISGvFGclSWEBpdIVSFyPY4OWKYnj0q0rlMXk0XQ69eW0drZt8U1bwZawuapx",
"zUXzbwAAAP//yp+J/10VAAA=", "cK2vu6oNvuai+TcAAP//9nxvI+cVAAA=",
} }
// GetSwagger returns the content of the embedded swagger specification file // GetSwagger returns the content of the embedded swagger specification file

View file

@ -31,9 +31,10 @@ func (h *APIHandlers) ListTrainings(ctx context.Context, req ListTrainingsReques
data := make([]Training, len(trainings)) data := make([]Training, len(trainings))
for idx, training := range trainings { for idx, training := range trainings {
data[idx] = Training{ data[idx] = Training{
Id: training.ID, Id: training.ID,
Name: training.Name, Name: training.Name,
Days: training.Days, Days: training.Days,
Description: training.Description,
} }
} }
@ -42,8 +43,9 @@ func (h *APIHandlers) ListTrainings(ctx context.Context, req ListTrainingsReques
func (h *APIHandlers) CreateTraining(ctx context.Context, req CreateTrainingRequestObject) (CreateTrainingResponseObject, error) { func (h *APIHandlers) CreateTraining(ctx context.Context, req CreateTrainingRequestObject) (CreateTrainingResponseObject, error) {
t := training.Training{ t := training.Training{
Name: req.Body.Name, Name: req.Body.Name,
Days: req.Body.Days, Days: req.Body.Days,
Description: req.Body.Description,
} }
err := h.trainingRepository.Create(&t) err := h.trainingRepository.Create(&t)
@ -57,9 +59,10 @@ func (h *APIHandlers) CreateTraining(ctx context.Context, req CreateTrainingRequ
} }
return CreateTraining201JSONResponse{ return CreateTraining201JSONResponse{
Id: t.ID, Id: t.ID,
Name: t.Name, Name: t.Name,
Days: t.Days, Days: t.Days,
Description: t.Description,
}, nil }, nil
} }
@ -101,17 +104,19 @@ func (h *APIHandlers) GetTraining(ctx context.Context, req GetTrainingRequestObj
} }
return GetTraining200JSONResponse{ return GetTraining200JSONResponse{
Id: t.ID, Id: t.ID,
Name: t.Name, Name: t.Name,
Days: t.Days, Days: t.Days,
Description: t.Description,
}, nil }, nil
} }
func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequestObject) (UpdateTrainingResponseObject, error) { func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequestObject) (UpdateTrainingResponseObject, error) {
t := training.Training{ t := training.Training{
ID: req.TrainingID, ID: req.TrainingID,
Name: req.Body.Name, Name: req.Body.Name,
Days: req.Body.Days, Days: req.Body.Days,
Description: req.Body.Description,
} }
err := h.trainingRepository.Update(&t) err := h.trainingRepository.Update(&t)
@ -125,8 +130,9 @@ func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequ
} }
return UpdateTraining200JSONResponse{ return UpdateTraining200JSONResponse{
Id: t.ID, Id: t.ID,
Name: t.Name, Name: t.Name,
Days: t.Days, Days: t.Days,
Description: t.Description,
}, nil }, nil
} }

View file

@ -11,7 +11,8 @@ func NewTrainingID() TrainingID {
} }
type Training struct { type Training struct {
ID TrainingID ID TrainingID
Name string Name string
Days int8 Days int8
Description string
} }

View file

@ -18,28 +18,34 @@ func NewInMemoryTrainingRepository() *InMemoryTrainingRepository {
} }
repo.Create(&Training{ repo.Create(&Training{
Name: "Kubernetes", Name: "Kubernetes",
Days: 2, Days: 2,
Description: "",
}) })
repo.Create(&Training{ repo.Create(&Training{
Name: "Terraform", Name: "Terraform",
Days: 1, Days: 1,
Description: "",
}) })
repo.Create(&Training{ repo.Create(&Training{
Name: "RKE2", Name: "RKE2",
Days: 1, Days: 1,
Description: "",
}) })
repo.Create(&Training{ repo.Create(&Training{
Name: "GitHub Actions", Name: "GitHub Actions",
Days: 1, Days: 1,
Description: "",
}) })
repo.Create(&Training{ repo.Create(&Training{
Name: "GitLab CI", Name: "GitLab CI",
Days: 1, Days: 1,
Description: "",
}) })
repo.Create(&Training{ repo.Create(&Training{
Name: "Prometheus", Name: "Prometheus",
Days: 2, Days: 2,
Description: "",
}) })
return repo return repo