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

@ -66,7 +66,7 @@ func (r *PostgresTrainingRepository) Create(training *Training) error {
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)
defer cancel()
@ -91,12 +91,12 @@ func (r *PostgresTrainingRepository) FindByID(id TrainingID) (*Training, error)
}
defer rows.Close()
training.Pricing = make([]TrainingPrice, 0)
training.Pricing, err = pgx.CollectRows[TrainingPrice](rows, func(row pgx.CollectableRow) (TrainingPrice, error) {
var price TrainingPrice
training.Pricing = make([]Price, 0)
training.Pricing, err = pgx.CollectRows[Price](rows, func(row pgx.CollectableRow) (Price, error) {
var price Price
err := row.Scan(&price.Amount, &price.Currency, &price.Type)
if err != nil {
return TrainingPrice{}, err
return Price{}, err
}
return price, nil
})
@ -132,7 +132,7 @@ func (r *PostgresTrainingRepository) FindAll() ([]Training, error) {
return Training{}, queryErr
}
training.Pricing, scanErr = pgx.CollectRows(priceRows, pgx.RowToStructByName[TrainingPrice])
training.Pricing, scanErr = pgx.CollectRows(priceRows, pgx.RowToStructByName[Price])
if scanErr != nil {
return Training{}, scanErr
}
@ -198,7 +198,7 @@ func (r *PostgresTrainingRepository) Update(training *Training) error {
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)
defer cancel()
@ -233,15 +233,15 @@ func (r *PostgresTrainingRepository) Delete(id TrainingID) error {
return nil
}
type PostgresTrainingDateRepository struct {
type PostgresDateRepository struct {
pg *pgxpool.Pool
}
func NewPostgresTrainingDateRepository(pg *pgxpool.Pool) *PostgresTrainingDateRepository {
return &PostgresTrainingDateRepository{pg: pg}
func NewPostgresDateRepository(pg *pgxpool.Pool) *PostgresDateRepository {
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)
defer cancel()
@ -266,11 +266,11 @@ func (r *PostgresTrainingDateRepository) Create(trainingID TrainingID, trainingD
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)
defer cancel()
var trainingDate TrainingDate
var trainingDate Date
err := r.pg.QueryRow(ctx, `SELECT * FROM training.dates WHERE id = $1`, id).
Scan(
&trainingDate.ID,
@ -292,7 +292,7 @@ func (r *PostgresTrainingDateRepository) FindByID(id TrainingDateID) (*TrainingD
return &trainingDate, nil
}
func (r *PostgresTrainingDateRepository) FindAll() ([]TrainingDate, error) {
func (r *PostgresDateRepository) FindAll() ([]Date, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
@ -302,9 +302,9 @@ func (r *PostgresTrainingDateRepository) FindAll() ([]TrainingDate, error) {
}
defer rows.Close()
var trainingDates []TrainingDate
var trainingDates []Date
for rows.Next() {
var trainingDate TrainingDate
var trainingDate Date
err := rows.Scan(
&trainingDate.ID,
&trainingDate.trainingID,
@ -328,7 +328,7 @@ func (r *PostgresTrainingDateRepository) FindAll() ([]TrainingDate, error) {
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)
defer cancel()
@ -338,9 +338,9 @@ func (r *PostgresTrainingDateRepository) FindAllByTrainingID(trainingID Training
}
defer rows.Close()
var trainingDates []TrainingDate
var trainingDates []Date
for rows.Next() {
var trainingDate TrainingDate
var trainingDate Date
err := rows.Scan(
&trainingDate.ID,
&trainingDate.trainingID,
@ -364,7 +364,7 @@ func (r *PostgresTrainingDateRepository) FindAllByTrainingID(trainingID Training
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)
defer cancel()
@ -377,9 +377,9 @@ func (r *PostgresTrainingDateRepository) FindUpcomingByTrainingID(trainingID Tra
}
defer rows.Close()
var trainingDates []TrainingDate
var trainingDates []Date
for rows.Next() {
var trainingDate TrainingDate
var trainingDate Date
err := rows.Scan(
&trainingDate.ID,
&trainingDate.trainingID,
@ -403,7 +403,7 @@ func (r *PostgresTrainingDateRepository) FindUpcomingByTrainingID(trainingID Tra
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)
defer cancel()
@ -419,7 +419,7 @@ func (r *PostgresTrainingDateRepository) Update(trainingDate *TrainingDate) erro
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)
defer cancel()
@ -431,20 +431,20 @@ func (r *PostgresTrainingDateRepository) Delete(id TrainingDateID) error {
return nil
}
type PostgresTrainingDateAttendeeRepository struct {
type PostgresAttendeeRepository struct {
pg *pgxpool.Pool
}
func NewPostgresTrainingDateAttendeeRepository(pg *pgxpool.Pool) *PostgresTrainingDateAttendeeRepository {
return &PostgresTrainingDateAttendeeRepository{pg: pg}
func NewPostgresAttendeeRepository(pg *pgxpool.Pool) *PostgresAttendeeRepository {
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)
defer cancel()
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)
RETURNING id
`, 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
}
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)
defer cancel()
var attendee TrainingDateAttendee
var attendee Attendee
err := r.pg.QueryRow(ctx, `
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
`, 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 {
@ -473,22 +473,22 @@ func (r *PostgresTrainingDateAttendeeRepository) FindByID(id TrainingDateAttende
return &attendee, nil
}
func (r *PostgresTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttendee, error) {
func (r *PostgresAttendeeRepository) FindAll() ([]Attendee, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
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
FROM training.date_attendees
FROM training.attendees
`)
if err != nil {
return nil, err
}
defer rows.Close()
var attendees []TrainingDateAttendee
var attendees []Attendee
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)
if err != nil {
return nil, err
@ -500,13 +500,13 @@ func (r *PostgresTrainingDateAttendeeRepository) FindAll() ([]TrainingDateAttend
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)
defer cancel()
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
FROM training.date_attendees
FROM training.attendees
WHERE date_id = $1
`, trainingDateID)
if err != nil {
@ -514,9 +514,9 @@ func (r *PostgresTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainin
}
defer rows.Close()
var attendees []TrainingDateAttendee
var attendees []Attendee
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)
if err != nil {
return nil, err
@ -528,12 +528,12 @@ func (r *PostgresTrainingDateAttendeeRepository) FindAllByTrainingDateID(trainin
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)
defer cancel()
_, 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
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)
@ -544,11 +544,11 @@ func (r *PostgresTrainingDateAttendeeRepository) Update(attendee *TrainingDateAt
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)
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 {
return err
}