feat(training): add fields published and retired
This commit is contained in:
parent
79b7567627
commit
df41b45905
9 changed files with 131 additions and 50 deletions
|
|
@ -560,6 +560,9 @@ components:
|
|||
$ref: "#/components/schemas/TrainingPrice"
|
||||
slug:
|
||||
type: string
|
||||
published:
|
||||
type: boolean
|
||||
default: false
|
||||
required:
|
||||
- name
|
||||
- days
|
||||
|
|
@ -573,9 +576,13 @@ components:
|
|||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/TrainingID"
|
||||
retired:
|
||||
type: boolean
|
||||
required:
|
||||
- id
|
||||
- slug
|
||||
- published
|
||||
- retired
|
||||
|
||||
TrainingID:
|
||||
type: integer
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE training.trainings
|
||||
DROP COLUMN published,
|
||||
DROP COLUMN retired;
|
||||
6
db/migrations/002_training-published-and-retired.up.sql
Normal file
6
db/migrations/002_training-published-and-retired.up.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN;
|
||||
|
||||
ALTER TABLE training.trainings ADD COLUMN published BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
ALTER TABLE training.trainings ADD COLUMN retired BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
COMMIT;
|
||||
|
|
@ -23,10 +23,31 @@ func NewFaker(trainingRepository training.Repository, trainingDateRepository tra
|
|||
|
||||
func (f *Faker) GenerateFakeData() error {
|
||||
var trainings = []training.Training{
|
||||
{
|
||||
Name: "Kubernetes v1",
|
||||
Days: 1,
|
||||
Description: "Kubernetes-v1",
|
||||
Published: false,
|
||||
Retired: true,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(3900),
|
||||
Currency: money.CZK,
|
||||
Type: training.OpenTrainingPrice,
|
||||
},
|
||||
{
|
||||
Amount: decimal.NewFromInt(24000),
|
||||
Currency: money.CZK,
|
||||
Type: training.CorporateTrainingPrice,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Kubernetes",
|
||||
Days: 2,
|
||||
Description: "Kubernetes",
|
||||
Published: true,
|
||||
Retired: false,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(450),
|
||||
|
|
@ -54,6 +75,8 @@ func (f *Faker) GenerateFakeData() error {
|
|||
Name: "Terraform",
|
||||
Days: 1,
|
||||
Description: "Terraform",
|
||||
Published: true,
|
||||
Retired: false,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(200),
|
||||
|
|
@ -81,6 +104,8 @@ func (f *Faker) GenerateFakeData() error {
|
|||
Name: "RKE2",
|
||||
Days: 1,
|
||||
Description: "RKE2",
|
||||
Published: false,
|
||||
Retired: false,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(200),
|
||||
|
|
@ -108,6 +133,8 @@ func (f *Faker) GenerateFakeData() error {
|
|||
Name: "GitHub Actions",
|
||||
Days: 1,
|
||||
Description: "GitHub Actions",
|
||||
Published: false,
|
||||
Retired: false,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(200),
|
||||
|
|
@ -135,6 +162,8 @@ func (f *Faker) GenerateFakeData() error {
|
|||
Name: "GitLab CI",
|
||||
Days: 1,
|
||||
Description: "GitLab CI",
|
||||
Published: true,
|
||||
Retired: false,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(200),
|
||||
|
|
@ -162,6 +191,8 @@ func (f *Faker) GenerateFakeData() error {
|
|||
Name: "Prometheus",
|
||||
Days: 2,
|
||||
Description: "Prometheus",
|
||||
Published: true,
|
||||
Retired: false,
|
||||
Pricing: []training.Price{
|
||||
{
|
||||
Amount: decimal.NewFromInt(450),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Package server provides primitives to interact with the openapi HTTP API.
|
||||
//
|
||||
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.2.0 DO NOT EDIT.
|
||||
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
|
|
@ -83,6 +83,7 @@ type NewTraining struct {
|
|||
Description string `json:"description"`
|
||||
Name string `json:"name"`
|
||||
Pricing []TrainingPrice `json:"pricing"`
|
||||
Published *bool `json:"published,omitempty"`
|
||||
Slug *string `json:"slug,omitempty"`
|
||||
}
|
||||
|
||||
|
|
@ -139,6 +140,8 @@ type Training struct {
|
|||
Id TrainingID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Pricing []TrainingPrice `json:"pricing"`
|
||||
Published bool `json:"published"`
|
||||
Retired bool `json:"retired"`
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
|
||||
|
|
@ -2431,45 +2434,46 @@ func (sh *strictHandler) ListTrainingUpcomingDates(ctx *fiber.Ctx, trainingID Tr
|
|||
// Base64 encoded, gzipped, json marshaled Swagger object
|
||||
var swaggerSpec = []string{
|
||||
|
||||
"H4sIAAAAAAAC/+xc3XLbuBV+FQzau9Ki0s3O7uiqXjvd9XQbu/7pRVNfQOSRiIQEGAC0o/HoSXrVd2nf",
|
||||
"awcASZEUKFKSZcleXcUhwYPv/B8AB3rCAU9SzoApiUdPOCWCJKBAmP/dCkIZZdNzouBUKWAhwMW5fhOC",
|
||||
"DARNFeUMj8pxSA9ExUh0cY49TPWAlKgIe5iRBPAIKzdZDwv4mlEBIR4pkYGHZRBBQvR8fxQwwSP8B38B",
|
||||
"17dvpd+Ccj73agx0A++D95lwNvCtxNYF6xkgNeDcxNl0BSCpX6+EdGNHtINSs1SPl0pQNsVzPbkAmXIm",
|
||||
"wVjeBVMgGIk/CMGFfhBwpoAp/SdJ05gGRKPyU8HHMSR/+iw1xKeebF/Zr85BERpLO32d12J+BAbA3MMX",
|
||||
"7IHENLxgaab2h8pgQFSDWED7yNVfecbCfcH6yBWaaAAFpHmhaqPLMwFEgctLr+FrBtLgTAVPQShq1a9h",
|
||||
"EDZzWIqH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||
"FjXPvbqL+OPZmQ4e/lO1F3fe6jmVk+6fZnnbbrUJvCVILob4tabh+f0Onc91Ku90PVU5Tnw7fNutjXoH",
|
||||
"7XPo8GdQiJRA0HhWdE33UmKWn9WelcfrrWGv7ex+11Gws2fAoZlf85BYjV+o4BVZXvensjK01hE1Acu+",
|
||||
"SnxaNCLMbUIUg91A1LV4YZ5XIvJm/qfzjGXve7uij98CCvcocst6w1FMqca9pHWFsGcW3il0dWokzRwa",
|
||||
"qafe2yvl+RMU9+asV4Iy3BmIHglKZj7ZMkHZk11Zdvua1spw6nevi83F8DDjQnsL2Irls5TfwayYi4Wy",
|
||||
"K1/tty25sKWlgwsb7ZdA9rq3qRXHVoUP44AHvMlBRUV1s4CweGSLdWukXVtbnNd7dFFIXDNZ09I6xIzN",
|
||||
"ANsubTsI4e8k2evyzIML6Y3kr4dye2SA+9LvrvPGtReA4U6B9F0AjiuJ7DTRTRYOnxTd/72TzPK+wBFF",
|
||||
"su47EX1jGloI9ADy1RJMPWddlX70T1zL4/yjiHjdt/f3nvouNWJ0RsBC/8+TC+/Jmtsz6JK/nUREv7y3",
|
||||
"2Sevq90FPd4kz33l1WGIZsBhhkdX7rfwlFx/O7CnJ/cPAq25e9tT2F3vi2pb1Ab7v1IbB7sRLBFuvyM8",
|
||||
"AoXuPNysv+Qdanx5lk3m6zSZl9imbpS0DV8E0NpJ2xHuX3u5wY6WWb96t2JNR1vc3/i9u9w6t1tes/OR",
|
||||
"kqfi3uARuGPOyXIxwMX3C3tncaVnTc/M7wud3LLnVarX7JOpZej35ZBpaeDre+Ma/XXOn095Ff0E7h98",
|
||||
"eTV9BY4uvM5mWE3FXFS3SmmwyQMSoxAeIOap9RczttbwPvL9WI+LuFSj74bDodFXPlmT4lVhLRKRMc9U",
|
||||
"rUcw74lf4Jvfz38LAAD//+HPwchvWQAA",
|
||||
}
|
||||
|
||||
// GetSwagger returns the content of the embedded swagger specification file
|
||||
|
|
|
|||
|
|
@ -85,11 +85,18 @@ func (h *APIHandlers) CreateTraining(ctx context.Context, req CreateTrainingRequ
|
|||
slug = *req.Body.Slug
|
||||
}
|
||||
|
||||
published := false
|
||||
if req.Body.Published != nil {
|
||||
published = *req.Body.Published
|
||||
}
|
||||
|
||||
t := training.Training{
|
||||
Name: req.Body.Name,
|
||||
Slug: slug,
|
||||
Days: req.Body.Days,
|
||||
Description: req.Body.Description,
|
||||
Published: published,
|
||||
Retired: false,
|
||||
Pricing: pricing,
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +125,8 @@ func (h *APIHandlers) CreateTraining(ctx context.Context, req CreateTrainingRequ
|
|||
Slug: t.Slug,
|
||||
Days: t.Days,
|
||||
Description: t.Description,
|
||||
Published: t.Published,
|
||||
Retired: t.Retired,
|
||||
Pricing: responsePricing,
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -173,6 +182,8 @@ func (h *APIHandlers) GetTraining(ctx context.Context, req GetTrainingRequestObj
|
|||
Slug: t.Slug,
|
||||
Days: t.Days,
|
||||
Description: t.Description,
|
||||
Published: t.Published,
|
||||
Retired: t.Retired,
|
||||
Pricing: pricing,
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -208,6 +219,8 @@ func (h *APIHandlers) GetTrainingBySlug(ctx context.Context, req GetTrainingBySl
|
|||
Slug: t.Slug,
|
||||
Days: t.Days,
|
||||
Description: t.Description,
|
||||
Published: t.Published,
|
||||
Retired: t.Retired,
|
||||
Pricing: pricing,
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -237,12 +250,19 @@ func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequ
|
|||
slug = *req.Body.Slug
|
||||
}
|
||||
|
||||
published := false
|
||||
if req.Body.Published != nil {
|
||||
published = *req.Body.Published
|
||||
}
|
||||
|
||||
t := training.Training{
|
||||
ID: req.TrainingID,
|
||||
Name: req.Body.Name,
|
||||
Slug: slug,
|
||||
Days: req.Body.Days,
|
||||
Description: req.Body.Description,
|
||||
Published: published,
|
||||
Retired: false,
|
||||
Pricing: pricing,
|
||||
}
|
||||
|
||||
|
|
@ -262,6 +282,8 @@ func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequ
|
|||
Slug: t.Slug,
|
||||
Days: t.Days,
|
||||
Description: t.Description,
|
||||
Published: t.Published,
|
||||
Retired: t.Retired,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -172,6 +172,8 @@ func TestServer(t *testing.T) {
|
|||
assert.Equal(t, tr.Name, trr.Name)
|
||||
assert.Equal(t, tr.ID, trr.Id)
|
||||
assert.Equal(t, tr.Slug, trr.Slug)
|
||||
assert.Equal(t, false, trr.Published)
|
||||
assert.Equal(t, false, trr.Retired)
|
||||
})
|
||||
|
||||
t.Run("List all trainings", func(t *testing.T) {
|
||||
|
|
@ -202,6 +204,8 @@ func TestServer(t *testing.T) {
|
|||
assert.NotEmpty(t, trr.Slug)
|
||||
assert.NotEmpty(t, trr.Description)
|
||||
assert.NotEmpty(t, trr.Days)
|
||||
assert.False(t, trr.Published)
|
||||
assert.False(t, trr.Retired)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -246,6 +250,8 @@ func TestServer(t *testing.T) {
|
|||
assert.NoError(t, err, "error unmarshalling response")
|
||||
assert.Equal(t, updTr.Name, trr.Name)
|
||||
assert.Equal(t, updatedSlug, trr.Slug)
|
||||
assert.Equal(t, false, trr.Published)
|
||||
assert.Equal(t, false, trr.Retired)
|
||||
})
|
||||
|
||||
t.Run("Delete training", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ type Training struct {
|
|||
Slug string
|
||||
Days int8
|
||||
Description string
|
||||
Published bool
|
||||
Retired bool
|
||||
Pricing []Price `db:"-"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ func (r *PostgresTrainingRepository) Create(training *Training) error {
|
|||
}
|
||||
|
||||
queryErr := tx.QueryRow(ctx, `
|
||||
INSERT INTO training.trainings (name, slug, description, days)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
INSERT INTO training.trainings (name, slug, description, days, published)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id
|
||||
`, training.Name, training.Slug, training.Description, training.Days).Scan(&training.ID)
|
||||
`, training.Name, training.Slug, training.Description, training.Days, training.Published).Scan(&training.ID)
|
||||
if queryErr != nil {
|
||||
return queryErr
|
||||
}
|
||||
|
|
@ -77,10 +77,10 @@ func (r *PostgresTrainingRepository) FindByID(id ID) (*Training, error) {
|
|||
|
||||
var training Training
|
||||
err := r.pg.QueryRow(ctx, `
|
||||
SELECT id, name, slug, description, days
|
||||
SELECT id, name, slug, description, days, published, retired
|
||||
FROM training.trainings
|
||||
WHERE id = $1
|
||||
`, id).Scan(&training.ID, &training.Name, &training.Slug, &training.Description, &training.Days)
|
||||
`, id).Scan(&training.ID, &training.Name, &training.Slug, &training.Description, &training.Days, &training.Published, &training.Retired)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -122,10 +122,10 @@ func (r *PostgresTrainingRepository) FindBySlug(slug string) (*Training, error)
|
|||
|
||||
var training Training
|
||||
err := r.pg.QueryRow(ctx, `
|
||||
SELECT id, name, slug, description, days
|
||||
SELECT id, name, slug, description, days, published, retired
|
||||
FROM training.trainings
|
||||
WHERE slug = $1
|
||||
`, slug).Scan(&training.ID, &training.Name, &training.Slug, &training.Description, &training.Days)
|
||||
`, slug).Scan(&training.ID, &training.Name, &training.Slug, &training.Description, &training.Days, &training.Published, &training.Retired)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -172,7 +172,7 @@ func (r *PostgresTrainingRepository) FindAll() ([]Training, error) {
|
|||
|
||||
trainings, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (Training, error) {
|
||||
var training Training
|
||||
scanErr := row.Scan(&training.ID, &training.Name, &training.Slug, &training.Description, &training.Days)
|
||||
scanErr := row.Scan(&training.ID, &training.Name, &training.Slug, &training.Description, &training.Days, &training.Published, &training.Retired)
|
||||
if scanErr != nil {
|
||||
return Training{}, scanErr
|
||||
}
|
||||
|
|
@ -217,9 +217,9 @@ func (r *PostgresTrainingRepository) Update(training *Training) error {
|
|||
|
||||
_, err = tx.Exec(ctx, `
|
||||
UPDATE training.trainings
|
||||
SET name = $1, slug = $2, description = $3, days = $4
|
||||
SET name = $1, slug = $2, description = $3, days = $4, published = $5, retired = $6
|
||||
WHERE id = $4
|
||||
`, training.Name, training.Slug, training.Description, training.Days, training.ID)
|
||||
`, training.Name, training.Slug, training.Description, training.Days, training.ID, training.Published, training.Retired)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
Reference in a new issue