1
0
Fork 0

refactor(training): use golang style of naming (do not repeat pacakge name in struct/func names)

This commit is contained in:
Vojtěch Mareš 2024-06-23 13:13:44 +02:00
parent e0f401f0a9
commit c3795dba6a
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
12 changed files with 232 additions and 232 deletions

View file

@ -548,7 +548,7 @@ components:
TrainingID: TrainingID:
type: integer type: integer
minimum: 1 minimum: 1
x-go-type: training.TrainingID x-go-type: training.ID
x-go-type-import: x-go-type-import:
path: gitlab.mareshq.com/hq/yggdrasil/pkg/training path: gitlab.mareshq.com/hq/yggdrasil/pkg/training
@ -654,7 +654,7 @@ components:
TrainingDateID: TrainingDateID:
type: integer type: integer
minimum: 1 minimum: 1
x-go-type: training.TrainingDateID x-go-type: training.DateID
x-go-type-import: x-go-type-import:
path: gitlab.mareshq.com/hq/yggdrasil/pkg/training path: gitlab.mareshq.com/hq/yggdrasil/pkg/training
@ -707,7 +707,7 @@ components:
TrainingDateAttendeeID: TrainingDateAttendeeID:
type: integer type: integer
minimum: 1 minimum: 1
x-go-type: training.TrainingDateAttendeeID x-go-type: training.AttendeeID
x-go-type-import: x-go-type-import:
path: gitlab.mareshq.com/hq/yggdrasil/pkg/training path: gitlab.mareshq.com/hq/yggdrasil/pkg/training

View file

@ -53,7 +53,7 @@ func main() {
} }
trainingRepo := training.NewPostgresTrainingRepository(pool) trainingRepo := training.NewPostgresTrainingRepository(pool)
trainingDateRepo := training.NewPostgresTrainingDateRepository(pool) trainingDateRepo := training.NewPostgresDateRepository(pool)
//trainingDateAttendeeRepo := training.NewPostgresTrainingDateAttendeeRepository(pool) //trainingDateAttendeeRepo := training.NewPostgresTrainingDateAttendeeRepository(pool)
f := faker.NewFaker(trainingRepo, trainingDateRepo) f := faker.NewFaker(trainingRepo, trainingDateRepo)

View file

@ -57,8 +57,8 @@ func Bootstrap(logger *zap.Logger) *server.Server {
} }
trainingRepo := training.NewPostgresTrainingRepository(pool) trainingRepo := training.NewPostgresTrainingRepository(pool)
trainingDateRepo := training.NewPostgresTrainingDateRepository(pool) trainingDateRepo := training.NewPostgresDateRepository(pool)
trainingDateAttendeeRepo := training.NewPostgresTrainingDateAttendeeRepository(pool) trainingDateAttendeeRepo := training.NewPostgresAttendeeRepository(pool)
apiHandlers := server.NewAPIHandlers(trainingRepo, trainingDateRepo, trainingDateAttendeeRepo) apiHandlers := server.NewAPIHandlers(trainingRepo, trainingDateRepo, trainingDateAttendeeRepo)
@ -78,8 +78,8 @@ func BootstrapInMemory(logger *zap.Logger) *server.Server {
} }
trainingRepository := training.NewInMemoryTrainingRepository() trainingRepository := training.NewInMemoryTrainingRepository()
trainingDateRepository := training.NewInMemoryTrainingDateRepository() trainingDateRepository := training.NewInMemoryDateRepository()
trainingDateAttendeeRepository := training.NewInMemoryTrainingDateAttendeeRepository() trainingDateAttendeeRepository := training.NewInMemoryAttendeeRepository()
f := faker.NewFaker(trainingRepository, trainingDateRepository) f := faker.NewFaker(trainingRepository, trainingDateRepository)
if err := f.GenerateFakeData(); err != nil { if err := f.GenerateFakeData(); err != nil {

View file

@ -10,11 +10,11 @@ import (
) )
type Faker struct { type Faker struct {
trainingRepository training.TrainingRepository trainingRepository training.Repository
trainingDateRepository training.TrainingDateRepository trainingDateRepository training.DateRepository
} }
func NewFaker(trainingRepository training.TrainingRepository, trainingDateRepository training.TrainingDateRepository) *Faker { func NewFaker(trainingRepository training.Repository, trainingDateRepository training.DateRepository) *Faker {
return &Faker{ return &Faker{
trainingRepository: trainingRepository, trainingRepository: trainingRepository,
trainingDateRepository: trainingDateRepository, trainingDateRepository: trainingDateRepository,
@ -27,7 +27,7 @@ func (f *Faker) GenerateFakeData() error {
Name: "Kubernetes", Name: "Kubernetes",
Days: 2, Days: 2,
Description: "Kubernetes", Description: "Kubernetes",
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(450), Amount: decimal.NewFromInt(450),
Currency: money.USD, Currency: money.USD,
@ -54,7 +54,7 @@ func (f *Faker) GenerateFakeData() error {
Name: "Terraform", Name: "Terraform",
Days: 1, Days: 1,
Description: "Terraform", Description: "Terraform",
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: money.USD, Currency: money.USD,
@ -81,7 +81,7 @@ func (f *Faker) GenerateFakeData() error {
Name: "RKE2", Name: "RKE2",
Days: 1, Days: 1,
Description: "RKE2", Description: "RKE2",
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: money.USD, Currency: money.USD,
@ -108,7 +108,7 @@ func (f *Faker) GenerateFakeData() error {
Name: "GitHub Actions", Name: "GitHub Actions",
Days: 1, Days: 1,
Description: "GitHub Actions", Description: "GitHub Actions",
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: money.USD, Currency: money.USD,
@ -135,7 +135,7 @@ func (f *Faker) GenerateFakeData() error {
Name: "GitLab CI", Name: "GitLab CI",
Days: 1, Days: 1,
Description: "GitLab CI", Description: "GitLab CI",
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: money.USD, Currency: money.USD,
@ -162,7 +162,7 @@ func (f *Faker) GenerateFakeData() error {
Name: "Prometheus", Name: "Prometheus",
Days: 2, Days: 2,
Description: "Prometheus", Description: "Prometheus",
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(450), Amount: decimal.NewFromInt(450),
Currency: money.USD, Currency: money.USD,
@ -230,7 +230,7 @@ func (f *Faker) GenerateFakeData() error {
} }
} }
td := training.TrainingDate{ td := training.Date{
Date: date, Date: date,
StartTime: date.Truncate(24 * time.Hour), StartTime: date.Truncate(24 * time.Hour),
Days: t.Days, Days: t.Days,

View file

@ -173,7 +173,7 @@ type TrainingDateAttendeeAttendanceUpdateRequest struct {
} }
// TrainingDateAttendeeID defines model for TrainingDateAttendeeID. // TrainingDateAttendeeID defines model for TrainingDateAttendeeID.
type TrainingDateAttendeeID = training.TrainingDateAttendeeID type TrainingDateAttendeeID = training.AttendeeID
// TrainingDateAttendeePaymentUpdateRequest defines model for TrainingDateAttendeePaymentUpdateRequest. // TrainingDateAttendeePaymentUpdateRequest defines model for TrainingDateAttendeePaymentUpdateRequest.
type TrainingDateAttendeePaymentUpdateRequest struct { type TrainingDateAttendeePaymentUpdateRequest struct {
@ -181,10 +181,10 @@ type TrainingDateAttendeePaymentUpdateRequest struct {
} }
// TrainingDateID defines model for TrainingDateID. // TrainingDateID defines model for TrainingDateID.
type TrainingDateID = training.TrainingDateID type TrainingDateID = training.DateID
// TrainingID defines model for TrainingID. // TrainingID defines model for TrainingID.
type TrainingID = training.TrainingID type TrainingID = training.ID
// TrainingPrice defines model for TrainingPrice. // TrainingPrice defines model for TrainingPrice.
type TrainingPrice struct { type TrainingPrice struct {
@ -2336,44 +2336,44 @@ func (sh *strictHandler) ListTrainingUpcomingDates(ctx *fiber.Ctx, trainingID Tr
// Base64 encoded, gzipped, json marshaled Swagger object // Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{ var swaggerSpec = []string{
"H4sIAAAAAAAC/+xczXLjuBF+FRSSW2hRk92t3dIpjj3ZdWUzdjx2Dpn4AJMtETMkwAFAe1QuPUlOeZfk", "H4sIAAAAAAAC/+xc3XLbuBV+FQzauzKi0t2d3dFV3Tjd9XQbu47di6a+gMkjEQkJMABoR+PRk/Sq79K+",
"vVIASIqkQJG0JEv26jQaCWx8/d9oNP2EA56knAFTEk+ecEoESUCBMP+7EYQyymbnRMGpUsBCgItz/UsI", "VwcASZEUKJL6sWSvrqJI4MF3/g8ODv2EA56knAFTEk+ecEoESUCBMP+7EYQyymbnRMGZUsBCgItz/UsI",
"MhA0VZQzPCnXIb0QFSvRxTn2MNULUqIi7GFGEsATrNxkPSzga0YFhHii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+FkCDi7ZX",
"ay832FGa9asD8wMdbTmU/1t3uSGvLLxm5yMlT8UrXW/AHXNOVpsBLr5f2DuLdzMGemb+4sfRLXu+E/Oa", "eH7t5QZ7SrN+dSh+oKMtB+9/6y435LWEl+x8pOSpeG3rFbhjzslqM8DF9zN7Z/EuxkDPzF/0OLllz3dg",
"fTK1DP22HDItDXy4Nw6Yr3P+RYpXMU/g/hsar2auwDGF1zlHqamYd4itUhps8oDEKIQHiHlq/cWsrc1K", "XrJPppah35ZDpqWBD/fGAfN1zr868SLmCdx/J+PFzBU4pvA65yg1FfOesFVKg00ekBiF8AAxT62/mLW1",
"T3w/1usiLtXku/F4bPSVb9akeFlYi0TknmeqNiOYj1Mv8S3uFv8PAAD//+Nifh+KVQAA", "WemJ78d6XcSlmnw3Ho+NvvLNmhQvC2uRiNzzTNVmBPNx6iW+xd3i/wEAAP//jH42mm5VAAA=",
} }
// GetSwagger returns the content of the embedded swagger specification file // GetSwagger returns the content of the embedded swagger specification file

View file

@ -13,12 +13,12 @@ import (
) )
type APIHandlers struct { type APIHandlers struct {
trainingRepository training.TrainingRepository trainingRepository training.Repository
trainingDateRepository training.TrainingDateRepository trainingDateRepository training.DateRepository
trainingDateAttendeeRepository training.TrainingDateAttendeeRepository trainingDateAttendeeRepository training.AttendeeRepository
} }
func NewAPIHandlers(trainingRepository training.TrainingRepository, trainingDateRepository training.TrainingDateRepository, trainingDateAttendeeRepository training.TrainingDateAttendeeRepository) *APIHandlers { func NewAPIHandlers(trainingRepository training.Repository, trainingDateRepository training.DateRepository, trainingDateAttendeeRepository training.AttendeeRepository) *APIHandlers {
return &APIHandlers{ return &APIHandlers{
trainingRepository: trainingRepository, trainingRepository: trainingRepository,
trainingDateRepository: trainingDateRepository, trainingDateRepository: trainingDateRepository,
@ -60,7 +60,7 @@ 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) {
pricing := make([]training.TrainingPrice, len(req.Body.Pricing)) pricing := make([]training.Price, len(req.Body.Pricing))
for idx, p := range req.Body.Pricing { for idx, p := range req.Body.Pricing {
amount, err := decimal.NewFromString(p.Amount) amount, err := decimal.NewFromString(p.Amount)
if err != nil { if err != nil {
@ -72,10 +72,10 @@ func (h *APIHandlers) CreateTraining(ctx context.Context, req CreateTrainingRequ
}}, nil }}, nil
} }
pricing[idx] = training.TrainingPrice{ pricing[idx] = training.Price{
Amount: amount, Amount: amount,
Currency: p.Currency, Currency: p.Currency,
Type: training.TrainingPriceType(p.Type), Type: training.PriceType(p.Type),
} }
} }
@ -169,7 +169,7 @@ func (h *APIHandlers) GetTraining(ctx context.Context, req GetTrainingRequestObj
} }
func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequestObject) (UpdateTrainingResponseObject, error) { func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequestObject) (UpdateTrainingResponseObject, error) {
pricing := make([]training.TrainingPrice, len(req.Body.Pricing)) pricing := make([]training.Price, len(req.Body.Pricing))
for idx, p := range req.Body.Pricing { for idx, p := range req.Body.Pricing {
amount, err := decimal.NewFromString(p.Amount) amount, err := decimal.NewFromString(p.Amount)
if err != nil { if err != nil {
@ -181,10 +181,10 @@ func (h *APIHandlers) UpdateTraining(ctx context.Context, req UpdateTrainingRequ
}}, nil }}, nil
} }
pricing[idx] = training.TrainingPrice{ pricing[idx] = training.Price{
Amount: amount, Amount: amount,
Currency: p.Currency, Currency: p.Currency,
Type: training.TrainingPriceType(p.Type), Type: training.PriceType(p.Type),
} }
} }
t := training.Training{ t := training.Training{
@ -273,7 +273,7 @@ func (h *APIHandlers) CreateTrainingDate(ctx context.Context, req CreateTraining
}}, nil }}, nil
} }
td := training.TrainingDate{ td := training.Date{
Date: req.Body.Date.Time, Date: req.Body.Date.Time,
StartTime: startTime, StartTime: startTime,
Days: req.Body.Days, Days: req.Body.Days,
@ -390,7 +390,7 @@ func (h *APIHandlers) UpdateTrainingDate(ctx context.Context, req UpdateTraining
}}, nil }}, nil
} }
td := training.TrainingDate{ td := training.Date{
ID: req.TrainingDateID, ID: req.TrainingDateID,
Date: req.Body.Date.Time, Date: req.Body.Date.Time,
StartTime: startTime, StartTime: startTime,
@ -577,7 +577,7 @@ func (h *APIHandlers) CreateTrainingDateAttendee(ctx context.Context, req Create
} }
} }
ta := training.TrainingDateAttendee{ ta := training.Attendee{
Name: req.Body.Name, Name: req.Body.Name,
Email: string(req.Body.Email), Email: string(req.Body.Email),
Phone: req.Body.Phone, Phone: req.Body.Phone,

View file

@ -80,8 +80,8 @@ func doDelete(t *testing.T, app *fiber.App, rawURL string) (*http.Response, erro
func TestServer(t *testing.T) { func TestServer(t *testing.T) {
//var err error //var err error
trainingRepo := training.NewInMemoryTrainingRepository() trainingRepo := training.NewInMemoryTrainingRepository()
trainingDateRepo := training.NewInMemoryTrainingDateRepository() trainingDateRepo := training.NewInMemoryDateRepository()
trainingDateAttendeeRepo := training.NewInMemoryTrainingDateAttendeeRepository() trainingDateAttendeeRepo := training.NewInMemoryAttendeeRepository()
handlers := NewAPIHandlers(trainingRepo, trainingDateRepo, trainingDateAttendeeRepo) handlers := NewAPIHandlers(trainingRepo, trainingDateRepo, trainingDateAttendeeRepo)
app := NewTestingServer(handlers) app := NewTestingServer(handlers)
@ -142,7 +142,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training", Name: "Testing Training",
Description: "This is a test training", Description: "This is a test training",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -166,7 +166,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training", Name: "Testing Training",
Description: "This is a test training", Description: "This is a test training",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -204,7 +204,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training", Name: "Testing Training",
Description: "This is a test training", Description: "This is a test training",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -243,7 +243,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -293,7 +293,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -318,7 +318,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -330,7 +330,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 0, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 0, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -362,7 +362,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -374,7 +374,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 0, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 0, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -423,7 +423,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -435,7 +435,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 0, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 0, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -482,7 +482,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -496,7 +496,7 @@ func TestServer(t *testing.T) {
upcomingTrainingCount := 5 upcomingTrainingCount := 5
for i := -4; i <= 5; i++ { for i := -4; i <= 5; i++ {
date := now.AddDate(0, 0, i) date := now.AddDate(0, 0, i)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -524,7 +524,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date 1", Name: "Testing Training for training date 1",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -538,7 +538,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date 2", Name: "Testing Training for training date 2",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -552,7 +552,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date 3", Name: "Testing Training for training date 3",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -568,7 +568,7 @@ func TestServer(t *testing.T) {
upcomingTrainingCount := 5 upcomingTrainingCount := 5
for i := -4; i <= upcomingTrainingCount; i++ { for i := -4; i <= upcomingTrainingCount; i++ {
date := now.AddDate(0, 0, i) date := now.AddDate(0, 0, i)
td1 := &training.TrainingDate{ td1 := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -581,7 +581,7 @@ func TestServer(t *testing.T) {
} }
_ = handlers.trainingDateRepository.Create(tr1.ID, td1) _ = handlers.trainingDateRepository.Create(tr1.ID, td1)
td2 := &training.TrainingDate{ td2 := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -594,7 +594,7 @@ func TestServer(t *testing.T) {
} }
_ = handlers.trainingDateRepository.Create(tr2.ID, td2) _ = handlers.trainingDateRepository.Create(tr2.ID, td2)
td3 := &training.TrainingDate{ td3 := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -628,7 +628,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -641,7 +641,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -668,7 +668,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -681,7 +681,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -726,7 +726,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -739,7 +739,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -753,9 +753,9 @@ func TestServer(t *testing.T) {
_ = handlers.trainingDateRepository.Create(tr.ID, td) _ = handlers.trainingDateRepository.Create(tr.ID, td)
attendeeCount := 9 attendeeCount := 9
attendees := make([]training.TrainingDateAttendee, attendeeCount) attendees := make([]training.Attendee, attendeeCount)
for i := range attendeeCount { for i := range attendeeCount {
nAtd := &training.TrainingDateAttendee{ nAtd := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",
@ -799,7 +799,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -812,7 +812,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -825,7 +825,7 @@ func TestServer(t *testing.T) {
} }
_ = handlers.trainingDateRepository.Create(tr.ID, td) _ = handlers.trainingDateRepository.Create(tr.ID, td)
attendee := &training.TrainingDateAttendee{ attendee := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",
@ -862,7 +862,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -875,7 +875,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -888,7 +888,7 @@ func TestServer(t *testing.T) {
} }
_ = handlers.trainingDateRepository.Create(tr.ID, td) _ = handlers.trainingDateRepository.Create(tr.ID, td)
attendee := &training.TrainingDateAttendee{ attendee := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",
@ -935,7 +935,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -948,7 +948,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -961,7 +961,7 @@ func TestServer(t *testing.T) {
} }
_ = handlers.trainingDateRepository.Create(tr.ID, td) _ = handlers.trainingDateRepository.Create(tr.ID, td)
attendee := &training.TrainingDateAttendee{ attendee := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",
@ -991,7 +991,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -1004,7 +1004,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -1021,7 +1021,7 @@ func TestServer(t *testing.T) {
Paid: true, Paid: true,
} }
attendee := &training.TrainingDateAttendee{ attendee := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",
@ -1064,7 +1064,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -1077,7 +1077,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -1094,7 +1094,7 @@ func TestServer(t *testing.T) {
Attended: true, Attended: true,
} }
attendee := &training.TrainingDateAttendee{ attendee := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",
@ -1137,7 +1137,7 @@ func TestServer(t *testing.T) {
Name: "Testing Training for training date", Name: "Testing Training for training date",
Description: "This is a test training for training date", Description: "This is a test training for training date",
Days: 1, Days: 1,
Pricing: []training.TrainingPrice{ Pricing: []training.Price{
{ {
Amount: decimal.NewFromInt(200), Amount: decimal.NewFromInt(200),
Currency: "EUR", Currency: "EUR",
@ -1150,7 +1150,7 @@ func TestServer(t *testing.T) {
date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC) date := time.Date(2024, time.May, 1, 9, 0, 0, 0, time.UTC)
td := &training.TrainingDate{ td := &training.Date{
Address: "Test Address 123, NYC", Address: "Test Address 123, NYC",
Capacity: 12, Capacity: 12,
Date: date, Date: date,
@ -1165,7 +1165,7 @@ func TestServer(t *testing.T) {
attendeeCount := 9 attendeeCount := 9
for range attendeeCount { for range attendeeCount {
nAtd := &training.TrainingDateAttendee{ nAtd := &training.Attendee{
Name: "John Doe", Name: "John Doe",
Email: "john.doe@example.com", Email: "john.doe@example.com",
Company: "Acme Inc.", Company: "Acme Inc.",

View file

@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS training.dates (
CONSTRAINT allowed_currencies CHECK (price_currency IN ('USD', 'EUR', 'CZK')) CONSTRAINT allowed_currencies CHECK (price_currency IN ('USD', 'EUR', 'CZK'))
); );
CREATE TABLE IF NOT EXISTS training.date_attendees ( CREATE TABLE IF NOT EXISTS training.attendees (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
date_id SERIAL REFERENCES training.dates(id), date_id SERIAL REFERENCES training.dates(id),
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,

View file

@ -6,14 +6,14 @@ import (
) )
type InMemoryTrainingRepository struct { type InMemoryTrainingRepository struct {
trainings map[TrainingID]Training trainings map[ID]Training
lock sync.RWMutex lock sync.RWMutex
ai int ai int
} }
func NewInMemoryTrainingRepository() *InMemoryTrainingRepository { func NewInMemoryTrainingRepository() *InMemoryTrainingRepository {
return &InMemoryTrainingRepository{ return &InMemoryTrainingRepository{
trainings: make(map[TrainingID]Training), trainings: make(map[ID]Training),
ai: 1, ai: 1,
} }
} }
@ -28,7 +28,7 @@ func (r *InMemoryTrainingRepository) Create(training *Training) error {
return nil return nil
} }
func (r *InMemoryTrainingRepository) FindByID(id TrainingID) (*Training, error) { func (r *InMemoryTrainingRepository) FindByID(id ID) (*Training, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
@ -58,7 +58,7 @@ func (r *InMemoryTrainingRepository) Update(training *Training) error {
return nil return nil
} }
func (r *InMemoryTrainingRepository) Delete(id TrainingID) error { func (r *InMemoryTrainingRepository) Delete(id ID) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@ -71,23 +71,23 @@ func (r *InMemoryTrainingRepository) Delete(id TrainingID) error {
return nil return nil
} }
type InMemoryTrainingDateRepository struct { type InMemoryDateRepository struct {
trainingDates map[TrainingDateID]TrainingDate trainingDates map[DateID]Date
trainingToDates map[TrainingID][]TrainingDateID trainingToDates map[ID][]DateID
lock sync.RWMutex lock sync.RWMutex
ai int ai int
} }
func NewInMemoryTrainingDateRepository() *InMemoryTrainingDateRepository { func NewInMemoryDateRepository() *InMemoryDateRepository {
return &InMemoryTrainingDateRepository{ return &InMemoryDateRepository{
trainingDates: make(map[TrainingDateID]TrainingDate), trainingDates: make(map[DateID]Date),
trainingToDates: make(map[TrainingID][]TrainingDateID), trainingToDates: make(map[ID][]DateID),
ai: 1, ai: 1,
} }
} }
func (r *InMemoryTrainingDateRepository) Create(trainingID TrainingID, trainingDate *TrainingDate) error { func (r *InMemoryDateRepository) Create(trainingID ID, trainingDate *Date) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@ -100,7 +100,7 @@ func (r *InMemoryTrainingDateRepository) Create(trainingID TrainingID, trainingD
return nil return nil
} }
func (r *InMemoryTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingDate, error) { func (r *InMemoryDateRepository) FindByID(id DateID) (*Date, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
@ -111,11 +111,11 @@ func (r *InMemoryTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingD
return &date, nil return &date, nil
} }
func (r *InMemoryTrainingDateRepository) FindAll() ([]TrainingDate, error) { func (r *InMemoryDateRepository) FindAll() ([]Date, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
dates := make([]TrainingDate, len(r.trainingDates)) dates := make([]Date, len(r.trainingDates))
for _, date := range r.trainingDates { for _, date := range r.trainingDates {
dates = append(dates, date) dates = append(dates, date)
} }
@ -123,11 +123,11 @@ func (r *InMemoryTrainingDateRepository) FindAll() ([]TrainingDate, error) {
return dates, nil return dates, nil
} }
func (r *InMemoryTrainingDateRepository) FindAllByTrainingID(trainingID TrainingID) ([]TrainingDate, error) { func (r *InMemoryDateRepository) FindAllByTrainingID(trainingID ID) ([]Date, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
dates := make([]TrainingDate, 0) dates := make([]Date, 0)
for _, id := range r.trainingToDates[trainingID] { for _, id := range r.trainingToDates[trainingID] {
dates = append(dates, r.trainingDates[id]) dates = append(dates, r.trainingDates[id])
} }
@ -135,12 +135,12 @@ func (r *InMemoryTrainingDateRepository) FindAllByTrainingID(trainingID Training
return dates, nil return dates, nil
} }
func (r *InMemoryTrainingDateRepository) FindUpcomingByTrainingID(trainingID TrainingID) ([]TrainingDate, error) { func (r *InMemoryDateRepository) FindUpcomingByTrainingID(trainingID ID) ([]Date, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
now := time.Now() now := time.Now()
var dates []TrainingDate var dates []Date
for _, id := range r.trainingToDates[trainingID] { for _, id := range r.trainingToDates[trainingID] {
date := r.trainingDates[id] date := r.trainingDates[id]
if date.Date.After(now) { if date.Date.After(now) {
@ -151,7 +151,7 @@ func (r *InMemoryTrainingDateRepository) FindUpcomingByTrainingID(trainingID Tra
return dates, nil return dates, nil
} }
func (r *InMemoryTrainingDateRepository) Update(trainingDate *TrainingDate) error { func (r *InMemoryDateRepository) Update(trainingDate *Date) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@ -161,7 +161,7 @@ func (r *InMemoryTrainingDateRepository) Update(trainingDate *TrainingDate) erro
return nil return nil
} }
func (r *InMemoryTrainingDateRepository) Delete(id TrainingDateID) error { func (r *InMemoryDateRepository) Delete(id DateID) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@ -182,23 +182,23 @@ func (r *InMemoryTrainingDateRepository) Delete(id TrainingDateID) error {
return nil return nil
} }
type InMemoryTrainingDateAttendeeRepository struct { type InMemoryAttendeeRepository struct {
attendees map[TrainingDateAttendeeID]TrainingDateAttendee attendees map[AttendeeID]Attendee
dateToAttendees map[TrainingDateID][]TrainingDateAttendeeID dateToAttendees map[DateID][]AttendeeID
lock sync.RWMutex lock sync.RWMutex
ai int ai int
} }
func NewInMemoryTrainingDateAttendeeRepository() *InMemoryTrainingDateAttendeeRepository { func NewInMemoryAttendeeRepository() *InMemoryAttendeeRepository {
return &InMemoryTrainingDateAttendeeRepository{ return &InMemoryAttendeeRepository{
attendees: make(map[TrainingDateAttendeeID]TrainingDateAttendee), attendees: make(map[AttendeeID]Attendee),
dateToAttendees: make(map[TrainingDateID][]TrainingDateAttendeeID), dateToAttendees: make(map[DateID][]AttendeeID),
ai: 1, ai: 1,
} }
} }
func (r *InMemoryTrainingDateAttendeeRepository) Create(trainingDateID TrainingDateID, attendee *TrainingDateAttendee) error { func (r *InMemoryAttendeeRepository) Create(trainingDateID DateID, attendee *Attendee) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@ -212,7 +212,7 @@ func (r *InMemoryTrainingDateAttendeeRepository) Create(trainingDateID TrainingD
return nil return nil
} }
func (r *InMemoryTrainingDateAttendeeRepository) FindByID(id TrainingDateAttendeeID) (*TrainingDateAttendee, error) { func (r *InMemoryAttendeeRepository) FindByID(id AttendeeID) (*Attendee, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
@ -223,11 +223,11 @@ func (r *InMemoryTrainingDateAttendeeRepository) FindByID(id TrainingDateAttende
return &attendee, nil return &attendee, nil
} }
func (r *InMemoryTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttendee, error) { func (r *InMemoryAttendeeRepository) FindAll() ([]Attendee, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
attendees := make([]TrainingDateAttendee, len(r.attendees)) attendees := make([]Attendee, len(r.attendees))
for _, attendee := range r.attendees { for _, attendee := range r.attendees {
attendees = append(attendees, attendee) attendees = append(attendees, attendee)
} }
@ -235,11 +235,11 @@ func (r *InMemoryTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttend
return attendees, nil return attendees, nil
} }
func (r *InMemoryTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainingDateID TrainingDateID) ([]TrainingDateAttendee, error) { func (r *InMemoryAttendeeRepository) FindAllByTrainingDateID(trainingDateID DateID) ([]Attendee, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
attendees := make([]TrainingDateAttendee, 0) attendees := make([]Attendee, 0)
for _, id := range r.dateToAttendees[trainingDateID] { for _, id := range r.dateToAttendees[trainingDateID] {
attendees = append(attendees, r.attendees[id]) attendees = append(attendees, r.attendees[id])
} }
@ -247,7 +247,7 @@ func (r *InMemoryTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainin
return attendees, nil return attendees, nil
} }
func (r *InMemoryTrainingDateAttendeeRepository) Update(attendee *TrainingDateAttendee) error { func (r *InMemoryAttendeeRepository) Update(attendee *Attendee) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
@ -257,7 +257,7 @@ func (r *InMemoryTrainingDateAttendeeRepository) Update(attendee *TrainingDateAt
return nil return nil
} }
func (r *InMemoryTrainingDateAttendeeRepository) Delete(id TrainingDateAttendeeID) error { func (r *InMemoryAttendeeRepository) Delete(id AttendeeID) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()

View file

@ -6,35 +6,35 @@ import (
"time" "time"
) )
type TrainingID = int type ID = int
type Training struct { type Training struct {
ID TrainingID ID ID
Name string Name string
Days int8 Days int8
Description string Description string
Pricing []TrainingPrice `db:"-"` Pricing []Price `db:"-"`
} }
type TrainingPrice struct { type Price struct {
Amount decimal.Decimal Amount decimal.Decimal
Currency money.Currency Currency money.Currency
Type TrainingPriceType Type PriceType
} }
type TrainingPriceType string type PriceType string
const ( const (
OpenTrainingPrice TrainingPriceType = "OPEN" OpenTrainingPrice PriceType = "OPEN"
CorporateTrainingPrice TrainingPriceType = "CORPORATE" CorporateTrainingPrice PriceType = "CORPORATE"
) )
type TrainingDateID = int type DateID = int
type TrainingDate struct { type Date struct {
trainingID TrainingID trainingID ID
ID TrainingDateID ID DateID
Date time.Time Date time.Time
StartTime time.Time StartTime time.Time
Days int8 Days int8
@ -46,12 +46,12 @@ type TrainingDate struct {
PriceCurrency money.Currency `db:"price_currency"` PriceCurrency money.Currency `db:"price_currency"`
} }
type TrainingDateAttendeeID = int type AttendeeID = int
type TrainingDateAttendee struct { type Attendee struct {
trainingDateID TrainingDateID trainingDateID DateID
ID TrainingDateAttendeeID ID AttendeeID
Name string Name string
Email string Email string
Phone string Phone string

View file

@ -66,7 +66,7 @@ func (r *PostgresTrainingRepository) Create(training *Training) error {
return nil return nil
} }
func (r *PostgresTrainingRepository) FindByID(id TrainingID) (*Training, error) { func (r *PostgresTrainingRepository) FindByID(id ID) (*Training, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -91,12 +91,12 @@ func (r *PostgresTrainingRepository) FindByID(id TrainingID) (*Training, error)
} }
defer rows.Close() defer rows.Close()
training.Pricing = make([]TrainingPrice, 0) training.Pricing = make([]Price, 0)
training.Pricing, err = pgx.CollectRows[TrainingPrice](rows, func(row pgx.CollectableRow) (TrainingPrice, error) { training.Pricing, err = pgx.CollectRows[Price](rows, func(row pgx.CollectableRow) (Price, error) {
var price TrainingPrice var price Price
err := row.Scan(&price.Amount, &price.Currency, &price.Type) err := row.Scan(&price.Amount, &price.Currency, &price.Type)
if err != nil { if err != nil {
return TrainingPrice{}, err return Price{}, err
} }
return price, nil return price, nil
}) })
@ -132,7 +132,7 @@ func (r *PostgresTrainingRepository) FindAll() ([]Training, error) {
return Training{}, queryErr return Training{}, queryErr
} }
training.Pricing, scanErr = pgx.CollectRows(priceRows, pgx.RowToStructByName[TrainingPrice]) training.Pricing, scanErr = pgx.CollectRows(priceRows, pgx.RowToStructByName[Price])
if scanErr != nil { if scanErr != nil {
return Training{}, scanErr return Training{}, scanErr
} }
@ -198,7 +198,7 @@ func (r *PostgresTrainingRepository) Update(training *Training) error {
return nil return nil
} }
func (r *PostgresTrainingRepository) Delete(id TrainingID) error { func (r *PostgresTrainingRepository) Delete(id ID) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -233,15 +233,15 @@ func (r *PostgresTrainingRepository) Delete(id TrainingID) error {
return nil return nil
} }
type PostgresTrainingDateRepository struct { type PostgresDateRepository struct {
pg *pgxpool.Pool pg *pgxpool.Pool
} }
func NewPostgresTrainingDateRepository(pg *pgxpool.Pool) *PostgresTrainingDateRepository { func NewPostgresDateRepository(pg *pgxpool.Pool) *PostgresDateRepository {
return &PostgresTrainingDateRepository{pg: pg} return &PostgresDateRepository{pg: pg}
} }
func (r *PostgresTrainingDateRepository) Create(trainingID TrainingID, trainingDate *TrainingDate) error { func (r *PostgresDateRepository) Create(trainingID ID, trainingDate *Date) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -266,11 +266,11 @@ func (r *PostgresTrainingDateRepository) Create(trainingID TrainingID, trainingD
return nil return nil
} }
func (r *PostgresTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingDate, error) { func (r *PostgresDateRepository) FindByID(id DateID) (*Date, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
var trainingDate TrainingDate var trainingDate Date
err := r.pg.QueryRow(ctx, `SELECT * FROM training.dates WHERE id = $1`, id). err := r.pg.QueryRow(ctx, `SELECT * FROM training.dates WHERE id = $1`, id).
Scan( Scan(
&trainingDate.ID, &trainingDate.ID,
@ -292,7 +292,7 @@ func (r *PostgresTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingD
return &trainingDate, nil return &trainingDate, nil
} }
func (r *PostgresTrainingDateRepository) FindAll() ([]TrainingDate, error) { func (r *PostgresDateRepository) FindAll() ([]Date, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -302,9 +302,9 @@ func (r *PostgresTrainingDateRepository) FindAll() ([]TrainingDate, error) {
} }
defer rows.Close() defer rows.Close()
var trainingDates []TrainingDate var trainingDates []Date
for rows.Next() { for rows.Next() {
var trainingDate TrainingDate var trainingDate Date
err := rows.Scan( err := rows.Scan(
&trainingDate.ID, &trainingDate.ID,
&trainingDate.trainingID, &trainingDate.trainingID,
@ -328,7 +328,7 @@ func (r *PostgresTrainingDateRepository) FindAll() ([]TrainingDate, error) {
return trainingDates, nil return trainingDates, nil
} }
func (r *PostgresTrainingDateRepository) FindAllByTrainingID(trainingID TrainingID) ([]TrainingDate, error) { func (r *PostgresDateRepository) FindAllByTrainingID(trainingID ID) ([]Date, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -338,9 +338,9 @@ func (r *PostgresTrainingDateRepository) FindAllByTrainingID(trainingID Training
} }
defer rows.Close() defer rows.Close()
var trainingDates []TrainingDate var trainingDates []Date
for rows.Next() { for rows.Next() {
var trainingDate TrainingDate var trainingDate Date
err := rows.Scan( err := rows.Scan(
&trainingDate.ID, &trainingDate.ID,
&trainingDate.trainingID, &trainingDate.trainingID,
@ -364,7 +364,7 @@ func (r *PostgresTrainingDateRepository) FindAllByTrainingID(trainingID Training
return trainingDates, nil return trainingDates, nil
} }
func (r *PostgresTrainingDateRepository) FindUpcomingByTrainingID(trainingID TrainingID) ([]TrainingDate, error) { func (r *PostgresDateRepository) FindUpcomingByTrainingID(trainingID ID) ([]Date, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -377,9 +377,9 @@ func (r *PostgresTrainingDateRepository) FindUpcomingByTrainingID(trainingID Tra
} }
defer rows.Close() defer rows.Close()
var trainingDates []TrainingDate var trainingDates []Date
for rows.Next() { for rows.Next() {
var trainingDate TrainingDate var trainingDate Date
err := rows.Scan( err := rows.Scan(
&trainingDate.ID, &trainingDate.ID,
&trainingDate.trainingID, &trainingDate.trainingID,
@ -403,7 +403,7 @@ func (r *PostgresTrainingDateRepository) FindUpcomingByTrainingID(trainingID Tra
return trainingDates, nil return trainingDates, nil
} }
func (r *PostgresTrainingDateRepository) Update(trainingDate *TrainingDate) error { func (r *PostgresDateRepository) Update(trainingDate *Date) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -419,7 +419,7 @@ func (r *PostgresTrainingDateRepository) Update(trainingDate *TrainingDate) erro
return nil return nil
} }
func (r *PostgresTrainingDateRepository) Delete(id TrainingDateID) error { func (r *PostgresDateRepository) Delete(id DateID) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -431,20 +431,20 @@ func (r *PostgresTrainingDateRepository) Delete(id TrainingDateID) error {
return nil return nil
} }
type PostgresTrainingDateAttendeeRepository struct { type PostgresAttendeeRepository struct {
pg *pgxpool.Pool pg *pgxpool.Pool
} }
func NewPostgresTrainingDateAttendeeRepository(pg *pgxpool.Pool) *PostgresTrainingDateAttendeeRepository { func NewPostgresAttendeeRepository(pg *pgxpool.Pool) *PostgresAttendeeRepository {
return &PostgresTrainingDateAttendeeRepository{pg: pg} return &PostgresAttendeeRepository{pg: pg}
} }
func (r *PostgresTrainingDateAttendeeRepository) Create(trainingDateID TrainingDateID, attendee *TrainingDateAttendee) error { func (r *PostgresAttendeeRepository) Create(trainingDateID DateID, attendee *Attendee) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
err := r.pg.QueryRow(ctx, ` err := r.pg.QueryRow(ctx, `
INSERT INTO training.date_attendees (date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency) INSERT INTO training.attendees (date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id RETURNING id
`, trainingDateID, attendee.Name, attendee.Email, attendee.Phone, attendee.Company, attendee.Position, attendee.IsStudent, attendee.HasPaid, attendee.HasAttended, attendee.BillAmount, attendee.BillCurrency). `, trainingDateID, attendee.Name, attendee.Email, attendee.Phone, attendee.Company, attendee.Position, attendee.IsStudent, attendee.HasPaid, attendee.HasAttended, attendee.BillAmount, attendee.BillCurrency).
@ -456,14 +456,14 @@ func (r *PostgresTrainingDateAttendeeRepository) Create(trainingDateID TrainingD
return nil return nil
} }
func (r *PostgresTrainingDateAttendeeRepository) FindByID(id TrainingDateAttendeeID) (*TrainingDateAttendee, error) { func (r *PostgresAttendeeRepository) FindByID(id AttendeeID) (*Attendee, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
var attendee TrainingDateAttendee var attendee Attendee
err := r.pg.QueryRow(ctx, ` err := r.pg.QueryRow(ctx, `
SELECT id, date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency SELECT id, date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency
FROM training.date_attendees FROM training.attendees
WHERE id = $1 WHERE id = $1
`, id).Scan(&attendee.ID, &attendee.trainingDateID, &attendee.Name, &attendee.Email, &attendee.Phone, &attendee.Company, &attendee.Position, &attendee.IsStudent, &attendee.HasPaid, &attendee.HasAttended, &attendee.BillAmount, &attendee.BillCurrency) `, id).Scan(&attendee.ID, &attendee.trainingDateID, &attendee.Name, &attendee.Email, &attendee.Phone, &attendee.Company, &attendee.Position, &attendee.IsStudent, &attendee.HasPaid, &attendee.HasAttended, &attendee.BillAmount, &attendee.BillCurrency)
if err != nil { if err != nil {
@ -473,22 +473,22 @@ func (r *PostgresTrainingDateAttendeeRepository) FindByID(id TrainingDateAttende
return &attendee, nil return &attendee, nil
} }
func (r *PostgresTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttendee, error) { func (r *PostgresAttendeeRepository) FindAll() ([]Attendee, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
rows, err := r.pg.Query(ctx, ` rows, err := r.pg.Query(ctx, `
SELECT id, date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency SELECT id, date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency
FROM training.date_attendees FROM training.attendees
`) `)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() defer rows.Close()
var attendees []TrainingDateAttendee var attendees []Attendee
for rows.Next() { for rows.Next() {
var attendee TrainingDateAttendee var attendee Attendee
err := rows.Scan(&attendee.ID, &attendee.trainingDateID, &attendee.Name, &attendee.Email, &attendee.Phone, &attendee.Company, &attendee.Position, &attendee.IsStudent, &attendee.HasPaid, &attendee.HasAttended, &attendee.BillAmount, &attendee.BillCurrency) err := rows.Scan(&attendee.ID, &attendee.trainingDateID, &attendee.Name, &attendee.Email, &attendee.Phone, &attendee.Company, &attendee.Position, &attendee.IsStudent, &attendee.HasPaid, &attendee.HasAttended, &attendee.BillAmount, &attendee.BillCurrency)
if err != nil { if err != nil {
return nil, err return nil, err
@ -500,13 +500,13 @@ func (r *PostgresTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttend
return attendees, nil return attendees, nil
} }
func (r *PostgresTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainingDateID TrainingDateID) ([]TrainingDateAttendee, error) { func (r *PostgresAttendeeRepository) FindAllByTrainingDateID(trainingDateID DateID) ([]Attendee, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
rows, err := r.pg.Query(ctx, ` rows, err := r.pg.Query(ctx, `
SELECT id, date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency SELECT id, date_id, name, email, phone, company, position, is_student, has_paid, has_attended, bill_amount, bill_currency
FROM training.date_attendees FROM training.attendees
WHERE date_id = $1 WHERE date_id = $1
`, trainingDateID) `, trainingDateID)
if err != nil { if err != nil {
@ -514,9 +514,9 @@ func (r *PostgresTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainin
} }
defer rows.Close() defer rows.Close()
var attendees []TrainingDateAttendee var attendees []Attendee
for rows.Next() { for rows.Next() {
var attendee TrainingDateAttendee var attendee Attendee
err := rows.Scan(&attendee.ID, &attendee.trainingDateID, &attendee.Name, &attendee.Email, &attendee.Phone, &attendee.Company, &attendee.Position, &attendee.IsStudent, &attendee.HasPaid, &attendee.HasAttended, &attendee.BillAmount, &attendee.BillCurrency) err := rows.Scan(&attendee.ID, &attendee.trainingDateID, &attendee.Name, &attendee.Email, &attendee.Phone, &attendee.Company, &attendee.Position, &attendee.IsStudent, &attendee.HasPaid, &attendee.HasAttended, &attendee.BillAmount, &attendee.BillCurrency)
if err != nil { if err != nil {
return nil, err return nil, err
@ -528,12 +528,12 @@ func (r *PostgresTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainin
return attendees, nil return attendees, nil
} }
func (r *PostgresTrainingDateAttendeeRepository) Update(attendee *TrainingDateAttendee) error { func (r *PostgresAttendeeRepository) Update(attendee *Attendee) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
_, err := r.pg.Exec(ctx, ` _, err := r.pg.Exec(ctx, `
UPDATE training.date_attendees UPDATE training.attendees
SET name = $1, email = $2, phone = $3, company = $4, position = $5, is_student = $6, has_paid = $7, has_attended = $8, bill_amount = $9, bill_currency = $10 SET name = $1, email = $2, phone = $3, company = $4, position = $5, is_student = $6, has_paid = $7, has_attended = $8, bill_amount = $9, bill_currency = $10
WHERE id = $10 WHERE id = $10
`, attendee.Name, attendee.Email, attendee.Phone, attendee.Company, attendee.Position, attendee.IsStudent, attendee.HasPaid, attendee.HasAttended, attendee.BillAmount, attendee.BillCurrency, attendee.ID) `, attendee.Name, attendee.Email, attendee.Phone, attendee.Company, attendee.Position, attendee.IsStudent, attendee.HasPaid, attendee.HasAttended, attendee.BillAmount, attendee.BillCurrency, attendee.ID)
@ -544,11 +544,11 @@ func (r *PostgresTrainingDateAttendeeRepository) Update(attendee *TrainingDateAt
return nil return nil
} }
func (r *PostgresTrainingDateAttendeeRepository) Delete(id TrainingDateAttendeeID) error { func (r *PostgresAttendeeRepository) Delete(id AttendeeID) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
_, err := r.pg.Exec(ctx, `DELETE FROM training.date_attendees WHERE id = $1`, id) _, err := r.pg.Exec(ctx, `DELETE FROM training.attendees WHERE id = $1`, id)
if err != nil { if err != nil {
return err return err
} }

View file

@ -1,28 +1,28 @@
package training package training
type TrainingRepository interface { type Repository interface {
Create(training *Training) error Create(training *Training) error
FindByID(id TrainingID) (*Training, error) FindByID(id ID) (*Training, error)
FindAll() ([]Training, error) FindAll() ([]Training, error)
Update(training *Training) error Update(training *Training) error
Delete(id TrainingID) error Delete(id ID) error
} }
type TrainingDateRepository interface { type DateRepository interface {
Create(trainingID TrainingID, trainingDate *TrainingDate) error Create(trainingID ID, trainingDate *Date) error
FindByID(id TrainingDateID) (*TrainingDate, error) FindByID(id DateID) (*Date, error)
FindAll() ([]TrainingDate, error) FindAll() ([]Date, error)
FindAllByTrainingID(trainingID TrainingID) ([]TrainingDate, error) FindAllByTrainingID(trainingID ID) ([]Date, error)
FindUpcomingByTrainingID(trainingID TrainingID) ([]TrainingDate, error) FindUpcomingByTrainingID(trainingID ID) ([]Date, error)
Update(trainingDate *TrainingDate) error Update(trainingDate *Date) error
Delete(id TrainingDateID) error Delete(id DateID) error
} }
type TrainingDateAttendeeRepository interface { type AttendeeRepository interface {
Create(trainingDateID TrainingDateID, attendee *TrainingDateAttendee) error Create(trainingDateID DateID, attendee *Attendee) error
FindByID(id TrainingDateAttendeeID) (*TrainingDateAttendee, error) FindByID(id AttendeeID) (*Attendee, error)
FindAll() ([]TrainingDateAttendee, error) FindAll() ([]Attendee, error)
FindAllByTrainingDateID(trainingDateID TrainingDateID) ([]TrainingDateAttendee, error) FindAllByTrainingDateID(trainingDateID DateID) ([]Attendee, error)
Update(attendee *TrainingDateAttendee) error Update(attendee *Attendee) error
Delete(id TrainingDateAttendeeID) error Delete(id AttendeeID) error
} }