From 80a8545ed74a8f14c06a8df05be0e9e32bbbf062 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 19 Jun 2024 21:36:35 +0100 Subject: [PATCH 001/248] fix some test stuff --- server/go.mod | 1 + server/go.sum | 3 + server/tests/blog_test.go | 151 +++++++++++++++++++++----------------- 3 files changed, 86 insertions(+), 69 deletions(-) diff --git a/server/go.mod b/server/go.mod index c5438c4..82894da 100644 --- a/server/go.mod +++ b/server/go.mod @@ -28,6 +28,7 @@ require ( cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/longrunning v0.5.5 // indirect cloud.google.com/go/storage v1.38.0 // indirect + github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1 // indirect diff --git a/server/go.sum b/server/go.sum index 16e38b3..e8c6b1d 100644 --- a/server/go.sum +++ b/server/go.sum @@ -16,6 +16,8 @@ cloud.google.com/go/storage v1.38.0/go.mod h1:tlUADB0mAb9BgYls9lq+8MGkfzOXuLrnHX firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= +github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/aws/aws-sdk-go-v2 v1.25.1 h1:P7hU6A5qEdmajGwvae/zDkOq+ULLC9tQBTwqqiwFGpI= github.com/aws/aws-sdk-go-v2 v1.25.1/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU= @@ -146,6 +148,7 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index c408d8b..cd2420a 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -1,10 +1,10 @@ package tests import ( - "bytes" "database/sql" "encoding/json" "fmt" + "github.com/DATA-DOG/go-sqlmock" "io" "log" "net/http" @@ -18,45 +18,48 @@ import ( "github.com/sean-david-welch/farmec-v2/server/services" "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/stretchr/testify/assert" ) -func setupTestDB() (*sql.DB, error) { - db, err := sql.Open("sqlite3", ":memory:") +func setupTestDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock, error) { + db, mock, err := sqlmock.New() if err != nil { - return nil, err + return nil, nil, fmt.Errorf("an error '%s' was not expected when opening a stub database connection", err) } + mock.ExpectExec("CREATE TABLE Blog").WillReturnResult(sqlmock.NewResult(1, 1)) + mock.ExpectExec(`INSERT INTO "Blog"`).WithArgs( + "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00", + ).WillReturnResult(sqlmock.NewResult(1, 1)) + + // Create table schema := `CREATE TABLE Blog ( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - Title TEXT, - Date TEXT, - MainImage TEXT, - Subheading TEXT, - Body TEXT, - Created DATETIME - );` - - _, err = db.Exec(schema) - if err != nil { - return nil, fmt.Errorf("failed to create schema: %w", err) + ID INTEGER PRIMARY KEY AUTOINCREMENT, + Title TEXT, + Date TEXT, + MainImage TEXT, + Subheading TEXT, + Body TEXT, + Created DATETIME + );` + + if _, err := db.Exec(schema); err != nil { + return nil, nil, fmt.Errorf("failed to create schema: %w", err) } - _, err = db.Exec(` - INSERT INTO Blog (Title, Date, MainImage, Subheading, Body, Created) - VALUES ('Test Title', '2023-01-01', 'image.jpg', 'Test Subheading', 'Test Body', '2023-01-01 10:00:00'); - `) - if err != nil { - return nil, fmt.Errorf("failed to insert test data: %w", err) + insertQuery := `INSERT INTO Blog (id, title, date, main_image, subheading, body, created) VALUES (?, ?, ?, ?, ?, ?, ?);` + if _, err := db.Exec(insertQuery, "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00"); err != nil { + return nil, nil, fmt.Errorf("failed to insert test data: %w", err) } - return db, nil + return db, mock, nil } -func initializeHandler() (*gin.Engine, *sql.DB) { - db, err := setupTestDB() +func initializeHandler(t *testing.T) (*gin.Engine, *sql.DB, sqlmock.Sqlmock) { + db, mock, err := setupTestDB(t) if err != nil { - log.Fatalf("Failed to connect to test database: %v", err) + log.Fatalf("Failed to set up test database: %v", err) } store := stores.NewBlogStore(db) @@ -68,11 +71,11 @@ func initializeHandler() (*gin.Engine, *sql.DB) { router.GET("/blogs", handler.GetBlogs) router.POST("/blogs", handler.CreateBlog) - return router, db + return router, db, mock } func TestGetBlogs(t *testing.T) { - router, db := initializeHandler() + router, db, mock := initializeHandler(t) defer func(db *sql.DB) { err := db.Close() if err != nil { @@ -80,6 +83,11 @@ func TestGetBlogs(t *testing.T) { } }(db) + // Setup mock expectation for the SELECT query + rows := sqlmock.NewRows([]string{"ID", "Title", "Date", "MainImage", "Subheading", "Body", "Created"}). + AddRow(1, "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00") + mock.ExpectQuery("SELECT * FROM Blog").WillReturnRows(rows) + server := httptest.NewServer(router) defer server.Close() @@ -104,47 +112,52 @@ func TestGetBlogs(t *testing.T) { assert.Len(t, blogs, 1) assert.Equal(t, "Test Title", blogs[0].Title) -} - -func TestCreateBlog(t *testing.T) { - router, db := initializeHandler() - defer func(db *sql.DB) { - err := db.Close() - if err != nil { - return - } - }(db) - - server := httptest.NewServer(router) - defer server.Close() - blog := types.Blog{ - Title: "New Blog", - Date: "2024-01-01", - MainImage: "new_image.jpg", - Subheading: "New Subheading", - Body: "New Body", - Created: "2024-01-01 12:00:00", + // Ensure all expectations were met + if err := mock.ExpectationsWereMet(); err != nil { + t.Errorf("there were unfulfilled expectations: %s", err) } - payload, _ := json.Marshal(blog) - - resp, err := http.Post(fmt.Sprintf("%s/blogs", server.URL), "application/json", bytes.NewBuffer(payload)) - if err != nil { - t.Fatalf("Request failed: %v", err) - } - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - return - } - }(resp.Body) - - var count int - err = db.QueryRow(`SELECT COUNT(*) FROM Blog WHERE Title = ?`, "New Blog").Scan(&count) - if err != nil { - t.Fatalf("Failed to query database: %v", err) - } - - assert.Equal(t, 1, count) - assert.Equal(t, http.StatusOK, resp.StatusCode) } + +//func TestCreateBlog(t *testing.T) { +// router, db := initializeHandler() +// defer func(db *sql.DB) { +// err := db.Close() +// if err != nil { +// return +// } +// }(db) +// +// server := httptest.NewServer(router) +// defer server.Close() +// +// blog := types.Blog{ +// Title: "New Blog", +// Date: "2024-01-01", +// MainImage: "new_image.jpg", +// Subheading: "New Subheading", +// Body: "New Body", +// Created: "2024-01-01 12:00:00", +// } +// payload, _ := json.Marshal(blog) +// +// resp, err := http.Post(fmt.Sprintf("%s/blogs", server.URL), "application/json", bytes.NewBuffer(payload)) +// if err != nil { +// t.Fatalf("Request failed: %v", err) +// } +// defer func(Body io.ReadCloser) { +// err := Body.Close() +// if err != nil { +// return +// } +// }(resp.Body) +// +// var count int +// err = db.QueryRow(`SELECT COUNT(*) FROM Blog WHERE Title = ?`, "New Blog").Scan(&count) +// if err != nil { +// t.Fatalf("Failed to query database: %v", err) +// } +// +// assert.Equal(t, 1, count) +// assert.Equal(t, http.StatusOK, resp.StatusCode) +//} From 3d1aed6fae9e790021e07d9766d397e445f47f0d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 19 Jun 2024 21:54:00 +0100 Subject: [PATCH 002/248] goodbye --- server/tests/blog_test.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index cd2420a..d60a97b 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -29,19 +29,18 @@ func setupTestDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock, error) { } mock.ExpectExec("CREATE TABLE Blog").WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectExec(`INSERT INTO "Blog"`).WithArgs( - "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00", + mock.ExpectExec("INSERT INTO Blog").WithArgs( + sqlmock.AnyArg(), "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00", ).WillReturnResult(sqlmock.NewResult(1, 1)) - // Create table schema := `CREATE TABLE Blog ( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - Title TEXT, - Date TEXT, - MainImage TEXT, - Subheading TEXT, - Body TEXT, - Created DATETIME + id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT, + date TEXT, + mainImage TEXT, + subheading TEXT, + body TEXT, + created DATETIME );` if _, err := db.Exec(schema); err != nil { @@ -83,8 +82,7 @@ func TestGetBlogs(t *testing.T) { } }(db) - // Setup mock expectation for the SELECT query - rows := sqlmock.NewRows([]string{"ID", "Title", "Date", "MainImage", "Subheading", "Body", "Created"}). + rows := sqlmock.NewRows([]string{"id", "title", "date", "mainImage", "subheading", "body", "created"}). AddRow(1, "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00") mock.ExpectQuery("SELECT * FROM Blog").WillReturnRows(rows) @@ -113,7 +111,6 @@ func TestGetBlogs(t *testing.T) { assert.Len(t, blogs, 1) assert.Equal(t, "Test Title", blogs[0].Title) - // Ensure all expectations were met if err := mock.ExpectationsWereMet(); err != nil { t.Errorf("there were unfulfilled expectations: %s", err) } From 99b72e846ced46b069791c35388e08bdf249e1b7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 22 Jun 2024 17:36:31 +0100 Subject: [PATCH 003/248] some sqlc stuff and goose --- .../20240622155747_initial_schema.sql | 192 ++++++++++++++++++ server/sql/queries/blogs.sql | 4 + server/sql/{schema => }/schema.sql | 0 server/sql/sqlc.yaml | 7 + 4 files changed, 203 insertions(+) create mode 100644 server/sql/migrations/20240622155747_initial_schema.sql create mode 100644 server/sql/queries/blogs.sql rename server/sql/{schema => }/schema.sql (100%) create mode 100644 server/sql/sqlc.yaml diff --git a/server/sql/migrations/20240622155747_initial_schema.sql b/server/sql/migrations/20240622155747_initial_schema.sql new file mode 100644 index 0000000..9de7528 --- /dev/null +++ b/server/sql/migrations/20240622155747_initial_schema.sql @@ -0,0 +1,192 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS Blog +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + date TEXT, + main_image TEXT, + subheading TEXT, + body TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Carousel +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + image TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Employee +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + email TEXT NOT NULL, + role TEXT NOT NULL, + profile_image TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Exhibition +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + date TEXT, + location TEXT, + info TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS LineItems +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + price REAL NOT NULL, + image TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Supplier +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + logo_image TEXT, + marketing_image TEXT, + description TEXT, + social_facebook TEXT, + social_twitter TEXT, + social_instagram TEXT, + social_youtube TEXT, + social_linkedin TEXT, + social_website TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Machine +( + id TEXT PRIMARY KEY, + supplier_id TEXT NOT NULL, + name TEXT NOT NULL, + machine_image TEXT, + description TEXT, + machine_link TEXT, + created TEXT, + FOREIGN KEY (supplier_id) REFERENCES Supplier (id) ON DELETE CASCADE +) STRICT; + +CREATE TABLE IF NOT EXISTS MachineRegistration +( + id TEXT PRIMARY KEY, + dealer_name TEXT NOT NULL, + dealer_address TEXT, + owner_name TEXT NOT NULL, + owner_address TEXT, + machine_model TEXT NOT NULL, + serial_number TEXT NOT NULL, + install_date TEXT, + invoice_number TEXT, + complete_supply INTEGER, + pdi_complete INTEGER, + pto_correct INTEGER, + machine_test_run INTEGER, + safety_induction INTEGER, + operator_handbook INTEGER, + date TEXT, + completed_by TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS WarrantyClaim +( + id TEXT PRIMARY KEY, + dealer TEXT NOT NULL, + dealer_contact TEXT, + owner_name TEXT NOT NULL, + machine_model TEXT NOT NULL, + serial_number TEXT NOT NULL, + install_date TEXT, + failure_date TEXT, + repair_date TEXT, + failure_details TEXT, + repair_details TEXT, + labour_hours TEXT, + completed_by TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS PartsRequired +( + id TEXT PRIMARY KEY, + warranty_id TEXT NOT NULL, + part_number TEXT, + quantity_needed TEXT NOT NULL, + invoice_number TEXT, + description TEXT, + FOREIGN KEY (warranty_id) REFERENCES WarrantyClaim (id) ON DELETE CASCADE +) STRICT; + +CREATE TABLE IF NOT EXISTS Privacy +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + body TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Product +( + id TEXT PRIMARY KEY, + machine_id TEXT NOT NULL, + name TEXT NOT NULL, + product_image TEXT, + description TEXT, + product_link TEXT, + FOREIGN KEY (machine_id) REFERENCES Machine (id) ON DELETE CASCADE +) STRICT; + +CREATE TABLE IF NOT EXISTS SpareParts +( + id TEXT PRIMARY KEY, + supplier_id TEXT NOT NULL, + name TEXT NOT NULL, + parts_image TEXT, + spare_parts_link TEXT, + FOREIGN KEY (supplier_id) REFERENCES Supplier (id) ON DELETE CASCADE +) STRICT; + +CREATE TABLE IF NOT EXISTS Terms +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + body TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Timeline +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + date TEXT, + body TEXT, + created TEXT +) STRICT; + +CREATE TABLE IF NOT EXISTS Video +( + id TEXT PRIMARY KEY, + supplier_id TEXT NOT NULL, + web_url TEXT, + title TEXT, + description TEXT, + video_id TEXT, + thumbnail_url TEXT, + created TEXT, + FOREIGN KEY (supplier_id) REFERENCES Supplier (id) ON DELETE CASCADE +) STRICT; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +SELECT 'down SQL query'; +-- +goose StatementEnd diff --git a/server/sql/queries/blogs.sql b/server/sql/queries/blogs.sql new file mode 100644 index 0000000..1ff15e3 --- /dev/null +++ b/server/sql/queries/blogs.sql @@ -0,0 +1,4 @@ +-- name: GetBlogs :many +SELECT id, title, date, main_image, subheading, body, created +FROM Blog +ORDER BY created DESC; diff --git a/server/sql/schema/schema.sql b/server/sql/schema.sql similarity index 100% rename from server/sql/schema/schema.sql rename to server/sql/schema.sql diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml new file mode 100644 index 0000000..0960efb --- /dev/null +++ b/server/sql/sqlc.yaml @@ -0,0 +1,7 @@ +version: "1" +packages: + - name: database + path: ../database/database.db + queries: ./queries + schema: ./schema.sql + engine: sqlite From f7e5e8c863d805c0335723df56a161ed0bc37ee6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 22 Jun 2024 17:37:03 +0100 Subject: [PATCH 004/248] update --- server/sql/sqlc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml index 0960efb..64a665c 100644 --- a/server/sql/sqlc.yaml +++ b/server/sql/sqlc.yaml @@ -1,4 +1,4 @@ -version: "1" +version: "2" packages: - name: database path: ../database/database.db From 8c2eac2457ad8916f4c3b3ce6e06e506744f139f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 22 Jun 2024 17:48:20 +0100 Subject: [PATCH 005/248] some stuff --- server/.gitignore | 1 - server/go.mod | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/server/.gitignore b/server/.gitignore index f0a5537..a0acbe1 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -3,7 +3,6 @@ .env-development .env-production service-account.json -/database /database/database.db /database/database.db-shm /database/database.db-wal diff --git a/server/go.mod b/server/go.mod index 82894da..17698d6 100644 --- a/server/go.mod +++ b/server/go.mod @@ -4,6 +4,7 @@ go 1.22.0 require ( firebase.google.com/go v3.13.0+incompatible + github.com/DATA-DOG/go-sqlmock v1.5.2 github.com/aws/aws-sdk-go-v2 v1.25.1 github.com/aws/aws-sdk-go-v2/config v1.27.3 github.com/aws/aws-sdk-go-v2/credentials v1.17.3 @@ -28,7 +29,6 @@ require ( cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/longrunning v0.5.5 // indirect cloud.google.com/go/storage v1.38.0 // indirect - github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1 // indirect From 0931e2054fca0cfd68c91903cb0fbd777c67aaab Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 10:24:39 +0100 Subject: [PATCH 006/248] queries for blog --- server/sql/queries/blogs.sql | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/sql/queries/blogs.sql b/server/sql/queries/blogs.sql index 1ff15e3..0ab4a41 100644 --- a/server/sql/queries/blogs.sql +++ b/server/sql/queries/blogs.sql @@ -2,3 +2,27 @@ SELECT id, title, date, main_image, subheading, body, created FROM Blog ORDER BY created DESC; + +-- name: GetBlogByID :one +SELECT * +FROM Blog +WHERE id = ?; + +-- name: CreateBlog :exec +INSERT into Blog +(id, title, date, main_image, subheading, body, created) +VALUES (?, ?, ?, ?, ?, ?, ?); + +-- name: UpdateBlogNoImage :exec +UPDATE Blog +SET title = ?, date = ?, subheading = ?, body = ? +WHERE id = ?; + +-- name: UpdateBlog :exec +UPDATE Blog +SET title = ?, date = ?, main_image = ?, subheading = ?, body = ? +WHERE id = ?; + +-- name: DeleteBlog :exec +DELETE from Blog +WHERE id = ? \ No newline at end of file From 9ac7eae5cec4bdc48646927aa11ecfa48debd22d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 10:24:47 +0100 Subject: [PATCH 007/248] some sqlc --- server/database/blogs.sql.go | 47 ++++++++++ server/database/db.go | 31 +++++++ server/database/models.go | 173 +++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 server/database/blogs.sql.go create mode 100644 server/database/db.go create mode 100644 server/database/models.go diff --git a/server/database/blogs.sql.go b/server/database/blogs.sql.go new file mode 100644 index 0000000..1c109d2 --- /dev/null +++ b/server/database/blogs.sql.go @@ -0,0 +1,47 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: blogs.sql + +package database + +import ( + "context" +) + +const getBlogs = `-- name: GetBlogs :many +SELECT id, title, date, main_image, subheading, body, created +FROM Blog +ORDER BY created DESC +` + +func (q *Queries) GetBlogs(ctx context.Context) ([]Blog, error) { + rows, err := q.db.QueryContext(ctx, getBlogs) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Blog + for rows.Next() { + var i Blog + if err := rows.Scan( + &i.ID, + &i.Title, + &i.Date, + &i.MainImage, + &i.Subheading, + &i.Body, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/server/database/db.go b/server/database/db.go new file mode 100644 index 0000000..a3cc795 --- /dev/null +++ b/server/database/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 + +package database + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/server/database/models.go b/server/database/models.go new file mode 100644 index 0000000..0ba5a73 --- /dev/null +++ b/server/database/models.go @@ -0,0 +1,173 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 + +package database + +import ( + "database/sql" +) + +type Blog struct { + ID string + Title string + Date sql.NullString + MainImage sql.NullString + Subheading sql.NullString + Body sql.NullString + Created sql.NullString +} + +type Carousel struct { + ID string + Name string + Image sql.NullString + Created sql.NullString +} + +type Employee struct { + ID string + Name string + Email string + Role string + ProfileImage sql.NullString + Created sql.NullString +} + +type Exhibition struct { + ID string + Title string + Date sql.NullString + Location sql.NullString + Info sql.NullString + Created sql.NullString +} + +type LineItem struct { + ID string + Name string + Price float64 + Image sql.NullString +} + +type Machine struct { + ID string + SupplierID string + Name string + MachineImage sql.NullString + Description sql.NullString + MachineLink sql.NullString + Created sql.NullString +} + +type MachineRegistration struct { + ID string + DealerName string + DealerAddress sql.NullString + OwnerName string + OwnerAddress sql.NullString + MachineModel string + SerialNumber string + InstallDate sql.NullString + InvoiceNumber sql.NullString + CompleteSupply sql.NullInt64 + PdiComplete sql.NullInt64 + PtoCorrect sql.NullInt64 + MachineTestRun sql.NullInt64 + SafetyInduction sql.NullInt64 + OperatorHandbook sql.NullInt64 + Date sql.NullString + CompletedBy sql.NullString + Created sql.NullString +} + +type PartsRequired struct { + ID string + WarrantyID string + PartNumber sql.NullString + QuantityNeeded string + InvoiceNumber sql.NullString + Description sql.NullString +} + +type Privacy struct { + ID string + Title string + Body sql.NullString + Created sql.NullString +} + +type Product struct { + ID string + MachineID string + Name string + ProductImage sql.NullString + Description sql.NullString + ProductLink sql.NullString +} + +type SparePart struct { + ID string + SupplierID string + Name string + PartsImage sql.NullString + SparePartsLink sql.NullString +} + +type Supplier struct { + ID string + Name string + LogoImage sql.NullString + MarketingImage sql.NullString + Description sql.NullString + SocialFacebook sql.NullString + SocialTwitter sql.NullString + SocialInstagram sql.NullString + SocialYoutube sql.NullString + SocialLinkedin sql.NullString + SocialWebsite sql.NullString + Created sql.NullString +} + +type Term struct { + ID string + Title string + Body sql.NullString + Created sql.NullString +} + +type Timeline struct { + ID string + Title string + Date sql.NullString + Body sql.NullString + Created sql.NullString +} + +type Video struct { + ID string + SupplierID string + WebUrl sql.NullString + Title sql.NullString + Description sql.NullString + VideoID sql.NullString + ThumbnailUrl sql.NullString + Created sql.NullString +} + +type WarrantyClaim struct { + ID string + Dealer string + DealerContact sql.NullString + OwnerName string + MachineModel string + SerialNumber string + InstallDate sql.NullString + FailureDate sql.NullString + RepairDate sql.NullString + FailureDetails sql.NullString + RepairDetails sql.NullString + LabourHours sql.NullString + CompletedBy sql.NullString + Created sql.NullString +} From 94e10dbb7c4f0aefb752464104164df5cbdff7cd Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 10:25:47 +0100 Subject: [PATCH 008/248] sqlc config --- server/sql/sqlc.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml index 64a665c..4b967e6 100644 --- a/server/sql/sqlc.yaml +++ b/server/sql/sqlc.yaml @@ -1,7 +1,9 @@ version: "2" -packages: - - name: database - path: ../database/database.db - queries: ./queries - schema: ./schema.sql - engine: sqlite +sql: + - engine: "sqlite" + queries: "./queries/*" + schema: "schema.sql" + gen: + go: + package: "database" + out: "../database" \ No newline at end of file From e754ffe49aabeab28dda4d2636ada8720abdee4a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 10:28:30 +0100 Subject: [PATCH 009/248] queries --- server/database/blogs.sql.go | 112 +++++++++++++++++++++++++++++++++++ server/sql/queries/blogs.sql | 9 ++- 2 files changed, 116 insertions(+), 5 deletions(-) diff --git a/server/database/blogs.sql.go b/server/database/blogs.sql.go index 1c109d2..fdc761e 100644 --- a/server/database/blogs.sql.go +++ b/server/database/blogs.sql.go @@ -7,8 +7,68 @@ package database import ( "context" + "database/sql" ) +const createBlog = `-- name: CreateBlog :exec +INSERT INTO Blog (id, title, date, main_image, subheading, body, created) +VALUES (?, ?, ?, ?, ?, ?, ?) +` + +type CreateBlogParams struct { + ID string + Title string + Date sql.NullString + MainImage sql.NullString + Subheading sql.NullString + Body sql.NullString + Created sql.NullString +} + +func (q *Queries) CreateBlog(ctx context.Context, arg CreateBlogParams) error { + _, err := q.db.ExecContext(ctx, createBlog, + arg.ID, + arg.Title, + arg.Date, + arg.MainImage, + arg.Subheading, + arg.Body, + arg.Created, + ) + return err +} + +const deleteBlog = `-- name: DeleteBlog :exec +DELETE FROM Blog +WHERE id = ? +` + +func (q *Queries) DeleteBlog(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteBlog, id) + return err +} + +const getBlogByID = `-- name: GetBlogByID :one +SELECT id, title, date, main_image, subheading, body, created +FROM Blog +WHERE id = ? +` + +func (q *Queries) GetBlogByID(ctx context.Context, id string) (Blog, error) { + row := q.db.QueryRowContext(ctx, getBlogByID, id) + var i Blog + err := row.Scan( + &i.ID, + &i.Title, + &i.Date, + &i.MainImage, + &i.Subheading, + &i.Body, + &i.Created, + ) + return i, err +} + const getBlogs = `-- name: GetBlogs :many SELECT id, title, date, main_image, subheading, body, created FROM Blog @@ -45,3 +105,55 @@ func (q *Queries) GetBlogs(ctx context.Context) ([]Blog, error) { } return items, nil } + +const updateBlog = `-- name: UpdateBlog :exec +UPDATE Blog +SET title = ?, date = ?, main_image = ?, subheading = ?, body = ? +WHERE id = ? +` + +type UpdateBlogParams struct { + Title string + Date sql.NullString + MainImage sql.NullString + Subheading sql.NullString + Body sql.NullString + ID string +} + +func (q *Queries) UpdateBlog(ctx context.Context, arg UpdateBlogParams) error { + _, err := q.db.ExecContext(ctx, updateBlog, + arg.Title, + arg.Date, + arg.MainImage, + arg.Subheading, + arg.Body, + arg.ID, + ) + return err +} + +const updateBlogNoImage = `-- name: UpdateBlogNoImage :exec +UPDATE Blog +SET title = ?, date = ?, subheading = ?, body = ? +WHERE id = ? +` + +type UpdateBlogNoImageParams struct { + Title string + Date sql.NullString + Subheading sql.NullString + Body sql.NullString + ID string +} + +func (q *Queries) UpdateBlogNoImage(ctx context.Context, arg UpdateBlogNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateBlogNoImage, + arg.Title, + arg.Date, + arg.Subheading, + arg.Body, + arg.ID, + ) + return err +} diff --git a/server/sql/queries/blogs.sql b/server/sql/queries/blogs.sql index 0ab4a41..2e048ae 100644 --- a/server/sql/queries/blogs.sql +++ b/server/sql/queries/blogs.sql @@ -4,13 +4,12 @@ FROM Blog ORDER BY created DESC; -- name: GetBlogByID :one -SELECT * +SELECT id, title, date, main_image, subheading, body, created FROM Blog WHERE id = ?; -- name: CreateBlog :exec -INSERT into Blog -(id, title, date, main_image, subheading, body, created) +INSERT INTO Blog (id, title, date, main_image, subheading, body, created) VALUES (?, ?, ?, ?, ?, ?, ?); -- name: UpdateBlogNoImage :exec @@ -24,5 +23,5 @@ SET title = ?, date = ?, main_image = ?, subheading = ?, body = ? WHERE id = ?; -- name: DeleteBlog :exec -DELETE from Blog -WHERE id = ? \ No newline at end of file +DELETE FROM Blog +WHERE id = ?; From bdedd9e3ecb1ad386fb5325a6d3c87a6f82b6bdb Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 10:59:57 +0100 Subject: [PATCH 010/248] json tags --- server/database/blogs.sql.go | 36 +++--- server/database/models.go | 232 +++++++++++++++++------------------ server/sql/sqlc.yaml | 3 +- 3 files changed, 136 insertions(+), 135 deletions(-) diff --git a/server/database/blogs.sql.go b/server/database/blogs.sql.go index fdc761e..3ec9d06 100644 --- a/server/database/blogs.sql.go +++ b/server/database/blogs.sql.go @@ -16,13 +16,13 @@ VALUES (?, ?, ?, ?, ?, ?, ?) ` type CreateBlogParams struct { - ID string - Title string - Date sql.NullString - MainImage sql.NullString - Subheading sql.NullString - Body sql.NullString - Created sql.NullString + ID string `json:"id"` + Title string `json:"title"` + Date sql.NullString `json:"date"` + MainImage sql.NullString `json:"main_image"` + Subheading sql.NullString `json:"subheading"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` } func (q *Queries) CreateBlog(ctx context.Context, arg CreateBlogParams) error { @@ -113,12 +113,12 @@ WHERE id = ? ` type UpdateBlogParams struct { - Title string - Date sql.NullString - MainImage sql.NullString - Subheading sql.NullString - Body sql.NullString - ID string + Title string `json:"title"` + Date sql.NullString `json:"date"` + MainImage sql.NullString `json:"main_image"` + Subheading sql.NullString `json:"subheading"` + Body sql.NullString `json:"body"` + ID string `json:"id"` } func (q *Queries) UpdateBlog(ctx context.Context, arg UpdateBlogParams) error { @@ -140,11 +140,11 @@ WHERE id = ? ` type UpdateBlogNoImageParams struct { - Title string - Date sql.NullString - Subheading sql.NullString - Body sql.NullString - ID string + Title string `json:"title"` + Date sql.NullString `json:"date"` + Subheading sql.NullString `json:"subheading"` + Body sql.NullString `json:"body"` + ID string `json:"id"` } func (q *Queries) UpdateBlogNoImage(ctx context.Context, arg UpdateBlogNoImageParams) error { diff --git a/server/database/models.go b/server/database/models.go index 0ba5a73..783a684 100644 --- a/server/database/models.go +++ b/server/database/models.go @@ -9,165 +9,165 @@ import ( ) type Blog struct { - ID string - Title string - Date sql.NullString - MainImage sql.NullString - Subheading sql.NullString - Body sql.NullString - Created sql.NullString + ID string `json:"id"` + Title string `json:"title"` + Date sql.NullString `json:"date"` + MainImage sql.NullString `json:"main_image"` + Subheading sql.NullString `json:"subheading"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` } type Carousel struct { - ID string - Name string - Image sql.NullString - Created sql.NullString + ID string `json:"id"` + Name string `json:"name"` + Image sql.NullString `json:"image"` + Created sql.NullString `json:"created"` } type Employee struct { - ID string - Name string - Email string - Role string - ProfileImage sql.NullString - Created sql.NullString + ID string `json:"id"` + Name string `json:"name"` + Email string `json:"email"` + Role string `json:"role"` + ProfileImage sql.NullString `json:"profile_image"` + Created sql.NullString `json:"created"` } type Exhibition struct { - ID string - Title string - Date sql.NullString - Location sql.NullString - Info sql.NullString - Created sql.NullString + ID string `json:"id"` + Title string `json:"title"` + Date sql.NullString `json:"date"` + Location sql.NullString `json:"location"` + Info sql.NullString `json:"info"` + Created sql.NullString `json:"created"` } type LineItem struct { - ID string - Name string - Price float64 - Image sql.NullString + ID string `json:"id"` + Name string `json:"name"` + Price float64 `json:"price"` + Image sql.NullString `json:"image"` } type Machine struct { - ID string - SupplierID string - Name string - MachineImage sql.NullString - Description sql.NullString - MachineLink sql.NullString - Created sql.NullString + ID string `json:"id"` + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + MachineImage sql.NullString `json:"machine_image"` + Description sql.NullString `json:"description"` + MachineLink sql.NullString `json:"machine_link"` + Created sql.NullString `json:"created"` } type MachineRegistration struct { - ID string - DealerName string - DealerAddress sql.NullString - OwnerName string - OwnerAddress sql.NullString - MachineModel string - SerialNumber string - InstallDate sql.NullString - InvoiceNumber sql.NullString - CompleteSupply sql.NullInt64 - PdiComplete sql.NullInt64 - PtoCorrect sql.NullInt64 - MachineTestRun sql.NullInt64 - SafetyInduction sql.NullInt64 - OperatorHandbook sql.NullInt64 - Date sql.NullString - CompletedBy sql.NullString - Created sql.NullString + ID string `json:"id"` + DealerName string `json:"dealer_name"` + DealerAddress sql.NullString `json:"dealer_address"` + OwnerName string `json:"owner_name"` + OwnerAddress sql.NullString `json:"owner_address"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + InvoiceNumber sql.NullString `json:"invoice_number"` + CompleteSupply sql.NullInt64 `json:"complete_supply"` + PdiComplete sql.NullInt64 `json:"pdi_complete"` + PtoCorrect sql.NullInt64 `json:"pto_correct"` + MachineTestRun sql.NullInt64 `json:"machine_test_run"` + SafetyInduction sql.NullInt64 `json:"safety_induction"` + OperatorHandbook sql.NullInt64 `json:"operator_handbook"` + Date sql.NullString `json:"date"` + CompletedBy sql.NullString `json:"completed_by"` + Created sql.NullString `json:"created"` } type PartsRequired struct { - ID string - WarrantyID string - PartNumber sql.NullString - QuantityNeeded string - InvoiceNumber sql.NullString - Description sql.NullString + ID string `json:"id"` + WarrantyID string `json:"warranty_id"` + PartNumber sql.NullString `json:"part_number"` + QuantityNeeded string `json:"quantity_needed"` + InvoiceNumber sql.NullString `json:"invoice_number"` + Description sql.NullString `json:"description"` } type Privacy struct { - ID string - Title string - Body sql.NullString - Created sql.NullString + ID string `json:"id"` + Title string `json:"title"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` } type Product struct { - ID string - MachineID string - Name string - ProductImage sql.NullString - Description sql.NullString - ProductLink sql.NullString + ID string `json:"id"` + MachineID string `json:"machine_id"` + Name string `json:"name"` + ProductImage sql.NullString `json:"product_image"` + Description sql.NullString `json:"description"` + ProductLink sql.NullString `json:"product_link"` } type SparePart struct { - ID string - SupplierID string - Name string - PartsImage sql.NullString - SparePartsLink sql.NullString + ID string `json:"id"` + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + PartsImage sql.NullString `json:"parts_image"` + SparePartsLink sql.NullString `json:"spare_parts_link"` } type Supplier struct { - ID string - Name string - LogoImage sql.NullString - MarketingImage sql.NullString - Description sql.NullString - SocialFacebook sql.NullString - SocialTwitter sql.NullString - SocialInstagram sql.NullString - SocialYoutube sql.NullString - SocialLinkedin sql.NullString - SocialWebsite sql.NullString - Created sql.NullString + ID string `json:"id"` + Name string `json:"name"` + LogoImage sql.NullString `json:"logo_image"` + MarketingImage sql.NullString `json:"marketing_image"` + Description sql.NullString `json:"description"` + SocialFacebook sql.NullString `json:"social_facebook"` + SocialTwitter sql.NullString `json:"social_twitter"` + SocialInstagram sql.NullString `json:"social_instagram"` + SocialYoutube sql.NullString `json:"social_youtube"` + SocialLinkedin sql.NullString `json:"social_linkedin"` + SocialWebsite sql.NullString `json:"social_website"` + Created sql.NullString `json:"created"` } type Term struct { - ID string - Title string - Body sql.NullString - Created sql.NullString + ID string `json:"id"` + Title string `json:"title"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` } type Timeline struct { - ID string - Title string - Date sql.NullString - Body sql.NullString - Created sql.NullString + ID string `json:"id"` + Title string `json:"title"` + Date sql.NullString `json:"date"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` } type Video struct { - ID string - SupplierID string - WebUrl sql.NullString - Title sql.NullString - Description sql.NullString - VideoID sql.NullString - ThumbnailUrl sql.NullString - Created sql.NullString + ID string `json:"id"` + SupplierID string `json:"supplier_id"` + WebUrl sql.NullString `json:"web_url"` + Title sql.NullString `json:"title"` + Description sql.NullString `json:"description"` + VideoID sql.NullString `json:"video_id"` + ThumbnailUrl sql.NullString `json:"thumbnail_url"` + Created sql.NullString `json:"created"` } type WarrantyClaim struct { - ID string - Dealer string - DealerContact sql.NullString - OwnerName string - MachineModel string - SerialNumber string - InstallDate sql.NullString - FailureDate sql.NullString - RepairDate sql.NullString - FailureDetails sql.NullString - RepairDetails sql.NullString - LabourHours sql.NullString - CompletedBy sql.NullString - Created sql.NullString + ID string `json:"id"` + Dealer string `json:"dealer"` + DealerContact sql.NullString `json:"dealer_contact"` + OwnerName string `json:"owner_name"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + FailureDate sql.NullString `json:"failure_date"` + RepairDate sql.NullString `json:"repair_date"` + FailureDetails sql.NullString `json:"failure_details"` + RepairDetails sql.NullString `json:"repair_details"` + LabourHours sql.NullString `json:"labour_hours"` + CompletedBy sql.NullString `json:"completed_by"` + Created sql.NullString `json:"created"` } diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml index 4b967e6..2521b1e 100644 --- a/server/sql/sqlc.yaml +++ b/server/sql/sqlc.yaml @@ -6,4 +6,5 @@ sql: gen: go: package: "database" - out: "../database" \ No newline at end of file + out: "../database" + emit_json_tags: true From 0a21198b57d2a1c964fa2c097ec847835b54f908 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 11:39:21 +0100 Subject: [PATCH 011/248] refactor blog store for sqlc --- server/stores/blogStore.go | 147 ++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 69 deletions(-) diff --git a/server/stores/blogStore.go b/server/stores/blogStore.go index 5ef9cfa..a4a809c 100644 --- a/server/stores/blogStore.go +++ b/server/stores/blogStore.go @@ -1,90 +1,83 @@ package stores import ( + "context" "database/sql" - "errors" "fmt" - "log" - "time" - "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/database" + "time" ) type BlogStore interface { - GetBlogs() ([]types.Blog, error) - GetBlogById(id string) (*types.Blog, error) - CreateBlog(blog *types.Blog) error - UpdateBlog(id string, blog *types.Blog) error + GetBlogs() ([]database.Blog, error) + GetBlogById(id string) (*database.Blog, error) + CreateBlog(blog *database.Blog) error + UpdateBlog(id string, blog *database.Blog) error DeleteBlog(id string) error } type BlogStoreImpl struct { - database *sql.DB + queries *database.Queries } -func NewBlogStore(database *sql.DB) *BlogStoreImpl { - return &BlogStoreImpl{database: database} +func NewBlogStore(sql *sql.DB) *BlogStoreImpl { + queries := database.New(sql) + return &BlogStoreImpl{ + queries: queries, + } } -func (store *BlogStoreImpl) GetBlogs() ([]types.Blog, error) { - var blogs []types.Blog - - query := `SELECT * FROM "Blog" ORDER BY "created" DESC` - rows, err := store.database.Query(query) +func (store *BlogStoreImpl) GetBlogs() ([]database.Blog, error) { + ctx := context.Background() + blogs, err := store.queries.GetBlogs(ctx) if err != nil { - return nil, fmt.Errorf("error occurred while querying databse: %w", err) + return nil, fmt.Errorf("error occurred while querying database: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - for rows.Next() { - var blog types.Blog - - err := rows.Scan(&blog.ID, &blog.Title, &blog.Date, &blog.MainImage, &blog.Subheading, &blog.Body, &blog.Created) - if err != nil { - return nil, fmt.Errorf("error occurred while scanning rows: %w", err) - } - - blogs = append(blogs, blog) - } - - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over rows: %w", err) + // Convert from the generated database to your database if needed + var result []database.Blog + for _, blog := range blogs { + result = append(result, database.Blog{ + ID: blog.ID, + Title: blog.Title, + Date: blog.Date, + MainImage: blog.MainImage, + Subheading: blog.Subheading, + Body: blog.Body, + Created: blog.Created, + }) } - return blogs, nil + return result, nil } -func (store *BlogStoreImpl) GetBlogById(id string) (*types.Blog, error) { - query := `SELECT * FROM "Blog" WHERE "id" = ?` - row := store.database.QueryRow(query, id) - - var blog types.Blog - - err := row.Scan(&blog.ID, &blog.Title, &blog.Date, &blog.MainImage, &blog.Subheading, &blog.Body, &blog.Created) +func (store *BlogStoreImpl) GetBlogById(id string) (*database.Blog, error) { + ctx := context.Background() + blog, err := store.queries.GetBlogByID(ctx, id) if err != nil { - - if errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error occurred while getting blog: %w", err) + return nil, fmt.Errorf("error occurred while querying database: %w", err) } return &blog, nil } -func (store *BlogStoreImpl) CreateBlog(blog *types.Blog) error { +func (store *BlogStoreImpl) CreateBlog(blog *database.Blog) error { + ctx := context.Background() blog.ID = uuid.NewString() - blog.Created = time.Now().String() - - query := `INSERT INTO "Blog" (id, title, date, main_image, subheading, body, created) VALUES (?, ?, ?, ?, ?, ?, ?)` + blog.Created = sql.NullString{String: time.Now().String(), Valid: true} + + params := database.CreateBlogParams{ + ID: blog.ID, + Title: blog.Title, + Date: blog.Date, + MainImage: blog.MainImage, + Subheading: blog.Subheading, + Body: blog.Body, + Created: blog.Created, + } - _, err := store.database.Exec(query, blog.ID, blog.Title, blog.Date, blog.MainImage, blog.Subheading, blog.Body, blog.Created) + err := store.queries.CreateBlog(ctx, params) if err != nil { return fmt.Errorf("error occurred while creating blog: %w", err) } @@ -92,27 +85,43 @@ func (store *BlogStoreImpl) CreateBlog(blog *types.Blog) error { return nil } -func (store *BlogStoreImpl) UpdateBlog(id string, blog *types.Blog) error { - query := `UPDATE "Blog" SET "title" = ?, "date" = ?, "subheading" = ?, "body" = ? WHERE "id" = ?` - args := []interface{}{blog.Title, blog.Date, blog.Subheading, blog.Body, id} - - if blog.MainImage != "" && blog.MainImage != "null" { - query = `UPDATE "Blog" SET "title" = ?, "date" = ?, "main_image" = ?, "subheading" = ?, "body" = ? WHERE "id" = ?` - args = []interface{}{blog.Title, blog.Date, blog.MainImage, blog.Subheading, blog.Body, id} - } - - _, err := store.database.Exec(query, args...) - if err != nil { - return fmt.Errorf("error occurred while updating blog: %w", err) +func (store *BlogStoreImpl) UpdateBlog(id string, blog *database.Blog) error { + ctx := context.Background() + + if blog.MainImage.Valid { + params := database.UpdateBlogParams{ + ID: blog.ID, + Title: blog.Title, + MainImage: blog.MainImage, + Date: blog.Date, + Subheading: blog.Subheading, + Body: blog.Body, + } + err := store.queries.UpdateBlog(ctx, params) + if err != nil { + return fmt.Errorf("error occurred while updating blog with image: %w", err) + } + } else { + params := database.UpdateBlogNoImageParams{ + ID: blog.ID, + Title: blog.Title, + Date: blog.Date, + Subheading: blog.Subheading, + Body: blog.Body, + } + err := store.queries.UpdateBlogNoImage(ctx, params) + if err != nil { + return fmt.Errorf("error occurred while updating blog without image: %w", err) + } } return nil } func (store *BlogStoreImpl) DeleteBlog(id string) error { - query := `DELETE FROM "Blog" WHERE "id" = ?` + ctx := context.Background() - _, err := store.database.Exec(query, id) + err := store.queries.DeleteBlog(ctx, id) if err != nil { return fmt.Errorf("error occurred while deleting blog: %w", err) } From f4c3e79fcb0b407daaa8aae2d8cd61a45def937f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 11:42:15 +0100 Subject: [PATCH 012/248] refactor blog service --- server/services/blogService.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/server/services/blogService.go b/server/services/blogService.go index 6bb162c..83bf105 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -1,7 +1,9 @@ package services import ( + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/database" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -27,7 +29,7 @@ func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *BlogServiceImpl) GetBlogs() ([]types.Blog, error) { +func (service *BlogServiceImpl) GetBlogs() ([]database.Blog, error) { blogs, err := service.store.GetBlogs() if err != nil { return nil, err @@ -36,7 +38,7 @@ func (service *BlogServiceImpl) GetBlogs() ([]types.Blog, error) { return blogs, nil } -func (service *BlogServiceImpl) GetBlogsByID(id string) (*types.Blog, error) { +func (service *BlogServiceImpl) GetBlogsByID(id string) (*database.Blog, error) { blog, err := service.store.GetBlogById(id) if err != nil { return nil, err @@ -45,20 +47,20 @@ func (service *BlogServiceImpl) GetBlogsByID(id string) (*types.Blog, error) { return blog, nil } -func (service *BlogServiceImpl) CreateBlog(blog *types.Blog) (*types.ModelResult, error) { +func (service *BlogServiceImpl) CreateBlog(blog *database.Blog) (*types.ModelResult, error) { image := blog.MainImage - if image == "" || image == "null" { + if !image.Valid { return nil, errors.New("image is empty") } - presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image) + presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - blog.MainImage = imageUrl + blog.MainImage = sql.NullString{String: imageUrl, Valid: true} if err := service.store.CreateBlog(blog); err != nil { return nil, err @@ -72,19 +74,19 @@ func (service *BlogServiceImpl) CreateBlog(blog *types.Blog) (*types.ModelResult return result, nil } -func (service *BlogServiceImpl) UpdateBlog(id string, blog *types.Blog) (*types.ModelResult, error) { +func (service *BlogServiceImpl) UpdateBlog(id string, blog *database.Blog) (*types.ModelResult, error) { image := blog.MainImage var presignedUrl, imageUrl string var err error - if image != "" && image != "null" { - presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image) + if image.Valid { + presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - blog.MainImage = imageUrl + blog.MainImage = sql.NullString{String: imageUrl, Valid: true} } if err := service.store.UpdateBlog(id, blog); err != nil { @@ -93,7 +95,7 @@ func (service *BlogServiceImpl) UpdateBlog(id string, blog *types.Blog) (*types. result := &types.ModelResult{ PresignedUrl: presignedUrl, - ImageUrl: image, + ImageUrl: image.String, } return result, nil @@ -105,7 +107,7 @@ func (service *BlogServiceImpl) DeleteBlog(id string) error { return err } - if err := service.s3Client.DeleteImageFromS3(blog.MainImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(blog.MainImage.String); err != nil { return err } From e2392dd0f6d7b859108b953ca35490648fb50615 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 11:49:15 +0100 Subject: [PATCH 013/248] refactor handler --- server/handlers/blogHandler.go | 6 +++--- server/services/blogService.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/handlers/blogHandler.go b/server/handlers/blogHandler.go index acc1c13..6a1b4cb 100644 --- a/server/handlers/blogHandler.go +++ b/server/handlers/blogHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/database" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type BlogHandler struct { @@ -41,7 +41,7 @@ func (handler *BlogHandler) GetBlogByID(context *gin.Context) { } func (handler *BlogHandler) CreateBlog(context *gin.Context) { - var blog types.Blog + var blog database.Blog if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while creating blog: %v", err) @@ -64,7 +64,7 @@ func (handler *BlogHandler) CreateBlog(context *gin.Context) { func (handler *BlogHandler) UpdateBlog(context *gin.Context) { id := context.Param("id") - var blog types.Blog + var blog database.Blog if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while updating blog: %v", err) diff --git a/server/services/blogService.go b/server/services/blogService.go index 83bf105..d7d259c 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -12,10 +12,10 @@ import ( ) type BlogService interface { - GetBlogs() ([]types.Blog, error) - GetBlogsByID(id string) (*types.Blog, error) - CreateBlog(blog *types.Blog) (*types.ModelResult, error) - UpdateBlog(id string, blog *types.Blog) (*types.ModelResult, error) + GetBlogs() ([]database.Blog, error) + GetBlogsByID(id string) (*database.Blog, error) + CreateBlog(blog *database.Blog) (*types.ModelResult, error) + UpdateBlog(id string, blog *database.Blog) (*types.ModelResult, error) DeleteBlog(id string) error } From 169cfee25babb1379224beab2243c646c033fad6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 11:50:47 +0100 Subject: [PATCH 014/248] update frontend code a bit --- client/src/forms/BlogForm.tsx | 170 +++++++++++------------ client/src/forms/CarouselForm.tsx | 166 +++++++++++------------ client/src/forms/EmployeeForm.tsx | 168 +++++++++++------------ client/src/forms/LineItemForm.tsx | 166 +++++++++++------------ client/src/forms/MachineForm.tsx | 202 ++++++++++++++-------------- client/src/forms/ProductForm.tsx | 196 +++++++++++++-------------- client/src/forms/SparePartsForm.tsx | 194 +++++++++++++------------- client/src/forms/SupplierForm.tsx | 196 +++++++++++++-------------- server/stores/blogStore.go | 4 +- 9 files changed, 731 insertions(+), 731 deletions(-) diff --git a/client/src/forms/BlogForm.tsx b/client/src/forms/BlogForm.tsx index 47e7194..a938ad6 100644 --- a/client/src/forms/BlogForm.tsx +++ b/client/src/forms/BlogForm.tsx @@ -13,94 +13,94 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - blog?: Blog; + id?: string; + blog?: Blog; } const BlogForm: React.FC = ({ id, blog }) => { - const [showForm, setShowForm] = useState(false); - const formFields = blog ? blogFormFields(blog) : blogFormFields(); - - const { - mutateAsync: createBlog, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('blogs'); - - const { - mutateAsync: updateBlog, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('blogs', id); - - const error = id ? updateError : createError; - const isError = id ? isUpdateError : isCreateError; - const submitBlog = id ? updateBlog : createBlog; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - const imageFile = formData.get('main_image') as File; - - const body: Blog = { - title: formData.get('title') as string, - date: formData.get('date') as string, - main_image: imageFile ? imageFile.name : 'null', - subheading: formData.get('subheading') as string, - body: formData.get('body') as string, - }; - - try { - const response = await submitBlog(body); - - if (imageFile) { - const imageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(imageData); - } - response && !isError && setShowForm(false); - } catch (error) { - console.error('error creating blog', error); - } - } - - if (createPending || updatingPending) return ; - - return ( -
- - - setShowForm(false)}> -
-

Blog Form

- {formFields.map(field => ( -
- - -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + const formFields = blog ? blogFormFields(blog) : blogFormFields(); + + const { + mutateAsync: createBlog, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('blogs'); + + const { + mutateAsync: updateBlog, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('blogs', id); + + const error = id ? updateError : createError; + const isError = id ? isUpdateError : isCreateError; + const submitBlog = id ? updateBlog : createBlog; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + const imageFile = formData.get('main_image') as File; + + const body: Blog = { + title: formData.get('title') as string, + date: formData.get('date') as string, + main_image: imageFile ? imageFile.name : '', + subheading: formData.get('subheading') as string, + body: formData.get('body') as string, + }; + + try { + const response = await submitBlog(body); + + if (imageFile) { + const imageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(imageData); + } + response && !isError && setShowForm(false); + } catch (error) { + console.error('error creating blog', error); + } + } + + if (createPending || updatingPending) return ; + + return ( +
+ + + setShowForm(false)}> +
+

Blog Form

+ {formFields.map(field => ( +
+ + +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default BlogForm; diff --git a/client/src/forms/CarouselForm.tsx b/client/src/forms/CarouselForm.tsx index aef8df9..bcec6d8 100644 --- a/client/src/forms/CarouselForm.tsx +++ b/client/src/forms/CarouselForm.tsx @@ -13,92 +13,92 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - carousel?: Carousel; + id?: string; + carousel?: Carousel; } const CarouselForm: React.FC = ({ id, carousel }) => { - const [showForm, setShowForm] = useState(false); - const formFields = carousel ? getFormFields(carousel) : getFormFields(); - - const { - mutateAsync: createCarousel, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('carousels'); - - const { - mutateAsync: updateCarousel, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('carousels', id); - - const error = id ? updateError : createError; - const isError = id ? isUpdateError : isCreateError; - const submitCarousel = id ? updateCarousel : createCarousel; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - const imageFile = formData.get('image') as File; - - const body: Carousel = { - name: formData.get('name') as string, - image: imageFile ? imageFile.name : 'null', - }; - - try { - const response = await submitCarousel(body); - - if (imageFile) { - const imageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(imageData); - } - - response && !isError && setShowForm(false); - } catch (error) { - console.error('error creating carousel', error); - } - } - - if (createPending || updatingPending) return ; - - return ( -
- - - setShowForm(false)}> -
-

Carousel Form

- {formFields.map(field => ( -
- - -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + const formFields = carousel ? getFormFields(carousel) : getFormFields(); + + const { + mutateAsync: createCarousel, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('carousels'); + + const { + mutateAsync: updateCarousel, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('carousels', id); + + const error = id ? updateError : createError; + const isError = id ? isUpdateError : isCreateError; + const submitCarousel = id ? updateCarousel : createCarousel; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + const imageFile = formData.get('image') as File; + + const body: Carousel = { + name: formData.get('name') as string, + image: imageFile ? imageFile.name : '', + }; + + try { + const response = await submitCarousel(body); + + if (imageFile) { + const imageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(imageData); + } + + response && !isError && setShowForm(false); + } catch (error) { + console.error('error creating carousel', error); + } + } + + if (createPending || updatingPending) return ; + + return ( +
+ + + setShowForm(false)}> +
+

Carousel Form

+ {formFields.map(field => ( +
+ + +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default CarouselForm; diff --git a/client/src/forms/EmployeeForm.tsx b/client/src/forms/EmployeeForm.tsx index ffda68d..75331d2 100644 --- a/client/src/forms/EmployeeForm.tsx +++ b/client/src/forms/EmployeeForm.tsx @@ -13,93 +13,93 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - employee?: Employee; + id?: string; + employee?: Employee; } const EmployeeForm: React.FC = ({ id, employee }) => { - const [showForm, setShowForm] = useState(false); - const formFields = employee ? employeeFormFields(employee) : employeeFormFields(); - - const { - mutateAsync: createEmployee, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('employees'); - - const { - mutateAsync: updateEmployee, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('employees', id); - - const error = id ? updateError : createError; - const isError = id ? isUpdateError : isCreateError; - const submitEmployee = id ? updateEmployee : createEmployee; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - const imageFile = formData.get('profile_image') as File; - - const body: Employee = { - name: formData.get('name') as string, - email: formData.get('email') as string, - role: formData.get('role') as string, - profile_image: imageFile ? imageFile.name : 'null', - }; - - try { - const response = await submitEmployee(body); - - if (imageFile) { - const imageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(imageData); - } - - response && !isError && setShowForm(false); - } catch (error) { - console.error('error creating employee', error); - } - } - - if (createPending || updatingPending) return ; - return ( -
- - - setShowForm(false)}> -
-

Employee Form

- {formFields.map(field => ( -
- - -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + const formFields = employee ? employeeFormFields(employee) : employeeFormFields(); + + const { + mutateAsync: createEmployee, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('employees'); + + const { + mutateAsync: updateEmployee, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('employees', id); + + const error = id ? updateError : createError; + const isError = id ? isUpdateError : isCreateError; + const submitEmployee = id ? updateEmployee : createEmployee; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + const imageFile = formData.get('profile_image') as File; + + const body: Employee = { + name: formData.get('name') as string, + email: formData.get('email') as string, + role: formData.get('role') as string, + profile_image: imageFile ? imageFile.name : '', + }; + + try { + const response = await submitEmployee(body); + + if (imageFile) { + const imageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(imageData); + } + + response && !isError && setShowForm(false); + } catch (error) { + console.error('error creating employee', error); + } + } + + if (createPending || updatingPending) return ; + return ( +
+ + + setShowForm(false)}> +
+

Employee Form

+ {formFields.map(field => ( +
+ + +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default EmployeeForm; diff --git a/client/src/forms/LineItemForm.tsx b/client/src/forms/LineItemForm.tsx index 607cb17..a749188 100644 --- a/client/src/forms/LineItemForm.tsx +++ b/client/src/forms/LineItemForm.tsx @@ -13,92 +13,92 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - lineItem?: LineItem; + id?: string; + lineItem?: LineItem; } const LineItemForm: React.FC = ({ id, lineItem }) => { - const [showForm, setShowForm] = useState(false); - const formFields = lineItem ? getFormFields(lineItem) : getFormFields(); - - const { - mutateAsync: createLineItem, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('lineitems'); - - const { - mutateAsync: updateLineItem, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('lineitems', id); - - const error = id ? updateError : createError; - const isError = id ? isUpdateError : isCreateError; - const submitLineItem = id ? updateLineItem : createLineItem; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - const imageFile = formData.get('image') as File; - - const body: LineItem = { - name: formData.get('name') as string, - price: parseFloat(formData.get('price') as string), - image: imageFile ? imageFile.name : 'null', - }; - - try { - const response = await submitLineItem(body); - - if (imageFile) { - const imageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(imageData); - } - - response && !isError && setShowForm(false); - } catch (error) { - console.error('error creating lineItem', error); - } - } - - if (createPending || updatingPending) return ; - return ( -
- - - setShowForm(false)}> -
-

LineItem Form

- {formFields.map(field => ( -
- - -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + const formFields = lineItem ? getFormFields(lineItem) : getFormFields(); + + const { + mutateAsync: createLineItem, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('lineitems'); + + const { + mutateAsync: updateLineItem, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('lineitems', id); + + const error = id ? updateError : createError; + const isError = id ? isUpdateError : isCreateError; + const submitLineItem = id ? updateLineItem : createLineItem; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + const imageFile = formData.get('image') as File; + + const body: LineItem = { + name: formData.get('name') as string, + price: parseFloat(formData.get('price') as string), + image: imageFile ? imageFile.name : '', + }; + + try { + const response = await submitLineItem(body); + + if (imageFile) { + const imageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(imageData); + } + + response && !isError && setShowForm(false); + } catch (error) { + console.error('error creating lineItem', error); + } + } + + if (createPending || updatingPending) return ; + return ( +
+ + + setShowForm(false)}> +
+

LineItem Form

+ {formFields.map(field => ( +
+ + +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default LineItemForm; diff --git a/client/src/forms/MachineForm.tsx b/client/src/forms/MachineForm.tsx index 1689fbb..660f084 100644 --- a/client/src/forms/MachineForm.tsx +++ b/client/src/forms/MachineForm.tsx @@ -11,110 +11,110 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - machine?: Machine; - suppliers: Supplier[]; + id?: string; + machine?: Machine; + suppliers: Supplier[]; } const MachineFrom: React.FC = ({ id, machine, suppliers }) => { - const [showForm, setShowForm] = useState(false); - - const formFields = machine ? getFormFields(suppliers, machine) : getFormFields(suppliers); - - const { - mutateAsync: createMachine, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('machines'); - - const { - mutateAsync: updateMachine, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('machines', id); - - const isError = id ? isUpdateError : isCreateError; - const error = id ? updateError : createError; - - const submitMachine = id ? updateMachine : createMachine; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - - const imageFile = formData.get('machine_image') as File; - - const body: Machine = { - supplier_id: formData.get('supplier_id') as string, - name: formData.get('name') as string, - machine_image: imageFile ? imageFile.name : 'null', - description: formData.get('description') as string, - machine_link: formData.get('machine_link') as string, - }; - - try { - const response = await submitMachine(body); - - if (imageFile) { - const machineImageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(machineImageData); - } - response && !isError && setShowForm(false); - } catch (error) { - console.error('Error creating machine', error); - } - } - - if (createPending || updatingPending) return ; - return ( -
- - - setShowForm(false)}> -
-

Machine Form

- {formFields.map(field => ( -
- - {field.type === 'select' ? ( - - ) : ( - - )} -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + + const formFields = machine ? getFormFields(suppliers, machine) : getFormFields(suppliers); + + const { + mutateAsync: createMachine, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('machines'); + + const { + mutateAsync: updateMachine, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('machines', id); + + const isError = id ? isUpdateError : isCreateError; + const error = id ? updateError : createError; + + const submitMachine = id ? updateMachine : createMachine; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + + const imageFile = formData.get('machine_image') as File; + + const body: Machine = { + supplier_id: formData.get('supplier_id') as string, + name: formData.get('name') as string, + machine_image: imageFile ? imageFile.name : '', + description: formData.get('description') as string, + machine_link: formData.get('machine_link') as string, + }; + + try { + const response = await submitMachine(body); + + if (imageFile) { + const machineImageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(machineImageData); + } + response && !isError && setShowForm(false); + } catch (error) { + console.error('Error creating machine', error); + } + } + + if (createPending || updatingPending) return ; + return ( +
+ + + setShowForm(false)}> +
+

Machine Form

+ {formFields.map(field => ( +
+ + {field.type === 'select' ? ( + + ) : ( + + )} +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default MachineFrom; diff --git a/client/src/forms/ProductForm.tsx b/client/src/forms/ProductForm.tsx index dfa16ed..4231262 100644 --- a/client/src/forms/ProductForm.tsx +++ b/client/src/forms/ProductForm.tsx @@ -12,107 +12,107 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - product?: Product; - machine: Machine; + id?: string; + product?: Product; + machine: Machine; } const ProductForm: React.FC = ({ id, product, machine }) => { - const [showForm, setShowForm] = useState(false); - - const formFields = id ? getFormFields(machine, product) : getFormFields(machine); - - const { - mutateAsync: createProduct, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('products'); - - const { - mutateAsync: updateProduct, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('products', id); - - const isError = id ? isUpdateError : isCreateError; - const error = id ? updateError : createError; - - const submitProduct = id ? updateProduct : createProduct; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - - const imageFile = formData.get('product_image') as File; - - const body: Product = { - machine_id: formData.get('machine_id') as string, - name: formData.get('name') as string, - product_image: imageFile ? imageFile.name : 'null', - description: formData.get('description') as string, - product_link: formData.get('product_link') as string, - }; - - try { - const response = await submitProduct(body); - - if (imageFile) { - const productImageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(productImageData); - } - response && !isError && setShowForm(false); - } catch (error) { - console.error('error creating product', error); - } - } - - if (createPending || updatingPending) return ; - return ( -
- - - setShowForm(false)}> -
-

Product Form

- {formFields.map(field => ( -
- - {field.type === 'select' ? ( - - ) : ( - - )} -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + + const formFields = id ? getFormFields(machine, product) : getFormFields(machine); + + const { + mutateAsync: createProduct, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('products'); + + const { + mutateAsync: updateProduct, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('products', id); + + const isError = id ? isUpdateError : isCreateError; + const error = id ? updateError : createError; + + const submitProduct = id ? updateProduct : createProduct; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + + const imageFile = formData.get('product_image') as File; + + const body: Product = { + machine_id: formData.get('machine_id') as string, + name: formData.get('name') as string, + product_image: imageFile ? imageFile.name : '', + description: formData.get('description') as string, + product_link: formData.get('product_link') as string, + }; + + try { + const response = await submitProduct(body); + + if (imageFile) { + const productImageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(productImageData); + } + response && !isError && setShowForm(false); + } catch (error) { + console.error('error creating product', error); + } + } + + if (createPending || updatingPending) return ; + return ( +
+ + + setShowForm(false)}> +
+

Product Form

+ {formFields.map(field => ( +
+ + {field.type === 'select' ? ( + + ) : ( + + )} +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default ProductForm; diff --git a/client/src/forms/SparePartsForm.tsx b/client/src/forms/SparePartsForm.tsx index e641eb8..beb0249 100644 --- a/client/src/forms/SparePartsForm.tsx +++ b/client/src/forms/SparePartsForm.tsx @@ -13,106 +13,106 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - sparepart?: Sparepart; - suppliers: Supplier[]; + id?: string; + sparepart?: Sparepart; + suppliers: Supplier[]; } const SparepartForm: React.FC = ({ id, sparepart, suppliers }) => { - const [showForm, setShowForm] = useState(false); - const formFields = sparepart ? getFormFields(suppliers, sparepart) : getFormFields(suppliers); - - const { - mutateAsync: createSparepart, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('spareparts'); - - const { - mutateAsync: updateSparepart, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('spareparts', id); - - const error = id ? updateError : createError; - const isError = id ? isUpdateError : isCreateError; - const submitSparepart = id ? updateSparepart : createSparepart; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - - const formData = new FormData(event.currentTarget as HTMLFormElement); - const imageFile = formData.get('parts_image') as File; - - const body: Sparepart = { - supplier_id: formData.get('supplier_id') as string, - name: formData.get('name') as string, - parts_image: imageFile ? imageFile.name : 'null', - spare_parts_link: formData.get('spare_parts_link') as string, - }; - - try { - const response = await submitSparepart(body); - - if (imageFile) { - const imageData = { - imageFile: imageFile, - presignedUrl: response.presignedUrl, - }; - await uploadFileToS3(imageData); - } - response && !isError && setShowForm(false); - } catch (error) { - console.error('error creating sparepart', error); - } - } - - if (createPending || updatingPending) return ; - return ( -
- - - setShowForm(false)}> -
-

Sparepart Form

- {formFields.map(field => ( -
- - {field.type === 'select' ? ( - - ) : ( - - )} -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + const formFields = sparepart ? getFormFields(suppliers, sparepart) : getFormFields(suppliers); + + const { + mutateAsync: createSparepart, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('spareparts'); + + const { + mutateAsync: updateSparepart, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('spareparts', id); + + const error = id ? updateError : createError; + const isError = id ? isUpdateError : isCreateError; + const submitSparepart = id ? updateSparepart : createSparepart; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + + const formData = new FormData(event.currentTarget as HTMLFormElement); + const imageFile = formData.get('parts_image') as File; + + const body: Sparepart = { + supplier_id: formData.get('supplier_id') as string, + name: formData.get('name') as string, + parts_image: imageFile ? imageFile.name : '', + spare_parts_link: formData.get('spare_parts_link') as string, + }; + + try { + const response = await submitSparepart(body); + + if (imageFile) { + const imageData = { + imageFile: imageFile, + presignedUrl: response.presignedUrl, + }; + await uploadFileToS3(imageData); + } + response && !isError && setShowForm(false); + } catch (error) { + console.error('error creating sparepart', error); + } + } + + if (createPending || updatingPending) return ; + return ( +
+ + + setShowForm(false)}> +
+

Sparepart Form

+ {formFields.map(field => ( +
+ + {field.type === 'select' ? ( + + ) : ( + + )} +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default SparepartForm; diff --git a/client/src/forms/SupplierForm.tsx b/client/src/forms/SupplierForm.tsx index 58e0332..ca4dad9 100644 --- a/client/src/forms/SupplierForm.tsx +++ b/client/src/forms/SupplierForm.tsx @@ -12,107 +12,107 @@ import { faPenToSquare } from '@fortawesome/free-solid-svg-icons/faPenToSquare'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { - id?: string; - supplier?: Supplier; + id?: string; + supplier?: Supplier; } const SupplierForm: React.FC = ({ id, supplier }) => { - const [showForm, setShowForm] = useState(false); - const formFields = supplier ? getFormFields(supplier) : getFormFields(); - - const { - mutateAsync: createSupplier, - isError: isCreateError, - error: createError, - isPending: createPending, - } = useMutateResource('suppliers'); - - const { - mutateAsync: updateSupplier, - isError: isUpdateError, - error: updateError, - isPending: updatingPending, - } = useMutateResource('suppliers', id); - - const error = id ? updateError : createError; - const isError = id ? isUpdateError : isCreateError; - const submitSupplier = id ? updateSupplier : createSupplier; - - async function handleSubmit(event: React.FormEvent) { - event.preventDefault(); - const formData = new FormData(event.currentTarget as HTMLFormElement); - - const logoFile = formData.get('logo_image') as File; - const marketingFile = formData.get('marketing_image') as File; - - const body: Supplier = { - name: formData.get('name') as string, - description: formData.get('description') as string, - logo_image: logoFile ? logoFile.name : 'null', - marketing_image: marketingFile ? marketingFile.name : 'null', - social_facebook: formData.get('social_facebook') as string, - social_twitter: formData.get('social_twitter') as string, - social_instagram: formData.get('social_instagram') as string, - social_youtube: formData.get('social_youtube') as string, - social_linkedin: formData.get('social_linkedin') as string, - social_website: formData.get('social_website') as string, - }; - - try { - const response = await submitSupplier(body); - - if (logoFile) { - const logoImageData = { - imageFile: logoFile, - presignedUrl: response.presignedLogoUrl, - }; - await uploadFileToS3(logoImageData); - } - if (marketingFile) { - const marketingImageData = { - imageFile: marketingFile, - presignedUrl: response.presignedMarketingUrl, - }; - await uploadFileToS3(marketingImageData); - } - - response && !isError && setShowForm(false); - } catch (error) { - console.error('Error creating supplier:', error); - } - } - - if (createPending || updatingPending) return ; - return ( -
- - - setShowForm(false)}> -
-

Supplier Form

- {formFields.map(field => ( -
- - -
- ))} - -
- - {isError &&

Error: {error?.message}

} -
-
- ); + const [showForm, setShowForm] = useState(false); + const formFields = supplier ? getFormFields(supplier) : getFormFields(); + + const { + mutateAsync: createSupplier, + isError: isCreateError, + error: createError, + isPending: createPending, + } = useMutateResource('suppliers'); + + const { + mutateAsync: updateSupplier, + isError: isUpdateError, + error: updateError, + isPending: updatingPending, + } = useMutateResource('suppliers', id); + + const error = id ? updateError : createError; + const isError = id ? isUpdateError : isCreateError; + const submitSupplier = id ? updateSupplier : createSupplier; + + async function handleSubmit(event: React.FormEvent) { + event.preventDefault(); + const formData = new FormData(event.currentTarget as HTMLFormElement); + + const logoFile = formData.get('logo_image') as File; + const marketingFile = formData.get('marketing_image') as File; + + const body: Supplier = { + name: formData.get('name') as string, + description: formData.get('description') as string, + logo_image: logoFile ? logoFile.name : '', + marketing_image: marketingFile ? marketingFile.name : '', + social_facebook: formData.get('social_facebook') as string, + social_twitter: formData.get('social_twitter') as string, + social_instagram: formData.get('social_instagram') as string, + social_youtube: formData.get('social_youtube') as string, + social_linkedin: formData.get('social_linkedin') as string, + social_website: formData.get('social_website') as string, + }; + + try { + const response = await submitSupplier(body); + + if (logoFile) { + const logoImageData = { + imageFile: logoFile, + presignedUrl: response.presignedLogoUrl, + }; + await uploadFileToS3(logoImageData); + } + if (marketingFile) { + const marketingImageData = { + imageFile: marketingFile, + presignedUrl: response.presignedMarketingUrl, + }; + await uploadFileToS3(marketingImageData); + } + + response && !isError && setShowForm(false); + } catch (error) { + console.error('Error creating supplier:', error); + } + } + + if (createPending || updatingPending) return ; + return ( +
+ + + setShowForm(false)}> +
+

Supplier Form

+ {formFields.map(field => ( +
+ + +
+ ))} + +
+ + {isError &&

Error: {error?.message}

} +
+
+ ); }; export default SupplierForm; diff --git a/server/stores/blogStore.go b/server/stores/blogStore.go index a4a809c..ea0cdbb 100644 --- a/server/stores/blogStore.go +++ b/server/stores/blogStore.go @@ -90,12 +90,12 @@ func (store *BlogStoreImpl) UpdateBlog(id string, blog *database.Blog) error { if blog.MainImage.Valid { params := database.UpdateBlogParams{ - ID: blog.ID, Title: blog.Title, MainImage: blog.MainImage, Date: blog.Date, Subheading: blog.Subheading, Body: blog.Body, + ID: id, } err := store.queries.UpdateBlog(ctx, params) if err != nil { @@ -103,11 +103,11 @@ func (store *BlogStoreImpl) UpdateBlog(id string, blog *database.Blog) error { } } else { params := database.UpdateBlogNoImageParams{ - ID: blog.ID, Title: blog.Title, Date: blog.Date, Subheading: blog.Subheading, Body: blog.Body, + ID: id, } err := store.queries.UpdateBlogNoImage(ctx, params) if err != nil { From 1c961bbf8d82c1eb45cf54f6258cbaa3a3417c05 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 12:03:02 +0100 Subject: [PATCH 015/248] refactor tests --- server/tests/blog_test.go | 93 ++++++++++++++------------------------- 1 file changed, 34 insertions(+), 59 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index d60a97b..a87d01f 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -5,8 +5,7 @@ import ( "encoding/json" "fmt" "github.com/DATA-DOG/go-sqlmock" - "io" - "log" + "github.com/stretchr/testify/require" "net/http" "net/http/httptest" "testing" @@ -22,44 +21,28 @@ import ( "github.com/stretchr/testify/assert" ) -func setupTestDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock, error) { +func setupTestDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock) { db, mock, err := sqlmock.New() - if err != nil { - return nil, nil, fmt.Errorf("an error '%s' was not expected when opening a stub database connection", err) - } - - mock.ExpectExec("CREATE TABLE Blog").WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectExec("INSERT INTO Blog").WithArgs( - sqlmock.AnyArg(), "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00", - ).WillReturnResult(sqlmock.NewResult(1, 1)) + require.NoError(t, err) schema := `CREATE TABLE Blog ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - title TEXT, - date TEXT, - mainImage TEXT, - subheading TEXT, - body TEXT, - created DATETIME - );` - - if _, err := db.Exec(schema); err != nil { - return nil, nil, fmt.Errorf("failed to create schema: %w", err) - } - - insertQuery := `INSERT INTO Blog (id, title, date, main_image, subheading, body, created) VALUES (?, ?, ?, ?, ?, ?, ?);` - if _, err := db.Exec(insertQuery, "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00"); err != nil { - return nil, nil, fmt.Errorf("failed to insert test data: %w", err) - } - - return db, mock, nil + id TEXT PRIMARY KEY, + title TEXT, + date TEXT, + main_image TEXT, + subheading TEXT, + body TEXT, + created TEXT + );` + + _, err = db.Exec(schema) + require.NoError(t, err) + + return db, mock } func initializeHandler(t *testing.T) (*gin.Engine, *sql.DB, sqlmock.Sqlmock) { - db, mock, err := setupTestDB(t) - if err != nil { - log.Fatalf("Failed to set up test database: %v", err) - } + db, mock := setupTestDB(t) store := stores.NewBlogStore(db) s3Client := lib.NewNoOpS3Client() @@ -75,45 +58,37 @@ func initializeHandler(t *testing.T) (*gin.Engine, *sql.DB, sqlmock.Sqlmock) { func TestGetBlogs(t *testing.T) { router, db, mock := initializeHandler(t) - defer func(db *sql.DB) { - err := db.Close() - if err != nil { - return - } - }(db) + defer db.Close() - rows := sqlmock.NewRows([]string{"id", "title", "date", "mainImage", "subheading", "body", "created"}). - AddRow(1, "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00") - mock.ExpectQuery("SELECT * FROM Blog").WillReturnRows(rows) + // Mock the expected query and result + rows := sqlmock.NewRows([]string{"id", "title", "date", "main_image", "subheading", "body", "created"}). + AddRow("1", "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00") + mock.ExpectQuery("SELECT id, title, date, main_image, subheading, body, created FROM Blog").WillReturnRows(rows) + // Create a test server server := httptest.NewServer(router) defer server.Close() + // Perform a GET request to /blogs resp, err := http.Get(fmt.Sprintf("%s/blogs", server.URL)) - if err != nil { - t.Fatalf("Request failed: %v", err) - } - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - return - } - }(resp.Body) + require.NoError(t, err) + defer resp.Body.Close() + // Check the response status code assert.Equal(t, http.StatusOK, resp.StatusCode) + // Parse the response body var blogs []types.Blog err = json.NewDecoder(resp.Body).Decode(&blogs) - if err != nil { - t.Fatalf("Failed to decode response: %v", err) - } + require.NoError(t, err) - assert.Len(t, blogs, 1) + // Validate the response + require.Len(t, blogs, 1) assert.Equal(t, "Test Title", blogs[0].Title) - if err := mock.ExpectationsWereMet(); err != nil { - t.Errorf("there were unfulfilled expectations: %s", err) - } + // Ensure all expectations were met + err = mock.ExpectationsWereMet() + require.NoError(t, err) } //func TestCreateBlog(t *testing.T) { From 2cf8aa8438e0a1d7fb9d659a3b4d9000bce322fd Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 12:05:07 +0100 Subject: [PATCH 016/248] refactor tests --- server/tests/blog_test.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index a87d01f..b51c9f1 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -58,35 +58,38 @@ func initializeHandler(t *testing.T) (*gin.Engine, *sql.DB, sqlmock.Sqlmock) { func TestGetBlogs(t *testing.T) { router, db, mock := initializeHandler(t) - defer db.Close() + defer func() { + err := db.Close() + if err != nil { + t.Fatalf("Error closing the database: %v", err) + } + }() - // Mock the expected query and result rows := sqlmock.NewRows([]string{"id", "title", "date", "main_image", "subheading", "body", "created"}). AddRow("1", "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00") mock.ExpectQuery("SELECT id, title, date, main_image, subheading, body, created FROM Blog").WillReturnRows(rows) - // Create a test server server := httptest.NewServer(router) defer server.Close() - // Perform a GET request to /blogs resp, err := http.Get(fmt.Sprintf("%s/blogs", server.URL)) require.NoError(t, err) - defer resp.Body.Close() + defer func() { + err := resp.Body.Close() + if err != nil { + t.Fatalf("Error closing response body: %v", err) + } + }() - // Check the response status code assert.Equal(t, http.StatusOK, resp.StatusCode) - // Parse the response body var blogs []types.Blog err = json.NewDecoder(resp.Body).Decode(&blogs) require.NoError(t, err) - // Validate the response require.Len(t, blogs, 1) assert.Equal(t, "Test Title", blogs[0].Title) - // Ensure all expectations were met err = mock.ExpectationsWereMet() require.NoError(t, err) } From d8e2ed994521b6772a1a009a6acd079d9270ef7c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 12:07:26 +0100 Subject: [PATCH 017/248] refactor using test suite --- server/tests/blog_test.go | 70 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index b51c9f1..59b821f 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/DATA-DOG/go-sqlmock" "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" "net/http" "net/http/httptest" "testing" @@ -17,13 +18,18 @@ import ( "github.com/sean-david-welch/farmec-v2/server/services" "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" - - "github.com/stretchr/testify/assert" ) -func setupTestDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock) { +type BlogTestSuite struct { + suite.Suite + db *sql.DB + mock sqlmock.Sqlmock + router *gin.Engine +} + +func (suite *BlogTestSuite) SetupTest() { db, mock, err := sqlmock.New() - require.NoError(t, err) + require.NoError(suite.T(), err) schema := `CREATE TABLE Blog ( id TEXT PRIMARY KEY, @@ -36,62 +42,56 @@ func setupTestDB(t *testing.T) (*sql.DB, sqlmock.Sqlmock) { );` _, err = db.Exec(schema) - require.NoError(t, err) + require.NoError(suite.T(), err) - return db, mock -} - -func initializeHandler(t *testing.T) (*gin.Engine, *sql.DB, sqlmock.Sqlmock) { - db, mock := setupTestDB(t) + suite.db = db + suite.mock = mock store := stores.NewBlogStore(db) s3Client := lib.NewNoOpS3Client() service := services.NewBlogService(store, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) - router := gin.Default() - router.GET("/blogs", handler.GetBlogs) - router.POST("/blogs", handler.CreateBlog) - - return router, db, mock + suite.router = gin.Default() + suite.router.GET("/blogs", handler.GetBlogs) + suite.router.POST("/blogs", handler.CreateBlog) } -func TestGetBlogs(t *testing.T) { - router, db, mock := initializeHandler(t) - defer func() { - err := db.Close() - if err != nil { - t.Fatalf("Error closing the database: %v", err) - } - }() +func (suite *BlogTestSuite) TearDownTest() { + err := suite.db.Close() + require.NoError(suite.T(), err) +} +func (suite *BlogTestSuite) TestGetBlogs() { rows := sqlmock.NewRows([]string{"id", "title", "date", "main_image", "subheading", "body", "created"}). AddRow("1", "Test Title", "2023-01-01", "image.jpg", "Test Subheading", "Test Body", "2023-01-01 10:00:00") - mock.ExpectQuery("SELECT id, title, date, main_image, subheading, body, created FROM Blog").WillReturnRows(rows) + suite.mock.ExpectQuery("SELECT id, title, date, main_image, subheading, body, created FROM Blog").WillReturnRows(rows) - server := httptest.NewServer(router) + server := httptest.NewServer(suite.router) defer server.Close() resp, err := http.Get(fmt.Sprintf("%s/blogs", server.URL)) - require.NoError(t, err) + require.NoError(suite.T(), err) defer func() { err := resp.Body.Close() - if err != nil { - t.Fatalf("Error closing response body: %v", err) - } + require.NoError(suite.T(), err) }() - assert.Equal(t, http.StatusOK, resp.StatusCode) + require.Equal(suite.T(), http.StatusOK, resp.StatusCode) var blogs []types.Blog err = json.NewDecoder(resp.Body).Decode(&blogs) - require.NoError(t, err) + require.NoError(suite.T(), err) - require.Len(t, blogs, 1) - assert.Equal(t, "Test Title", blogs[0].Title) + require.Len(suite.T(), blogs, 1) + require.Equal(suite.T(), "Test Title", blogs[0].Title) + + err = suite.mock.ExpectationsWereMet() + require.NoError(suite.T(), err) +} - err = mock.ExpectationsWereMet() - require.NoError(t, err) +func TestBlogTestSuite(t *testing.T) { + suite.Run(t, new(BlogTestSuite)) } //func TestCreateBlog(t *testing.T) { From 6e140fadbb9ce2daffaae0c862dd9348cca3399a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 23 Jun 2024 12:14:28 +0100 Subject: [PATCH 018/248] create blog test --- server/tests/blog_test.go | 80 ++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index 59b821f..d1014fc 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -1,6 +1,7 @@ package tests import ( + "bytes" "database/sql" "encoding/json" "fmt" @@ -90,49 +91,42 @@ func (suite *BlogTestSuite) TestGetBlogs() { require.NoError(suite.T(), err) } +func (suite *BlogTestSuite) TestCreateBlog() { + blog := types.Blog{ + Title: "New Blog", + Date: "2024-01-01", + MainImage: "new_image.jpg", + Subheading: "New Subheading", + Body: "New Body", + Created: "2024-01-01 12:00:00", + } + payload, _ := json.Marshal(blog) + + suite.mock.ExpectExec("INSERT INTO Blog"). + WithArgs(sqlmock.AnyArg(), blog.Title, blog.Date, blog.MainImage, blog.Subheading, blog.Body, blog.Created). + WillReturnResult(sqlmock.NewResult(1, 1)) + + server := httptest.NewServer(suite.router) + defer server.Close() + + resp, err := http.Post(fmt.Sprintf("%s/blogs", server.URL), "application/json", bytes.NewBuffer(payload)) + require.NoError(suite.T(), err) + defer func() { + err := resp.Body.Close() + require.NoError(suite.T(), err) + }() + + require.Equal(suite.T(), http.StatusCreated, resp.StatusCode) + + err = suite.mock.ExpectationsWereMet() + require.NoError(suite.T(), err) + + var count int + err = suite.db.QueryRow(`SELECT COUNT(*) FROM Blog WHERE title = ?`, "New Blog").Scan(&count) + require.NoError(suite.T(), err) + require.Equal(suite.T(), 1, count) +} + func TestBlogTestSuite(t *testing.T) { suite.Run(t, new(BlogTestSuite)) } - -//func TestCreateBlog(t *testing.T) { -// router, db := initializeHandler() -// defer func(db *sql.DB) { -// err := db.Close() -// if err != nil { -// return -// } -// }(db) -// -// server := httptest.NewServer(router) -// defer server.Close() -// -// blog := types.Blog{ -// Title: "New Blog", -// Date: "2024-01-01", -// MainImage: "new_image.jpg", -// Subheading: "New Subheading", -// Body: "New Body", -// Created: "2024-01-01 12:00:00", -// } -// payload, _ := json.Marshal(blog) -// -// resp, err := http.Post(fmt.Sprintf("%s/blogs", server.URL), "application/json", bytes.NewBuffer(payload)) -// if err != nil { -// t.Fatalf("Request failed: %v", err) -// } -// defer func(Body io.ReadCloser) { -// err := Body.Close() -// if err != nil { -// return -// } -// }(resp.Body) -// -// var count int -// err = db.QueryRow(`SELECT COUNT(*) FROM Blog WHERE Title = ?`, "New Blog").Scan(&count) -// if err != nil { -// t.Fatalf("Failed to query database: %v", err) -// } -// -// assert.Equal(t, 1, count) -// assert.Equal(t, http.StatusOK, resp.StatusCode) -//} From 462f56fdd28ccfe2d24d748c818419be9a4a6b5e Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 10 Jul 2024 20:03:33 +0100 Subject: [PATCH 019/248] commit tests --- server/tests/blog_test.go | 52 ++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index d1014fc..0fb317c 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "github.com/DATA-DOG/go-sqlmock" + "github.com/sean-david-welch/farmec-v2/server/database" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "net/http" @@ -18,7 +19,6 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/services" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" ) type BlogTestSuite struct { @@ -32,17 +32,25 @@ func (suite *BlogTestSuite) SetupTest() { db, mock, err := sqlmock.New() require.NoError(suite.T(), err) - schema := `CREATE TABLE Blog ( - id TEXT PRIMARY KEY, - title TEXT, - date TEXT, - main_image TEXT, - subheading TEXT, - body TEXT, - created TEXT - );` - - _, err = db.Exec(schema) + mock.ExpectExec(`CREATE TABLE Blog \( + id TEXT PRIMARY KEY, + title TEXT, + date TEXT, + main_image TEXT, + subheading TEXT, + body TEXT, + created TEXT + \);`).WillReturnResult(sqlmock.NewResult(0, 0)) + + _, err = db.Exec(`CREATE TABLE Blog ( + id TEXT PRIMARY KEY, + title TEXT, + date TEXT, + main_image TEXT, + subheading TEXT, + body TEXT, + created TEXT + );`) require.NoError(suite.T(), err) suite.db = db @@ -80,27 +88,31 @@ func (suite *BlogTestSuite) TestGetBlogs() { require.Equal(suite.T(), http.StatusOK, resp.StatusCode) - var blogs []types.Blog + var blogs []database.Blog err = json.NewDecoder(resp.Body).Decode(&blogs) require.NoError(suite.T(), err) require.Len(suite.T(), blogs, 1) require.Equal(suite.T(), "Test Title", blogs[0].Title) + require.Equal(suite.T(), "2023-01-01", blogs[0].Date.String) err = suite.mock.ExpectationsWereMet() require.NoError(suite.T(), err) } func (suite *BlogTestSuite) TestCreateBlog() { - blog := types.Blog{ + blog := database.Blog{ + ID: "", Title: "New Blog", - Date: "2024-01-01", - MainImage: "new_image.jpg", - Subheading: "New Subheading", - Body: "New Body", - Created: "2024-01-01 12:00:00", + Date: sql.NullString{String: "2024-06-23", Valid: true}, + MainImage: sql.NullString{String: "image.jpg", Valid: true}, + Subheading: sql.NullString{String: "This is a subheading", Valid: true}, + Body: sql.NullString{String: "This is the body of the blog.", Valid: true}, + Created: sql.NullString{String: "2024-06-23 10:00:00", Valid: true}, } - payload, _ := json.Marshal(blog) + + payload, err := json.Marshal(blog) + require.NoError(suite.T(), err) suite.mock.ExpectExec("INSERT INTO Blog"). WithArgs(sqlmock.AnyArg(), blog.Title, blog.Date, blog.MainImage, blog.Subheading, blog.Body, blog.Created). From 3bcb0cc86fd1c1d41220fbd1a7f0223d87c141d0 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:31:38 +0100 Subject: [PATCH 020/248] refactor sqlc out --- server/{database => db}/blogs.sql.go | 2 +- server/{database => db}/db.go | 2 +- server/{database => db}/models.go | 2 +- server/handlers/blogHandler.go | 6 +++--- server/services/blogService.go | 18 ++++++++-------- server/sql/sqlc.yaml | 4 ++-- server/stores/blogStore.go | 32 ++++++++++++++-------------- server/tests/blog_test.go | 6 +++--- 8 files changed, 36 insertions(+), 36 deletions(-) rename server/{database => db}/blogs.sql.go (99%) rename server/{database => db}/db.go (97%) rename server/{database => db}/models.go (99%) diff --git a/server/database/blogs.sql.go b/server/db/blogs.sql.go similarity index 99% rename from server/database/blogs.sql.go rename to server/db/blogs.sql.go index 3ec9d06..e958def 100644 --- a/server/database/blogs.sql.go +++ b/server/db/blogs.sql.go @@ -3,7 +3,7 @@ // sqlc v1.26.0 // source: blogs.sql -package database +package db import ( "context" diff --git a/server/database/db.go b/server/db/db.go similarity index 97% rename from server/database/db.go rename to server/db/db.go index a3cc795..17d86e9 100644 --- a/server/database/db.go +++ b/server/db/db.go @@ -2,7 +2,7 @@ // versions: // sqlc v1.26.0 -package database +package db import ( "context" diff --git a/server/database/models.go b/server/db/models.go similarity index 99% rename from server/database/models.go rename to server/db/models.go index 783a684..cea0311 100644 --- a/server/database/models.go +++ b/server/db/models.go @@ -2,7 +2,7 @@ // versions: // sqlc v1.26.0 -package database +package db import ( "database/sql" diff --git a/server/handlers/blogHandler.go b/server/handlers/blogHandler.go index 6a1b4cb..f9b1531 100644 --- a/server/handlers/blogHandler.go +++ b/server/handlers/blogHandler.go @@ -1,7 +1,7 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/database" + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" @@ -41,7 +41,7 @@ func (handler *BlogHandler) GetBlogByID(context *gin.Context) { } func (handler *BlogHandler) CreateBlog(context *gin.Context) { - var blog database.Blog + var blog db.Blog if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while creating blog: %v", err) @@ -64,7 +64,7 @@ func (handler *BlogHandler) CreateBlog(context *gin.Context) { func (handler *BlogHandler) UpdateBlog(context *gin.Context) { id := context.Param("id") - var blog database.Blog + var blog db.Blog if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while updating blog: %v", err) diff --git a/server/services/blogService.go b/server/services/blogService.go index d7d259c..a19fd6f 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -3,7 +3,7 @@ package services import ( "database/sql" "errors" - "github.com/sean-david-welch/farmec-v2/server/database" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -12,10 +12,10 @@ import ( ) type BlogService interface { - GetBlogs() ([]database.Blog, error) - GetBlogsByID(id string) (*database.Blog, error) - CreateBlog(blog *database.Blog) (*types.ModelResult, error) - UpdateBlog(id string, blog *database.Blog) (*types.ModelResult, error) + GetBlogs() ([]db.Blog, error) + GetBlogsByID(id string) (*db.Blog, error) + CreateBlog(blog *db.Blog) (*types.ModelResult, error) + UpdateBlog(id string, blog *db.Blog) (*types.ModelResult, error) DeleteBlog(id string) error } @@ -29,7 +29,7 @@ func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *BlogServiceImpl) GetBlogs() ([]database.Blog, error) { +func (service *BlogServiceImpl) GetBlogs() ([]db.Blog, error) { blogs, err := service.store.GetBlogs() if err != nil { return nil, err @@ -38,7 +38,7 @@ func (service *BlogServiceImpl) GetBlogs() ([]database.Blog, error) { return blogs, nil } -func (service *BlogServiceImpl) GetBlogsByID(id string) (*database.Blog, error) { +func (service *BlogServiceImpl) GetBlogsByID(id string) (*db.Blog, error) { blog, err := service.store.GetBlogById(id) if err != nil { return nil, err @@ -47,7 +47,7 @@ func (service *BlogServiceImpl) GetBlogsByID(id string) (*database.Blog, error) return blog, nil } -func (service *BlogServiceImpl) CreateBlog(blog *database.Blog) (*types.ModelResult, error) { +func (service *BlogServiceImpl) CreateBlog(blog *db.Blog) (*types.ModelResult, error) { image := blog.MainImage if !image.Valid { @@ -74,7 +74,7 @@ func (service *BlogServiceImpl) CreateBlog(blog *database.Blog) (*types.ModelRes return result, nil } -func (service *BlogServiceImpl) UpdateBlog(id string, blog *database.Blog) (*types.ModelResult, error) { +func (service *BlogServiceImpl) UpdateBlog(id string, blog *db.Blog) (*types.ModelResult, error) { image := blog.MainImage var presignedUrl, imageUrl string diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml index 2521b1e..85ee997 100644 --- a/server/sql/sqlc.yaml +++ b/server/sql/sqlc.yaml @@ -5,6 +5,6 @@ sql: schema: "schema.sql" gen: go: - package: "database" - out: "../database" + package: "db" + out: "../db" emit_json_tags: true diff --git a/server/stores/blogStore.go b/server/stores/blogStore.go index ea0cdbb..f063bd5 100644 --- a/server/stores/blogStore.go +++ b/server/stores/blogStore.go @@ -5,30 +5,30 @@ import ( "database/sql" "fmt" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/database" + "github.com/sean-david-welch/farmec-v2/server/db" "time" ) type BlogStore interface { - GetBlogs() ([]database.Blog, error) - GetBlogById(id string) (*database.Blog, error) - CreateBlog(blog *database.Blog) error - UpdateBlog(id string, blog *database.Blog) error + GetBlogs() ([]db.Blog, error) + GetBlogById(id string) (*db.Blog, error) + CreateBlog(blog *db.Blog) error + UpdateBlog(id string, blog *db.Blog) error DeleteBlog(id string) error } type BlogStoreImpl struct { - queries *database.Queries + queries *db.Queries } func NewBlogStore(sql *sql.DB) *BlogStoreImpl { - queries := database.New(sql) + queries := db.New(sql) return &BlogStoreImpl{ queries: queries, } } -func (store *BlogStoreImpl) GetBlogs() ([]database.Blog, error) { +func (store *BlogStoreImpl) GetBlogs() ([]db.Blog, error) { ctx := context.Background() blogs, err := store.queries.GetBlogs(ctx) if err != nil { @@ -36,9 +36,9 @@ func (store *BlogStoreImpl) GetBlogs() ([]database.Blog, error) { } // Convert from the generated database to your database if needed - var result []database.Blog + var result []db.Blog for _, blog := range blogs { - result = append(result, database.Blog{ + result = append(result, db.Blog{ ID: blog.ID, Title: blog.Title, Date: blog.Date, @@ -52,7 +52,7 @@ func (store *BlogStoreImpl) GetBlogs() ([]database.Blog, error) { return result, nil } -func (store *BlogStoreImpl) GetBlogById(id string) (*database.Blog, error) { +func (store *BlogStoreImpl) GetBlogById(id string) (*db.Blog, error) { ctx := context.Background() blog, err := store.queries.GetBlogByID(ctx, id) if err != nil { @@ -62,12 +62,12 @@ func (store *BlogStoreImpl) GetBlogById(id string) (*database.Blog, error) { return &blog, nil } -func (store *BlogStoreImpl) CreateBlog(blog *database.Blog) error { +func (store *BlogStoreImpl) CreateBlog(blog *db.Blog) error { ctx := context.Background() blog.ID = uuid.NewString() blog.Created = sql.NullString{String: time.Now().String(), Valid: true} - params := database.CreateBlogParams{ + params := db.CreateBlogParams{ ID: blog.ID, Title: blog.Title, Date: blog.Date, @@ -85,11 +85,11 @@ func (store *BlogStoreImpl) CreateBlog(blog *database.Blog) error { return nil } -func (store *BlogStoreImpl) UpdateBlog(id string, blog *database.Blog) error { +func (store *BlogStoreImpl) UpdateBlog(id string, blog *db.Blog) error { ctx := context.Background() if blog.MainImage.Valid { - params := database.UpdateBlogParams{ + params := db.UpdateBlogParams{ Title: blog.Title, MainImage: blog.MainImage, Date: blog.Date, @@ -102,7 +102,7 @@ func (store *BlogStoreImpl) UpdateBlog(id string, blog *database.Blog) error { return fmt.Errorf("error occurred while updating blog with image: %w", err) } } else { - params := database.UpdateBlogNoImageParams{ + params := db.UpdateBlogNoImageParams{ Title: blog.Title, Date: blog.Date, Subheading: blog.Subheading, diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index 0fb317c..73681d2 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -6,7 +6,7 @@ import ( "encoding/json" "fmt" "github.com/DATA-DOG/go-sqlmock" - "github.com/sean-david-welch/farmec-v2/server/database" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "net/http" @@ -88,7 +88,7 @@ func (suite *BlogTestSuite) TestGetBlogs() { require.Equal(suite.T(), http.StatusOK, resp.StatusCode) - var blogs []database.Blog + var blogs []db.Blog err = json.NewDecoder(resp.Body).Decode(&blogs) require.NoError(suite.T(), err) @@ -101,7 +101,7 @@ func (suite *BlogTestSuite) TestGetBlogs() { } func (suite *BlogTestSuite) TestCreateBlog() { - blog := database.Blog{ + blog := db.Blog{ ID: "", Title: "New Blog", Date: sql.NullString{String: "2024-06-23", Valid: true}, From c39ed6709212298f43b23885856b377cb7527c99 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:32:39 +0100 Subject: [PATCH 021/248] refactor --- server/tests/blog_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index 73681d2..f4130a0 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -29,7 +29,7 @@ type BlogTestSuite struct { } func (suite *BlogTestSuite) SetupTest() { - db, mock, err := sqlmock.New() + database, mock, err := sqlmock.New() require.NoError(suite.T(), err) mock.ExpectExec(`CREATE TABLE Blog \( @@ -42,7 +42,7 @@ func (suite *BlogTestSuite) SetupTest() { created TEXT \);`).WillReturnResult(sqlmock.NewResult(0, 0)) - _, err = db.Exec(`CREATE TABLE Blog ( + _, err = database.Exec(`CREATE TABLE Blog ( id TEXT PRIMARY KEY, title TEXT, date TEXT, @@ -53,10 +53,10 @@ func (suite *BlogTestSuite) SetupTest() { );`) require.NoError(suite.T(), err) - suite.db = db + suite.db = database suite.mock = mock - store := stores.NewBlogStore(db) + store := stores.NewBlogStore(database) s3Client := lib.NewNoOpS3Client() service := services.NewBlogService(store, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) From e428559f764a500f8f21669aa8024f9fa5c86732 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:34:48 +0100 Subject: [PATCH 022/248] ignore database --- server/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/server/.gitignore b/server/.gitignore index a0acbe1..f0a5537 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -3,6 +3,7 @@ .env-development .env-production service-account.json +/database /database/database.db /database/database.db-shm /database/database.db-wal From ecdc672789db8523ef46fbd0c839b7cf4d420568 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:48:24 +0100 Subject: [PATCH 023/248] update sql queries lower case --- server/sql/queries/blogs.sql | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server/sql/queries/blogs.sql b/server/sql/queries/blogs.sql index 2e048ae..d130b4c 100644 --- a/server/sql/queries/blogs.sql +++ b/server/sql/queries/blogs.sql @@ -1,27 +1,27 @@ -- name: GetBlogs :many -SELECT id, title, date, main_image, subheading, body, created -FROM Blog -ORDER BY created DESC; +select id, title, date, main_image, subheading, body, created +from Blog +order by created desc; -- name: GetBlogByID :one -SELECT id, title, date, main_image, subheading, body, created -FROM Blog -WHERE id = ?; +select id, title, date, main_image, subheading, body, created +from Blog +where id = ?; -- name: CreateBlog :exec -INSERT INTO Blog (id, title, date, main_image, subheading, body, created) -VALUES (?, ?, ?, ?, ?, ?, ?); +insert into Blog (id, title, date, main_image, subheading, body, created) +values (?, ?, ?, ?, ?, ?, ?); -- name: UpdateBlogNoImage :exec -UPDATE Blog -SET title = ?, date = ?, subheading = ?, body = ? -WHERE id = ?; +update Blog +set title = ?, date = ?, subheading = ?, body = ? +where id = ?; -- name: UpdateBlog :exec -UPDATE Blog -SET title = ?, date = ?, main_image = ?, subheading = ?, body = ? -WHERE id = ?; +update Blog +set title = ?, date = ?, main_image = ?, subheading = ?, body = ? +where id = ?; -- name: DeleteBlog :exec -DELETE FROM Blog -WHERE id = ?; +delete from Blog +where id = ?; From 12a8802b0316f542a2e26e9b55821286d6d51697 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:53:35 +0100 Subject: [PATCH 024/248] supplier queries --- server/sql/queries/suppliers.sql | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 server/sql/queries/suppliers.sql diff --git a/server/sql/queries/suppliers.sql b/server/sql/queries/suppliers.sql new file mode 100644 index 0000000..de734c2 --- /dev/null +++ b/server/sql/queries/suppliers.sql @@ -0,0 +1,35 @@ +-- name: GetSuppliers :many +select id, name, logo_image, marketing_image, + description, social_facebook, social_instagram, + social_linkedin, social_twitter, social_youtube, social_website, created +from Supplier +order by created desc ; + +-- name: GetSupplierByID :one +select id, name, logo_image, marketing_image, + description, social_facebook, social_instagram, + social_linkedin, social_twitter, social_youtube, social_website, created +from Supplier +where id = ?; + +-- name: CreateSupplier :exec +insert into Supplier (id, name, logo_image, marketing_image, description, + social_facebook, social_twitter, social_instagram, + social_youtube, social_linkedin, social_website, created) +values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: UpdateSupplierNoImage :exec +update Supplier +set name = ?, description = ?, social_facebook = ?, social_twitter = ?, + social_instagram = ?, social_youtube = ?, social_linkedin = ?, social_website = ? +where id = ?; + +-- name: UpdateSupplier :exec +update Supplier +set name = ?, logo_image = ?, marketing_image = ?, description = ?, + social_facebook = ?, social_twitter = ?, social_instagram = ?, social_youtube = ?, + social_linkedin = ?, social_website = ? +where id = ?; + +-- name: DeleteSupplier :exec +delete from Supplier where id = ? \ No newline at end of file From 3df92e0a12b841c3a4e7ba8b0674a523ace42c4d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:54:45 +0100 Subject: [PATCH 025/248] supplier queries gen --- server/db/blogs.sql.go | 32 ++--- server/db/suppliers.sql.go | 237 +++++++++++++++++++++++++++++++++++++ 2 files changed, 253 insertions(+), 16 deletions(-) create mode 100644 server/db/suppliers.sql.go diff --git a/server/db/blogs.sql.go b/server/db/blogs.sql.go index e958def..8eefc07 100644 --- a/server/db/blogs.sql.go +++ b/server/db/blogs.sql.go @@ -11,8 +11,8 @@ import ( ) const createBlog = `-- name: CreateBlog :exec -INSERT INTO Blog (id, title, date, main_image, subheading, body, created) -VALUES (?, ?, ?, ?, ?, ?, ?) +insert into Blog (id, title, date, main_image, subheading, body, created) +values (?, ?, ?, ?, ?, ?, ?) ` type CreateBlogParams struct { @@ -39,8 +39,8 @@ func (q *Queries) CreateBlog(ctx context.Context, arg CreateBlogParams) error { } const deleteBlog = `-- name: DeleteBlog :exec -DELETE FROM Blog -WHERE id = ? +delete from Blog +where id = ? ` func (q *Queries) DeleteBlog(ctx context.Context, id string) error { @@ -49,9 +49,9 @@ func (q *Queries) DeleteBlog(ctx context.Context, id string) error { } const getBlogByID = `-- name: GetBlogByID :one -SELECT id, title, date, main_image, subheading, body, created -FROM Blog -WHERE id = ? +select id, title, date, main_image, subheading, body, created +from Blog +where id = ? ` func (q *Queries) GetBlogByID(ctx context.Context, id string) (Blog, error) { @@ -70,9 +70,9 @@ func (q *Queries) GetBlogByID(ctx context.Context, id string) (Blog, error) { } const getBlogs = `-- name: GetBlogs :many -SELECT id, title, date, main_image, subheading, body, created -FROM Blog -ORDER BY created DESC +select id, title, date, main_image, subheading, body, created +from Blog +order by created desc ` func (q *Queries) GetBlogs(ctx context.Context) ([]Blog, error) { @@ -107,9 +107,9 @@ func (q *Queries) GetBlogs(ctx context.Context) ([]Blog, error) { } const updateBlog = `-- name: UpdateBlog :exec -UPDATE Blog -SET title = ?, date = ?, main_image = ?, subheading = ?, body = ? -WHERE id = ? +update Blog +set title = ?, date = ?, main_image = ?, subheading = ?, body = ? +where id = ? ` type UpdateBlogParams struct { @@ -134,9 +134,9 @@ func (q *Queries) UpdateBlog(ctx context.Context, arg UpdateBlogParams) error { } const updateBlogNoImage = `-- name: UpdateBlogNoImage :exec -UPDATE Blog -SET title = ?, date = ?, subheading = ?, body = ? -WHERE id = ? +update Blog +set title = ?, date = ?, subheading = ?, body = ? +where id = ? ` type UpdateBlogNoImageParams struct { diff --git a/server/db/suppliers.sql.go b/server/db/suppliers.sql.go new file mode 100644 index 0000000..5b4b978 --- /dev/null +++ b/server/db/suppliers.sql.go @@ -0,0 +1,237 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: suppliers.sql + +package db + +import ( + "context" + "database/sql" +) + +const createSupplier = `-- name: CreateSupplier :exec +insert into Supplier (id, name, logo_image, marketing_image, description, + social_facebook, social_twitter, social_instagram, + social_youtube, social_linkedin, social_website, created) +values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +` + +type CreateSupplierParams struct { + ID string `json:"id"` + Name string `json:"name"` + LogoImage sql.NullString `json:"logo_image"` + MarketingImage sql.NullString `json:"marketing_image"` + Description sql.NullString `json:"description"` + SocialFacebook sql.NullString `json:"social_facebook"` + SocialTwitter sql.NullString `json:"social_twitter"` + SocialInstagram sql.NullString `json:"social_instagram"` + SocialYoutube sql.NullString `json:"social_youtube"` + SocialLinkedin sql.NullString `json:"social_linkedin"` + SocialWebsite sql.NullString `json:"social_website"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateSupplier(ctx context.Context, arg CreateSupplierParams) error { + _, err := q.db.ExecContext(ctx, createSupplier, + arg.ID, + arg.Name, + arg.LogoImage, + arg.MarketingImage, + arg.Description, + arg.SocialFacebook, + arg.SocialTwitter, + arg.SocialInstagram, + arg.SocialYoutube, + arg.SocialLinkedin, + arg.SocialWebsite, + arg.Created, + ) + return err +} + +const deleteSupplier = `-- name: DeleteSupplier :exec +delete from Supplier where id = ? +` + +func (q *Queries) DeleteSupplier(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteSupplier, id) + return err +} + +const getSupplierByID = `-- name: GetSupplierByID :one +; + +select id, name, logo_image, marketing_image, + description, social_facebook, social_instagram, + social_linkedin, social_twitter, social_youtube, social_website, created +from Supplier +where id = ? +` + +type GetSupplierByIDRow struct { + ID string `json:"id"` + Name string `json:"name"` + LogoImage sql.NullString `json:"logo_image"` + MarketingImage sql.NullString `json:"marketing_image"` + Description sql.NullString `json:"description"` + SocialFacebook sql.NullString `json:"social_facebook"` + SocialInstagram sql.NullString `json:"social_instagram"` + SocialLinkedin sql.NullString `json:"social_linkedin"` + SocialTwitter sql.NullString `json:"social_twitter"` + SocialYoutube sql.NullString `json:"social_youtube"` + SocialWebsite sql.NullString `json:"social_website"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) GetSupplierByID(ctx context.Context, id string) (GetSupplierByIDRow, error) { + row := q.db.QueryRowContext(ctx, getSupplierByID, id) + var i GetSupplierByIDRow + err := row.Scan( + &i.ID, + &i.Name, + &i.LogoImage, + &i.MarketingImage, + &i.Description, + &i.SocialFacebook, + &i.SocialInstagram, + &i.SocialLinkedin, + &i.SocialTwitter, + &i.SocialYoutube, + &i.SocialWebsite, + &i.Created, + ) + return i, err +} + +const getSuppliers = `-- name: GetSuppliers :many +select id, name, logo_image, marketing_image, + description, social_facebook, social_instagram, + social_linkedin, social_twitter, social_youtube, social_website, created +from Supplier +order by created desc +` + +type GetSuppliersRow struct { + ID string `json:"id"` + Name string `json:"name"` + LogoImage sql.NullString `json:"logo_image"` + MarketingImage sql.NullString `json:"marketing_image"` + Description sql.NullString `json:"description"` + SocialFacebook sql.NullString `json:"social_facebook"` + SocialInstagram sql.NullString `json:"social_instagram"` + SocialLinkedin sql.NullString `json:"social_linkedin"` + SocialTwitter sql.NullString `json:"social_twitter"` + SocialYoutube sql.NullString `json:"social_youtube"` + SocialWebsite sql.NullString `json:"social_website"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) GetSuppliers(ctx context.Context) ([]GetSuppliersRow, error) { + rows, err := q.db.QueryContext(ctx, getSuppliers) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetSuppliersRow + for rows.Next() { + var i GetSuppliersRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.LogoImage, + &i.MarketingImage, + &i.Description, + &i.SocialFacebook, + &i.SocialInstagram, + &i.SocialLinkedin, + &i.SocialTwitter, + &i.SocialYoutube, + &i.SocialWebsite, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateSupplier = `-- name: UpdateSupplier :exec +update Supplier +set name = ?, logo_image = ?, marketing_image = ?, description = ?, + social_facebook = ?, social_twitter = ?, social_instagram = ?, social_youtube = ?, + social_linkedin = ?, social_website = ? +where id = ? +` + +type UpdateSupplierParams struct { + Name string `json:"name"` + LogoImage sql.NullString `json:"logo_image"` + MarketingImage sql.NullString `json:"marketing_image"` + Description sql.NullString `json:"description"` + SocialFacebook sql.NullString `json:"social_facebook"` + SocialTwitter sql.NullString `json:"social_twitter"` + SocialInstagram sql.NullString `json:"social_instagram"` + SocialYoutube sql.NullString `json:"social_youtube"` + SocialLinkedin sql.NullString `json:"social_linkedin"` + SocialWebsite sql.NullString `json:"social_website"` + ID string `json:"id"` +} + +func (q *Queries) UpdateSupplier(ctx context.Context, arg UpdateSupplierParams) error { + _, err := q.db.ExecContext(ctx, updateSupplier, + arg.Name, + arg.LogoImage, + arg.MarketingImage, + arg.Description, + arg.SocialFacebook, + arg.SocialTwitter, + arg.SocialInstagram, + arg.SocialYoutube, + arg.SocialLinkedin, + arg.SocialWebsite, + arg.ID, + ) + return err +} + +const updateSupplierNoImage = `-- name: UpdateSupplierNoImage :exec +update Supplier +set name = ?, description = ?, social_facebook = ?, social_twitter = ?, + social_instagram = ?, social_youtube = ?, social_linkedin = ?, social_website = ? +where id = ? +` + +type UpdateSupplierNoImageParams struct { + Name string `json:"name"` + Description sql.NullString `json:"description"` + SocialFacebook sql.NullString `json:"social_facebook"` + SocialTwitter sql.NullString `json:"social_twitter"` + SocialInstagram sql.NullString `json:"social_instagram"` + SocialYoutube sql.NullString `json:"social_youtube"` + SocialLinkedin sql.NullString `json:"social_linkedin"` + SocialWebsite sql.NullString `json:"social_website"` + ID string `json:"id"` +} + +func (q *Queries) UpdateSupplierNoImage(ctx context.Context, arg UpdateSupplierNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateSupplierNoImage, + arg.Name, + arg.Description, + arg.SocialFacebook, + arg.SocialTwitter, + arg.SocialInstagram, + arg.SocialYoutube, + arg.SocialLinkedin, + arg.SocialWebsite, + arg.ID, + ) + return err +} From 852fad822b565d5875918107e975c68161def0cf Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 16:54:54 +0100 Subject: [PATCH 026/248] makefile sqlc --- server/makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/makefile b/server/makefile index 68f8fcd..16bc99a 100644 --- a/server/makefile +++ b/server/makefile @@ -18,4 +18,7 @@ dev: ENV=development PORT=8000 air database: - scp -i ~/.ssh/farmec.pem -r ${REMOTE_HOST}:/home/seanwelch/server/bin/database/* ./database/ \ No newline at end of file + scp -i ~/.ssh/farmec.pem -r ${REMOTE_HOST}:/home/seanwelch/server/bin/database/* ./database/ + +sqlc: + cd sql && sqlc generate \ No newline at end of file From aa43bab8dd691d27892272d92169f2a3740acd5a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 17:05:05 +0100 Subject: [PATCH 027/248] carousel queries --- server/sql/queries/carousel.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 server/sql/queries/carousel.sql diff --git a/server/sql/queries/carousel.sql b/server/sql/queries/carousel.sql new file mode 100644 index 0000000..fdfa719 --- /dev/null +++ b/server/sql/queries/carousel.sql @@ -0,0 +1,14 @@ +--name: GetCarousels :many +select id, name, image, created from Carousel order by created desc; + +-- name: GetCarouselByID :one +select id, name, image, created from Carousel where id = ?; + +-- name: CreateCarousel :exec +insert into Carousel (id, name, image, created) VALUES (?, ?, ?, ?); + +-- name: UpdateCarousel :exec +update Carousel set name = ?, image = ? where id = ?; + +-- name: DeleteCarousel :exec +delete from Carousel where id = ?; \ No newline at end of file From ac2b0eb0318ffcec150994c4a4c3a6c7b96e06b3 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 17:05:52 +0100 Subject: [PATCH 028/248] carousel gen code --- server/db/carousel.sql.go | 104 ++++++++++++++++++++++++++++++++ server/sql/queries/carousel.sql | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 server/db/carousel.sql.go diff --git a/server/db/carousel.sql.go b/server/db/carousel.sql.go new file mode 100644 index 0000000..d5504ad --- /dev/null +++ b/server/db/carousel.sql.go @@ -0,0 +1,104 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: carousel.sql + +package db + +import ( + "context" + "database/sql" +) + +const createCarousel = `-- name: CreateCarousel :exec +insert into Carousel (id, name, image, created) VALUES (?, ?, ?, ?) +` + +type CreateCarouselParams struct { + ID string `json:"id"` + Name string `json:"name"` + Image sql.NullString `json:"image"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateCarousel(ctx context.Context, arg CreateCarouselParams) error { + _, err := q.db.ExecContext(ctx, createCarousel, + arg.ID, + arg.Name, + arg.Image, + arg.Created, + ) + return err +} + +const deleteCarousel = `-- name: DeleteCarousel :exec +delete from Carousel where id = ? +` + +func (q *Queries) DeleteCarousel(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteCarousel, id) + return err +} + +const getCarouselByID = `-- name: GetCarouselByID :one +select id, name, image, created from Carousel where id = ? +` + +func (q *Queries) GetCarouselByID(ctx context.Context, id string) (Carousel, error) { + row := q.db.QueryRowContext(ctx, getCarouselByID, id) + var i Carousel + err := row.Scan( + &i.ID, + &i.Name, + &i.Image, + &i.Created, + ) + return i, err +} + +const getCarousels = `-- name: GetCarousels :many +select id, name, image, created from Carousel order by created desc +` + +func (q *Queries) GetCarousels(ctx context.Context) ([]Carousel, error) { + rows, err := q.db.QueryContext(ctx, getCarousels) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Carousel + for rows.Next() { + var i Carousel + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Image, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateCarousel = `-- name: UpdateCarousel :exec +update Carousel set name = ?, image = ? where id = ? +` + +type UpdateCarouselParams struct { + Name string `json:"name"` + Image sql.NullString `json:"image"` + ID string `json:"id"` +} + +func (q *Queries) UpdateCarousel(ctx context.Context, arg UpdateCarouselParams) error { + _, err := q.db.ExecContext(ctx, updateCarousel, arg.Name, arg.Image, arg.ID) + return err +} diff --git a/server/sql/queries/carousel.sql b/server/sql/queries/carousel.sql index fdfa719..8d0cf75 100644 --- a/server/sql/queries/carousel.sql +++ b/server/sql/queries/carousel.sql @@ -1,4 +1,4 @@ ---name: GetCarousels :many +-- name: GetCarousels :many select id, name, image, created from Carousel order by created desc; -- name: GetCarouselByID :one From 06d583fd191001727b948777a8d92d2c9be2a492 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 17:21:28 +0100 Subject: [PATCH 029/248] employees.sql --- server/sql/queries/employees.sql | 23 +++++++++++++++++++++++ server/sql/queries/suppliers.sql | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 server/sql/queries/employees.sql diff --git a/server/sql/queries/employees.sql b/server/sql/queries/employees.sql new file mode 100644 index 0000000..34f209c --- /dev/null +++ b/server/sql/queries/employees.sql @@ -0,0 +1,23 @@ +-- name: GetEmployees :many +select id, name, email, role, profile_image, created +from Employee order by created desc; + +-- name: GetEmployee :one +select id, name, email, role, profile_image, created from Employee where id = ?; + +-- name: CreateEmployee :exec +insert into Employee (id, name, email, role, profile_image, created) +values (?, ?, ?, ?, ?, ?); + +-- name: UpdateEmployeeNoImage :exec +update Employee +set name = ?, email = ?, role = ? +where id = ?; + +-- name: UpdateEmployee :exec +update Employee +set name = ?, email = ?, role = ?, profile_image = ? +where id = ?; + +-- name: DeleteEmployee :exec +delete from Employee where id = ?; diff --git a/server/sql/queries/suppliers.sql b/server/sql/queries/suppliers.sql index de734c2..2b2bd47 100644 --- a/server/sql/queries/suppliers.sql +++ b/server/sql/queries/suppliers.sql @@ -3,7 +3,7 @@ select id, name, logo_image, marketing_image, description, social_facebook, social_instagram, social_linkedin, social_twitter, social_youtube, social_website, created from Supplier -order by created desc ; +order by created desc; -- name: GetSupplierByID :one select id, name, logo_image, marketing_image, From 61eaf6e82e492485b7d6d7199de4759345bb3e35 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 17:22:04 +0100 Subject: [PATCH 030/248] employees.sql.go --- server/db/employees.sql.go | 147 +++++++++++++++++++++++++++++++++++++ server/db/suppliers.sql.go | 2 - 2 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 server/db/employees.sql.go diff --git a/server/db/employees.sql.go b/server/db/employees.sql.go new file mode 100644 index 0000000..55e20cb --- /dev/null +++ b/server/db/employees.sql.go @@ -0,0 +1,147 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: employees.sql + +package db + +import ( + "context" + "database/sql" +) + +const createEmployee = `-- name: CreateEmployee :exec +insert into Employee (id, name, email, role, profile_image, created) +values (?, ?, ?, ?, ?, ?) +` + +type CreateEmployeeParams struct { + ID string `json:"id"` + Name string `json:"name"` + Email string `json:"email"` + Role string `json:"role"` + ProfileImage sql.NullString `json:"profile_image"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateEmployee(ctx context.Context, arg CreateEmployeeParams) error { + _, err := q.db.ExecContext(ctx, createEmployee, + arg.ID, + arg.Name, + arg.Email, + arg.Role, + arg.ProfileImage, + arg.Created, + ) + return err +} + +const deleteEmployee = `-- name: DeleteEmployee :exec +delete from Employee where id = ? +` + +func (q *Queries) DeleteEmployee(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteEmployee, id) + return err +} + +const getEmployee = `-- name: GetEmployee :one +select id, name, email, role, profile_image, created from Employee where id = ? +` + +func (q *Queries) GetEmployee(ctx context.Context, id string) (Employee, error) { + row := q.db.QueryRowContext(ctx, getEmployee, id) + var i Employee + err := row.Scan( + &i.ID, + &i.Name, + &i.Email, + &i.Role, + &i.ProfileImage, + &i.Created, + ) + return i, err +} + +const getEmployees = `-- name: GetEmployees :many +select id, name, email, role, profile_image, created +from Employee order by created desc +` + +func (q *Queries) GetEmployees(ctx context.Context) ([]Employee, error) { + rows, err := q.db.QueryContext(ctx, getEmployees) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Employee + for rows.Next() { + var i Employee + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Email, + &i.Role, + &i.ProfileImage, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateEmployee = `-- name: UpdateEmployee :exec +update Employee +set name = ?, email = ?, role = ?, profile_image = ? +where id = ? +` + +type UpdateEmployeeParams struct { + Name string `json:"name"` + Email string `json:"email"` + Role string `json:"role"` + ProfileImage sql.NullString `json:"profile_image"` + ID string `json:"id"` +} + +func (q *Queries) UpdateEmployee(ctx context.Context, arg UpdateEmployeeParams) error { + _, err := q.db.ExecContext(ctx, updateEmployee, + arg.Name, + arg.Email, + arg.Role, + arg.ProfileImage, + arg.ID, + ) + return err +} + +const updateEmployeeNoImage = `-- name: UpdateEmployeeNoImage :exec +update Employee +set name = ?, email = ?, role = ? +where id = ? +` + +type UpdateEmployeeNoImageParams struct { + Name string `json:"name"` + Email string `json:"email"` + Role string `json:"role"` + ID string `json:"id"` +} + +func (q *Queries) UpdateEmployeeNoImage(ctx context.Context, arg UpdateEmployeeNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateEmployeeNoImage, + arg.Name, + arg.Email, + arg.Role, + arg.ID, + ) + return err +} diff --git a/server/db/suppliers.sql.go b/server/db/suppliers.sql.go index 5b4b978..c18c694 100644 --- a/server/db/suppliers.sql.go +++ b/server/db/suppliers.sql.go @@ -60,8 +60,6 @@ func (q *Queries) DeleteSupplier(ctx context.Context, id string) error { } const getSupplierByID = `-- name: GetSupplierByID :one -; - select id, name, logo_image, marketing_image, description, social_facebook, social_instagram, social_linkedin, social_twitter, social_youtube, social_website, created From ea5d6fed7f2c44c24d7a99fa59ce2b5e8eb083b7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 14 Jul 2024 17:26:51 +0100 Subject: [PATCH 031/248] exhibition sql queries and gen code --- server/db/exhibition.sql.go | 122 ++++++++++++++++++++++++++++++ server/sql/queries/exhibition.sql | 16 ++++ 2 files changed, 138 insertions(+) create mode 100644 server/db/exhibition.sql.go create mode 100644 server/sql/queries/exhibition.sql diff --git a/server/db/exhibition.sql.go b/server/db/exhibition.sql.go new file mode 100644 index 0000000..5560445 --- /dev/null +++ b/server/db/exhibition.sql.go @@ -0,0 +1,122 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: exhibition.sql + +package db + +import ( + "context" + "database/sql" +) + +const createExhibition = `-- name: CreateExhibition :exec +insert into Exhibition (id, title, date, location, info, created) values (?, ?, ?, ?, ?, ?) +` + +type CreateExhibitionParams struct { + ID string `json:"id"` + Title string `json:"title"` + Date sql.NullString `json:"date"` + Location sql.NullString `json:"location"` + Info sql.NullString `json:"info"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateExhibition(ctx context.Context, arg CreateExhibitionParams) error { + _, err := q.db.ExecContext(ctx, createExhibition, + arg.ID, + arg.Title, + arg.Date, + arg.Location, + arg.Info, + arg.Created, + ) + return err +} + +const deleteExhibition = `-- name: DeleteExhibition :exec +delete from Exhibition where id = ? +` + +func (q *Queries) DeleteExhibition(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteExhibition, id) + return err +} + +const getExhibitionByID = `-- name: GetExhibitionByID :one +select id, title, date, location, info, created from Exhibition where id = ? +` + +func (q *Queries) GetExhibitionByID(ctx context.Context, id string) (Exhibition, error) { + row := q.db.QueryRowContext(ctx, getExhibitionByID, id) + var i Exhibition + err := row.Scan( + &i.ID, + &i.Title, + &i.Date, + &i.Location, + &i.Info, + &i.Created, + ) + return i, err +} + +const getExhibitions = `-- name: GetExhibitions :many +select id, title, date, location, info, created from Exhibition order by created desc +` + +func (q *Queries) GetExhibitions(ctx context.Context) ([]Exhibition, error) { + rows, err := q.db.QueryContext(ctx, getExhibitions) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Exhibition + for rows.Next() { + var i Exhibition + if err := rows.Scan( + &i.ID, + &i.Title, + &i.Date, + &i.Location, + &i.Info, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateExhibition = `-- name: UpdateExhibition :exec +update Exhibition +set title = ?, date = ?, location = ?, info = ? +where id = ? +` + +type UpdateExhibitionParams struct { + Title string `json:"title"` + Date sql.NullString `json:"date"` + Location sql.NullString `json:"location"` + Info sql.NullString `json:"info"` + ID string `json:"id"` +} + +func (q *Queries) UpdateExhibition(ctx context.Context, arg UpdateExhibitionParams) error { + _, err := q.db.ExecContext(ctx, updateExhibition, + arg.Title, + arg.Date, + arg.Location, + arg.Info, + arg.ID, + ) + return err +} diff --git a/server/sql/queries/exhibition.sql b/server/sql/queries/exhibition.sql new file mode 100644 index 0000000..459e372 --- /dev/null +++ b/server/sql/queries/exhibition.sql @@ -0,0 +1,16 @@ +-- name: GetExhibitions :many +select id, title, date, location, info, created from Exhibition order by created desc; + +-- name: GetExhibitionByID :one +select id, title, date, location, info, created from Exhibition where id = ?; + +-- name: CreateExhibition :exec +insert into Exhibition (id, title, date, location, info, created) values (?, ?, ?, ?, ?, ?); + +-- name: UpdateExhibition :exec +update Exhibition +set title = ?, date = ?, location = ?, info = ? +where id = ?; + +-- name: DeleteExhibition :exec +delete from Exhibition where id = ?; \ No newline at end of file From 3b8d4ed4ae085295ff09627b64cfe2c26af5b693 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 15 Jul 2024 07:02:50 +0100 Subject: [PATCH 032/248] line items start --- server/sql/queries/lineitems.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 server/sql/queries/lineitems.sql diff --git a/server/sql/queries/lineitems.sql b/server/sql/queries/lineitems.sql new file mode 100644 index 0000000..2cd65ee --- /dev/null +++ b/server/sql/queries/lineitems.sql @@ -0,0 +1,2 @@ +-- name: GetLineItems :many +select id, name, price, image from LineItems; \ No newline at end of file From 044524d4a9bc0fa148e86f1e1b95333fc1876d09 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:36:57 +0100 Subject: [PATCH 033/248] rename package --- server/routes/blogRoutes.go | 4 ++-- server/routes/carouselRoutes.go | 4 ++-- server/routes/checkoutRoutes.go | 4 ++-- server/routes/employeeRoutes.go | 4 ++-- server/routes/exhibitionRoutes.go | 4 ++-- server/routes/lineItemRoutes.go | 4 ++-- server/routes/machineRoutes.go | 4 ++-- server/routes/partsRoutes.go | 4 ++-- server/routes/privacyRoutes.go | 4 ++-- server/routes/productRoutes.go | 4 ++-- server/routes/registrationRoutes.go | 4 ++-- server/routes/supplierRoutes.go | 4 ++-- server/routes/termsRoutes.go | 4 ++-- server/routes/timelineRoutes.go | 4 ++-- server/routes/videoRoutes.go | 4 ++-- server/routes/warrantyRoutes.go | 4 ++-- server/services/blogService.go | 6 +++--- server/services/carouselService.go | 6 +++--- server/services/checkoutService.go | 6 +++--- server/services/employeeService.go | 6 +++--- server/services/exhibitionService.go | 6 +++--- server/services/lineItemService.go | 6 +++--- server/services/machineService.go | 6 +++--- server/services/partsService.go | 6 +++--- server/services/privacyService.go | 6 +++--- server/services/productService.go | 6 +++--- server/services/registrationService.go | 6 +++--- server/services/supplierService.go | 6 +++--- server/services/termsService.go | 6 +++--- server/services/timelineService.go | 6 +++--- server/services/videoService.go | 6 +++--- server/services/warrantyService.go | 6 +++--- server/{stores => store}/blogStore.go | 2 +- server/{stores => store}/carouselStore.go | 2 +- server/{stores => store}/employeeStore.go | 2 +- server/{stores => store}/exhibitionStore.go | 2 +- server/{stores => store}/lineitemStore.go | 2 +- server/{stores => store}/machineStore.go | 2 +- server/{stores => store}/partsStore.go | 2 +- server/{stores => store}/privacyStore.go | 2 +- server/{stores => store}/productStore.go | 2 +- server/{stores => store}/registrationStore.go | 2 +- server/{stores => store}/supplierStore.go | 2 +- server/{stores => store}/termsStore.go | 2 +- server/{stores => store}/timelineStore.go | 2 +- server/{stores => store}/videoStore.go | 2 +- server/{stores => store}/warrantyStore.go | 2 +- server/tests/blog_test.go | 4 ++-- 48 files changed, 97 insertions(+), 97 deletions(-) rename server/{stores => store}/blogStore.go (99%) rename server/{stores => store}/carouselStore.go (99%) rename server/{stores => store}/employeeStore.go (99%) rename server/{stores => store}/exhibitionStore.go (99%) rename server/{stores => store}/lineitemStore.go (99%) rename server/{stores => store}/machineStore.go (99%) rename server/{stores => store}/partsStore.go (99%) rename server/{stores => store}/privacyStore.go (99%) rename server/{stores => store}/productStore.go (99%) rename server/{stores => store}/registrationStore.go (99%) rename server/{stores => store}/supplierStore.go (99%) rename server/{stores => store}/termsStore.go (99%) rename server/{stores => store}/timelineStore.go (99%) rename server/{stores => store}/videoStore.go (99%) rename server/{stores => store}/warrantyStore.go (99%) diff --git a/server/routes/blogRoutes.go b/server/routes/blogRoutes.go index 2a7c58c..a3e8336 100644 --- a/server/routes/blogRoutes.go +++ b/server/routes/blogRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitBlogs(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - blogStore := stores.NewBlogStore(database) + blogStore := store.NewBlogStore(database) service := services.NewBlogService(blogStore, s3Client, "Blogs") handler := handlers.NewBlogHandler(service) diff --git a/server/routes/carouselRoutes.go b/server/routes/carouselRoutes.go index cd818d4..6e4c999 100644 --- a/server/routes/carouselRoutes.go +++ b/server/routes/carouselRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitCarousel(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleare *middleware.AdminMiddleware) { - carouselStore := stores.NewCarouselStore(database) + carouselStore := store.NewCarouselStore(database) carouselService := services.NewCarouselService(carouselStore, s3Client, "Carousels") carouselHandler := handlers.NewCarouselHandler(carouselService) diff --git a/server/routes/checkoutRoutes.go b/server/routes/checkoutRoutes.go index 3f8e6ae..02de1a6 100644 --- a/server/routes/checkoutRoutes.go +++ b/server/routes/checkoutRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitCheckout(router *gin.Engine, database *sql.DB, secrets *lib.Secrets) { - itemStore := stores.NewLineItemStore(database) + itemStore := store.NewLineItemStore(database) service := services.NewCheckoutService(secrets, itemStore) handler := handlers.NewCheckoutHandler(service) diff --git a/server/routes/employeeRoutes.go b/server/routes/employeeRoutes.go index dbaee87..5f3b4ae 100644 --- a/server/routes/employeeRoutes.go +++ b/server/routes/employeeRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitializeEmployee(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - employeeStore := stores.NewEmployeeStore(database) + employeeStore := store.NewEmployeeStore(database) service := services.NewEmployeeService(employeeStore, s3Client, "Employees") handler := handlers.NewEmployeeHandler(service) diff --git a/server/routes/exhibitionRoutes.go b/server/routes/exhibitionRoutes.go index 755ae0e..b212c15 100644 --- a/server/routes/exhibitionRoutes.go +++ b/server/routes/exhibitionRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitExhibitions(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - exhibitionStore := stores.NewExhibitionStore(database) + exhibitionStore := store.NewExhibitionStore(database) service := services.NewExhibitionService(exhibitionStore) handler := handlers.NewExhibitionHandler(service) diff --git a/server/routes/lineItemRoutes.go b/server/routes/lineItemRoutes.go index 36fa7ad..d8e5efd 100644 --- a/server/routes/lineItemRoutes.go +++ b/server/routes/lineItemRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitLineItems(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - itemStore := stores.NewLineItemStore(database) + itemStore := store.NewLineItemStore(database) service := services.NewLineItemService(itemStore, s3Client, "Lineitems") handler := handlers.NewLineItemHandler(service) diff --git a/server/routes/machineRoutes.go b/server/routes/machineRoutes.go index 4eb6426..71c42be 100644 --- a/server/routes/machineRoutes.go +++ b/server/routes/machineRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitMachines(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - machineStore := stores.NewMachineStore(database) + machineStore := store.NewMachineStore(database) machineService := services.NewMachineService(machineStore, s3Client, "Machines") machineHandler := handlers.NewMachineHandler(machineService) diff --git a/server/routes/partsRoutes.go b/server/routes/partsRoutes.go index a39201b..e5d1223 100644 --- a/server/routes/partsRoutes.go +++ b/server/routes/partsRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitParts(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - partsStore := stores.NewPartsStore(database) + partsStore := store.NewPartsStore(database) partsService := services.NewPartsService(partsStore, s3Client, "Spareparts") partsHandler := handlers.NewPartsHandler(partsService) diff --git a/server/routes/privacyRoutes.go b/server/routes/privacyRoutes.go index 8202231..c771e10 100644 --- a/server/routes/privacyRoutes.go +++ b/server/routes/privacyRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitPrivacy(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - privacyStore := stores.NewPrivacyStore(database) + privacyStore := store.NewPrivacyStore(database) service := services.NewPrivacyService(privacyStore) handler := handlers.NewPrivacyHandler(service) diff --git a/server/routes/productRoutes.go b/server/routes/productRoutes.go index ffcaec0..5e06212 100644 --- a/server/routes/productRoutes.go +++ b/server/routes/productRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitProduct(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - productStore := stores.NewProductStore(database) + productStore := store.NewProductStore(database) productService := services.NewProductService(productStore, s3Client, "Products") productHandler := handlers.NewProductHandler(productService) diff --git a/server/routes/registrationRoutes.go b/server/routes/registrationRoutes.go index 4112a99..1a1d8d6 100644 --- a/server/routes/registrationRoutes.go +++ b/server/routes/registrationRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitRegistrations(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - store := stores.NewRegistrationStore(database) + store := store.NewRegistrationStore(database) service := services.NewRegistrationService(store, smtp) handler := handlers.NewRegistrationHandler(service) diff --git a/server/routes/supplierRoutes.go b/server/routes/supplierRoutes.go index eeb86cf..2c36039 100644 --- a/server/routes/supplierRoutes.go +++ b/server/routes/supplierRoutes.go @@ -9,11 +9,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitSuppliers(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - supplierStore := stores.NewSupplierStore(database) + supplierStore := store.NewSupplierStore(database) supplierService := services.NewSupplierService(supplierStore, s3Client, "Suppliers") supplierHandler := handlers.NewSupplierContoller(supplierService) diff --git a/server/routes/termsRoutes.go b/server/routes/termsRoutes.go index cd27699..f577399 100644 --- a/server/routes/termsRoutes.go +++ b/server/routes/termsRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitTerms(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - termsStore := stores.NewTermsStore(database) + termsStore := store.NewTermsStore(database) service := services.NewTermsService(termsStore) handler := handlers.NewTermsHandler(service) diff --git a/server/routes/timelineRoutes.go b/server/routes/timelineRoutes.go index 9e422d4..23a65af 100644 --- a/server/routes/timelineRoutes.go +++ b/server/routes/timelineRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitTimelines(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - timelineStore := stores.NewTimelineStore(database) + timelineStore := store.NewTimelineStore(database) service := services.NewTimelineService(timelineStore) handler := handlers.NewTimelineHandler(service) diff --git a/server/routes/videoRoutes.go b/server/routes/videoRoutes.go index 6ee7c34..d7d6c90 100644 --- a/server/routes/videoRoutes.go +++ b/server/routes/videoRoutes.go @@ -10,7 +10,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "google.golang.org/api/option" "google.golang.org/api/youtube/v3" ) @@ -21,7 +21,7 @@ func InitVideos(router *gin.Engine, database *sql.DB, secrets *lib.Secrets, admi log.Fatal("error calling YouTube API: ", err) } - videoStore := stores.NewVideoStore(database) + videoStore := store.NewVideoStore(database) videoService := services.NewVideoService(videoStore, youtubeService) videoHandler := handlers.NewVideoHandler(videoService) diff --git a/server/routes/warrantyRoutes.go b/server/routes/warrantyRoutes.go index fe7bfa3..25301d5 100644 --- a/server/routes/warrantyRoutes.go +++ b/server/routes/warrantyRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) func InitWarranty(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - warrantyStore := stores.NewWarrantyStore(database) + warrantyStore := store.NewWarrantyStore(database) service := services.NewWarrantyService(warrantyStore, smtp) handler := handlers.NewWarrantyHandler(service) diff --git a/server/services/blogService.go b/server/services/blogService.go index a19fd6f..a0c0580 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -7,7 +7,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,12 +20,12 @@ type BlogService interface { } type BlogServiceImpl struct { - store stores.BlogStore + store store.BlogStore s3Client lib.S3Client folder string } -func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { +func NewBlogService(store store.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/carouselService.go b/server/services/carouselService.go index f64d0ba..93e7539 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -17,12 +17,12 @@ type CarouselService interface { } type CarouselServiceImpl struct { - store stores.CarouselStore + store store.CarouselStore s3Client lib.S3Client folder string } -func NewCarouselService(store stores.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { +func NewCarouselService(store store.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { return &CarouselServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 3e9e250..6d85f6b 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -4,7 +4,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/stripe/stripe-go/v76" "github.com/stripe/stripe-go/v76/checkout/session" ) @@ -16,10 +16,10 @@ type CheckoutService interface { type CheckoutServiceImpl struct { secrets *lib.Secrets - store stores.LineItemStore + store store.LineItemStore } -func NewCheckoutService(secrets *lib.Secrets, store stores.LineItemStore) *CheckoutServiceImpl { +func NewCheckoutService(secrets *lib.Secrets, store store.LineItemStore) *CheckoutServiceImpl { return &CheckoutServiceImpl{secrets: secrets, store: store} } func (service *CheckoutServiceImpl) CreateCheckoutSession(id string) (*stripe.CheckoutSession, error) { diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 68f49cb..978157c 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -17,12 +17,12 @@ type EmployeeService interface { } type EmployeeServiceImpl struct { - store stores.EmployeeStore + store store.EmployeeStore s3Client lib.S3Client folder string } -func NewEmployeeService(store stores.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { +func NewEmployeeService(store store.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index 50e5a42..6ad058a 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type ExhibitionService interface { } type ExhibitionServiceImpl struct { - store stores.ExhibitionStore + store store.ExhibitionStore } -func NewExhibitionService(store stores.ExhibitionStore) *ExhibitionServiceImpl { +func NewExhibitionService(store store.ExhibitionStore) *ExhibitionServiceImpl { return &ExhibitionServiceImpl{store: store} } diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index 1a94295..68e42a7 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -18,12 +18,12 @@ type LineItemService interface { } type LineItemServiceImpl struct { - store stores.LineItemStore + store store.LineItemStore s3Client lib.S3Client folder string } -func NewLineItemService(store stores.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { +func NewLineItemService(store store.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/machineService.go b/server/services/machineService.go index 568d279..78c55dd 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,10 +20,10 @@ type MachineService interface { type MachineServiceImpl struct { folder string s3Client lib.S3Client - store stores.MachineStore + store store.MachineStore } -func NewMachineService(store stores.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { +func NewMachineService(store store.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { return &MachineServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/partsService.go b/server/services/partsService.go index 5d4bf32..d7f4b68 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -6,7 +6,7 @@ import ( "log" url2 "net/url" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,10 +20,10 @@ type PartsService interface { type PartsServiceImpl struct { folder string s3Client lib.S3Client - store stores.PartsStore + store store.PartsStore } -func NewPartsService(store stores.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { +func NewPartsService(store store.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { return &PartsServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/privacyService.go b/server/services/privacyService.go index a7ce5d6..aa933d2 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type PrivacyService interface { } type PrivacyServiceImpl struct { - store stores.PrivacyStore + store store.PrivacyStore } -func NewPrivacyService(store stores.PrivacyStore) *PrivacyServiceImpl { +func NewPrivacyService(store store.PrivacyStore) *PrivacyServiceImpl { return &PrivacyServiceImpl{store: store} } diff --git a/server/services/productService.go b/server/services/productService.go index bec0423..aa55e4a 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -19,10 +19,10 @@ type ProductService interface { type ProductServiceImpl struct { folder string s3Client lib.S3Client - store stores.ProductStore + store store.ProductStore } -func NewProductService(store stores.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { +func NewProductService(store store.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { return &ProductServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/registrationService.go b/server/services/registrationService.go index d3a0e84..3b09f23 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -2,7 +2,7 @@ package services import ( "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" "net/smtp" ) @@ -17,10 +17,10 @@ type RegistrationService interface { type RegistrationServiceImpl struct { smtpClient lib.SMTPClient - store stores.RegistrationStore + store store.RegistrationStore } -func NewRegistrationService(store stores.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { +func NewRegistrationService(store store.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 52781ea..2098017 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,10 +20,10 @@ type SupplierService interface { type SupplierServiceImpl struct { folder string s3Client lib.S3Client - store stores.SupplierStore + store store.SupplierStore } -func NewSupplierService(store stores.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { +func NewSupplierService(store store.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { return &SupplierServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/termsService.go b/server/services/termsService.go index e3eb97d..5bdc86a 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type TermsService interface { } type TermsServiceImpl struct { - store stores.TermsStore + store store.TermsStore } -func NewTermsService(store stores.TermsStore) *TermsServiceImpl { +func NewTermsService(store store.TermsStore) *TermsServiceImpl { return &TermsServiceImpl{store: store} } diff --git a/server/services/timelineService.go b/server/services/timelineService.go index fe873ca..19a6e18 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type TimelineService interface { } type TimelineServiceImpl struct { - store stores.TimelineStore + store store.TimelineStore } -func NewTimelineService(store stores.TimelineStore) *TimelineServiceImpl { +func NewTimelineService(store store.TimelineStore) *TimelineServiceImpl { return &TimelineServiceImpl{store: store} } diff --git a/server/services/videoService.go b/server/services/videoService.go index 6934538..3a298ee 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" "google.golang.org/api/youtube/v3" ) @@ -18,11 +18,11 @@ type VideoService interface { } type VideoServiceImpl struct { - store stores.VideoStore + store store.VideoStore youtubeService *youtube.Service } -func NewVideoService(store stores.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { +func NewVideoService(store store.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { return &VideoServiceImpl{ store: store, youtubeService: youtubeService, diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index bce9595..2abe3ec 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -2,7 +2,7 @@ package services import ( "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" "github.com/sean-david-welch/farmec-v2/server/types" "net/smtp" ) @@ -17,10 +17,10 @@ type WarrantyService interface { type WarrantyServiceImpl struct { smtpClient lib.SMTPClient - store stores.WarrantyStore + store store.WarrantyStore } -func NewWarrantyService(store stores.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { +func NewWarrantyService(store store.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { return &WarrantyServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/stores/blogStore.go b/server/store/blogStore.go similarity index 99% rename from server/stores/blogStore.go rename to server/store/blogStore.go index f063bd5..5312c22 100644 --- a/server/stores/blogStore.go +++ b/server/store/blogStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "context" diff --git a/server/stores/carouselStore.go b/server/store/carouselStore.go similarity index 99% rename from server/stores/carouselStore.go rename to server/store/carouselStore.go index 090c65d..54f0b60 100644 --- a/server/stores/carouselStore.go +++ b/server/store/carouselStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/employeeStore.go b/server/store/employeeStore.go similarity index 99% rename from server/stores/employeeStore.go rename to server/store/employeeStore.go index 1b14a8e..320ff79 100644 --- a/server/stores/employeeStore.go +++ b/server/store/employeeStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/exhibitionStore.go b/server/store/exhibitionStore.go similarity index 99% rename from server/stores/exhibitionStore.go rename to server/store/exhibitionStore.go index 11d9a0a..2e3bc23 100644 --- a/server/stores/exhibitionStore.go +++ b/server/store/exhibitionStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/lineitemStore.go b/server/store/lineitemStore.go similarity index 99% rename from server/stores/lineitemStore.go rename to server/store/lineitemStore.go index 3e8da50..95b70e7 100644 --- a/server/stores/lineitemStore.go +++ b/server/store/lineitemStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/machineStore.go b/server/store/machineStore.go similarity index 99% rename from server/stores/machineStore.go rename to server/store/machineStore.go index 558e436..8bef8bb 100644 --- a/server/stores/machineStore.go +++ b/server/store/machineStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/partsStore.go b/server/store/partsStore.go similarity index 99% rename from server/stores/partsStore.go rename to server/store/partsStore.go index cc694f4..56c5855 100644 --- a/server/stores/partsStore.go +++ b/server/store/partsStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/privacyStore.go b/server/store/privacyStore.go similarity index 99% rename from server/stores/privacyStore.go rename to server/store/privacyStore.go index 95cab0b..0513023 100644 --- a/server/stores/privacyStore.go +++ b/server/store/privacyStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/productStore.go b/server/store/productStore.go similarity index 99% rename from server/stores/productStore.go rename to server/store/productStore.go index 6801af7..9f05d8f 100644 --- a/server/stores/productStore.go +++ b/server/store/productStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/registrationStore.go b/server/store/registrationStore.go similarity index 99% rename from server/stores/registrationStore.go rename to server/store/registrationStore.go index 4a0357c..99efb97 100644 --- a/server/stores/registrationStore.go +++ b/server/store/registrationStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/supplierStore.go b/server/store/supplierStore.go similarity index 99% rename from server/stores/supplierStore.go rename to server/store/supplierStore.go index b867c73..f4efa39 100644 --- a/server/stores/supplierStore.go +++ b/server/store/supplierStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/termsStore.go b/server/store/termsStore.go similarity index 99% rename from server/stores/termsStore.go rename to server/store/termsStore.go index 3bcc82f..980b98c 100644 --- a/server/stores/termsStore.go +++ b/server/store/termsStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/timelineStore.go b/server/store/timelineStore.go similarity index 99% rename from server/stores/timelineStore.go rename to server/store/timelineStore.go index 5dee360..329eb97 100644 --- a/server/stores/timelineStore.go +++ b/server/store/timelineStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/videoStore.go b/server/store/videoStore.go similarity index 99% rename from server/stores/videoStore.go rename to server/store/videoStore.go index 683446e..317b20e 100644 --- a/server/stores/videoStore.go +++ b/server/store/videoStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/stores/warrantyStore.go b/server/store/warrantyStore.go similarity index 99% rename from server/stores/warrantyStore.go rename to server/store/warrantyStore.go index 6823038..62f6b3d 100644 --- a/server/stores/warrantyStore.go +++ b/server/store/warrantyStore.go @@ -1,4 +1,4 @@ -package stores +package store import ( "database/sql" diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index f4130a0..bebc72d 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -18,7 +18,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/store" ) type BlogTestSuite struct { @@ -56,7 +56,7 @@ func (suite *BlogTestSuite) SetupTest() { suite.db = database suite.mock = mock - store := stores.NewBlogStore(database) + store := store.NewBlogStore(database) s3Client := lib.NewNoOpS3Client() service := services.NewBlogService(store, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) From 2e29619e045861b39adb488841d26a2fb26eb97b Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:38:05 +0100 Subject: [PATCH 034/248] fix an error in exhibition --- server/store/exhibitionStore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/store/exhibitionStore.go b/server/store/exhibitionStore.go index 2e3bc23..480449e 100644 --- a/server/store/exhibitionStore.go +++ b/server/store/exhibitionStore.go @@ -67,7 +67,7 @@ func (store *ExhibitionStoreImpl) CreateExhibition(exhibition *types.Exhibition) } func (store *ExhibitionStoreImpl) UpdateExhibition(id string, exhibition *types.Exhibition) error { - query := `UPDATE "Exhibiton" SET "title" = ?, "date" = ?, "location" = ?, "info" = ? WHERE "id" = ?` + query := `UPDATE "Exhibition" SET "title" = ?, "date" = ?, "location" = ?, "info" = ? WHERE "id" = ?` _, err := store.database.Exec(query, id, exhibition.Title, exhibition.Date, exhibition.Location, exhibition.Info) if err != nil { From dcae4085f0b35d3ffa18e3cee93e7aaa6dc0bf89 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:38:44 +0100 Subject: [PATCH 035/248] change it back --- server/routes/blogRoutes.go | 4 ++-- server/routes/carouselRoutes.go | 4 ++-- server/routes/checkoutRoutes.go | 4 ++-- server/routes/employeeRoutes.go | 4 ++-- server/routes/exhibitionRoutes.go | 4 ++-- server/routes/lineItemRoutes.go | 4 ++-- server/routes/machineRoutes.go | 4 ++-- server/routes/partsRoutes.go | 4 ++-- server/routes/privacyRoutes.go | 4 ++-- server/routes/productRoutes.go | 4 ++-- server/routes/registrationRoutes.go | 4 ++-- server/routes/supplierRoutes.go | 4 ++-- server/routes/termsRoutes.go | 4 ++-- server/routes/timelineRoutes.go | 4 ++-- server/routes/videoRoutes.go | 4 ++-- server/routes/warrantyRoutes.go | 4 ++-- server/services/blogService.go | 6 +++--- server/services/carouselService.go | 6 +++--- server/services/checkoutService.go | 6 +++--- server/services/employeeService.go | 6 +++--- server/services/exhibitionService.go | 6 +++--- server/services/lineItemService.go | 6 +++--- server/services/machineService.go | 6 +++--- server/services/partsService.go | 6 +++--- server/services/privacyService.go | 6 +++--- server/services/productService.go | 6 +++--- server/services/registrationService.go | 6 +++--- server/services/supplierService.go | 6 +++--- server/services/termsService.go | 6 +++--- server/services/timelineService.go | 6 +++--- server/services/videoService.go | 6 +++--- server/services/warrantyService.go | 6 +++--- server/{store => stores}/blogStore.go | 2 +- server/{store => stores}/carouselStore.go | 2 +- server/{store => stores}/employeeStore.go | 2 +- server/{store => stores}/exhibitionStore.go | 2 +- server/{store => stores}/lineitemStore.go | 2 +- server/{store => stores}/machineStore.go | 2 +- server/{store => stores}/partsStore.go | 2 +- server/{store => stores}/privacyStore.go | 2 +- server/{store => stores}/productStore.go | 2 +- server/{store => stores}/registrationStore.go | 2 +- server/{store => stores}/supplierStore.go | 2 +- server/{store => stores}/termsStore.go | 2 +- server/{store => stores}/timelineStore.go | 2 +- server/{store => stores}/videoStore.go | 2 +- server/{store => stores}/warrantyStore.go | 2 +- server/tests/blog_test.go | 4 ++-- 48 files changed, 97 insertions(+), 97 deletions(-) rename server/{store => stores}/blogStore.go (99%) rename server/{store => stores}/carouselStore.go (99%) rename server/{store => stores}/employeeStore.go (99%) rename server/{store => stores}/exhibitionStore.go (99%) rename server/{store => stores}/lineitemStore.go (99%) rename server/{store => stores}/machineStore.go (99%) rename server/{store => stores}/partsStore.go (99%) rename server/{store => stores}/privacyStore.go (99%) rename server/{store => stores}/productStore.go (99%) rename server/{store => stores}/registrationStore.go (99%) rename server/{store => stores}/supplierStore.go (99%) rename server/{store => stores}/termsStore.go (99%) rename server/{store => stores}/timelineStore.go (99%) rename server/{store => stores}/videoStore.go (99%) rename server/{store => stores}/warrantyStore.go (99%) diff --git a/server/routes/blogRoutes.go b/server/routes/blogRoutes.go index a3e8336..2a7c58c 100644 --- a/server/routes/blogRoutes.go +++ b/server/routes/blogRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitBlogs(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - blogStore := store.NewBlogStore(database) + blogStore := stores.NewBlogStore(database) service := services.NewBlogService(blogStore, s3Client, "Blogs") handler := handlers.NewBlogHandler(service) diff --git a/server/routes/carouselRoutes.go b/server/routes/carouselRoutes.go index 6e4c999..cd818d4 100644 --- a/server/routes/carouselRoutes.go +++ b/server/routes/carouselRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitCarousel(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleare *middleware.AdminMiddleware) { - carouselStore := store.NewCarouselStore(database) + carouselStore := stores.NewCarouselStore(database) carouselService := services.NewCarouselService(carouselStore, s3Client, "Carousels") carouselHandler := handlers.NewCarouselHandler(carouselService) diff --git a/server/routes/checkoutRoutes.go b/server/routes/checkoutRoutes.go index 02de1a6..3f8e6ae 100644 --- a/server/routes/checkoutRoutes.go +++ b/server/routes/checkoutRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitCheckout(router *gin.Engine, database *sql.DB, secrets *lib.Secrets) { - itemStore := store.NewLineItemStore(database) + itemStore := stores.NewLineItemStore(database) service := services.NewCheckoutService(secrets, itemStore) handler := handlers.NewCheckoutHandler(service) diff --git a/server/routes/employeeRoutes.go b/server/routes/employeeRoutes.go index 5f3b4ae..dbaee87 100644 --- a/server/routes/employeeRoutes.go +++ b/server/routes/employeeRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitializeEmployee(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - employeeStore := store.NewEmployeeStore(database) + employeeStore := stores.NewEmployeeStore(database) service := services.NewEmployeeService(employeeStore, s3Client, "Employees") handler := handlers.NewEmployeeHandler(service) diff --git a/server/routes/exhibitionRoutes.go b/server/routes/exhibitionRoutes.go index b212c15..755ae0e 100644 --- a/server/routes/exhibitionRoutes.go +++ b/server/routes/exhibitionRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitExhibitions(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - exhibitionStore := store.NewExhibitionStore(database) + exhibitionStore := stores.NewExhibitionStore(database) service := services.NewExhibitionService(exhibitionStore) handler := handlers.NewExhibitionHandler(service) diff --git a/server/routes/lineItemRoutes.go b/server/routes/lineItemRoutes.go index d8e5efd..36fa7ad 100644 --- a/server/routes/lineItemRoutes.go +++ b/server/routes/lineItemRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitLineItems(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - itemStore := store.NewLineItemStore(database) + itemStore := stores.NewLineItemStore(database) service := services.NewLineItemService(itemStore, s3Client, "Lineitems") handler := handlers.NewLineItemHandler(service) diff --git a/server/routes/machineRoutes.go b/server/routes/machineRoutes.go index 71c42be..4eb6426 100644 --- a/server/routes/machineRoutes.go +++ b/server/routes/machineRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitMachines(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - machineStore := store.NewMachineStore(database) + machineStore := stores.NewMachineStore(database) machineService := services.NewMachineService(machineStore, s3Client, "Machines") machineHandler := handlers.NewMachineHandler(machineService) diff --git a/server/routes/partsRoutes.go b/server/routes/partsRoutes.go index e5d1223..a39201b 100644 --- a/server/routes/partsRoutes.go +++ b/server/routes/partsRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitParts(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - partsStore := store.NewPartsStore(database) + partsStore := stores.NewPartsStore(database) partsService := services.NewPartsService(partsStore, s3Client, "Spareparts") partsHandler := handlers.NewPartsHandler(partsService) diff --git a/server/routes/privacyRoutes.go b/server/routes/privacyRoutes.go index c771e10..8202231 100644 --- a/server/routes/privacyRoutes.go +++ b/server/routes/privacyRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitPrivacy(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - privacyStore := store.NewPrivacyStore(database) + privacyStore := stores.NewPrivacyStore(database) service := services.NewPrivacyService(privacyStore) handler := handlers.NewPrivacyHandler(service) diff --git a/server/routes/productRoutes.go b/server/routes/productRoutes.go index 5e06212..ffcaec0 100644 --- a/server/routes/productRoutes.go +++ b/server/routes/productRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitProduct(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - productStore := store.NewProductStore(database) + productStore := stores.NewProductStore(database) productService := services.NewProductService(productStore, s3Client, "Products") productHandler := handlers.NewProductHandler(productService) diff --git a/server/routes/registrationRoutes.go b/server/routes/registrationRoutes.go index 1a1d8d6..4112a99 100644 --- a/server/routes/registrationRoutes.go +++ b/server/routes/registrationRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitRegistrations(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - store := store.NewRegistrationStore(database) + store := stores.NewRegistrationStore(database) service := services.NewRegistrationService(store, smtp) handler := handlers.NewRegistrationHandler(service) diff --git a/server/routes/supplierRoutes.go b/server/routes/supplierRoutes.go index 2c36039..eeb86cf 100644 --- a/server/routes/supplierRoutes.go +++ b/server/routes/supplierRoutes.go @@ -9,11 +9,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitSuppliers(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - supplierStore := store.NewSupplierStore(database) + supplierStore := stores.NewSupplierStore(database) supplierService := services.NewSupplierService(supplierStore, s3Client, "Suppliers") supplierHandler := handlers.NewSupplierContoller(supplierService) diff --git a/server/routes/termsRoutes.go b/server/routes/termsRoutes.go index f577399..cd27699 100644 --- a/server/routes/termsRoutes.go +++ b/server/routes/termsRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitTerms(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - termsStore := store.NewTermsStore(database) + termsStore := stores.NewTermsStore(database) service := services.NewTermsService(termsStore) handler := handlers.NewTermsHandler(service) diff --git a/server/routes/timelineRoutes.go b/server/routes/timelineRoutes.go index 23a65af..9e422d4 100644 --- a/server/routes/timelineRoutes.go +++ b/server/routes/timelineRoutes.go @@ -7,11 +7,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitTimelines(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - timelineStore := store.NewTimelineStore(database) + timelineStore := stores.NewTimelineStore(database) service := services.NewTimelineService(timelineStore) handler := handlers.NewTimelineHandler(service) diff --git a/server/routes/videoRoutes.go b/server/routes/videoRoutes.go index d7d6c90..6ee7c34 100644 --- a/server/routes/videoRoutes.go +++ b/server/routes/videoRoutes.go @@ -10,7 +10,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "google.golang.org/api/option" "google.golang.org/api/youtube/v3" ) @@ -21,7 +21,7 @@ func InitVideos(router *gin.Engine, database *sql.DB, secrets *lib.Secrets, admi log.Fatal("error calling YouTube API: ", err) } - videoStore := store.NewVideoStore(database) + videoStore := stores.NewVideoStore(database) videoService := services.NewVideoService(videoStore, youtubeService) videoHandler := handlers.NewVideoHandler(videoService) diff --git a/server/routes/warrantyRoutes.go b/server/routes/warrantyRoutes.go index 25301d5..fe7bfa3 100644 --- a/server/routes/warrantyRoutes.go +++ b/server/routes/warrantyRoutes.go @@ -8,11 +8,11 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitWarranty(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - warrantyStore := store.NewWarrantyStore(database) + warrantyStore := stores.NewWarrantyStore(database) service := services.NewWarrantyService(warrantyStore, smtp) handler := handlers.NewWarrantyHandler(service) diff --git a/server/services/blogService.go b/server/services/blogService.go index a0c0580..a19fd6f 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -7,7 +7,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,12 +20,12 @@ type BlogService interface { } type BlogServiceImpl struct { - store store.BlogStore + store stores.BlogStore s3Client lib.S3Client folder string } -func NewBlogService(store store.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { +func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/carouselService.go b/server/services/carouselService.go index 93e7539..f64d0ba 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -17,12 +17,12 @@ type CarouselService interface { } type CarouselServiceImpl struct { - store store.CarouselStore + store stores.CarouselStore s3Client lib.S3Client folder string } -func NewCarouselService(store store.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { +func NewCarouselService(store stores.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { return &CarouselServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 6d85f6b..3e9e250 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -4,7 +4,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/stripe/stripe-go/v76" "github.com/stripe/stripe-go/v76/checkout/session" ) @@ -16,10 +16,10 @@ type CheckoutService interface { type CheckoutServiceImpl struct { secrets *lib.Secrets - store store.LineItemStore + store stores.LineItemStore } -func NewCheckoutService(secrets *lib.Secrets, store store.LineItemStore) *CheckoutServiceImpl { +func NewCheckoutService(secrets *lib.Secrets, store stores.LineItemStore) *CheckoutServiceImpl { return &CheckoutServiceImpl{secrets: secrets, store: store} } func (service *CheckoutServiceImpl) CreateCheckoutSession(id string) (*stripe.CheckoutSession, error) { diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 978157c..68f49cb 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -17,12 +17,12 @@ type EmployeeService interface { } type EmployeeServiceImpl struct { - store store.EmployeeStore + store stores.EmployeeStore s3Client lib.S3Client folder string } -func NewEmployeeService(store store.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { +func NewEmployeeService(store stores.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index 6ad058a..50e5a42 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type ExhibitionService interface { } type ExhibitionServiceImpl struct { - store store.ExhibitionStore + store stores.ExhibitionStore } -func NewExhibitionService(store store.ExhibitionStore) *ExhibitionServiceImpl { +func NewExhibitionService(store stores.ExhibitionStore) *ExhibitionServiceImpl { return &ExhibitionServiceImpl{store: store} } diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index 68e42a7..1a94295 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -18,12 +18,12 @@ type LineItemService interface { } type LineItemServiceImpl struct { - store store.LineItemStore + store stores.LineItemStore s3Client lib.S3Client folder string } -func NewLineItemService(store store.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { +func NewLineItemService(store stores.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/machineService.go b/server/services/machineService.go index 78c55dd..568d279 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,10 +20,10 @@ type MachineService interface { type MachineServiceImpl struct { folder string s3Client lib.S3Client - store store.MachineStore + store stores.MachineStore } -func NewMachineService(store store.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { +func NewMachineService(store stores.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { return &MachineServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/partsService.go b/server/services/partsService.go index d7f4b68..5d4bf32 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -6,7 +6,7 @@ import ( "log" url2 "net/url" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,10 +20,10 @@ type PartsService interface { type PartsServiceImpl struct { folder string s3Client lib.S3Client - store store.PartsStore + store stores.PartsStore } -func NewPartsService(store store.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { +func NewPartsService(store stores.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { return &PartsServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/privacyService.go b/server/services/privacyService.go index aa933d2..a7ce5d6 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type PrivacyService interface { } type PrivacyServiceImpl struct { - store store.PrivacyStore + store stores.PrivacyStore } -func NewPrivacyService(store store.PrivacyStore) *PrivacyServiceImpl { +func NewPrivacyService(store stores.PrivacyStore) *PrivacyServiceImpl { return &PrivacyServiceImpl{store: store} } diff --git a/server/services/productService.go b/server/services/productService.go index aa55e4a..bec0423 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -19,10 +19,10 @@ type ProductService interface { type ProductServiceImpl struct { folder string s3Client lib.S3Client - store store.ProductStore + store stores.ProductStore } -func NewProductService(store store.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { +func NewProductService(store stores.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { return &ProductServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/registrationService.go b/server/services/registrationService.go index 3b09f23..d3a0e84 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -2,7 +2,7 @@ package services import ( "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" "net/smtp" ) @@ -17,10 +17,10 @@ type RegistrationService interface { type RegistrationServiceImpl struct { smtpClient lib.SMTPClient - store store.RegistrationStore + store stores.RegistrationStore } -func NewRegistrationService(store store.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { +func NewRegistrationService(store stores.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 2098017..52781ea 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -5,7 +5,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,10 +20,10 @@ type SupplierService interface { type SupplierServiceImpl struct { folder string s3Client lib.S3Client - store store.SupplierStore + store stores.SupplierStore } -func NewSupplierService(store store.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { +func NewSupplierService(store stores.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { return &SupplierServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/termsService.go b/server/services/termsService.go index 5bdc86a..e3eb97d 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type TermsService interface { } type TermsServiceImpl struct { - store store.TermsStore + store stores.TermsStore } -func NewTermsService(store store.TermsStore) *TermsServiceImpl { +func NewTermsService(store stores.TermsStore) *TermsServiceImpl { return &TermsServiceImpl{store: store} } diff --git a/server/services/timelineService.go b/server/services/timelineService.go index 19a6e18..fe873ca 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -1,7 +1,7 @@ package services import ( - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -13,10 +13,10 @@ type TimelineService interface { } type TimelineServiceImpl struct { - store store.TimelineStore + store stores.TimelineStore } -func NewTimelineService(store store.TimelineStore) *TimelineServiceImpl { +func NewTimelineService(store stores.TimelineStore) *TimelineServiceImpl { return &TimelineServiceImpl{store: store} } diff --git a/server/services/videoService.go b/server/services/videoService.go index 3a298ee..6934538 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" "google.golang.org/api/youtube/v3" ) @@ -18,11 +18,11 @@ type VideoService interface { } type VideoServiceImpl struct { - store store.VideoStore + store stores.VideoStore youtubeService *youtube.Service } -func NewVideoService(store store.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { +func NewVideoService(store stores.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { return &VideoServiceImpl{ store: store, youtubeService: youtubeService, diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index 2abe3ec..bce9595 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -2,7 +2,7 @@ package services import ( "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" "net/smtp" ) @@ -17,10 +17,10 @@ type WarrantyService interface { type WarrantyServiceImpl struct { smtpClient lib.SMTPClient - store store.WarrantyStore + store stores.WarrantyStore } -func NewWarrantyService(store store.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { +func NewWarrantyService(store stores.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { return &WarrantyServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/store/blogStore.go b/server/stores/blogStore.go similarity index 99% rename from server/store/blogStore.go rename to server/stores/blogStore.go index 5312c22..f063bd5 100644 --- a/server/store/blogStore.go +++ b/server/stores/blogStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "context" diff --git a/server/store/carouselStore.go b/server/stores/carouselStore.go similarity index 99% rename from server/store/carouselStore.go rename to server/stores/carouselStore.go index 54f0b60..090c65d 100644 --- a/server/store/carouselStore.go +++ b/server/stores/carouselStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/employeeStore.go b/server/stores/employeeStore.go similarity index 99% rename from server/store/employeeStore.go rename to server/stores/employeeStore.go index 320ff79..1b14a8e 100644 --- a/server/store/employeeStore.go +++ b/server/stores/employeeStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/exhibitionStore.go b/server/stores/exhibitionStore.go similarity index 99% rename from server/store/exhibitionStore.go rename to server/stores/exhibitionStore.go index 480449e..cd854f0 100644 --- a/server/store/exhibitionStore.go +++ b/server/stores/exhibitionStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/lineitemStore.go b/server/stores/lineitemStore.go similarity index 99% rename from server/store/lineitemStore.go rename to server/stores/lineitemStore.go index 95b70e7..3e8da50 100644 --- a/server/store/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/machineStore.go b/server/stores/machineStore.go similarity index 99% rename from server/store/machineStore.go rename to server/stores/machineStore.go index 8bef8bb..558e436 100644 --- a/server/store/machineStore.go +++ b/server/stores/machineStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/partsStore.go b/server/stores/partsStore.go similarity index 99% rename from server/store/partsStore.go rename to server/stores/partsStore.go index 56c5855..cc694f4 100644 --- a/server/store/partsStore.go +++ b/server/stores/partsStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/privacyStore.go b/server/stores/privacyStore.go similarity index 99% rename from server/store/privacyStore.go rename to server/stores/privacyStore.go index 0513023..95cab0b 100644 --- a/server/store/privacyStore.go +++ b/server/stores/privacyStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/productStore.go b/server/stores/productStore.go similarity index 99% rename from server/store/productStore.go rename to server/stores/productStore.go index 9f05d8f..6801af7 100644 --- a/server/store/productStore.go +++ b/server/stores/productStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/registrationStore.go b/server/stores/registrationStore.go similarity index 99% rename from server/store/registrationStore.go rename to server/stores/registrationStore.go index 99efb97..4a0357c 100644 --- a/server/store/registrationStore.go +++ b/server/stores/registrationStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/supplierStore.go b/server/stores/supplierStore.go similarity index 99% rename from server/store/supplierStore.go rename to server/stores/supplierStore.go index f4efa39..b867c73 100644 --- a/server/store/supplierStore.go +++ b/server/stores/supplierStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/termsStore.go b/server/stores/termsStore.go similarity index 99% rename from server/store/termsStore.go rename to server/stores/termsStore.go index 980b98c..3bcc82f 100644 --- a/server/store/termsStore.go +++ b/server/stores/termsStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/timelineStore.go b/server/stores/timelineStore.go similarity index 99% rename from server/store/timelineStore.go rename to server/stores/timelineStore.go index 329eb97..5dee360 100644 --- a/server/store/timelineStore.go +++ b/server/stores/timelineStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/videoStore.go b/server/stores/videoStore.go similarity index 99% rename from server/store/videoStore.go rename to server/stores/videoStore.go index 317b20e..683446e 100644 --- a/server/store/videoStore.go +++ b/server/stores/videoStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/store/warrantyStore.go b/server/stores/warrantyStore.go similarity index 99% rename from server/store/warrantyStore.go rename to server/stores/warrantyStore.go index 62f6b3d..6823038 100644 --- a/server/store/warrantyStore.go +++ b/server/stores/warrantyStore.go @@ -1,4 +1,4 @@ -package store +package stores import ( "database/sql" diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index bebc72d..f4130a0 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -18,7 +18,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/store" + "github.com/sean-david-welch/farmec-v2/server/stores" ) type BlogTestSuite struct { @@ -56,7 +56,7 @@ func (suite *BlogTestSuite) SetupTest() { suite.db = database suite.mock = mock - store := store.NewBlogStore(database) + store := stores.NewBlogStore(database) s3Client := lib.NewNoOpS3Client() service := services.NewBlogService(store, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) From 92826f00d24c38c1d7ef7e456d8a6a7d3b6e2f5f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:40:19 +0100 Subject: [PATCH 036/248] remove ordering --- server/stores/exhibitionStore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stores/exhibitionStore.go b/server/stores/exhibitionStore.go index cd854f0..6c6c4c3 100644 --- a/server/stores/exhibitionStore.go +++ b/server/stores/exhibitionStore.go @@ -28,7 +28,7 @@ func NewExhibitionStore(database *sql.DB) *ExhibitionStoreImpl { func (store *ExhibitionStoreImpl) GetExhibitions() ([]types.Exhibition, error) { var exhibitions []types.Exhibition - query := `SELECT * FROM "Exhibition" ORDER BY "created" ASC` + query := `SELECT * FROM "Exhibition" ORDER BY "created"` rows, err := store.database.Query(query) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) From 98eaf6e420c7d7f6862393363e3fbd3a3440e683 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:40:28 +0100 Subject: [PATCH 037/248] remove trailing comma --- server/stores/employeeStore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/stores/employeeStore.go b/server/stores/employeeStore.go index 1b14a8e..a6372ad 100644 --- a/server/stores/employeeStore.go +++ b/server/stores/employeeStore.go @@ -30,7 +30,7 @@ func NewEmployeeStore(database *sql.DB) *EmployeeStoreImpl { func (store *EmployeeStoreImpl) GetEmployees() ([]types.Employee, error) { var employees []types.Employee - query := `SELECT * FROM "Employee" ORDER BY "created" ASC` + query := `SELECT * FROM "Employee" ORDER BY "created"` rows, err := store.database.Query(query) if err != nil { return nil, err @@ -92,7 +92,7 @@ func (store *EmployeeStoreImpl) CreateEmployee(employee *types.Employee) error { } func (store *EmployeeStoreImpl) UpdateEmployee(id string, employee *types.Employee) error { - query := `UPDATE "Employee" SET name = ?, email = ?, role = ?, WHERE "id" = ?` + query := `UPDATE "Employee" SET name = ?, email = ?, role = ? WHERE id = ?` args := []interface{}{id, employee.Name, employee.Email, employee.Role} if employee.ProfileImage != "" && employee.ProfileImage != "null" { From 876039a1b25debcb7043fae89968daadcf941169 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:41:19 +0100 Subject: [PATCH 038/248] fix timeline query --- server/stores/timelineStore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stores/timelineStore.go b/server/stores/timelineStore.go index 5dee360..3cedd28 100644 --- a/server/stores/timelineStore.go +++ b/server/stores/timelineStore.go @@ -70,7 +70,7 @@ func (store *TimelineStoreImpl) CreateTimeline(timeline *types.Timeline) error { } func (store *TimelineStoreImpl) UpdateTimeline(id string, timeline *types.Timeline) error { - query := `UPDATE "Timeline" SET title = ?, data = %2, body = ? WHERE "id" = ?` + query := `UPDATE "Timeline" SET title = ?, date = ?, body = ? WHERE "id" = ?` _, err := store.database.Exec(query, timeline.Title, timeline.Date, timeline.Body, id) if err != nil { From 972452476547edc0794eed921d9ec12568a55af1 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:41:36 +0100 Subject: [PATCH 039/248] fix lineitem query --- server/stores/lineitemStore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stores/lineitemStore.go b/server/stores/lineitemStore.go index 3e8da50..9fa952e 100644 --- a/server/stores/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -89,7 +89,7 @@ func (store *LineItemStoreImpl) CreateLineItem(lineItem *types.LineItem) error { } func (store *LineItemStoreImpl) UpdateLineItem(id string, lineItem *types.LineItem) error { - query := `UPDATE "LineItems" SET "name" = ?, "price" = ?, WHERE "id" = ?` + query := `UPDATE "LineItems" SET "name" = ?, "price" = ? WHERE "id" = ?` args := []interface{}{id, lineItem.Name, lineItem.Price} if lineItem.Image != "" && lineItem.Image != "null" { From 13515e323e5524873a0eff1ba1ce58e747f5fbd6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:42:07 +0100 Subject: [PATCH 040/248] remove trailing comma --- server/stores/registrationStore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/stores/registrationStore.go b/server/stores/registrationStore.go index 4a0357c..dd5e666 100644 --- a/server/stores/registrationStore.go +++ b/server/stores/registrationStore.go @@ -117,7 +117,7 @@ func (store *RegistrationStoreImpl) UpdateRegistration(id string, registration * "dealer_name" = ?, "dealer_address" = ?, "owner_name" = ?, "owner_address" = ?, "machine_model" = ?, "serial_number" = ?, "install_date" = ?, "invoice_number" = ?, "complete_supply" = ?, "pdi_complete" = ?, "pto_correct" = ?, "machine_test_run" = ?, - "safety_induction" = ?, "operator_handbook" = ?, "date" = ?, "completed_by" = ?, + "safety_induction" = ?, "operator_handbook" = ?, "date" = ?, "completed_by" = ? WHERE "id" = ?` _, err := store.database.Exec( From 25346a69f17337be84405410657d42f5f92ecadc Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:56:22 +0100 Subject: [PATCH 041/248] line items queries --- server/sql/queries/lineitems.sql | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/sql/queries/lineitems.sql b/server/sql/queries/lineitems.sql index 2cd65ee..c230422 100644 --- a/server/sql/queries/lineitems.sql +++ b/server/sql/queries/lineitems.sql @@ -1,2 +1,17 @@ -- name: GetLineItems :many -select id, name, price, image from LineItems; \ No newline at end of file +select id, name, price, image from LineItems; + +-- name: GetLineItemByID :one +select id, name, price, image from LineItems where id = ?; + +-- name: CreateLineItem :exec +insert into LineItems (id, name, price, image) values (?, ?, ?, ?); + +-- name: UpdateLineItemNoImage :exec +update LineItems set name = ?, price = ? where id = ?; + +-- name: UpdateLineItem :exec +update LineItems set name = ?, price = ?, image = ? where id = ?; + +-- name: DeleteLineItem :exec +delete from LineItems where id = ?; \ No newline at end of file From d9b8b929c34a829facb4c210c354e9704c0b68a0 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 20:56:49 +0100 Subject: [PATCH 042/248] line items gen code --- server/db/lineitems.sql.go | 125 +++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 server/db/lineitems.sql.go diff --git a/server/db/lineitems.sql.go b/server/db/lineitems.sql.go new file mode 100644 index 0000000..219f46e --- /dev/null +++ b/server/db/lineitems.sql.go @@ -0,0 +1,125 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: lineitems.sql + +package db + +import ( + "context" + "database/sql" +) + +const createLineItem = `-- name: CreateLineItem :exec +insert into LineItems (id, name, price, image) values (?, ?, ?, ?) +` + +type CreateLineItemParams struct { + ID string `json:"id"` + Name string `json:"name"` + Price float64 `json:"price"` + Image sql.NullString `json:"image"` +} + +func (q *Queries) CreateLineItem(ctx context.Context, arg CreateLineItemParams) error { + _, err := q.db.ExecContext(ctx, createLineItem, + arg.ID, + arg.Name, + arg.Price, + arg.Image, + ) + return err +} + +const deleteLineItem = `-- name: DeleteLineItem :exec +delete from LineItems where id = ? +` + +func (q *Queries) DeleteLineItem(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteLineItem, id) + return err +} + +const getLineItemByID = `-- name: GetLineItemByID :one +select id, name, price, image from LineItems where id = ? +` + +func (q *Queries) GetLineItemByID(ctx context.Context, id string) (LineItem, error) { + row := q.db.QueryRowContext(ctx, getLineItemByID, id) + var i LineItem + err := row.Scan( + &i.ID, + &i.Name, + &i.Price, + &i.Image, + ) + return i, err +} + +const getLineItems = `-- name: GetLineItems :many +select id, name, price, image from LineItems +` + +func (q *Queries) GetLineItems(ctx context.Context) ([]LineItem, error) { + rows, err := q.db.QueryContext(ctx, getLineItems) + if err != nil { + return nil, err + } + defer rows.Close() + var items []LineItem + for rows.Next() { + var i LineItem + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Price, + &i.Image, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateLineItem = `-- name: UpdateLineItem :exec +update LineItems set name = ?, price = ?, image = ? where id = ? +` + +type UpdateLineItemParams struct { + Name string `json:"name"` + Price float64 `json:"price"` + Image sql.NullString `json:"image"` + ID string `json:"id"` +} + +func (q *Queries) UpdateLineItem(ctx context.Context, arg UpdateLineItemParams) error { + _, err := q.db.ExecContext(ctx, updateLineItem, + arg.Name, + arg.Price, + arg.Image, + arg.ID, + ) + return err +} + +const updateLineItemNoImage = `-- name: UpdateLineItemNoImage :exec +update LineItems set name = ?, price = ? where id = ? +` + +type UpdateLineItemNoImageParams struct { + Name string `json:"name"` + Price float64 `json:"price"` + ID string `json:"id"` +} + +func (q *Queries) UpdateLineItemNoImage(ctx context.Context, arg UpdateLineItemNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateLineItemNoImage, arg.Name, arg.Price, arg.ID) + return err +} From 58cfb4c7663cba52c81921d1fef5cefd7561b613 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 21:03:18 +0100 Subject: [PATCH 043/248] machines queries --- server/sql/queries/lineitems.sql | 25 ++++++++++++++++++------ server/sql/queries/machines.sql | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 server/sql/queries/machines.sql diff --git a/server/sql/queries/lineitems.sql b/server/sql/queries/lineitems.sql index c230422..5dc77d2 100644 --- a/server/sql/queries/lineitems.sql +++ b/server/sql/queries/lineitems.sql @@ -1,17 +1,30 @@ -- name: GetLineItems :many -select id, name, price, image from LineItems; +select id, name, price, image +from LineItems; -- name: GetLineItemByID :one -select id, name, price, image from LineItems where id = ?; +select id, name, price, image +from LineItems +where id = ?; -- name: CreateLineItem :exec -insert into LineItems (id, name, price, image) values (?, ?, ?, ?); +insert into LineItems (id, name, price, image) +values (?, ?, ?, ?); -- name: UpdateLineItemNoImage :exec -update LineItems set name = ?, price = ? where id = ?; +update LineItems +set name = ?, + price = ? +where id = ?; -- name: UpdateLineItem :exec -update LineItems set name = ?, price = ?, image = ? where id = ?; +update LineItems +set name = ?, + price = ?, + image = ? +where id = ?; -- name: DeleteLineItem :exec -delete from LineItems where id = ?; \ No newline at end of file +delete +from LineItems +where id = ?; \ No newline at end of file diff --git a/server/sql/queries/machines.sql b/server/sql/queries/machines.sql new file mode 100644 index 0000000..260d7df --- /dev/null +++ b/server/sql/queries/machines.sql @@ -0,0 +1,33 @@ +-- name: GetMachines :many +select id, supplier_id, name, machine_image, description, machine_link, created +from Machine +where supplier_id = ?; + +-- name :GetMachineByID :one +select id, supplier_id, name, machine_image, description, machine_link, created +from Machine +where id = ?; + +-- name :CreateMachine :exec +insert into Machine (id, supplier_id, name, machine_image, description, machine_link, created) +values (?, ?, ?, ?, ?, ?, ?); + +--name :UpdateMachineNoImage :exec +update Machine +set supplier_id = ?, + name = ?, + description = ?, + machine_link = ? +where id = ?; + +--name :UpdateMachine :exec +update Machine +set supplier_id = ?, + name = ?, + machine_image = ?, + description = ?, + machine_link = ? +where id = ?; + +--name :DeleteMachine :exec +delete from Machine where id = ?; \ No newline at end of file From 713715760735a1248738bc40fbd8eb4f9398ba1a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 21:05:21 +0100 Subject: [PATCH 044/248] machines gen code --- server/db/lineitems.sql.go | 25 +++-- server/db/machines.sql.go | 165 ++++++++++++++++++++++++++++++++ server/sql/queries/machines.sql | 10 +- 3 files changed, 189 insertions(+), 11 deletions(-) create mode 100644 server/db/machines.sql.go diff --git a/server/db/lineitems.sql.go b/server/db/lineitems.sql.go index 219f46e..c253f11 100644 --- a/server/db/lineitems.sql.go +++ b/server/db/lineitems.sql.go @@ -11,7 +11,8 @@ import ( ) const createLineItem = `-- name: CreateLineItem :exec -insert into LineItems (id, name, price, image) values (?, ?, ?, ?) +insert into LineItems (id, name, price, image) +values (?, ?, ?, ?) ` type CreateLineItemParams struct { @@ -32,7 +33,9 @@ func (q *Queries) CreateLineItem(ctx context.Context, arg CreateLineItemParams) } const deleteLineItem = `-- name: DeleteLineItem :exec -delete from LineItems where id = ? +delete +from LineItems +where id = ? ` func (q *Queries) DeleteLineItem(ctx context.Context, id string) error { @@ -41,7 +44,9 @@ func (q *Queries) DeleteLineItem(ctx context.Context, id string) error { } const getLineItemByID = `-- name: GetLineItemByID :one -select id, name, price, image from LineItems where id = ? +select id, name, price, image +from LineItems +where id = ? ` func (q *Queries) GetLineItemByID(ctx context.Context, id string) (LineItem, error) { @@ -57,7 +62,8 @@ func (q *Queries) GetLineItemByID(ctx context.Context, id string) (LineItem, err } const getLineItems = `-- name: GetLineItems :many -select id, name, price, image from LineItems +select id, name, price, image +from LineItems ` func (q *Queries) GetLineItems(ctx context.Context) ([]LineItem, error) { @@ -89,7 +95,11 @@ func (q *Queries) GetLineItems(ctx context.Context) ([]LineItem, error) { } const updateLineItem = `-- name: UpdateLineItem :exec -update LineItems set name = ?, price = ?, image = ? where id = ? +update LineItems +set name = ?, + price = ?, + image = ? +where id = ? ` type UpdateLineItemParams struct { @@ -110,7 +120,10 @@ func (q *Queries) UpdateLineItem(ctx context.Context, arg UpdateLineItemParams) } const updateLineItemNoImage = `-- name: UpdateLineItemNoImage :exec -update LineItems set name = ?, price = ? where id = ? +update LineItems +set name = ?, + price = ? +where id = ? ` type UpdateLineItemNoImageParams struct { diff --git a/server/db/machines.sql.go b/server/db/machines.sql.go new file mode 100644 index 0000000..7ac2186 --- /dev/null +++ b/server/db/machines.sql.go @@ -0,0 +1,165 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: machines.sql + +package db + +import ( + "context" + "database/sql" +) + +const createMachine = `-- name: CreateMachine :exec +insert into Machine (id, supplier_id, name, machine_image, description, machine_link, created) +values (?, ?, ?, ?, ?, ?, ?) +` + +type CreateMachineParams struct { + ID string `json:"id"` + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + MachineImage sql.NullString `json:"machine_image"` + Description sql.NullString `json:"description"` + MachineLink sql.NullString `json:"machine_link"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateMachine(ctx context.Context, arg CreateMachineParams) error { + _, err := q.db.ExecContext(ctx, createMachine, + arg.ID, + arg.SupplierID, + arg.Name, + arg.MachineImage, + arg.Description, + arg.MachineLink, + arg.Created, + ) + return err +} + +const deleteMachine = `-- name: DeleteMachine :exec +delete from Machine where id = ? +` + +func (q *Queries) DeleteMachine(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteMachine, id) + return err +} + +const getMachineByID = `-- name: GetMachineByID :one +select id, supplier_id, name, machine_image, description, machine_link, created +from Machine +where id = ? +` + +func (q *Queries) GetMachineByID(ctx context.Context, id string) (Machine, error) { + row := q.db.QueryRowContext(ctx, getMachineByID, id) + var i Machine + err := row.Scan( + &i.ID, + &i.SupplierID, + &i.Name, + &i.MachineImage, + &i.Description, + &i.MachineLink, + &i.Created, + ) + return i, err +} + +const getMachines = `-- name: GetMachines :many +select id, supplier_id, name, machine_image, description, machine_link, created +from Machine +where supplier_id = ? +` + +func (q *Queries) GetMachines(ctx context.Context, supplierID string) ([]Machine, error) { + rows, err := q.db.QueryContext(ctx, getMachines, supplierID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Machine + for rows.Next() { + var i Machine + if err := rows.Scan( + &i.ID, + &i.SupplierID, + &i.Name, + &i.MachineImage, + &i.Description, + &i.MachineLink, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateMachine = `-- name: UpdateMachine :exec +update Machine +set supplier_id = ?, + name = ?, + machine_image = ?, + description = ?, + machine_link = ? +where id = ? +` + +type UpdateMachineParams struct { + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + MachineImage sql.NullString `json:"machine_image"` + Description sql.NullString `json:"description"` + MachineLink sql.NullString `json:"machine_link"` + ID string `json:"id"` +} + +func (q *Queries) UpdateMachine(ctx context.Context, arg UpdateMachineParams) error { + _, err := q.db.ExecContext(ctx, updateMachine, + arg.SupplierID, + arg.Name, + arg.MachineImage, + arg.Description, + arg.MachineLink, + arg.ID, + ) + return err +} + +const updateMachineNoImage = `-- name: UpdateMachineNoImage :exec +update Machine +set supplier_id = ?, + name = ?, + description = ?, + machine_link = ? +where id = ? +` + +type UpdateMachineNoImageParams struct { + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + Description sql.NullString `json:"description"` + MachineLink sql.NullString `json:"machine_link"` + ID string `json:"id"` +} + +func (q *Queries) UpdateMachineNoImage(ctx context.Context, arg UpdateMachineNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateMachineNoImage, + arg.SupplierID, + arg.Name, + arg.Description, + arg.MachineLink, + arg.ID, + ) + return err +} diff --git a/server/sql/queries/machines.sql b/server/sql/queries/machines.sql index 260d7df..10f7430 100644 --- a/server/sql/queries/machines.sql +++ b/server/sql/queries/machines.sql @@ -3,16 +3,16 @@ select id, supplier_id, name, machine_image, description, machine_link, created from Machine where supplier_id = ?; --- name :GetMachineByID :one +-- name: GetMachineByID :one select id, supplier_id, name, machine_image, description, machine_link, created from Machine where id = ?; --- name :CreateMachine :exec +-- name: CreateMachine :exec insert into Machine (id, supplier_id, name, machine_image, description, machine_link, created) values (?, ?, ?, ?, ?, ?, ?); ---name :UpdateMachineNoImage :exec +-- name: UpdateMachineNoImage :exec update Machine set supplier_id = ?, name = ?, @@ -20,7 +20,7 @@ set supplier_id = ?, machine_link = ? where id = ?; ---name :UpdateMachine :exec +-- name: UpdateMachine :exec update Machine set supplier_id = ?, name = ?, @@ -29,5 +29,5 @@ set supplier_id = ?, machine_link = ? where id = ?; ---name :DeleteMachine :exec +-- name: DeleteMachine :exec delete from Machine where id = ?; \ No newline at end of file From 23e02b0ac52f772126847acea3c2f0cc40e18b69 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 21:12:04 +0100 Subject: [PATCH 045/248] part store fix --- server/stores/partsStore.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/stores/partsStore.go b/server/stores/partsStore.go index cc694f4..46dc0de 100644 --- a/server/stores/partsStore.go +++ b/server/stores/partsStore.go @@ -93,7 +93,7 @@ func (store *PartsStoreImpl) CreatePart(part *types.Sparepart) error { part.ID = uuid.NewString() query := `INSERT INTO "SpareParts" (id, supplier_id, name, parts_image, spare_parts_link) - VALUES (?, $2, $3, $4, $5)` + VALUES (?, ?, ?, ?, ?)` _, err := store.database.Exec(query, part.ID, part.SupplierID, part.Name, part.PartsImage, part.SparePartsLink) @@ -105,11 +105,11 @@ func (store *PartsStoreImpl) CreatePart(part *types.Sparepart) error { } func (store *PartsStoreImpl) UpdatePart(id string, part *types.Sparepart) error { - query := `UPDATE "SpareParts" SET supplier_id = $2, name = $3, spare_parts_link = $4 WHERE ID = ?` + query := `UPDATE "SpareParts" SET supplier_id = ?, name = ?, spare_parts_link = ? WHERE ID = ?` args := []interface{}{id, part.SupplierID, part.Name, part.SparePartsLink} if part.PartsImage != "" && part.PartsImage != "null" { - query = `UPDATE "SpareParts" SET supplier_id = $2, name = $3, parts_image = $4, spare_parts_link = $5 WHERE ID = ?` + query = `UPDATE "SpareParts" SET supplier_id = ?, name = ?, parts_image = ?, spare_parts_link = ? WHERE ID = ?` args = []interface{}{id, part.SupplierID, part.Name, part.PartsImage, part.SparePartsLink} } From 2b2cbaacbde607ba0920e67269a82e12f2e43a8c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 21:13:39 +0100 Subject: [PATCH 046/248] spare parts sql --- server/sql/queries/spareparts.sql | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 server/sql/queries/spareparts.sql diff --git a/server/sql/queries/spareparts.sql b/server/sql/queries/spareparts.sql new file mode 100644 index 0000000..2c14409 --- /dev/null +++ b/server/sql/queries/spareparts.sql @@ -0,0 +1,33 @@ +-- name: GetParts :many +select id, supplier_id, name, parts_image, spare_parts_link +from SpareParts +where supplier_id = ?; + +-- name: GetPartByID :one +select id, supplier_id, name, parts_image, spare_parts_link +from SpareParts +where id = ?; + +-- name: CreateSparePart :exec +insert into SpareParts (id, supplier_id, name, parts_image, spare_parts_link) +values (?, ?, ?, ?, ?); + +-- name: UpdateSparePartNoImage :exec +update SpareParts +set supplier_id = ?, + name = ?, + spare_parts_link = ? +where id = ?; + +-- name: UpdateSparePart :exec +update SpareParts +set supplier_id = ?, + name = ?, + parts_image = ?, + spare_parts_link = ? +where id = ?; + +-- name: DeleteSparePart :exec +delete +from SpareParts +where id = ?; \ No newline at end of file From 248bbb1f23c612062ba92a992c7fd33ffc40f534 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Wed, 28 Aug 2024 21:13:50 +0100 Subject: [PATCH 047/248] spare parts gen code --- server/db/spareparts.sql.go | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 server/db/spareparts.sql.go diff --git a/server/db/spareparts.sql.go b/server/db/spareparts.sql.go new file mode 100644 index 0000000..b14b775 --- /dev/null +++ b/server/db/spareparts.sql.go @@ -0,0 +1,153 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: spareparts.sql + +package db + +import ( + "context" + "database/sql" +) + +const createSparePart = `-- name: CreateSparePart :exec +insert into SpareParts (id, supplier_id, name, parts_image, spare_parts_link) +values (?, ?, ?, ?, ?) +` + +type CreateSparePartParams struct { + ID string `json:"id"` + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + PartsImage sql.NullString `json:"parts_image"` + SparePartsLink sql.NullString `json:"spare_parts_link"` +} + +func (q *Queries) CreateSparePart(ctx context.Context, arg CreateSparePartParams) error { + _, err := q.db.ExecContext(ctx, createSparePart, + arg.ID, + arg.SupplierID, + arg.Name, + arg.PartsImage, + arg.SparePartsLink, + ) + return err +} + +const deleteSparePart = `-- name: DeleteSparePart :exec +delete +from SpareParts +where id = ? +` + +func (q *Queries) DeleteSparePart(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteSparePart, id) + return err +} + +const getPartByID = `-- name: GetPartByID :one +select id, supplier_id, name, parts_image, spare_parts_link +from SpareParts +where id = ? +` + +func (q *Queries) GetPartByID(ctx context.Context, id string) (SparePart, error) { + row := q.db.QueryRowContext(ctx, getPartByID, id) + var i SparePart + err := row.Scan( + &i.ID, + &i.SupplierID, + &i.Name, + &i.PartsImage, + &i.SparePartsLink, + ) + return i, err +} + +const getParts = `-- name: GetParts :many +select id, supplier_id, name, parts_image, spare_parts_link +from SpareParts +where supplier_id = ? +` + +func (q *Queries) GetParts(ctx context.Context, supplierID string) ([]SparePart, error) { + rows, err := q.db.QueryContext(ctx, getParts, supplierID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []SparePart + for rows.Next() { + var i SparePart + if err := rows.Scan( + &i.ID, + &i.SupplierID, + &i.Name, + &i.PartsImage, + &i.SparePartsLink, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateSparePart = `-- name: UpdateSparePart :exec +update SpareParts +set supplier_id = ?, + name = ?, + parts_image = ?, + spare_parts_link = ? +where id = ? +` + +type UpdateSparePartParams struct { + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + PartsImage sql.NullString `json:"parts_image"` + SparePartsLink sql.NullString `json:"spare_parts_link"` + ID string `json:"id"` +} + +func (q *Queries) UpdateSparePart(ctx context.Context, arg UpdateSparePartParams) error { + _, err := q.db.ExecContext(ctx, updateSparePart, + arg.SupplierID, + arg.Name, + arg.PartsImage, + arg.SparePartsLink, + arg.ID, + ) + return err +} + +const updateSparePartNoImage = `-- name: UpdateSparePartNoImage :exec +update SpareParts +set supplier_id = ?, + name = ?, + spare_parts_link = ? +where id = ? +` + +type UpdateSparePartNoImageParams struct { + SupplierID string `json:"supplier_id"` + Name string `json:"name"` + SparePartsLink sql.NullString `json:"spare_parts_link"` + ID string `json:"id"` +} + +func (q *Queries) UpdateSparePartNoImage(ctx context.Context, arg UpdateSparePartNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateSparePartNoImage, + arg.SupplierID, + arg.Name, + arg.SparePartsLink, + arg.ID, + ) + return err +} From 68a531a72ad47b0e28506d68bd1c7ffa211e3f0c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 19:52:05 +0100 Subject: [PATCH 048/248] privacy sql --- server/sql/queries/privacy.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 server/sql/queries/privacy.sql diff --git a/server/sql/queries/privacy.sql b/server/sql/queries/privacy.sql new file mode 100644 index 0000000..418b260 --- /dev/null +++ b/server/sql/queries/privacy.sql @@ -0,0 +1,14 @@ +-- name: GetPrivacies :many +select id, title, body, created from Privacy; + +-- name: GetPrivacyByID :one +select id, title, body, created from Privacy where id = ?; + +-- name: CreatePrivacy :exec +insert into Privacy (id, title, body, created) VALUES (?, ?, ?, ?); + +-- name: UpdatePrivacy :exec +update Privacy set title = ?, body = ? where id = ?; + +-- name: DeletePrivacy :exec +delete from Privacy where id = ?; \ No newline at end of file From c37e364171767ca6b88a96ab18dcb01d22df2a39 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:10:35 +0100 Subject: [PATCH 049/248] privacy gen code --- server/db/blogs.sql.go | 2 +- server/db/carousel.sql.go | 2 +- server/db/db.go | 2 +- server/db/employees.sql.go | 2 +- server/db/exhibition.sql.go | 2 +- server/db/lineitems.sql.go | 2 +- server/db/machines.sql.go | 2 +- server/db/models.go | 2 +- server/db/privacy.sql.go | 104 ++++++++++++++++++++++++++++++++++++ server/db/spareparts.sql.go | 2 +- server/db/suppliers.sql.go | 2 +- 11 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 server/db/privacy.sql.go diff --git a/server/db/blogs.sql.go b/server/db/blogs.sql.go index 8eefc07..bf3776e 100644 --- a/server/db/blogs.sql.go +++ b/server/db/blogs.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: blogs.sql package db diff --git a/server/db/carousel.sql.go b/server/db/carousel.sql.go index d5504ad..faae7de 100644 --- a/server/db/carousel.sql.go +++ b/server/db/carousel.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: carousel.sql package db diff --git a/server/db/db.go b/server/db/db.go index 17d86e9..41b7a34 100644 --- a/server/db/db.go +++ b/server/db/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package db diff --git a/server/db/employees.sql.go b/server/db/employees.sql.go index 55e20cb..005cbe6 100644 --- a/server/db/employees.sql.go +++ b/server/db/employees.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: employees.sql package db diff --git a/server/db/exhibition.sql.go b/server/db/exhibition.sql.go index 5560445..48639df 100644 --- a/server/db/exhibition.sql.go +++ b/server/db/exhibition.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: exhibition.sql package db diff --git a/server/db/lineitems.sql.go b/server/db/lineitems.sql.go index c253f11..49c7215 100644 --- a/server/db/lineitems.sql.go +++ b/server/db/lineitems.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: lineitems.sql package db diff --git a/server/db/machines.sql.go b/server/db/machines.sql.go index 7ac2186..8e734e0 100644 --- a/server/db/machines.sql.go +++ b/server/db/machines.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: machines.sql package db diff --git a/server/db/models.go b/server/db/models.go index cea0311..3ca23f6 100644 --- a/server/db/models.go +++ b/server/db/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 package db diff --git a/server/db/privacy.sql.go b/server/db/privacy.sql.go new file mode 100644 index 0000000..d76b782 --- /dev/null +++ b/server/db/privacy.sql.go @@ -0,0 +1,104 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 +// source: privacy.sql + +package db + +import ( + "context" + "database/sql" +) + +const createPrivacy = `-- name: CreatePrivacy :exec +insert into Privacy (id, title, body, created) VALUES (?, ?, ?, ?) +` + +type CreatePrivacyParams struct { + ID string `json:"id"` + Title string `json:"title"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreatePrivacy(ctx context.Context, arg CreatePrivacyParams) error { + _, err := q.db.ExecContext(ctx, createPrivacy, + arg.ID, + arg.Title, + arg.Body, + arg.Created, + ) + return err +} + +const deletePrivacy = `-- name: DeletePrivacy :exec +delete from Privacy where id = ? +` + +func (q *Queries) DeletePrivacy(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deletePrivacy, id) + return err +} + +const getPrivacies = `-- name: GetPrivacies :many +select id, title, body, created from Privacy +` + +func (q *Queries) GetPrivacies(ctx context.Context) ([]Privacy, error) { + rows, err := q.db.QueryContext(ctx, getPrivacies) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Privacy + for rows.Next() { + var i Privacy + if err := rows.Scan( + &i.ID, + &i.Title, + &i.Body, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getPrivacyByID = `-- name: GetPrivacyByID :one +select id, title, body, created from Privacy where id = ? +` + +func (q *Queries) GetPrivacyByID(ctx context.Context, id string) (Privacy, error) { + row := q.db.QueryRowContext(ctx, getPrivacyByID, id) + var i Privacy + err := row.Scan( + &i.ID, + &i.Title, + &i.Body, + &i.Created, + ) + return i, err +} + +const updatePrivacy = `-- name: UpdatePrivacy :exec +update Privacy set title = ?, body = ? where id = ? +` + +type UpdatePrivacyParams struct { + Title string `json:"title"` + Body sql.NullString `json:"body"` + ID string `json:"id"` +} + +func (q *Queries) UpdatePrivacy(ctx context.Context, arg UpdatePrivacyParams) error { + _, err := q.db.ExecContext(ctx, updatePrivacy, arg.Title, arg.Body, arg.ID) + return err +} diff --git a/server/db/spareparts.sql.go b/server/db/spareparts.sql.go index b14b775..01cabad 100644 --- a/server/db/spareparts.sql.go +++ b/server/db/spareparts.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: spareparts.sql package db diff --git a/server/db/suppliers.sql.go b/server/db/suppliers.sql.go index c18c694..26f985a 100644 --- a/server/db/suppliers.sql.go +++ b/server/db/suppliers.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.26.0 +// sqlc v1.27.0 // source: suppliers.sql package db From 2380091adf6ba555b48e664948e622452e0fcc86 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:10:42 +0100 Subject: [PATCH 050/248] product sql --- server/sql/queries/product.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 server/sql/queries/product.sql diff --git a/server/sql/queries/product.sql b/server/sql/queries/product.sql new file mode 100644 index 0000000..cdc6607 --- /dev/null +++ b/server/sql/queries/product.sql @@ -0,0 +1,17 @@ +-- name: GetProducts :many +select id, machine_id, name, product_image, description, product_link from Product; + +-- name: GetProductByID :one +select id, machine_id, name, product_image, description, product_link from Product where id = ?; + +-- name: CreateProduct :exec +insert into Product (id, machine_id, name, product_image, description, product_link) values (?, ?, ?, ?, ?, ?); + +-- name: UpdateProductNoImage :exec +update Product set machine_id = ?, name = ?, description = ?, product_link = ? where id = ?; + +-- name: UpdateProduct :exec +update Product set machine_id = ?, name = ?, product_image = ?, description = ?, product_link = ? where id = ?; + +-- name: DeleteProduct :exec +delete from Product where id = ?; \ No newline at end of file From aeb0c38f005ff8e21c55ac716306184ec797dd63 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:12:29 +0100 Subject: [PATCH 051/248] product gen code --- server/db/product.sql.go | 145 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 server/db/product.sql.go diff --git a/server/db/product.sql.go b/server/db/product.sql.go new file mode 100644 index 0000000..5521844 --- /dev/null +++ b/server/db/product.sql.go @@ -0,0 +1,145 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 +// source: product.sql + +package db + +import ( + "context" + "database/sql" +) + +const createProduct = `-- name: CreateProduct :exec +insert into Product (id, machine_id, name, product_image, description, product_link) values (?, ?, ?, ?, ?, ?) +` + +type CreateProductParams struct { + ID string `json:"id"` + MachineID string `json:"machine_id"` + Name string `json:"name"` + ProductImage sql.NullString `json:"product_image"` + Description sql.NullString `json:"description"` + ProductLink sql.NullString `json:"product_link"` +} + +func (q *Queries) CreateProduct(ctx context.Context, arg CreateProductParams) error { + _, err := q.db.ExecContext(ctx, createProduct, + arg.ID, + arg.MachineID, + arg.Name, + arg.ProductImage, + arg.Description, + arg.ProductLink, + ) + return err +} + +const deleteProduct = `-- name: DeleteProduct :exec +delete from Product where id = ? +` + +func (q *Queries) DeleteProduct(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteProduct, id) + return err +} + +const getProductByID = `-- name: GetProductByID :one +select id, machine_id, name, product_image, description, product_link from Product where id = ? +` + +func (q *Queries) GetProductByID(ctx context.Context, id string) (Product, error) { + row := q.db.QueryRowContext(ctx, getProductByID, id) + var i Product + err := row.Scan( + &i.ID, + &i.MachineID, + &i.Name, + &i.ProductImage, + &i.Description, + &i.ProductLink, + ) + return i, err +} + +const getProducts = `-- name: GetProducts :many +select id, machine_id, name, product_image, description, product_link from Product +` + +func (q *Queries) GetProducts(ctx context.Context) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getProducts) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Product + for rows.Next() { + var i Product + if err := rows.Scan( + &i.ID, + &i.MachineID, + &i.Name, + &i.ProductImage, + &i.Description, + &i.ProductLink, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateProduct = `-- name: UpdateProduct :exec +update Product set machine_id = ?, name = ?, product_image = ?, description = ?, product_link = ? where id = ? +` + +type UpdateProductParams struct { + MachineID string `json:"machine_id"` + Name string `json:"name"` + ProductImage sql.NullString `json:"product_image"` + Description sql.NullString `json:"description"` + ProductLink sql.NullString `json:"product_link"` + ID string `json:"id"` +} + +func (q *Queries) UpdateProduct(ctx context.Context, arg UpdateProductParams) error { + _, err := q.db.ExecContext(ctx, updateProduct, + arg.MachineID, + arg.Name, + arg.ProductImage, + arg.Description, + arg.ProductLink, + arg.ID, + ) + return err +} + +const updateProductNoImage = `-- name: UpdateProductNoImage :exec +update Product set machine_id = ?, name = ?, description = ?, product_link = ? where id = ? +` + +type UpdateProductNoImageParams struct { + MachineID string `json:"machine_id"` + Name string `json:"name"` + Description sql.NullString `json:"description"` + ProductLink sql.NullString `json:"product_link"` + ID string `json:"id"` +} + +func (q *Queries) UpdateProductNoImage(ctx context.Context, arg UpdateProductNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateProductNoImage, + arg.MachineID, + arg.Name, + arg.Description, + arg.ProductLink, + arg.ID, + ) + return err +} From d1907f4e2e585ae1790b15defa6a750bdd70f4a6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:12:33 +0100 Subject: [PATCH 052/248] format --- server/sql/queries/product.sql | 29 +++++++++++++++++++++++------ server/sql/queries/registration.sql | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 server/sql/queries/registration.sql diff --git a/server/sql/queries/product.sql b/server/sql/queries/product.sql index cdc6607..f7eb610 100644 --- a/server/sql/queries/product.sql +++ b/server/sql/queries/product.sql @@ -1,17 +1,34 @@ -- name: GetProducts :many -select id, machine_id, name, product_image, description, product_link from Product; +select id, machine_id, name, product_image, description, product_link +from Product; -- name: GetProductByID :one -select id, machine_id, name, product_image, description, product_link from Product where id = ?; +select id, machine_id, name, product_image, description, product_link +from Product +where id = ?; -- name: CreateProduct :exec -insert into Product (id, machine_id, name, product_image, description, product_link) values (?, ?, ?, ?, ?, ?); +insert into Product (id, machine_id, name, product_image, description, product_link) +values (?, ?, ?, ?, ?, ?); -- name: UpdateProductNoImage :exec -update Product set machine_id = ?, name = ?, description = ?, product_link = ? where id = ?; +update Product +set machine_id = ?, + name = ?, + description = ?, + product_link = ? +where id = ?; -- name: UpdateProduct :exec -update Product set machine_id = ?, name = ?, product_image = ?, description = ?, product_link = ? where id = ?; +update Product +set machine_id = ?, + name = ?, + product_image = ?, + description = ?, + product_link = ? +where id = ?; -- name: DeleteProduct :exec -delete from Product where id = ?; \ No newline at end of file +delete +from Product +where id = ?; \ No newline at end of file diff --git a/server/sql/queries/registration.sql b/server/sql/queries/registration.sql new file mode 100644 index 0000000..d7bb7e9 --- /dev/null +++ b/server/sql/queries/registration.sql @@ -0,0 +1,20 @@ +-- name: GetRegistrations :many +select id, + dealer_name, + dealer_address, + owner_name, + owner_address, + machine_model, + serial_number, + install_date, + invoice_number, + complete_supply, + pdi_complete, + pto_correct, + machine_test_run, + safety_induction, + operator_handbook, + date, + completed_by, + created +from MachineRegistration; \ No newline at end of file From 00656804a0f61d0df19a58f7014ed235ec89e2be Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:17:48 +0100 Subject: [PATCH 053/248] registration queries --- server/sql/queries/registration.sql | 56 ++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/server/sql/queries/registration.sql b/server/sql/queries/registration.sql index d7bb7e9..ef070ec 100644 --- a/server/sql/queries/registration.sql +++ b/server/sql/queries/registration.sql @@ -17,4 +17,58 @@ select id, date, completed_by, created -from MachineRegistration; \ No newline at end of file +from MachineRegistration; + +-- name: GetRegistrationsByID :one +select id, + dealer_name, + dealer_address, + owner_name, + owner_address, + machine_model, + serial_number, + install_date, + invoice_number, + complete_supply, + pdi_complete, + pto_correct, + machine_test_run, + safety_induction, + operator_handbook, + date, + completed_by, + created +from MachineRegistration +where id = ?; + +-- name: CreateRegistration :exec +insert into MachineRegistration (id, dealer_name, dealer_address, owner_name, owner_address, machine_model, + serial_number, install_date, invoice_number, complete_supply, pdi_complete, + pto_correct, machine_test_run, safety_induction, operator_handbook, date, completed_by, + created) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: UpdateRegistration :exec +update MachineRegistration +set dealer_name = ?, + dealer_address = ?, + owner_name = ?, + owner_address = ?, + machine_model = ?, + serial_number = ?, + install_date = ?, + invoice_number = ?, + complete_supply = ?, + pdi_complete = ?, + pto_correct = ?, + machine_test_run = ?, + safety_induction = ?, + operator_handbook = ?, + date = ?, + completed_by = ? +where id = ?; + +-- name: DeleteRegistration :exec +delete +from MachineRegistration +where id = ?; \ No newline at end of file From 0d2962fe8ea81d66070cf85f99ceaa5fd2c2cfc4 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:18:17 +0100 Subject: [PATCH 054/248] registration gen code --- server/db/registration.sql.go | 252 ++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 server/db/registration.sql.go diff --git a/server/db/registration.sql.go b/server/db/registration.sql.go new file mode 100644 index 0000000..5c8ed14 --- /dev/null +++ b/server/db/registration.sql.go @@ -0,0 +1,252 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: registration.sql + +package db + +import ( + "context" + "database/sql" +) + +const createRegistration = `-- name: CreateRegistration :exec +insert into MachineRegistration (id, dealer_name, dealer_address, owner_name, owner_address, machine_model, + serial_number, install_date, invoice_number, complete_supply, pdi_complete, + pto_correct, machine_test_run, safety_induction, operator_handbook, date, completed_by, + created) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +` + +type CreateRegistrationParams struct { + ID string `json:"id"` + DealerName string `json:"dealer_name"` + DealerAddress sql.NullString `json:"dealer_address"` + OwnerName string `json:"owner_name"` + OwnerAddress sql.NullString `json:"owner_address"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + InvoiceNumber sql.NullString `json:"invoice_number"` + CompleteSupply sql.NullInt64 `json:"complete_supply"` + PdiComplete sql.NullInt64 `json:"pdi_complete"` + PtoCorrect sql.NullInt64 `json:"pto_correct"` + MachineTestRun sql.NullInt64 `json:"machine_test_run"` + SafetyInduction sql.NullInt64 `json:"safety_induction"` + OperatorHandbook sql.NullInt64 `json:"operator_handbook"` + Date sql.NullString `json:"date"` + CompletedBy sql.NullString `json:"completed_by"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateRegistration(ctx context.Context, arg CreateRegistrationParams) error { + _, err := q.db.ExecContext(ctx, createRegistration, + arg.ID, + arg.DealerName, + arg.DealerAddress, + arg.OwnerName, + arg.OwnerAddress, + arg.MachineModel, + arg.SerialNumber, + arg.InstallDate, + arg.InvoiceNumber, + arg.CompleteSupply, + arg.PdiComplete, + arg.PtoCorrect, + arg.MachineTestRun, + arg.SafetyInduction, + arg.OperatorHandbook, + arg.Date, + arg.CompletedBy, + arg.Created, + ) + return err +} + +const deleteRegistration = `-- name: DeleteRegistration :exec +delete +from MachineRegistration +where id = ? +` + +func (q *Queries) DeleteRegistration(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteRegistration, id) + return err +} + +const getRegistrations = `-- name: GetRegistrations :many +select id, + dealer_name, + dealer_address, + owner_name, + owner_address, + machine_model, + serial_number, + install_date, + invoice_number, + complete_supply, + pdi_complete, + pto_correct, + machine_test_run, + safety_induction, + operator_handbook, + date, + completed_by, + created +from MachineRegistration +` + +func (q *Queries) GetRegistrations(ctx context.Context) ([]MachineRegistration, error) { + rows, err := q.db.QueryContext(ctx, getRegistrations) + if err != nil { + return nil, err + } + defer rows.Close() + var items []MachineRegistration + for rows.Next() { + var i MachineRegistration + if err := rows.Scan( + &i.ID, + &i.DealerName, + &i.DealerAddress, + &i.OwnerName, + &i.OwnerAddress, + &i.MachineModel, + &i.SerialNumber, + &i.InstallDate, + &i.InvoiceNumber, + &i.CompleteSupply, + &i.PdiComplete, + &i.PtoCorrect, + &i.MachineTestRun, + &i.SafetyInduction, + &i.OperatorHandbook, + &i.Date, + &i.CompletedBy, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getRegistrationsByID = `-- name: GetRegistrationsByID :one +select id, + dealer_name, + dealer_address, + owner_name, + owner_address, + machine_model, + serial_number, + install_date, + invoice_number, + complete_supply, + pdi_complete, + pto_correct, + machine_test_run, + safety_induction, + operator_handbook, + date, + completed_by, + created +from MachineRegistration +where id = ? +` + +func (q *Queries) GetRegistrationsByID(ctx context.Context, id string) (MachineRegistration, error) { + row := q.db.QueryRowContext(ctx, getRegistrationsByID, id) + var i MachineRegistration + err := row.Scan( + &i.ID, + &i.DealerName, + &i.DealerAddress, + &i.OwnerName, + &i.OwnerAddress, + &i.MachineModel, + &i.SerialNumber, + &i.InstallDate, + &i.InvoiceNumber, + &i.CompleteSupply, + &i.PdiComplete, + &i.PtoCorrect, + &i.MachineTestRun, + &i.SafetyInduction, + &i.OperatorHandbook, + &i.Date, + &i.CompletedBy, + &i.Created, + ) + return i, err +} + +const updateRegistration = `-- name: UpdateRegistration :exec +update MachineRegistration +set dealer_name = ?, + dealer_address = ?, + owner_name = ?, + owner_address = ?, + machine_model = ?, + serial_number = ?, + install_date = ?, + invoice_number = ?, + complete_supply = ?, + pdi_complete = ?, + pto_correct = ?, + machine_test_run = ?, + safety_induction = ?, + operator_handbook = ?, + date = ?, + completed_by = ? +where id = ? +` + +type UpdateRegistrationParams struct { + DealerName string `json:"dealer_name"` + DealerAddress sql.NullString `json:"dealer_address"` + OwnerName string `json:"owner_name"` + OwnerAddress sql.NullString `json:"owner_address"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + InvoiceNumber sql.NullString `json:"invoice_number"` + CompleteSupply sql.NullInt64 `json:"complete_supply"` + PdiComplete sql.NullInt64 `json:"pdi_complete"` + PtoCorrect sql.NullInt64 `json:"pto_correct"` + MachineTestRun sql.NullInt64 `json:"machine_test_run"` + SafetyInduction sql.NullInt64 `json:"safety_induction"` + OperatorHandbook sql.NullInt64 `json:"operator_handbook"` + Date sql.NullString `json:"date"` + CompletedBy sql.NullString `json:"completed_by"` + ID string `json:"id"` +} + +func (q *Queries) UpdateRegistration(ctx context.Context, arg UpdateRegistrationParams) error { + _, err := q.db.ExecContext(ctx, updateRegistration, + arg.DealerName, + arg.DealerAddress, + arg.OwnerName, + arg.OwnerAddress, + arg.MachineModel, + arg.SerialNumber, + arg.InstallDate, + arg.InvoiceNumber, + arg.CompleteSupply, + arg.PdiComplete, + arg.PtoCorrect, + arg.MachineTestRun, + arg.SafetyInduction, + arg.OperatorHandbook, + arg.Date, + arg.CompletedBy, + arg.ID, + ) + return err +} From aced8f7cb0df40006d1a43d8628c7457a4a38d72 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:18:39 +0100 Subject: [PATCH 055/248] something else --- server/db/blogs.sql.go | 2 +- server/db/carousel.sql.go | 2 +- server/db/db.go | 2 +- server/db/employees.sql.go | 2 +- server/db/exhibition.sql.go | 2 +- server/db/lineitems.sql.go | 2 +- server/db/machines.sql.go | 2 +- server/db/models.go | 2 +- server/db/privacy.sql.go | 2 +- server/db/product.sql.go | 31 ++++++++++++++++++++++++------- server/db/spareparts.sql.go | 2 +- server/db/suppliers.sql.go | 2 +- 12 files changed, 35 insertions(+), 18 deletions(-) diff --git a/server/db/blogs.sql.go b/server/db/blogs.sql.go index bf3776e..8eefc07 100644 --- a/server/db/blogs.sql.go +++ b/server/db/blogs.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: blogs.sql package db diff --git a/server/db/carousel.sql.go b/server/db/carousel.sql.go index faae7de..d5504ad 100644 --- a/server/db/carousel.sql.go +++ b/server/db/carousel.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: carousel.sql package db diff --git a/server/db/db.go b/server/db/db.go index 41b7a34..17d86e9 100644 --- a/server/db/db.go +++ b/server/db/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 package db diff --git a/server/db/employees.sql.go b/server/db/employees.sql.go index 005cbe6..55e20cb 100644 --- a/server/db/employees.sql.go +++ b/server/db/employees.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: employees.sql package db diff --git a/server/db/exhibition.sql.go b/server/db/exhibition.sql.go index 48639df..5560445 100644 --- a/server/db/exhibition.sql.go +++ b/server/db/exhibition.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: exhibition.sql package db diff --git a/server/db/lineitems.sql.go b/server/db/lineitems.sql.go index 49c7215..c253f11 100644 --- a/server/db/lineitems.sql.go +++ b/server/db/lineitems.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: lineitems.sql package db diff --git a/server/db/machines.sql.go b/server/db/machines.sql.go index 8e734e0..7ac2186 100644 --- a/server/db/machines.sql.go +++ b/server/db/machines.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: machines.sql package db diff --git a/server/db/models.go b/server/db/models.go index 3ca23f6..cea0311 100644 --- a/server/db/models.go +++ b/server/db/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 package db diff --git a/server/db/privacy.sql.go b/server/db/privacy.sql.go index d76b782..bc619d3 100644 --- a/server/db/privacy.sql.go +++ b/server/db/privacy.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: privacy.sql package db diff --git a/server/db/product.sql.go b/server/db/product.sql.go index 5521844..911b4dd 100644 --- a/server/db/product.sql.go +++ b/server/db/product.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: product.sql package db @@ -11,7 +11,8 @@ import ( ) const createProduct = `-- name: CreateProduct :exec -insert into Product (id, machine_id, name, product_image, description, product_link) values (?, ?, ?, ?, ?, ?) +insert into Product (id, machine_id, name, product_image, description, product_link) +values (?, ?, ?, ?, ?, ?) ` type CreateProductParams struct { @@ -36,7 +37,9 @@ func (q *Queries) CreateProduct(ctx context.Context, arg CreateProductParams) er } const deleteProduct = `-- name: DeleteProduct :exec -delete from Product where id = ? +delete +from Product +where id = ? ` func (q *Queries) DeleteProduct(ctx context.Context, id string) error { @@ -45,7 +48,9 @@ func (q *Queries) DeleteProduct(ctx context.Context, id string) error { } const getProductByID = `-- name: GetProductByID :one -select id, machine_id, name, product_image, description, product_link from Product where id = ? +select id, machine_id, name, product_image, description, product_link +from Product +where id = ? ` func (q *Queries) GetProductByID(ctx context.Context, id string) (Product, error) { @@ -63,7 +68,8 @@ func (q *Queries) GetProductByID(ctx context.Context, id string) (Product, error } const getProducts = `-- name: GetProducts :many -select id, machine_id, name, product_image, description, product_link from Product +select id, machine_id, name, product_image, description, product_link +from Product ` func (q *Queries) GetProducts(ctx context.Context) ([]Product, error) { @@ -97,7 +103,13 @@ func (q *Queries) GetProducts(ctx context.Context) ([]Product, error) { } const updateProduct = `-- name: UpdateProduct :exec -update Product set machine_id = ?, name = ?, product_image = ?, description = ?, product_link = ? where id = ? +update Product +set machine_id = ?, + name = ?, + product_image = ?, + description = ?, + product_link = ? +where id = ? ` type UpdateProductParams struct { @@ -122,7 +134,12 @@ func (q *Queries) UpdateProduct(ctx context.Context, arg UpdateProductParams) er } const updateProductNoImage = `-- name: UpdateProductNoImage :exec -update Product set machine_id = ?, name = ?, description = ?, product_link = ? where id = ? +update Product +set machine_id = ?, + name = ?, + description = ?, + product_link = ? +where id = ? ` type UpdateProductNoImageParams struct { diff --git a/server/db/spareparts.sql.go b/server/db/spareparts.sql.go index 01cabad..b14b775 100644 --- a/server/db/spareparts.sql.go +++ b/server/db/spareparts.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: spareparts.sql package db diff --git a/server/db/suppliers.sql.go b/server/db/suppliers.sql.go index 26f985a..c18c694 100644 --- a/server/db/suppliers.sql.go +++ b/server/db/suppliers.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.26.0 // source: suppliers.sql package db From f39707aea8affd98a72495f66cc56eacc2b863f8 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:22:40 +0100 Subject: [PATCH 056/248] terms sql --- server/sql/queries/terms.sql | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 server/sql/queries/terms.sql diff --git a/server/sql/queries/terms.sql b/server/sql/queries/terms.sql new file mode 100644 index 0000000..818b05f --- /dev/null +++ b/server/sql/queries/terms.sql @@ -0,0 +1,25 @@ +-- name: GetTerms :many +select id, title, body, created +from Terms; + +-- name: GetTermByID :one +select id, title, body, created +from Terms +where id = ?; + +-- name: CreateTerm :exec +insert into Terms (id, title, body, created) +values (?, ?, ?, ?); + +-- name: UpdateTerm :exec +update Terms +set id = ?, + title = ?, + body = ?, + created = ? +where id = ?; + +-- name: DeleteTerm :exec +delete +from Terms +where id = ?; \ No newline at end of file From e4b4925786df98fb4c446c54231ae1343541c7a1 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:22:55 +0100 Subject: [PATCH 057/248] terms gen code --- server/db/terms.sql.go | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 server/db/terms.sql.go diff --git a/server/db/terms.sql.go b/server/db/terms.sql.go new file mode 100644 index 0000000..8d176f2 --- /dev/null +++ b/server/db/terms.sql.go @@ -0,0 +1,123 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: terms.sql + +package db + +import ( + "context" + "database/sql" +) + +const createTerm = `-- name: CreateTerm :exec +insert into Terms (id, title, body, created) +values (?, ?, ?, ?) +` + +type CreateTermParams struct { + ID string `json:"id"` + Title string `json:"title"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateTerm(ctx context.Context, arg CreateTermParams) error { + _, err := q.db.ExecContext(ctx, createTerm, + arg.ID, + arg.Title, + arg.Body, + arg.Created, + ) + return err +} + +const deleteTerm = `-- name: DeleteTerm :exec +delete +from Terms +where id = ? +` + +func (q *Queries) DeleteTerm(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteTerm, id) + return err +} + +const getTermByID = `-- name: GetTermByID :one +select id, title, body, created +from Terms +where id = ? +` + +func (q *Queries) GetTermByID(ctx context.Context, id string) (Term, error) { + row := q.db.QueryRowContext(ctx, getTermByID, id) + var i Term + err := row.Scan( + &i.ID, + &i.Title, + &i.Body, + &i.Created, + ) + return i, err +} + +const getTerms = `-- name: GetTerms :many +select id, title, body, created +from Terms +` + +func (q *Queries) GetTerms(ctx context.Context) ([]Term, error) { + rows, err := q.db.QueryContext(ctx, getTerms) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Term + for rows.Next() { + var i Term + if err := rows.Scan( + &i.ID, + &i.Title, + &i.Body, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateTerm = `-- name: UpdateTerm :exec +update Terms +set id = ?, + title = ?, + body = ?, + created = ? +where id = ? +` + +type UpdateTermParams struct { + ID string `json:"id"` + Title string `json:"title"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` + ID_2 string `json:"id_2"` +} + +func (q *Queries) UpdateTerm(ctx context.Context, arg UpdateTermParams) error { + _, err := q.db.ExecContext(ctx, updateTerm, + arg.ID, + arg.Title, + arg.Body, + arg.Created, + arg.ID_2, + ) + return err +} From 18dee4e1376cde6ff58b438f6daad8c69a6ac76e Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:30:11 +0100 Subject: [PATCH 058/248] timeline sql --- server/sql/queries/timeline.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 server/sql/queries/timeline.sql diff --git a/server/sql/queries/timeline.sql b/server/sql/queries/timeline.sql new file mode 100644 index 0000000..e8cf54b --- /dev/null +++ b/server/sql/queries/timeline.sql @@ -0,0 +1,14 @@ +-- name: GetTimelines :many +select id, title, date, body, created from Timeline; + +-- name: GetTimelineByID :one +select id, title, date, body, created from Timeline where id = ?; + +-- name: CreateTimeline :exec +insert into Timeline (id, title, date, body, created) values (?, ?, ?, ?, ?); + +-- name: UpdateTimeline :exec +update Timeline set title = ?, date = ?, body = ? where id = ?; + +-- name: DeleteTimeline :exec +delete from Timeline where id = ?; From c4f0d0da1497ac090a8aba3062dee2ad37dac8a3 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:30:35 +0100 Subject: [PATCH 059/248] timeline gen code --- server/db/timeline.sql.go | 114 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 server/db/timeline.sql.go diff --git a/server/db/timeline.sql.go b/server/db/timeline.sql.go new file mode 100644 index 0000000..2740c2e --- /dev/null +++ b/server/db/timeline.sql.go @@ -0,0 +1,114 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: timeline.sql + +package db + +import ( + "context" + "database/sql" +) + +const createTimeline = `-- name: CreateTimeline :exec +insert into Timeline (id, title, date, body, created) values (?, ?, ?, ?, ?) +` + +type CreateTimelineParams struct { + ID string `json:"id"` + Title string `json:"title"` + Date sql.NullString `json:"date"` + Body sql.NullString `json:"body"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateTimeline(ctx context.Context, arg CreateTimelineParams) error { + _, err := q.db.ExecContext(ctx, createTimeline, + arg.ID, + arg.Title, + arg.Date, + arg.Body, + arg.Created, + ) + return err +} + +const deleteTimeline = `-- name: DeleteTimeline :exec +delete from Timeline where id = ? +` + +func (q *Queries) DeleteTimeline(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteTimeline, id) + return err +} + +const getTimelineByID = `-- name: GetTimelineByID :one +select id, title, date, body, created from Timeline where id = ? +` + +func (q *Queries) GetTimelineByID(ctx context.Context, id string) (Timeline, error) { + row := q.db.QueryRowContext(ctx, getTimelineByID, id) + var i Timeline + err := row.Scan( + &i.ID, + &i.Title, + &i.Date, + &i.Body, + &i.Created, + ) + return i, err +} + +const getTimelines = `-- name: GetTimelines :many +select id, title, date, body, created from Timeline +` + +func (q *Queries) GetTimelines(ctx context.Context) ([]Timeline, error) { + rows, err := q.db.QueryContext(ctx, getTimelines) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Timeline + for rows.Next() { + var i Timeline + if err := rows.Scan( + &i.ID, + &i.Title, + &i.Date, + &i.Body, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateTimeline = `-- name: UpdateTimeline :exec +update Timeline set title = ?, date = ?, body = ? where id = ? +` + +type UpdateTimelineParams struct { + Title string `json:"title"` + Date sql.NullString `json:"date"` + Body sql.NullString `json:"body"` + ID string `json:"id"` +} + +func (q *Queries) UpdateTimeline(ctx context.Context, arg UpdateTimelineParams) error { + _, err := q.db.ExecContext(ctx, updateTimeline, + arg.Title, + arg.Date, + arg.Body, + arg.ID, + ) + return err +} From c0b54a3207c4ef22d51207c6fd3725123555c484 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:33:12 +0100 Subject: [PATCH 060/248] format --- server/sql/queries/timeline.sql | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/server/sql/queries/timeline.sql b/server/sql/queries/timeline.sql index e8cf54b..6da8b61 100644 --- a/server/sql/queries/timeline.sql +++ b/server/sql/queries/timeline.sql @@ -1,14 +1,24 @@ -- name: GetTimelines :many -select id, title, date, body, created from Timeline; +select id, title, date, body, created +from Timeline; -- name: GetTimelineByID :one -select id, title, date, body, created from Timeline where id = ?; +select id, title, date, body, created +from Timeline +where id = ?; -- name: CreateTimeline :exec -insert into Timeline (id, title, date, body, created) values (?, ?, ?, ?, ?); +insert into Timeline (id, title, date, body, created) +values (?, ?, ?, ?, ?); -- name: UpdateTimeline :exec -update Timeline set title = ?, date = ?, body = ? where id = ?; +update Timeline +set title = ?, + date = ?, + body = ? +where id = ?; -- name: DeleteTimeline :exec -delete from Timeline where id = ?; +delete +from Timeline +where id = ?; From c834b20dd2cfeb761adb0f7d7224b8f5b89ac735 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:39:29 +0100 Subject: [PATCH 061/248] video sql --- server/sql/queries/video.sql | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 server/sql/queries/video.sql diff --git a/server/sql/queries/video.sql b/server/sql/queries/video.sql new file mode 100644 index 0000000..0353d1f --- /dev/null +++ b/server/sql/queries/video.sql @@ -0,0 +1,40 @@ +-- name: SelectVideos :many +select id, + supplier_id, + web_url, + title, + description, + video_id, + thumbnail_url, + created +from Video +where supplier_id = ?; + +-- name: SelectVideoByID :one +select id, + supplier_id, + web_url, + title, + description, + video_id, + thumbnail_url, + created +from Video +where id = ?; + +-- name: CreateVideo :exec +insert into Video (id, supplier_id, web_url, title, description, video_id, thumbnail_url, created) +values (?, ?, ?, ?, ?, ?, ?, ?); + +-- name: UpdateVideo :exec +update Video +set supplier_id = ?, + web_url = ?, + title = ?, + description = ?, + video_id = ?, + thumbnail_url = ? +where id = ?; + +-- name: DeleteVideo :exec +delete from Video where id = ?; From 95d113ff55f1e116c47a2a47598a290aed15beb9 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:41:13 +0100 Subject: [PATCH 062/248] video gen code --- server/db/timeline.sql.go | 20 +++-- server/db/video.sql.go | 158 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 server/db/video.sql.go diff --git a/server/db/timeline.sql.go b/server/db/timeline.sql.go index 2740c2e..828b8c0 100644 --- a/server/db/timeline.sql.go +++ b/server/db/timeline.sql.go @@ -11,7 +11,8 @@ import ( ) const createTimeline = `-- name: CreateTimeline :exec -insert into Timeline (id, title, date, body, created) values (?, ?, ?, ?, ?) +insert into Timeline (id, title, date, body, created) +values (?, ?, ?, ?, ?) ` type CreateTimelineParams struct { @@ -34,7 +35,9 @@ func (q *Queries) CreateTimeline(ctx context.Context, arg CreateTimelineParams) } const deleteTimeline = `-- name: DeleteTimeline :exec -delete from Timeline where id = ? +delete +from Timeline +where id = ? ` func (q *Queries) DeleteTimeline(ctx context.Context, id string) error { @@ -43,7 +46,9 @@ func (q *Queries) DeleteTimeline(ctx context.Context, id string) error { } const getTimelineByID = `-- name: GetTimelineByID :one -select id, title, date, body, created from Timeline where id = ? +select id, title, date, body, created +from Timeline +where id = ? ` func (q *Queries) GetTimelineByID(ctx context.Context, id string) (Timeline, error) { @@ -60,7 +65,8 @@ func (q *Queries) GetTimelineByID(ctx context.Context, id string) (Timeline, err } const getTimelines = `-- name: GetTimelines :many -select id, title, date, body, created from Timeline +select id, title, date, body, created +from Timeline ` func (q *Queries) GetTimelines(ctx context.Context) ([]Timeline, error) { @@ -93,7 +99,11 @@ func (q *Queries) GetTimelines(ctx context.Context) ([]Timeline, error) { } const updateTimeline = `-- name: UpdateTimeline :exec -update Timeline set title = ?, date = ?, body = ? where id = ? +update Timeline +set title = ?, + date = ?, + body = ? +where id = ? ` type UpdateTimelineParams struct { diff --git a/server/db/video.sql.go b/server/db/video.sql.go new file mode 100644 index 0000000..b387289 --- /dev/null +++ b/server/db/video.sql.go @@ -0,0 +1,158 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: video.sql + +package db + +import ( + "context" + "database/sql" +) + +const createVideo = `-- name: CreateVideo :exec +insert into Video (id, supplier_id, web_url, title, description, video_id, thumbnail_url, created) +values (?, ?, ?, ?, ?, ?, ?, ?) +` + +type CreateVideoParams struct { + ID string `json:"id"` + SupplierID string `json:"supplier_id"` + WebUrl sql.NullString `json:"web_url"` + Title sql.NullString `json:"title"` + Description sql.NullString `json:"description"` + VideoID sql.NullString `json:"video_id"` + ThumbnailUrl sql.NullString `json:"thumbnail_url"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateVideo(ctx context.Context, arg CreateVideoParams) error { + _, err := q.db.ExecContext(ctx, createVideo, + arg.ID, + arg.SupplierID, + arg.WebUrl, + arg.Title, + arg.Description, + arg.VideoID, + arg.ThumbnailUrl, + arg.Created, + ) + return err +} + +const deleteVideo = `-- name: DeleteVideo :exec +delete from Video where id = ? +` + +func (q *Queries) DeleteVideo(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteVideo, id) + return err +} + +const selectVideoByID = `-- name: SelectVideoByID :one +select id, + supplier_id, + web_url, + title, + description, + video_id, + thumbnail_url, + created +from Video +where id = ? +` + +func (q *Queries) SelectVideoByID(ctx context.Context, id string) (Video, error) { + row := q.db.QueryRowContext(ctx, selectVideoByID, id) + var i Video + err := row.Scan( + &i.ID, + &i.SupplierID, + &i.WebUrl, + &i.Title, + &i.Description, + &i.VideoID, + &i.ThumbnailUrl, + &i.Created, + ) + return i, err +} + +const selectVideos = `-- name: SelectVideos :many +select id, + supplier_id, + web_url, + title, + description, + video_id, + thumbnail_url, + created +from Video +where supplier_id = ? +` + +func (q *Queries) SelectVideos(ctx context.Context, supplierID string) ([]Video, error) { + rows, err := q.db.QueryContext(ctx, selectVideos, supplierID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Video + for rows.Next() { + var i Video + if err := rows.Scan( + &i.ID, + &i.SupplierID, + &i.WebUrl, + &i.Title, + &i.Description, + &i.VideoID, + &i.ThumbnailUrl, + &i.Created, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateVideo = `-- name: UpdateVideo :exec +update Video +set supplier_id = ?, + web_url = ?, + title = ?, + description = ?, + video_id = ?, + thumbnail_url = ? +where id = ? +` + +type UpdateVideoParams struct { + SupplierID string `json:"supplier_id"` + WebUrl sql.NullString `json:"web_url"` + Title sql.NullString `json:"title"` + Description sql.NullString `json:"description"` + VideoID sql.NullString `json:"video_id"` + ThumbnailUrl sql.NullString `json:"thumbnail_url"` + ID string `json:"id"` +} + +func (q *Queries) UpdateVideo(ctx context.Context, arg UpdateVideoParams) error { + _, err := q.db.ExecContext(ctx, updateVideo, + arg.SupplierID, + arg.WebUrl, + arg.Title, + arg.Description, + arg.VideoID, + arg.ThumbnailUrl, + arg.ID, + ) + return err +} From 5f2a7e7af6c4048cfca66875bcd8d918ac64bfae Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:53:45 +0100 Subject: [PATCH 063/248] warranty sql --- server/sql/queries/warranty.sql | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 server/sql/queries/warranty.sql diff --git a/server/sql/queries/warranty.sql b/server/sql/queries/warranty.sql new file mode 100644 index 0000000..abafa40 --- /dev/null +++ b/server/sql/queries/warranty.sql @@ -0,0 +1,62 @@ +-- name: GetWarranties :many +select id, dealer, owner_name +from WarrantyClaim +order by created desc; + +-- name: GetWarrantyByID :one +select wc.id, + wc.dealer, + wc.dealer_contact, + wc.owner_name, + wc.machine_model, + wc.serial_number, + wc.install_date, + wc.failure_date, + wc.repair_date, + wc.failure_details, + wc.repair_details, + wc.labour_hours, + wc.completed_by, + wc.created, + pr.id as part_id, + pr.part_number, + pr.quantity_needed, + pr.invoice_number, + pr.description +from WarrantyClaim wc + left join + PartsRequired pr on wc.id = pr.warranty_id +where wc.id = ?; + +-- name: CreateWarranty :exec +insert into WarrantyClaim (id, dealer, dealer_contact, owner_name, machine_model, serial_number, install_date, + failure_date, repair_date, failure_details, repair_details, labour_hours, completed_by, + created) +values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); +insert into PartsRequired (id, warranty_id, part_number, quantity_needed, invoice_number, description) +values (?, ?, ?, ?, ?, ?); + +-- name: UpdateWarranty :exec +update WarrantyClaim +set dealer = ?, + dealer_contact = ?, + owner_name = ?, + machine_model = ?, + serial_number = ?, + install_date = ?, + failure_date = ?, + repair_date = ?, + failure_details = ?, + repair_details = ?, + labour_hours = ?, + completed_by = ? +where id = ?; +delete +from PartsRequired +where warranty_id = ?; +insert into PartsRequired (id, warranty_id, part_number, quantity_needed, invoice_number, description) +values (?, ?, ?, ?, ?, ?); + +-- name: DeleteWarranty :exec +delete from PartsRequired where warranty_id = ?; +delete from WarrantyClaim where id = ?; From 775047a370c4e31443e87320f355f88f41fbdfe2 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:56:47 +0100 Subject: [PATCH 064/248] fix some queries --- server/sql/queries/warranty.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/sql/queries/warranty.sql b/server/sql/queries/warranty.sql index abafa40..d960a7a 100644 --- a/server/sql/queries/warranty.sql +++ b/server/sql/queries/warranty.sql @@ -33,6 +33,8 @@ insert into WarrantyClaim (id, dealer, dealer_contact, owner_name, machine_model failure_date, repair_date, failure_details, repair_details, labour_hours, completed_by, created) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); + +-- name: CreatePartsRequired :exec insert into PartsRequired (id, warranty_id, part_number, quantity_needed, invoice_number, description) values (?, ?, ?, ?, ?, ?); @@ -51,11 +53,11 @@ set dealer = ?, labour_hours = ?, completed_by = ? where id = ?; + +-- name: DeletePartRequired :exec delete from PartsRequired where warranty_id = ?; -insert into PartsRequired (id, warranty_id, part_number, quantity_needed, invoice_number, description) -values (?, ?, ?, ?, ?, ?); -- name: DeleteWarranty :exec delete from PartsRequired where warranty_id = ?; From e2d40573249cb0c036dee348ffd37742a089c069 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 29 Aug 2024 20:57:14 +0100 Subject: [PATCH 065/248] warranty sql gen --- server/db/warranty.sql.go | 263 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 server/db/warranty.sql.go diff --git a/server/db/warranty.sql.go b/server/db/warranty.sql.go new file mode 100644 index 0000000..8da62fa --- /dev/null +++ b/server/db/warranty.sql.go @@ -0,0 +1,263 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: warranty.sql + +package db + +import ( + "context" + "database/sql" +) + +const createPartsRequired = `-- name: CreatePartsRequired :exec +insert into PartsRequired (id, warranty_id, part_number, quantity_needed, invoice_number, description) +values (?, ?, ?, ?, ?, ?) +` + +type CreatePartsRequiredParams struct { + ID string `json:"id"` + WarrantyID string `json:"warranty_id"` + PartNumber sql.NullString `json:"part_number"` + QuantityNeeded string `json:"quantity_needed"` + InvoiceNumber sql.NullString `json:"invoice_number"` + Description sql.NullString `json:"description"` +} + +func (q *Queries) CreatePartsRequired(ctx context.Context, arg CreatePartsRequiredParams) error { + _, err := q.db.ExecContext(ctx, createPartsRequired, + arg.ID, + arg.WarrantyID, + arg.PartNumber, + arg.QuantityNeeded, + arg.InvoiceNumber, + arg.Description, + ) + return err +} + +const createWarranty = `-- name: CreateWarranty :exec +insert into WarrantyClaim (id, dealer, dealer_contact, owner_name, machine_model, serial_number, install_date, + failure_date, repair_date, failure_details, repair_details, labour_hours, completed_by, + created) +values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +` + +type CreateWarrantyParams struct { + ID string `json:"id"` + Dealer string `json:"dealer"` + DealerContact sql.NullString `json:"dealer_contact"` + OwnerName string `json:"owner_name"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + FailureDate sql.NullString `json:"failure_date"` + RepairDate sql.NullString `json:"repair_date"` + FailureDetails sql.NullString `json:"failure_details"` + RepairDetails sql.NullString `json:"repair_details"` + LabourHours sql.NullString `json:"labour_hours"` + CompletedBy sql.NullString `json:"completed_by"` + Created sql.NullString `json:"created"` +} + +func (q *Queries) CreateWarranty(ctx context.Context, arg CreateWarrantyParams) error { + _, err := q.db.ExecContext(ctx, createWarranty, + arg.ID, + arg.Dealer, + arg.DealerContact, + arg.OwnerName, + arg.MachineModel, + arg.SerialNumber, + arg.InstallDate, + arg.FailureDate, + arg.RepairDate, + arg.FailureDetails, + arg.RepairDetails, + arg.LabourHours, + arg.CompletedBy, + arg.Created, + ) + return err +} + +const deletePartRequired = `-- name: DeletePartRequired :exec +delete +from PartsRequired +where warranty_id = ? +` + +func (q *Queries) DeletePartRequired(ctx context.Context, warrantyID string) error { + _, err := q.db.ExecContext(ctx, deletePartRequired, warrantyID) + return err +} + +const deleteWarranty = `-- name: DeleteWarranty :exec +delete from PartsRequired where warranty_id = ? +` + +func (q *Queries) DeleteWarranty(ctx context.Context, warrantyID string) error { + _, err := q.db.ExecContext(ctx, deleteWarranty, warrantyID) + return err +} + +const getWarranties = `-- name: GetWarranties :many +select id, dealer, owner_name +from WarrantyClaim +order by created desc +` + +type GetWarrantiesRow struct { + ID string `json:"id"` + Dealer string `json:"dealer"` + OwnerName string `json:"owner_name"` +} + +func (q *Queries) GetWarranties(ctx context.Context) ([]GetWarrantiesRow, error) { + rows, err := q.db.QueryContext(ctx, getWarranties) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetWarrantiesRow + for rows.Next() { + var i GetWarrantiesRow + if err := rows.Scan(&i.ID, &i.Dealer, &i.OwnerName); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getWarrantyByID = `-- name: GetWarrantyByID :one +select wc.id, + wc.dealer, + wc.dealer_contact, + wc.owner_name, + wc.machine_model, + wc.serial_number, + wc.install_date, + wc.failure_date, + wc.repair_date, + wc.failure_details, + wc.repair_details, + wc.labour_hours, + wc.completed_by, + wc.created, + pr.id as part_id, + pr.part_number, + pr.quantity_needed, + pr.invoice_number, + pr.description +from WarrantyClaim wc + left join + PartsRequired pr on wc.id = pr.warranty_id +where wc.id = ? +` + +type GetWarrantyByIDRow struct { + ID string `json:"id"` + Dealer string `json:"dealer"` + DealerContact sql.NullString `json:"dealer_contact"` + OwnerName string `json:"owner_name"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + FailureDate sql.NullString `json:"failure_date"` + RepairDate sql.NullString `json:"repair_date"` + FailureDetails sql.NullString `json:"failure_details"` + RepairDetails sql.NullString `json:"repair_details"` + LabourHours sql.NullString `json:"labour_hours"` + CompletedBy sql.NullString `json:"completed_by"` + Created sql.NullString `json:"created"` + PartID sql.NullString `json:"part_id"` + PartNumber sql.NullString `json:"part_number"` + QuantityNeeded sql.NullString `json:"quantity_needed"` + InvoiceNumber sql.NullString `json:"invoice_number"` + Description sql.NullString `json:"description"` +} + +func (q *Queries) GetWarrantyByID(ctx context.Context, id string) (GetWarrantyByIDRow, error) { + row := q.db.QueryRowContext(ctx, getWarrantyByID, id) + var i GetWarrantyByIDRow + err := row.Scan( + &i.ID, + &i.Dealer, + &i.DealerContact, + &i.OwnerName, + &i.MachineModel, + &i.SerialNumber, + &i.InstallDate, + &i.FailureDate, + &i.RepairDate, + &i.FailureDetails, + &i.RepairDetails, + &i.LabourHours, + &i.CompletedBy, + &i.Created, + &i.PartID, + &i.PartNumber, + &i.QuantityNeeded, + &i.InvoiceNumber, + &i.Description, + ) + return i, err +} + +const updateWarranty = `-- name: UpdateWarranty :exec +update WarrantyClaim +set dealer = ?, + dealer_contact = ?, + owner_name = ?, + machine_model = ?, + serial_number = ?, + install_date = ?, + failure_date = ?, + repair_date = ?, + failure_details = ?, + repair_details = ?, + labour_hours = ?, + completed_by = ? +where id = ? +` + +type UpdateWarrantyParams struct { + Dealer string `json:"dealer"` + DealerContact sql.NullString `json:"dealer_contact"` + OwnerName string `json:"owner_name"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + FailureDate sql.NullString `json:"failure_date"` + RepairDate sql.NullString `json:"repair_date"` + FailureDetails sql.NullString `json:"failure_details"` + RepairDetails sql.NullString `json:"repair_details"` + LabourHours sql.NullString `json:"labour_hours"` + CompletedBy sql.NullString `json:"completed_by"` + ID string `json:"id"` +} + +func (q *Queries) UpdateWarranty(ctx context.Context, arg UpdateWarrantyParams) error { + _, err := q.db.ExecContext(ctx, updateWarranty, + arg.Dealer, + arg.DealerContact, + arg.OwnerName, + arg.MachineModel, + arg.SerialNumber, + arg.InstallDate, + arg.FailureDate, + arg.RepairDate, + arg.FailureDetails, + arg.RepairDetails, + arg.LabourHours, + arg.CompletedBy, + arg.ID, + ) + return err +} From 045f6054868f1c0eced8d5609ecd93fa12921a66 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 31 Aug 2024 16:47:52 +0100 Subject: [PATCH 066/248] some query integration for machnines --- server/stores/machineStore.go | 94 ++++++++++++----------------------- 1 file changed, 31 insertions(+), 63 deletions(-) diff --git a/server/stores/machineStore.go b/server/stores/machineStore.go index 558e436..7062819 100644 --- a/server/stores/machineStore.go +++ b/server/stores/machineStore.go @@ -1,10 +1,10 @@ package stores import ( + "context" "database/sql" - "errors" "fmt" - "log" + "github.com/sean-david-welch/farmec-v2/server/db" "time" "github.com/google/uuid" @@ -12,82 +12,50 @@ import ( ) type MachineStore interface { - GetMachines(id string) ([]types.Machine, error) - GetMachineById(id string) (*types.Machine, error) - CreateMachine(machine *types.Machine) error - UpdateMachine(id string, machine *types.Machine) error + GetMachines(id string) ([]db.Machine, error) + GetMachineById(id string) (*db.Machine, error) + CreateMachine(machine *db.Machine) error + UpdateMachine(id string, machine *db.Machine) error DeleteMachine(id string) error } type MachineStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewMachineStore(database *sql.DB) *MachineStoreImpl { - return &MachineStoreImpl{database: database} +func NewMachineStore(sql *sql.DB) *MachineStoreImpl { + queries := db.New(sql) + return &MachineStoreImpl{queries: queries} } -func ScanMachine(row interface{}, machine *types.Machine) error { - var scanner interface { - Scan(dest ...interface{}) error - } - - switch value := row.(type) { - case *sql.Row: - scanner = value - case *sql.Rows: - scanner = value - default: - return fmt.Errorf("unsupported type: %T", value) - } - - return scanner.Scan(&machine.ID, &machine.SupplierID, &machine.Name, &machine.MachineImage, &machine.Description, &machine.MachineLink, &machine.Created) -} - -func (store *MachineStoreImpl) GetMachines(id string) ([]types.Machine, error) { - var machines []types.Machine - - query := `SELECT * FROM "Machine" WHERE "supplier_id" = ?` - rows, err := store.database.Query(query, id) +func (store *MachineStoreImpl) GetMachines(id string) ([]db.Machine, error) { + ctx := context.Background() + machines, err := store.queries.GetMachines(ctx, id) if err != nil { - return nil, fmt.Errorf("error executing query: %w", err) - } - - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var machine types.Machine - - if err := ScanMachine(rows, &machine); err != nil { - return nil, fmt.Errorf("error scanning row: %w", err) - } - machines = append(machines, machine) + return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) } - if err = rows.Err(); err != nil { - return nil, fmt.Errorf("error after iterating over rows: %w", err) + var result []db.Machine + for _, machine := range machines { + result = append(result, db.Machine{ + ID: machine.ID, + SupplierID: machine.SupplierID, + Name: machine.Name, + MachineImage: machine.MachineImage, + Description: machine.Description, + MachineLink: machine.MachineLink, + Created: machine.Created, + }) } - return machines, nil + return result, nil } -func (store *MachineStoreImpl) GetMachineById(id string) (*types.Machine, error) { - query := `SELECT * FROM "Machine" WHERE id = ?` - row := store.database.QueryRow(query, id) - - var machine types.Machine - - if err := ScanMachine(row, &machine); err != nil { - - if errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error scanning row: %w", err) +func (store *MachineStoreImpl) GetMachineById(id string) (*db.Machine, error) { + ctx := context.Background() + machine, err := store.queries.GetMachineByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) } return &machine, nil From 384337465ba68e17adce616d1f12535db4e60182 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 31 Aug 2024 16:57:31 +0100 Subject: [PATCH 067/248] fix blog store with pointer to context - will be updated in caller --- server/stores/blogStore.go | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/server/stores/blogStore.go b/server/stores/blogStore.go index f063bd5..37f34af 100644 --- a/server/stores/blogStore.go +++ b/server/stores/blogStore.go @@ -10,11 +10,11 @@ import ( ) type BlogStore interface { - GetBlogs() ([]db.Blog, error) - GetBlogById(id string) (*db.Blog, error) - CreateBlog(blog *db.Blog) error - UpdateBlog(id string, blog *db.Blog) error - DeleteBlog(id string) error + GetBlogs(ctx context.Context) ([]db.Blog, error) + GetBlogById(ctx context.Context, id string) (*db.Blog, error) + CreateBlog(ctx context.Context, blog *db.Blog) error + UpdateBlog(ctx context.Context, id string, blog *db.Blog) error + DeleteBlog(ctx context.Context, id string) error } type BlogStoreImpl struct { @@ -28,14 +28,12 @@ func NewBlogStore(sql *sql.DB) *BlogStoreImpl { } } -func (store *BlogStoreImpl) GetBlogs() ([]db.Blog, error) { - ctx := context.Background() +func (store *BlogStoreImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { blogs, err := store.queries.GetBlogs(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) } - // Convert from the generated database to your database if needed var result []db.Blog for _, blog := range blogs { result = append(result, db.Blog{ @@ -52,8 +50,7 @@ func (store *BlogStoreImpl) GetBlogs() ([]db.Blog, error) { return result, nil } -func (store *BlogStoreImpl) GetBlogById(id string) (*db.Blog, error) { - ctx := context.Background() +func (store *BlogStoreImpl) GetBlogById(ctx context.Context, id string) (*db.Blog, error) { blog, err := store.queries.GetBlogByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) @@ -62,8 +59,7 @@ func (store *BlogStoreImpl) GetBlogById(id string) (*db.Blog, error) { return &blog, nil } -func (store *BlogStoreImpl) CreateBlog(blog *db.Blog) error { - ctx := context.Background() +func (store *BlogStoreImpl) CreateBlog(ctx context.Context, blog *db.Blog) error { blog.ID = uuid.NewString() blog.Created = sql.NullString{String: time.Now().String(), Valid: true} @@ -85,9 +81,7 @@ func (store *BlogStoreImpl) CreateBlog(blog *db.Blog) error { return nil } -func (store *BlogStoreImpl) UpdateBlog(id string, blog *db.Blog) error { - ctx := context.Background() - +func (store *BlogStoreImpl) UpdateBlog(ctx context.Context, id string, blog *db.Blog) error { if blog.MainImage.Valid { params := db.UpdateBlogParams{ Title: blog.Title, @@ -118,9 +112,7 @@ func (store *BlogStoreImpl) UpdateBlog(id string, blog *db.Blog) error { return nil } -func (store *BlogStoreImpl) DeleteBlog(id string) error { - ctx := context.Background() - +func (store *BlogStoreImpl) DeleteBlog(ctx context.Context, id string) error { err := store.queries.DeleteBlog(ctx, id) if err != nil { return fmt.Errorf("error occurred while deleting blog: %w", err) From e4adcf8c476f8559211eb81edc0ae37f9c4ab82c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 31 Aug 2024 16:57:57 +0100 Subject: [PATCH 068/248] fix context pointers --- server/stores/machineStore.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/stores/machineStore.go b/server/stores/machineStore.go index 7062819..2e9b3b8 100644 --- a/server/stores/machineStore.go +++ b/server/stores/machineStore.go @@ -12,11 +12,11 @@ import ( ) type MachineStore interface { - GetMachines(id string) ([]db.Machine, error) - GetMachineById(id string) (*db.Machine, error) - CreateMachine(machine *db.Machine) error - UpdateMachine(id string, machine *db.Machine) error - DeleteMachine(id string) error + GetMachines(ctx context.Context, id string) ([]db.Machine, error) + GetMachineById(ctx context.Context, id string) (*db.Machine, error) + CreateMachine(ctx context.Context, machine *db.Machine) error + UpdateMachine(ctx context.Context, id string, machine *db.Machine) error + DeleteMachine(ctx context.Context, id string) error } type MachineStoreImpl struct { @@ -62,6 +62,7 @@ func (store *MachineStoreImpl) GetMachineById(id string) (*db.Machine, error) { } func (store *MachineStoreImpl) CreateMachine(machine *types.Machine) error { + ctx := context.Background() machine.ID = uuid.NewString() machine.Created = time.Now().String() From ef431ea5da961d23563a8811c59e5c67041ba83e Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 31 Aug 2024 17:04:46 +0100 Subject: [PATCH 069/248] create machine --- server/stores/machineStore.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/server/stores/machineStore.go b/server/stores/machineStore.go index 2e9b3b8..9e21164 100644 --- a/server/stores/machineStore.go +++ b/server/stores/machineStore.go @@ -28,8 +28,7 @@ func NewMachineStore(sql *sql.DB) *MachineStoreImpl { return &MachineStoreImpl{queries: queries} } -func (store *MachineStoreImpl) GetMachines(id string) ([]db.Machine, error) { - ctx := context.Background() +func (store *MachineStoreImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { machines, err := store.queries.GetMachines(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) @@ -51,8 +50,7 @@ func (store *MachineStoreImpl) GetMachines(id string) ([]db.Machine, error) { return result, nil } -func (store *MachineStoreImpl) GetMachineById(id string) (*db.Machine, error) { - ctx := context.Background() +func (store *MachineStoreImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { machine, err := store.queries.GetMachineByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) @@ -61,18 +59,22 @@ func (store *MachineStoreImpl) GetMachineById(id string) (*db.Machine, error) { return &machine, nil } -func (store *MachineStoreImpl) CreateMachine(machine *types.Machine) error { - ctx := context.Background() +func (store *MachineStoreImpl) CreateMachine(ctx context.Context, machine *db.Machine) error { machine.ID = uuid.NewString() - machine.Created = time.Now().String() - - query := `INSERT INTO "Machine" (id, supplier_id, name, machine_image, description, machine_link, created) - VALUES (?, ?, ?, ?, ?, ?, ?)` - - _, err := store.database.Exec(query, machine.ID, machine.SupplierID, machine.Name, machine.MachineImage, machine.Description, machine.MachineLink, machine.Created) + machine.Created = sql.NullString{String: time.Now().String(), Valid: true} + + params := db.CreateMachineParams{ + ID: machine.ID, + SupplierID: machine.SupplierID, + Name: machine.Name, + MachineImage: machine.MachineImage, + Description: machine.Description, + MachineLink: machine.MachineLink, + Created: machine.Created, + } - if err != nil { - return fmt.Errorf("error creating machine: %w", err) + if err := store.queries.CreateMachine(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating a machine: %w", err) } return nil From 3ff52c8e536d6d35ec5f7e4d338382219e673523 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 31 Aug 2024 17:16:00 +0100 Subject: [PATCH 070/248] update machine --- server/stores/machineStore.go | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/server/stores/machineStore.go b/server/stores/machineStore.go index 9e21164..d3f3d22 100644 --- a/server/stores/machineStore.go +++ b/server/stores/machineStore.go @@ -8,7 +8,6 @@ import ( "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" ) type MachineStore interface { @@ -80,21 +79,31 @@ func (store *MachineStoreImpl) CreateMachine(ctx context.Context, machine *db.Ma return nil } -func (store *MachineStoreImpl) UpdateMachine(id string, machine *types.Machine) error { - query := `UPDATE "Machine" SET supplier_id = ?, name = ?, description = ?, machine_link = ? WHERE ID = ?` - args := []interface{}{machine.SupplierID, machine.Name, machine.Description, machine.MachineLink, id} - - if machine.MachineImage != "" && machine.MachineImage != "null" { - query = `UPDATE "Machine" SET supplier_id = ?, name = ?, machine_image = ?, description = ?, machine_link = ? WHERE ID = ?` - args = []interface{}{machine.SupplierID, machine.Name, machine.MachineImage, machine.Description, machine.MachineLink, id} - } - - _, err := store.database.Exec(query, args...) - - if err != nil { - return fmt.Errorf("error updating machine: %w", err) +func (store *MachineStoreImpl) UpdateMachine(ctx context.Context, id string, machine *db.Machine) error { + if machine.MachineImage.Valid { + params := db.UpdateMachineParams{ + SupplierID: machine.SupplierID, + Name: machine.Name, + MachineImage: machine.MachineImage, + Description: machine.Description, + MachineLink: machine.MachineLink, + ID: machine.ID, + } + if err := store.queries.UpdateMachine(ctx, params); err != nil { + return fmt.Errorf("error ocurred while updating a machine with image: %w", err) + } + } else { + params := db.UpdateMachineNoImageParams{ + SupplierID: machine.SupplierID, + Name: machine.Name, + Description: machine.Description, + MachineLink: machine.MachineLink, + ID: machine.ID, + } + if err := store.queries.UpdateMachineNoImage(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating the machine without image: %w", err) + } } - return nil } From c8af6f86531271bb608bda9fc62545ccf253b365 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sat, 31 Aug 2024 17:20:17 +0100 Subject: [PATCH 071/248] delet machine --- server/stores/machineStore.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/server/stores/machineStore.go b/server/stores/machineStore.go index d3f3d22..4c2c0cc 100644 --- a/server/stores/machineStore.go +++ b/server/stores/machineStore.go @@ -107,13 +107,9 @@ func (store *MachineStoreImpl) UpdateMachine(ctx context.Context, id string, mac return nil } -func (store *MachineStoreImpl) DeleteMachine(id string) error { - query := `DELETE FROM "Machine" WHERE id = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error deleting machine: %w", err) +func (store *MachineStoreImpl) DeleteMachine(ctx context.Context, id string) error { + if err := store.queries.DeleteMachine(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting machine: %w", err) } - return nil } From ccd9d9936dabc5f17f847c12567b226eeea7c442 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 11:41:37 +0100 Subject: [PATCH 072/248] fix machine store --- server/stores/machineStore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/stores/machineStore.go b/server/stores/machineStore.go index 4c2c0cc..06e307b 100644 --- a/server/stores/machineStore.go +++ b/server/stores/machineStore.go @@ -87,7 +87,7 @@ func (store *MachineStoreImpl) UpdateMachine(ctx context.Context, id string, mac MachineImage: machine.MachineImage, Description: machine.Description, MachineLink: machine.MachineLink, - ID: machine.ID, + ID: id, } if err := store.queries.UpdateMachine(ctx, params); err != nil { return fmt.Errorf("error ocurred while updating a machine with image: %w", err) @@ -98,7 +98,7 @@ func (store *MachineStoreImpl) UpdateMachine(ctx context.Context, id string, mac Name: machine.Name, Description: machine.Description, MachineLink: machine.MachineLink, - ID: machine.ID, + ID: id, } if err := store.queries.UpdateMachineNoImage(ctx, params); err != nil { return fmt.Errorf("error occurred while updating the machine without image: %w", err) From cdad5031d56252d8e161a68ba2524a082b93003d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 13:37:55 +0100 Subject: [PATCH 073/248] exhibitions --- server/stores/exhibitionStore.go | 58 ++++++++++++++------------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/server/stores/exhibitionStore.go b/server/stores/exhibitionStore.go index 6c6c4c3..191dc4c 100644 --- a/server/stores/exhibitionStore.go +++ b/server/stores/exhibitionStore.go @@ -1,59 +1,51 @@ package stores import ( + "context" "database/sql" "fmt" - "log" + "github.com/sean-david-welch/farmec-v2/server/db" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" ) type ExhibitionStore interface { - GetExhibitions() ([]types.Exhibition, error) - CreateExhibition(exhibition *types.Exhibition) error - UpdateExhibition(id string, exhibition *types.Exhibition) error - DeleteExhibition(id string) error + GetExhibitions(ctx context.Context) ([]db.Exhibition, error) + CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error + UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error + DeleteExhibition(ctx context.Context, id string) error } type ExhibitionStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewExhibitionStore(database *sql.DB) *ExhibitionStoreImpl { - return &ExhibitionStoreImpl{database: database} +func NewExhibitionStore(sql *sql.DB) *ExhibitionStoreImpl { + queries := db.New(sql) + return &ExhibitionStoreImpl{queries: queries} } -func (store *ExhibitionStoreImpl) GetExhibitions() ([]types.Exhibition, error) { - var exhibitions []types.Exhibition - - query := `SELECT * FROM "Exhibition" ORDER BY "created"` - rows, err := store.database.Query(query) +func (store *ExhibitionStoreImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { + exhibitions, err := store.queries.GetExhibitions(ctx) if err != nil { - return nil, fmt.Errorf("error occurred while querying database: %w", err) + return nil, fmt.Errorf("An error occurred while querying the database for machines: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var exhibition types.Exhibition - err := rows.Scan(&exhibition.ID, &exhibition.Title, &exhibition.Date, &exhibition.Location, &exhibition.Info, &exhibition.Created) - if err != nil { - return nil, fmt.Errorf("error occurred while scanning rows: %w", err) - } - - exhibitions = append(exhibitions, exhibition) + var result []db.Exhibition + for _, exhibition := range exhibitions { + result = append(result, db.Exhibition{ + ID: exhibition.ID, + Title: exhibition.Title, + Date: exhibition.Date, + Location: exhibition.Location, + Info: exhibition.Info, + Created: exhibition.Created, + }) } - - return exhibitions, nil } -func (store *ExhibitionStoreImpl) CreateExhibition(exhibition *types.Exhibition) error { +func (store *ExhibitionStoreImpl) CreateExhibition(exhibition *db.Exhibition) error { exhibition.ID = uuid.NewString() exhibition.Created = time.Now().String() @@ -66,7 +58,7 @@ func (store *ExhibitionStoreImpl) CreateExhibition(exhibition *types.Exhibition) return nil } -func (store *ExhibitionStoreImpl) UpdateExhibition(id string, exhibition *types.Exhibition) error { +func (store *ExhibitionStoreImpl) UpdateExhibition(id string, exhibition *db.Exhibition) error { query := `UPDATE "Exhibition" SET "title" = ?, "date" = ?, "location" = ?, "info" = ? WHERE "id" = ?` _, err := store.database.Exec(query, id, exhibition.Title, exhibition.Date, exhibition.Location, exhibition.Info) From 173a08160b593edc9e35095edb0da7b35eff05cc Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 13:46:59 +0100 Subject: [PATCH 074/248] create exhibition --- server/stores/exhibitionStore.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/server/stores/exhibitionStore.go b/server/stores/exhibitionStore.go index 191dc4c..b005bef 100644 --- a/server/stores/exhibitionStore.go +++ b/server/stores/exhibitionStore.go @@ -29,7 +29,7 @@ func NewExhibitionStore(sql *sql.DB) *ExhibitionStoreImpl { func (store *ExhibitionStoreImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { exhibitions, err := store.queries.GetExhibitions(ctx) if err != nil { - return nil, fmt.Errorf("An error occurred while querying the database for machines: %w", err) + return nil, fmt.Errorf("an error occurred while querying the database for exhibitions: %w", err) } var result []db.Exhibition @@ -43,16 +43,28 @@ func (store *ExhibitionStoreImpl) GetExhibitions(ctx context.Context) ([]db.Exhi Created: exhibition.Created, }) } + + return exhibitions, nil } -func (store *ExhibitionStoreImpl) CreateExhibition(exhibition *db.Exhibition) error { +func (store *ExhibitionStoreImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { exhibition.ID = uuid.NewString() - exhibition.Created = time.Now().String() + exhibition.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } - query := `INSERT INTO "Exhibition" (id, title, date, location, info, created) VALUES (?, ?, ?, ?, ?, ?)` - _, err := store.database.Exec(query, exhibition.ID, exhibition.Title, exhibition.Date, exhibition.Location, exhibition.Info, exhibition.Created) - if err != nil { - return fmt.Errorf("error creating exhibition: %w", err) + params := db.CreateExhibitionParams{ + ID: exhibition.ID, + Title: exhibition.Title, + Date: exhibition.Date, + Location: exhibition.Location, + Info: exhibition.Info, + Created: exhibition.Created, + } + + if err := store.queries.CreateExhibition(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating an exhibitions: %w", err) } return nil From aeb79d131ef51f81aa3182470f98c55566f10aa4 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 13:50:52 +0100 Subject: [PATCH 075/248] update/delete exhibition --- server/stores/exhibitionStore.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/server/stores/exhibitionStore.go b/server/stores/exhibitionStore.go index b005bef..f3bde1e 100644 --- a/server/stores/exhibitionStore.go +++ b/server/stores/exhibitionStore.go @@ -70,24 +70,24 @@ func (store *ExhibitionStoreImpl) CreateExhibition(ctx context.Context, exhibiti return nil } -func (store *ExhibitionStoreImpl) UpdateExhibition(id string, exhibition *db.Exhibition) error { - query := `UPDATE "Exhibition" SET "title" = ?, "date" = ?, "location" = ?, "info" = ? WHERE "id" = ?` - - _, err := store.database.Exec(query, id, exhibition.Title, exhibition.Date, exhibition.Location, exhibition.Info) - if err != nil { - return fmt.Errorf("error updating exhibition: %w", err) +func (store *ExhibitionStoreImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { + params := db.UpdateExhibitionParams{ + Title: exhibition.Title, + Date: exhibition.Date, + Location: exhibition.Location, + Info: exhibition.Info, + ID: id, } + if err := store.queries.UpdateExhibition(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating an exhiibtion: %w", err) + } return nil } -func (store *ExhibitionStoreImpl) DeleteExhibition(id string) error { - query := `DELETE FROM "Exhibition" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error deleting exhibiton: %w", err) +func (store *ExhibitionStoreImpl) DeleteExhibition(ctx context.Context, id string) error { + if err := store.queries.DeleteExhibition(ctx, id); err != nil { + return fmt.Errorf("error occurred while delting an exhibition: %w", err) } - return nil } From 3a85bd669beba17487d166c58d5462f73bbbd3e7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 13:54:19 +0100 Subject: [PATCH 076/248] employee types --- server/stores/employeeStore.go | 58 ++++++++++------------------------ 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/server/stores/employeeStore.go b/server/stores/employeeStore.go index a6372ad..767a6ca 100644 --- a/server/stores/employeeStore.go +++ b/server/stores/employeeStore.go @@ -1,68 +1,42 @@ package stores import ( + "context" "database/sql" "errors" "fmt" - "log" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type EmployeeStore interface { - GetEmployees() ([]types.Employee, error) - GetEmployeeById(id string) (*types.Employee, error) - CreateEmployee(employee *types.Employee) error - UpdateEmployee(id string, employee *types.Employee) error - DeleteEmployee(id string) error + GetEmployees(ctx context.Context) ([]db.Employee, error) + GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) + CreateEmployee(ctx context.Context, employee *db.Employee) error + UpdateEmployee(ctx context.Context, id string, employee *db.Employee) error + DeleteEmployee(ctx context.Context, id string) error } type EmployeeStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewEmployeeStore(database *sql.DB) *EmployeeStoreImpl { - return &EmployeeStoreImpl{database: database} +func NewEmployeeStore(sql *sql.DB) *EmployeeStoreImpl { + queries := db.New(sql) + return &EmployeeStoreImpl{queries: queries} } -func (store *EmployeeStoreImpl) GetEmployees() ([]types.Employee, error) { - var employees []types.Employee +func (store *EmployeeStoreImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { - query := `SELECT * FROM "Employee" ORDER BY "created"` - rows, err := store.database.Query(query) - if err != nil { - return nil, err - } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var employee types.Employee - - err := rows.Scan(&employee.ID, &employee.Name, &employee.Email, &employee.Role, &employee.ProfileImage, &employee.Created) - if err != nil { - return nil, fmt.Errorf("error occurred while scanning rows: %v", err) - } - employees = append(employees, employee) - } - - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over the rows: %w", err) - } - - return employees, nil } -func (store *EmployeeStoreImpl) GetEmployeeById(id string) (*types.Employee, error) { +func (store *EmployeeStoreImpl) GetEmployeeById(id string) (*db.Employee, error) { query := `SELECT * FROM "Employee" WHERE "id" = ?` row := store.database.QueryRow(query, id) - var employee types.Employee + var employee db.Employee err := row.Scan(&employee.ID, &employee.Name, &employee.Email, &employee.Role, &employee.ProfileImage, &employee.Created) if err != nil { @@ -76,7 +50,7 @@ func (store *EmployeeStoreImpl) GetEmployeeById(id string) (*types.Employee, err return &employee, nil } -func (store *EmployeeStoreImpl) CreateEmployee(employee *types.Employee) error { +func (store *EmployeeStoreImpl) CreateEmployee(employee *db.Employee) error { employee.ID = uuid.NewString() employee.Created = time.Now().String() @@ -91,7 +65,7 @@ func (store *EmployeeStoreImpl) CreateEmployee(employee *types.Employee) error { return nil } -func (store *EmployeeStoreImpl) UpdateEmployee(id string, employee *types.Employee) error { +func (store *EmployeeStoreImpl) UpdateEmployee(id string, employee *db.Employee) error { query := `UPDATE "Employee" SET name = ?, email = ?, role = ? WHERE id = ?` args := []interface{}{id, employee.Name, employee.Email, employee.Role} From bd042ada97926d4225ef9b466224906fd387a00d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 14:04:07 +0100 Subject: [PATCH 077/248] employee get --- server/stores/employeeStore.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/server/stores/employeeStore.go b/server/stores/employeeStore.go index 767a6ca..56c56d0 100644 --- a/server/stores/employeeStore.go +++ b/server/stores/employeeStore.go @@ -29,7 +29,24 @@ func NewEmployeeStore(sql *sql.DB) *EmployeeStoreImpl { } func (store *EmployeeStoreImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { + employees, err := store.queries.GetEmployees(ctx) + if err != nil { + return nil, fmt.Errorf("error occurred while querying employees: %w", err) + } + + var result []db.Employee + for _, employee := range employees { + result = append(result, db.Employee{ + ID: employee.ID, + Name: employee.Name, + Email: employee.Email, + Role: employee.Role, + ProfileImage: employee.ProfileImage, + Created: employee.Created, + }) + } + return result, nil } func (store *EmployeeStoreImpl) GetEmployeeById(id string) (*db.Employee, error) { From 8b898f8abd57034896b2e8b619cd7aacfbe4c1cc Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 14:32:29 +0100 Subject: [PATCH 078/248] employee store --- server/stores/employeeStore.go | 83 ++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/server/stores/employeeStore.go b/server/stores/employeeStore.go index 56c56d0..60725c7 100644 --- a/server/stores/employeeStore.go +++ b/server/stores/employeeStore.go @@ -3,7 +3,6 @@ package stores import ( "context" "database/sql" - "errors" "fmt" "time" @@ -49,62 +48,66 @@ func (store *EmployeeStoreImpl) GetEmployees(ctx context.Context) ([]db.Employee return result, nil } -func (store *EmployeeStoreImpl) GetEmployeeById(id string) (*db.Employee, error) { - query := `SELECT * FROM "Employee" WHERE "id" = ?` - row := store.database.QueryRow(query, id) - - var employee db.Employee - - err := row.Scan(&employee.ID, &employee.Name, &employee.Email, &employee.Role, &employee.ProfileImage, &employee.Created) +func (store *EmployeeStoreImpl) GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) { + employee, err := store.queries.GetEmployee(ctx, id) if err != nil { - if errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error scanning row: %w", err) + return nil, fmt.Errorf("error occurred while querying the database for employee: %w", err) } return &employee, nil } -func (store *EmployeeStoreImpl) CreateEmployee(employee *db.Employee) error { +func (store *EmployeeStoreImpl) CreateEmployee(ctx context.Context, employee *db.Employee) error { employee.ID = uuid.NewString() - employee.Created = time.Now().String() - - query := `INSERT INTO "Employee" (id, name, email, role, profile_image, created) - VALUES (?, ?, ?, ?, ?, ?)` + employee.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } + params := db.CreateEmployeeParams{ + ID: employee.ID, + Name: employee.Name, + Email: employee.Email, + Role: employee.Role, + ProfileImage: employee.ProfileImage, + Created: employee.Created, + } - _, err := store.database.Exec(query, employee.ID, employee.Name, employee.Email, employee.Role, employee.ProfileImage, employee.Created) - if err != nil { - return err + if err := store.queries.CreateEmployee(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating an employee: %w", err) } return nil } -func (store *EmployeeStoreImpl) UpdateEmployee(id string, employee *db.Employee) error { - query := `UPDATE "Employee" SET name = ?, email = ?, role = ? WHERE id = ?` - args := []interface{}{id, employee.Name, employee.Email, employee.Role} - - if employee.ProfileImage != "" && employee.ProfileImage != "null" { - query = `UPDATE "Employee" SET name = ?, email = ?, role = ?, profile_image = ? WHERE "id" = ?` - args = []interface{}{id, employee.Name, employee.Email, employee.Role, employee.ProfileImage} - } - - _, err := store.database.Exec(query, args...) - if err != nil { - return err +func (store *EmployeeStoreImpl) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) error { + if employee.ProfileImage.Valid { + params := db.UpdateEmployeeParams{ + Name: employee.Name, + Email: employee.Email, + Role: employee.Role, + ProfileImage: employee.ProfileImage, + ID: id, + } + if err := store.queries.UpdateEmployee(ctx, params); err != nil { + return fmt.Errorf("error occurred while updatig an employee: %w", err) + } + } else { + params := db.UpdateEmployeeNoImageParams{ + Name: employee.Name, + Email: employee.Email, + Role: employee.Role, + ID: id, + } + if err := store.queries.UpdateEmployeeNoImage(ctx, params); err != nil { + return fmt.Errorf("an error occurred while updating the employee: %w", err) + } } - return nil } -func (store *EmployeeStoreImpl) DeleteEmployee(id string) error { - query := `DELETE FROM "Employee" WHERE "id" = ?` - _, err := store.database.Exec(query, id) - if err != nil { - return err +func (store *EmployeeStoreImpl) DeleteEmployee(ctx context.Context, id string) error { + if err := store.queries.DeleteEmployee(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting employee: %w", err) } - return nil } From 63e2219144c7014e1a06295cfd5240e437995862 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 14:51:36 +0100 Subject: [PATCH 079/248] carousels start --- server/stores/carouselStore.go | 98 ++++++++++++++-------------------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/server/stores/carouselStore.go b/server/stores/carouselStore.go index 090c65d..b85a96c 100644 --- a/server/stores/carouselStore.go +++ b/server/stores/carouselStore.go @@ -1,96 +1,80 @@ package stores import ( + "context" "database/sql" - "errors" "fmt" - "log" + "github.com/sean-david-welch/farmec-v2/server/db" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" ) type CarouselStore interface { - GetCarousels() ([]types.Carousel, error) - GetCarouselById(id string) (*types.Carousel, error) - CreateCarousel(carousel *types.Carousel) error - UpdateCarousel(id string, carousel *types.Carousel) error - DeleteCarousel(id string) error + GetCarousels(ctx context.Context) ([]db.Carousel, error) + GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) + CreateCarousel(ctx context.Context, carousel *db.Carousel) error + UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) error + DeleteCarousel(ctx context.Context, id string) error } type CarouselStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewCarouselStore(database *sql.DB) *CarouselStoreImpl { - return &CarouselStoreImpl{database: database} +func NewCarouselStore(sql *sql.DB) *CarouselStoreImpl { + queries := db.New(sql) + return &CarouselStoreImpl{queries: queries} } -func (store *CarouselStoreImpl) GetCarousels() ([]types.Carousel, error) { - var carousels []types.Carousel - - query := `SELECT * FROM "Carousel"` - rows, err := store.database.Query(query) +func (store *CarouselStoreImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { + carousels, err := store.queries.GetCarousels(ctx) if err != nil { - return nil, fmt.Errorf("error executing query: %w", err) - } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var carousel types.Carousel - - if err := rows.Scan(&carousel.ID, &carousel.Name, &carousel.Image, &carousel.Created); err != nil { - return nil, fmt.Errorf("error occurred while scanning rows: %w", err) - } - carousels = append(carousels, carousel) + return nil, fmt.Errorf("error occurred while querying the database for carousels: %w", err) } - if err = rows.Err(); err != nil { - return nil, fmt.Errorf("error after iterating over rows: %w", err) + var result []db.Carousel + for _, carousel := range carousels { + result = append(result, db.Carousel{ + ID: carousel.ID, + Name: carousel.Name, + Image: carousel.Image, + Created: carousel.Created, + }) } - - return carousels, nil + return result, nil } -func (store *CarouselStoreImpl) GetCarouselById(id string) (*types.Carousel, error) { - query := `SELECT * FROM "Carousel" WHERE id = ?` - row := store.database.QueryRow(query, id) - - var carousel types.Carousel - - if err := row.Scan(&carousel.ID, &carousel.Name, &carousel.Image, &carousel.Created); err != nil { - if errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error scanning row: %w", err) +func (store *CarouselStoreImpl) GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) { + carousel, err := store.queries.GetCarouselByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("error occurred while querying the database for carousel: %w", err) } return &carousel, nil } -func (store *CarouselStoreImpl) CreateCarousel(carousel *types.Carousel) error { +func (store *CarouselStoreImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) error { carousel.ID = uuid.NewString() - carousel.Created = time.Now().String() - - query := `INSERT INTO "Carousel" - (id, name, image, created) - VALUES (?, ?, ?, ?)` + carousel.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } - _, err := store.database.Exec(query, carousel.ID, carousel.Name, carousel.Image, carousel.Created) - if err != nil { - return fmt.Errorf("error creating carousel: %w", err) + params := db.CreateCarouselParams{ + ID: carousel.ID, + Name: carousel.Name, + Image: carousel.Image, + Created: carousel.Created, } + if err := store.queries.CreateCarousel(ctx, params); err != nil { + return fmt.Errorf("error occurred while create a carousel: %w", err) + } return nil } -func (store *CarouselStoreImpl) UpdateCarousel(id string, carousel *types.Carousel) error { +func (store *CarouselStoreImpl) UpdateCarousel(id string, carousel *db.Carousel) error { query := `UPDATE "Carousel" SET name = ? WHERE id = ?` args := []interface{}{carousel.Name, id} From 82670540ef526462253e193a53040760003b0054 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 14:56:52 +0100 Subject: [PATCH 080/248] carousel sql again --- server/sql/queries/carousel.sql | 3 +++ server/stores/carouselStore.go | 21 ++++++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/server/sql/queries/carousel.sql b/server/sql/queries/carousel.sql index 8d0cf75..f2fd22a 100644 --- a/server/sql/queries/carousel.sql +++ b/server/sql/queries/carousel.sql @@ -10,5 +10,8 @@ insert into Carousel (id, name, image, created) VALUES (?, ?, ?, ?); -- name: UpdateCarousel :exec update Carousel set name = ?, image = ? where id = ?; +-- name: UpdateCarouselNoImage :exec +update Carousel set name = ? where id = ?; + -- name: DeleteCarousel :exec delete from Carousel where id = ?; \ No newline at end of file diff --git a/server/stores/carouselStore.go b/server/stores/carouselStore.go index b85a96c..cbd001f 100644 --- a/server/stores/carouselStore.go +++ b/server/stores/carouselStore.go @@ -74,21 +74,16 @@ func (store *CarouselStoreImpl) CreateCarousel(ctx context.Context, carousel *db return nil } -func (store *CarouselStoreImpl) UpdateCarousel(id string, carousel *db.Carousel) error { - query := `UPDATE "Carousel" SET name = ? WHERE id = ?` - args := []interface{}{carousel.Name, id} - - if carousel.Image != "" && carousel.Image != "null" { - query = `UPDATE "Carousel" SET name = ?, image = ? WHERE id = ?` - args = []interface{}{carousel.Name, carousel.Image, id} +func (store *CarouselStoreImpl) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) error { + if carousel.Image.Valid { + params := db.UpdateCarouselParams{ + Name: carousel.Name, + Image: carousel.Image, + ID: id, + } + } else { } - _, err := store.database.Exec(query, args...) - if err != nil { - return fmt.Errorf("error updating carousel: %w", err) - } - - return nil } func (store *CarouselStoreImpl) DeleteCarousel(id string) error { From 94cdbe474974ec2e2ff8de9ecd89c616411994a9 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 14:57:22 +0100 Subject: [PATCH 081/248] carousel gen sql --- server/db/carousel.sql.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/db/carousel.sql.go b/server/db/carousel.sql.go index d5504ad..ed1091f 100644 --- a/server/db/carousel.sql.go +++ b/server/db/carousel.sql.go @@ -102,3 +102,17 @@ func (q *Queries) UpdateCarousel(ctx context.Context, arg UpdateCarouselParams) _, err := q.db.ExecContext(ctx, updateCarousel, arg.Name, arg.Image, arg.ID) return err } + +const updateCarouselNoImage = `-- name: UpdateCarouselNoImage :exec +update Carousel set name = ? where id = ? +` + +type UpdateCarouselNoImageParams struct { + Name string `json:"name"` + ID string `json:"id"` +} + +func (q *Queries) UpdateCarouselNoImage(ctx context.Context, arg UpdateCarouselNoImageParams) error { + _, err := q.db.ExecContext(ctx, updateCarouselNoImage, arg.Name, arg.ID) + return err +} From 963fce389277114d4795a75085e5a909ebdbc7ec Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 14:59:51 +0100 Subject: [PATCH 082/248] update carousel --- server/stores/carouselStore.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/stores/carouselStore.go b/server/stores/carouselStore.go index cbd001f..d6916de 100644 --- a/server/stores/carouselStore.go +++ b/server/stores/carouselStore.go @@ -81,9 +81,19 @@ func (store *CarouselStoreImpl) UpdateCarousel(ctx context.Context, id string, c Image: carousel.Image, ID: id, } + if err := store.queries.UpdateCarousel(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a carousel: %w", err) + } } else { + params := db.UpdateCarouselNoImageParams{ + Name: carousel.Name, + ID: id, + } + if err := store.queries.UpdateCarouselNoImage(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a carousel: %w", err) + } } - + return nil } func (store *CarouselStoreImpl) DeleteCarousel(id string) error { From d5b2c6a26f67f0bd87d1db31d0e2c3bb4bcb667b Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 15:03:00 +0100 Subject: [PATCH 083/248] update carousel again --- server/stores/carouselStore.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/server/stores/carouselStore.go b/server/stores/carouselStore.go index d6916de..c813489 100644 --- a/server/stores/carouselStore.go +++ b/server/stores/carouselStore.go @@ -96,13 +96,9 @@ func (store *CarouselStoreImpl) UpdateCarousel(ctx context.Context, id string, c return nil } -func (store *CarouselStoreImpl) DeleteCarousel(id string) error { - query := `DELETE FROM "Carousel" WHERE id = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error deleting supplier: %w", err) +func (store *CarouselStoreImpl) DeleteCarousel(ctx context.Context, id string) error { + if err := store.queries.DeleteCarousel(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting a carousel: %w", err) } - return nil } From 13158990f857470f0a1ab686336b1fa71d223ad9 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 16:45:25 +0100 Subject: [PATCH 084/248] some video store --- server/stores/videoStore.go | 91 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/server/stores/videoStore.go b/server/stores/videoStore.go index 683446e..5ac886f 100644 --- a/server/stores/videoStore.go +++ b/server/stores/videoStore.go @@ -1,78 +1,75 @@ package stores import ( + "context" "database/sql" "fmt" - "log" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type VideoStore interface { - GetVideos(id string) ([]types.Video, error) - CreateVideo(video *types.Video) error - UpdateVideo(id string, video *types.Video) error - DeleteVideo(id string) error + GetVideos(ctx context.Context, id string) ([]db.Video, error) + CreateVideo(ctx context.Context, video *db.Video) error + UpdateVideo(ctx context.Context, id string, video *db.Video) error + DeleteVideo(ctx context.Context, id string) error } type VideoStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewVideoStore(database *sql.DB) *VideoStoreImpl { - return &VideoStoreImpl{database: database} +func NewVideoStore(sql *sql.DB) *VideoStoreImpl { + queries := db.New(sql) + return &VideoStoreImpl{queries: queries} } -func (store *VideoStoreImpl) GetVideos(id string) ([]types.Video, error) { - var videos []types.Video - - query := `SELECT * FROM "Video" WHERE "supplier_id" = ?` - rows, err := store.database.Query(query, id) +func (store *VideoStoreImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { + videos, err := store.queries.SelectVideos(ctx, id) if err != nil { - return nil, fmt.Errorf("error executing query: %w", err) + return nil, fmt.Errorf("error occurred while getting videos from the database: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var video types.Video - - err := rows.Scan(&video.ID, &video.SupplierID, &video.WebURL, &video.Title, &video.Description, &video.VideoID, &video.ThumbnailURL, &video.Created) - if err != nil { - return nil, fmt.Errorf("error scanning row: %w", err) - } - - videos = append(videos, video) + var result []db.Video + for _, video := range videos { + result = append(result, db.Video{ + ID: video.ID, + SupplierID: video.SupplierID, + WebUrl: video.WebUrl, + Title: video.Title, + Description: video.Description, + VideoID: video.VideoID, + ThumbnailUrl: video.ThumbnailUrl, + Created: video.Created, + }) } - - if err = rows.Err(); err != nil { - return nil, fmt.Errorf("error after iterating over rows: %w", err) - } - - return videos, nil + return result, nil } -func (store *VideoStoreImpl) CreateVideo(video *types.Video) error { - +func (store *VideoStoreImpl) CreateVideo(ctx context.Context, video *db.Video) error { video.ID = uuid.NewString() - video.Created = time.Now().String() - - query := `INSERT INTO "Video" ("id", "supplier_id", "web_url", "title", "description", "video_id", "thumbnail_url", "created") VALUES (?, ?, ?, ?, ?, ?, ?, ?)` - _, err := store.database.Exec(query, video.ID, video.SupplierID, video.WebURL, video.Title, video.Description, video.VideoID, video.ThumbnailURL, video.Created) - - if err != nil { - return fmt.Errorf("error creating video: %w", err) + video.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } + params := db.CreateVideoParams{ + ID: video.ID, + SupplierID: video.SupplierID, + WebUrl: video.WebUrl, + Title: video.Title, + Description: video.Description, + VideoID: video.VideoID, + ThumbnailUrl: video.ThumbnailUrl, + Created: video.Created, + } + if err := store.queries.CreateVideo(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating a video in the db: %w", err) } - return nil } -func (store *VideoStoreImpl) UpdateVideo(id string, video *types.Video) error { +func (store *VideoStoreImpl) UpdateVideo(id string, video *db.Video) error { query := `UPDATE "Video" SET "supplier_id" = ?, "web_url" = ?, "title" = ?, "description" = ?, "video_id" = ?, "thumbnail_url" = ? WHERE "id" = ?` _, err := store.database.Exec(query, video.SupplierID, video.WebURL, video.Title, video.Description, video.VideoID, video.ThumbnailURL, id) From 15487740fb471a8917d85873f2416e532b559a26 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 16:51:14 +0100 Subject: [PATCH 085/248] some video store more --- server/stores/videoStore.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/server/stores/videoStore.go b/server/stores/videoStore.go index 5ac886f..d8da917 100644 --- a/server/stores/videoStore.go +++ b/server/stores/videoStore.go @@ -69,25 +69,25 @@ func (store *VideoStoreImpl) CreateVideo(ctx context.Context, video *db.Video) e return nil } -func (store *VideoStoreImpl) UpdateVideo(id string, video *db.Video) error { - query := `UPDATE "Video" SET "supplier_id" = ?, "web_url" = ?, "title" = ?, "description" = ?, "video_id" = ?, "thumbnail_url" = ? WHERE "id" = ?` - - _, err := store.database.Exec(query, video.SupplierID, video.WebURL, video.Title, video.Description, video.VideoID, video.ThumbnailURL, id) - - if err != nil { - return fmt.Errorf("error updating video: %w", err) +func (store *VideoStoreImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { + params := db.UpdateVideoParams{ + SupplierID: video.SupplierID, + WebUrl: video.ThumbnailUrl, + Title: video.ThumbnailUrl, + Description: video.ThumbnailUrl, + VideoID: video.ThumbnailUrl, + ThumbnailUrl: video.ThumbnailUrl, + ID: id, + } + if err := store.queries.UpdateVideo(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a video: %w", err) } - return nil } -func (store *VideoStoreImpl) DeleteVideo(id string) error { - query := `DELETE FROM "Video" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error deleting video: %w", err) +func (store *VideoStoreImpl) DeleteVideo(ctx context.Context, id string) error { + if err := store.queries.DeleteMachine(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting video: %w", err) } - return nil } From 94ba58f0cee5e6d9631f61c24a8c8b991fb5fc3d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 16:53:28 +0100 Subject: [PATCH 086/248] timeline store types --- server/stores/timelineStore.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/server/stores/timelineStore.go b/server/stores/timelineStore.go index 3cedd28..282b1b5 100644 --- a/server/stores/timelineStore.go +++ b/server/stores/timelineStore.go @@ -1,20 +1,21 @@ package stores import ( + "context" "database/sql" "fmt" "log" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type TimelineStore interface { - GetTimelines() ([]types.Timeline, error) - CreateTimeline(timeline *types.Timeline) error - UpdateTimeline(id string, timeline *types.Timeline) error - DeleteTimeline(id string) error + GetTimelines(ctx context.Context) ([]db.Timeline, error) + CreateTimeline(ctx context.Context, timeline *db.Timeline) error + UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error + DeleteTimeline(ctx context.Context, id string) error } type TimelineStoreImpl struct { @@ -25,8 +26,8 @@ func NewTimelineStore(database *sql.DB) *TimelineStoreImpl { return &TimelineStoreImpl{database: database} } -func (store *TimelineStoreImpl) GetTimelines() ([]types.Timeline, error) { - var timelines []types.Timeline +func (store *TimelineStoreImpl) GetTimelines() ([]db.Timeline, error) { + var timelines []db.Timeline query := `SELECT * FROM "Timeline"` rows, err := store.database.Query(query) @@ -40,7 +41,7 @@ func (store *TimelineStoreImpl) GetTimelines() ([]types.Timeline, error) { }() for rows.Next() { - var timeline types.Timeline + var timeline db.Timeline if err := rows.Scan(&timeline.ID, &timeline.Title, &timeline.Date, &timeline.Body, &timeline.Created); err != nil { return nil, fmt.Errorf("error occurred while scanning rows: %w", err) @@ -55,7 +56,7 @@ func (store *TimelineStoreImpl) GetTimelines() ([]types.Timeline, error) { return timelines, nil } -func (store *TimelineStoreImpl) CreateTimeline(timeline *types.Timeline) error { +func (store *TimelineStoreImpl) CreateTimeline(timeline *db.Timeline) error { timeline.ID = uuid.NewString() timeline.Created = time.Now().String() @@ -69,7 +70,7 @@ func (store *TimelineStoreImpl) CreateTimeline(timeline *types.Timeline) error { return nil } -func (store *TimelineStoreImpl) UpdateTimeline(id string, timeline *types.Timeline) error { +func (store *TimelineStoreImpl) UpdateTimeline(id string, timeline *db.Timeline) error { query := `UPDATE "Timeline" SET title = ?, date = ?, body = ? WHERE "id" = ?` _, err := store.database.Exec(query, timeline.Title, timeline.Date, timeline.Body, id) From 67d2257a1fab42d6de1dc3892c6b165f9be488c7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 16:59:09 +0100 Subject: [PATCH 087/248] timeline create --- server/stores/timelineStore.go | 66 ++++++++++++++++------------------ 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/server/stores/timelineStore.go b/server/stores/timelineStore.go index 282b1b5..e896aa7 100644 --- a/server/stores/timelineStore.go +++ b/server/stores/timelineStore.go @@ -4,7 +4,6 @@ import ( "context" "database/sql" "fmt" - "log" "time" "github.com/google/uuid" @@ -19,54 +18,51 @@ type TimelineStore interface { } type TimelineStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewTimelineStore(database *sql.DB) *TimelineStoreImpl { - return &TimelineStoreImpl{database: database} +func NewTimelineStore(sql *sql.DB) *TimelineStoreImpl { + queries := db.New(sql) + return &TimelineStoreImpl{queries: queries} } -func (store *TimelineStoreImpl) GetTimelines() ([]db.Timeline, error) { - var timelines []db.Timeline - - query := `SELECT * FROM "Timeline"` - rows, err := store.database.Query(query) +func (store *TimelineStoreImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { + timelines, err := store.queries.GetTimelines(ctx) if err != nil { - return nil, err - } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var timeline db.Timeline - - if err := rows.Scan(&timeline.ID, &timeline.Title, &timeline.Date, &timeline.Body, &timeline.Created); err != nil { - return nil, fmt.Errorf("error occurred while scanning rows: %w", err) - } - timelines = append(timelines, timeline) + return nil, fmt.Errorf("error occurred while getting timelines from the db: %w", err) } - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over rows: %w", err) + var result []db.Timeline + for _, timeline := range timelines { + result = append(result, db.Timeline{ + ID: timeline.ID, + Title: timeline.Title, + Date: timeline.Date, + Body: timeline.Body, + Created: timeline.Created, + }) } - - return timelines, nil + return result, nil } -func (store *TimelineStoreImpl) CreateTimeline(timeline *db.Timeline) error { +func (store *TimelineStoreImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { timeline.ID = uuid.NewString() - timeline.Created = time.Now().String() - - query := `INSERT INTO "Timeline" (id, title, date, body, created) VALUES (?, ?, ?, ?, ?)` + timeline.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } - _, err := store.database.Exec(query, timeline.ID, timeline.Title, timeline.Date, timeline.Body, timeline.Created) - if err != nil { - return fmt.Errorf("error occurred while creating timeline: %w", err) + params := db.CreateTimelineParams{ + ID: timeline.ID, + Title: timeline.Title, + Date: timeline.Date, + Body: timeline.Body, + Created: timeline.Created, } + if err := store.queries.CreateTimeline(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating a timeline: %w", err) + } return nil } From 72d9e706b76a7b26ad61bd46104fa8a95ced13b1 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:06:59 +0100 Subject: [PATCH 088/248] timeline stroe --- server/stores/timelineStore.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/server/stores/timelineStore.go b/server/stores/timelineStore.go index e896aa7..6cf485a 100644 --- a/server/stores/timelineStore.go +++ b/server/stores/timelineStore.go @@ -66,24 +66,22 @@ func (store *TimelineStoreImpl) CreateTimeline(ctx context.Context, timeline *db return nil } -func (store *TimelineStoreImpl) UpdateTimeline(id string, timeline *db.Timeline) error { - query := `UPDATE "Timeline" SET title = ?, date = ?, body = ? WHERE "id" = ?` - - _, err := store.database.Exec(query, timeline.Title, timeline.Date, timeline.Body, id) - if err != nil { - return fmt.Errorf("error occurred while updating timeline: %w", err) +func (store *TimelineStoreImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { + params := db.UpdateTimelineParams{ + Title: timeline.Title, + Date: timeline.Date, + Body: timeline.Body, + ID: id, + } + if err := store.queries.UpdateTimeline(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a timeline: %w", err) } - return nil } -func (store *TimelineStoreImpl) DeleteTimeline(id string) error { - query := `DELETE FROM "Timeline" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error occurred while deleting timeline: %w", err) +func (store *TimelineStoreImpl) DeleteTimeline(ctx context.Context, id string) error { + if err := store.queries.DeleteTimeline(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting the timeline: %w", err) } - return nil } From 334fb1920c70a1345cc858a1898ba0e4fbf961bb Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:30:44 +0100 Subject: [PATCH 089/248] some terms --- server/stores/termsStore.go | 67 +++++++++++++++---------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/server/stores/termsStore.go b/server/stores/termsStore.go index 3bcc82f..5e2fec6 100644 --- a/server/stores/termsStore.go +++ b/server/stores/termsStore.go @@ -1,66 +1,53 @@ package stores import ( + "context" "database/sql" "fmt" - "log" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type TermsStore interface { - GetTerms() ([]types.Terms, error) - CreateTerm(term *types.Terms) error - UpdateTerm(id string, term *types.Terms) error - DeleteTerm(id string) error + GetTerms(ctx context.Context) ([]db.Term, error) + CreateTerm(ctx context.Context, term *db.Term) error + UpdateTerm(ctx context.Context, id string, term *db.Term) error + DeleteTerm(ctx context.Context, id string) error } type TermsStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewTermsStore(database *sql.DB) *TermsStoreImpl { - return &TermsStoreImpl{database: database} +func NewTermsStore(sql *sql.DB) *TermsStoreImpl { + queries := db.New(sql) + return &TermsStoreImpl{queries: queries} } -func (store *TermsStoreImpl) GetTerms() ([]types.Terms, error) { - var terms []types.Terms - - query := `SELECT * FROM "Terms"` - rows, err := store.database.Query(query) +func (store *TermsStoreImpl) GetTerms(ctx context.Context) ([]db.Term, error) { + terms, err := store.queries.GetTerms(ctx) if err != nil { - return nil, err + return nil, fmt.Errorf("error occurred while querying the database for terms: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var term types.Terms - - if err := rows.Scan(&term.ID, &term.Title, &term.Body, &term.Created); err != nil { - return nil, fmt.Errorf("error occurred while scanning row: %w", err) - } - - terms = append(terms, term) - - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over rows: %w", err) - } + var result []db.Term + for _, term := range terms { + result = append(result, db.Term{ + ID: term.ID, + Title: term.Title, + Body: term.Body, + Created: term.Created, + }) } - - return terms, err + return result, nil } -func (store *TermsStoreImpl) CreateTerm(term *types.Terms) error { +func (store *TermsStoreImpl) CreateTerm(term *db.Term) error { term.ID = uuid.NewString() term.Created = time.Now().String() - query := `INSERT INTO "Terms" (id, title, body, created) VALUES (?, ?, ?, ?)` + query := `INSERT INTO "Term" (id, title, body, created) VALUES (?, ?, ?, ?)` _, err := store.database.Exec(query, term.ID, term.Title, term.Body, term.Created) if err != nil { @@ -70,8 +57,8 @@ func (store *TermsStoreImpl) CreateTerm(term *types.Terms) error { return nil } -func (store *TermsStoreImpl) UpdateTerm(id string, term *types.Terms) error { - query := `UPDATE "Terms" SET title = ?, body = ? where id = ?` +func (store *TermsStoreImpl) UpdateTerm(id string, term *db.Term) error { + query := `UPDATE "Term" SET title = ?, body = ? where id = ?` _, err := store.database.Exec(query, term.Title, term.Body, id) if err != nil { @@ -82,7 +69,7 @@ func (store *TermsStoreImpl) UpdateTerm(id string, term *types.Terms) error { } func (store *TermsStoreImpl) DeleteTerm(id string) error { - query := `DELETE FROM "Terms" WHERE "id" = ?` + query := `DELETE FROM "Term" WHERE "id" = ?` _, err := store.database.Exec(query, id) if err != nil { From b73df8b054deec69a17d5311fc7f9a51718f4fa3 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:35:31 +0100 Subject: [PATCH 090/248] create term --- server/stores/termsStore.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/stores/termsStore.go b/server/stores/termsStore.go index 5e2fec6..52024ce 100644 --- a/server/stores/termsStore.go +++ b/server/stores/termsStore.go @@ -43,17 +43,21 @@ func (store *TermsStoreImpl) GetTerms(ctx context.Context) ([]db.Term, error) { return result, nil } -func (store *TermsStoreImpl) CreateTerm(term *db.Term) error { +func (store *TermsStoreImpl) CreateTerm(ctx context.Context, term *db.Term) error { term.ID = uuid.NewString() - term.Created = time.Now().String() - - query := `INSERT INTO "Term" (id, title, body, created) VALUES (?, ?, ?, ?)` - - _, err := store.database.Exec(query, term.ID, term.Title, term.Body, term.Created) - if err != nil { - return fmt.Errorf("error occurred while creating term term: %w", err) + term.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } + params := db.CreateTermParams{ + ID: term.ID, + Title: term.Title, + Body: term.Body, + Created: term.Created, + } + if err := store.queries.CreateTerm(ctx, params); err != nil { + return fmt.Errorf("error occured while creating a term: %w", err) } - return nil } From 6e941970b8e287629546c523b2ac98b1496493f4 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:36:41 +0100 Subject: [PATCH 091/248] fix term sql --- server/sql/queries/terms.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/sql/queries/terms.sql b/server/sql/queries/terms.sql index 818b05f..d159092 100644 --- a/server/sql/queries/terms.sql +++ b/server/sql/queries/terms.sql @@ -13,8 +13,7 @@ values (?, ?, ?, ?); -- name: UpdateTerm :exec update Terms -set id = ?, - title = ?, +set title = ?, body = ?, created = ? where id = ?; From b444df357f185ec64dfe28e11e811ec81d6bebd5 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:36:56 +0100 Subject: [PATCH 092/248] fix term sql gen --- server/db/terms.sql.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/server/db/terms.sql.go b/server/db/terms.sql.go index 8d176f2..f7c485a 100644 --- a/server/db/terms.sql.go +++ b/server/db/terms.sql.go @@ -96,28 +96,25 @@ func (q *Queries) GetTerms(ctx context.Context) ([]Term, error) { const updateTerm = `-- name: UpdateTerm :exec update Terms -set id = ?, - title = ?, +set title = ?, body = ?, created = ? where id = ? ` type UpdateTermParams struct { - ID string `json:"id"` Title string `json:"title"` Body sql.NullString `json:"body"` Created sql.NullString `json:"created"` - ID_2 string `json:"id_2"` + ID string `json:"id"` } func (q *Queries) UpdateTerm(ctx context.Context, arg UpdateTermParams) error { _, err := q.db.ExecContext(ctx, updateTerm, - arg.ID, arg.Title, arg.Body, arg.Created, - arg.ID_2, + arg.ID, ) return err } From c4c773bbecaec9c1e2a9bf5fce5f7c7723eafca6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:42:49 +0100 Subject: [PATCH 093/248] terms store --- server/stores/termsStore.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/server/stores/termsStore.go b/server/stores/termsStore.go index 52024ce..b2e30ce 100644 --- a/server/stores/termsStore.go +++ b/server/stores/termsStore.go @@ -61,24 +61,22 @@ func (store *TermsStoreImpl) CreateTerm(ctx context.Context, term *db.Term) erro return nil } -func (store *TermsStoreImpl) UpdateTerm(id string, term *db.Term) error { - query := `UPDATE "Term" SET title = ?, body = ? where id = ?` - - _, err := store.database.Exec(query, term.Title, term.Body, id) - if err != nil { - return fmt.Errorf("error occurred while updating term term: %w", err) +func (store *TermsStoreImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { + params := db.UpdateTermParams{ + Title: term.Title, + Body: term.Body, + Created: term.Created, + ID: id, + } + if err := store.queries.UpdateTerm(ctx, params); err != nil { + return fmt.Errorf("error ocurred while updating a machine with image: %w", err) } - return nil } -func (store *TermsStoreImpl) DeleteTerm(id string) error { - query := `DELETE FROM "Term" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error occurred while deleting term term: %w", err) +func (store *TermsStoreImpl) DeleteTerm(ctx context.Context, id string) error { + if err := store.queries.DeleteTerm(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting term: %w", err) } - return nil } From ebbe66d43af3d18d7686b8a751673101ac7624be Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:48:05 +0100 Subject: [PATCH 094/248] suppliers store init --- server/stores/supplierStore.go | 96 +++++++++++++--------------------- 1 file changed, 35 insertions(+), 61 deletions(-) diff --git a/server/stores/supplierStore.go b/server/stores/supplierStore.go index b867c73..edeb39d 100644 --- a/server/stores/supplierStore.go +++ b/server/stores/supplierStore.go @@ -1,86 +1,60 @@ package stores import ( + "context" "database/sql" "errors" "fmt" - "log" + "github.com/sean-david-welch/farmec-v2/server/db" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" ) type SupplierStore interface { - GetSuppliers() ([]types.Supplier, error) - CreateSupplier(supplier *types.Supplier) error - GetSupplierById(id string) (*types.Supplier, error) - UpdateSupplier(id string, supplier *types.Supplier) error - DeleteSupplier(id string) error + GetSuppliers(ctx context.Context) ([]db.Supplier, error) + CreateSupplier(ctx context.Context, supplier *db.Supplier) error + GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) + UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) error + DeleteSupplier(ctx context.Context, id string) error } type SupplierStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewSupplierStore(database *sql.DB) *SupplierStoreImpl { - return &SupplierStoreImpl{database: database} +func NewSupplierStore(sql *sql.DB) *SupplierStoreImpl { + queries := db.New(sql) + return &SupplierStoreImpl{queries: queries} } -func scanSupplier(row interface{}, supplier *types.Supplier) error { - var scanner interface { - Scan(dest ...interface{}) error - } - - switch value := row.(type) { - case *sql.Row: - scanner = value - case *sql.Rows: - scanner = value - default: - return fmt.Errorf("unsupported type: %T", value) - } - - return scanner.Scan( - &supplier.ID, &supplier.Name, &supplier.LogoImage, - &supplier.MarketingImage, &supplier.Description, - &supplier.SocialFacebook, &supplier.SocialInstagram, &supplier.SocialLinkedin, - &supplier.SocialTwitter, &supplier.SocialYoutube, &supplier.SocialWebsite, &supplier.Created, - ) -} - -func (store *SupplierStoreImpl) GetSuppliers() ([]types.Supplier, error) { - var suppliers []types.Supplier - - query := `SELECT * FROM "Supplier" ORDER BY created DESC` - rows, err := store.database.Query(query) - +func (store *SupplierStoreImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { + suppliers, err := store.queries.GetSuppliers(ctx) if err != nil { - return nil, fmt.Errorf("error executing query: %w", err) + return nil, fmt.Errorf("error occurred while getting suppliers from the db: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - for rows.Next() { - var supplier types.Supplier - - if err := scanSupplier(rows, &supplier); err != nil { - return nil, fmt.Errorf("error scanning row: %w", err) - } - suppliers = append(suppliers, supplier) + var result []db.Supplier + for _, supplier := range suppliers { + result = append(result, db.Supplier{ + ID: supplier.ID, + Name: supplier.Name, + LogoImage: supplier.LogoImage, + MarketingImage: supplier.MarketingImage, + Description: supplier.Description, + SocialFacebook: supplier.SocialFacebook, + SocialTwitter: supplier.SocialTwitter, + SocialInstagram: supplier.SocialInstagram, + SocialYoutube: supplier.SocialYoutube, + SocialLinkedin: supplier.SocialLinkedin, + SocialWebsite: supplier.SocialWebsite, + Created: supplier.Created, + }) } - - if err = rows.Err(); err != nil { - return nil, fmt.Errorf("error after iterating over rows: %w", err) - } - - return suppliers, nil + return result, nil } -func (store *SupplierStoreImpl) CreateSupplier(supplier *types.Supplier) error { +func (store *SupplierStoreImpl) CreateSupplier(supplier *db.Supplier) error { supplier.ID = uuid.NewString() supplier.Created = time.Now().String() @@ -98,11 +72,11 @@ func (store *SupplierStoreImpl) CreateSupplier(supplier *types.Supplier) error { return nil } -func (store *SupplierStoreImpl) GetSupplierById(id string) (*types.Supplier, error) { +func (store *SupplierStoreImpl) GetSupplierById(id string) (*db.Supplier, error) { query := `SELECT * FROM "Supplier" WHERE id = ?` row := store.database.QueryRow(query, id) - var supplier types.Supplier + var supplier db.Supplier if err := scanSupplier(row, &supplier); err != nil { @@ -116,7 +90,7 @@ func (store *SupplierStoreImpl) GetSupplierById(id string) (*types.Supplier, err return &supplier, nil } -func (store *SupplierStoreImpl) UpdateSupplier(id string, supplier *types.Supplier) error { +func (store *SupplierStoreImpl) UpdateSupplier(id string, supplier *db.Supplier) error { query := `UPDATE "Supplier" SET name = ?, description = ?, From e674c32509a181459a98d6945e3e67ff23c7f18a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 17:54:13 +0100 Subject: [PATCH 095/248] create supplier --- server/stores/supplierStore.go | 45 ++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/server/stores/supplierStore.go b/server/stores/supplierStore.go index edeb39d..a4c3738 100644 --- a/server/stores/supplierStore.go +++ b/server/stores/supplierStore.go @@ -54,24 +54,6 @@ func (store *SupplierStoreImpl) GetSuppliers(ctx context.Context) ([]db.Supplier return result, nil } -func (store *SupplierStoreImpl) CreateSupplier(supplier *db.Supplier) error { - - supplier.ID = uuid.NewString() - supplier.Created = time.Now().String() - - query := `INSERT INTO "Supplier" - (id, name, logo_image, marketing_image, description, social_facebook, social_instagram, social_linkedin, social_twitter, social_youtube, social_website, created) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` - - _, err := store.database.Exec(query, supplier.ID, supplier.Name, supplier.LogoImage, supplier.MarketingImage, supplier.Description, supplier.SocialFacebook, supplier.SocialInstagram, supplier.SocialLinkedin, supplier.SocialTwitter, supplier.SocialYoutube, supplier.SocialWebsite, supplier.Created) - - if err != nil { - return fmt.Errorf("error creating supplier: %w", err) - } - - return nil -} - func (store *SupplierStoreImpl) GetSupplierById(id string) (*db.Supplier, error) { query := `SELECT * FROM "Supplier" WHERE id = ?` row := store.database.QueryRow(query, id) @@ -90,6 +72,33 @@ func (store *SupplierStoreImpl) GetSupplierById(id string) (*db.Supplier, error) return &supplier, nil } +func (store *SupplierStoreImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) error { + supplier.ID = uuid.NewString() + supplier.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } + + params := db.CreateSupplierParams{ + ID: supplier.ID, + Name: supplier.Name, + LogoImage: supplier.LogoImage, + MarketingImage: supplier.MarketingImage, + Description: supplier.Description, + SocialFacebook: supplier.SocialFacebook, + SocialTwitter: supplier.SocialTwitter, + SocialInstagram: supplier.SocialInstagram, + SocialYoutube: supplier.SocialYoutube, + SocialLinkedin: supplier.SocialLinkedin, + SocialWebsite: supplier.SocialWebsite, + Created: supplier.Created, + } + if err := store.queries.CreateSupplier(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating supplier: %w", err) + } + return nil +} + func (store *SupplierStoreImpl) UpdateSupplier(id string, supplier *db.Supplier) error { query := `UPDATE "Supplier" SET name = ?, From 529b7bc31abf69a6c433b4c72ad614dea31a6974 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 18:12:40 +0100 Subject: [PATCH 096/248] dunnoy why --- server/stores/supplierStore.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/server/stores/supplierStore.go b/server/stores/supplierStore.go index a4c3738..4032fe0 100644 --- a/server/stores/supplierStore.go +++ b/server/stores/supplierStore.go @@ -3,7 +3,6 @@ package stores import ( "context" "database/sql" - "errors" "fmt" "github.com/sean-david-welch/farmec-v2/server/db" "time" @@ -54,21 +53,25 @@ func (store *SupplierStoreImpl) GetSuppliers(ctx context.Context) ([]db.Supplier return result, nil } -func (store *SupplierStoreImpl) GetSupplierById(id string) (*db.Supplier, error) { - query := `SELECT * FROM "Supplier" WHERE id = ?` - row := store.database.QueryRow(query, id) - - var supplier db.Supplier - - if err := scanSupplier(row, &supplier); err != nil { - - if errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error scanning row: %w", err) +func (store *SupplierStoreImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { + supplierRow, err := store.queries.GetSupplierByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("error occurred while getting suppliers from the db: %w", err) + } + supplier := db.Supplier{ + ID: supplierRow.ID, + Name: supplierRow.Name, + LogoImage: supplierRow.LogoImage, + MarketingImage: supplierRow.MarketingImage, + Description: supplierRow.Description, + SocialFacebook: supplierRow.SocialFacebook, + SocialTwitter: supplierRow.SocialTwitter, + SocialInstagram: supplierRow.SocialInstagram, + SocialYoutube: supplierRow.SocialYoutube, + SocialLinkedin: supplierRow.SocialLinkedin, + SocialWebsite: supplierRow.SocialWebsite, + Created: supplierRow.Created, } - return &supplier, nil } From 6c0a2a690af4e01232ce7635695d5aac4d907a42 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 18:25:43 +0100 Subject: [PATCH 097/248] supplier store --- server/stores/supplierStore.go | 78 ++++++++++++++++------------------ 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/server/stores/supplierStore.go b/server/stores/supplierStore.go index 4032fe0..85b6507 100644 --- a/server/stores/supplierStore.go +++ b/server/stores/supplierStore.go @@ -102,52 +102,46 @@ func (store *SupplierStoreImpl) CreateSupplier(ctx context.Context, supplier *db return nil } -func (store *SupplierStoreImpl) UpdateSupplier(id string, supplier *db.Supplier) error { - query := `UPDATE "Supplier" SET - name = ?, - description = ?, - social_facebook = ?, - social_instagram = ?, - social_linkedin = ?, - social_twitter = ?, - social_youtube = ?, - social_website = ? - WHERE id = ?` - args := []interface{}{supplier.Name, supplier.Description, supplier.SocialFacebook, supplier.SocialInstagram, supplier.SocialLinkedin, supplier.SocialTwitter, supplier.SocialYoutube, supplier.SocialWebsite, id} - - if supplier.LogoImage != "" && supplier.LogoImage != "null" && supplier.MarketingImage != "" && supplier.MarketingImage != "null" { - query = `UPDATE "Supplier" SET - name = ?, - logo_image = ?, - marketing_image = ?, - description = ?, - social_facebook = ?, - social_instagram = ?, - social_linkedin = ?, - social_twitter = ?, - social_youtube = ?, - social_website = ? - WHERE id = ?` - args = []interface{}{supplier.Name, supplier.LogoImage, supplier.MarketingImage, supplier.Description, supplier.SocialFacebook, supplier.SocialInstagram, supplier.SocialLinkedin, supplier.SocialTwitter, supplier.SocialYoutube, supplier.SocialWebsite, id} - } - - _, err := store.database.Exec(query, args...) - - if err != nil { - return fmt.Errorf("error updating supplier: %w", err) +func (store *SupplierStoreImpl) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) error { + if supplier.LogoImage.Valid && supplier.MarketingImage.Valid { + params := db.UpdateSupplierParams{ + Name: supplier.Name, + LogoImage: supplier.LogoImage, + MarketingImage: supplier.MarketingImage, + Description: supplier.Description, + SocialFacebook: supplier.SocialFacebook, + SocialTwitter: supplier.SocialTwitter, + SocialInstagram: supplier.SocialInstagram, + SocialYoutube: supplier.SocialYoutube, + SocialLinkedin: supplier.SocialLinkedin, + SocialWebsite: supplier.SocialWebsite, + ID: id, + } + if err := store.queries.UpdateSupplier(ctx, params); err != nil { + return fmt.Errorf("error while updating the supplier: %w", err) + } + } else { + params := db.UpdateSupplierNoImageParams{ + Name: supplier.Name, + Description: supplier.Description, + SocialFacebook: supplier.SocialFacebook, + SocialTwitter: supplier.SocialTwitter, + SocialInstagram: supplier.SocialInstagram, + SocialYoutube: supplier.SocialYoutube, + SocialLinkedin: supplier.SocialLinkedin, + SocialWebsite: supplier.SocialWebsite, + ID: id, + } + if err := store.queries.UpdateSupplierNoImage(ctx, params); err != nil { + return fmt.Errorf("error while updating the supplier: %w", err) + } } - return nil } -func (store *SupplierStoreImpl) DeleteSupplier(id string) error { - query := `DELETE FROM "Supplier" WHERE id = ?` - - _, err := store.database.Exec(query, id) - - if err != nil { - return fmt.Errorf("error deleting supplier: %w", err) +func (store *SupplierStoreImpl) DeleteSupplier(ctx context.Context, id string) error { + if err := store.queries.DeleteSupplier(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting supplier: %w", err) } - return nil } From fdfd19ef4a3210fcac63b7419f72bd144585af87 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 20:58:35 +0100 Subject: [PATCH 098/248] updarte warranty sql --- server/sql/queries/warranty.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/sql/queries/warranty.sql b/server/sql/queries/warranty.sql index d960a7a..eb36ff0 100644 --- a/server/sql/queries/warranty.sql +++ b/server/sql/queries/warranty.sql @@ -3,7 +3,7 @@ select id, dealer, owner_name from WarrantyClaim order by created desc; --- name: GetWarrantyByID :one +-- name: GetWarrantyByID :many select wc.id, wc.dealer, wc.dealer_contact, From 1afe9ef6125df4fef2a4469e0cd15ae527fda13b Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 20:58:39 +0100 Subject: [PATCH 099/248] updarte warranty sql gen code --- server/db/warranty.sql.go | 68 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/server/db/warranty.sql.go b/server/db/warranty.sql.go index 8da62fa..9dba75b 100644 --- a/server/db/warranty.sql.go +++ b/server/db/warranty.sql.go @@ -135,7 +135,7 @@ func (q *Queries) GetWarranties(ctx context.Context) ([]GetWarrantiesRow, error) return items, nil } -const getWarrantyByID = `-- name: GetWarrantyByID :one +const getWarrantyByID = `-- name: GetWarrantyByID :many select wc.id, wc.dealer, wc.dealer_contact, @@ -183,31 +183,47 @@ type GetWarrantyByIDRow struct { Description sql.NullString `json:"description"` } -func (q *Queries) GetWarrantyByID(ctx context.Context, id string) (GetWarrantyByIDRow, error) { - row := q.db.QueryRowContext(ctx, getWarrantyByID, id) - var i GetWarrantyByIDRow - err := row.Scan( - &i.ID, - &i.Dealer, - &i.DealerContact, - &i.OwnerName, - &i.MachineModel, - &i.SerialNumber, - &i.InstallDate, - &i.FailureDate, - &i.RepairDate, - &i.FailureDetails, - &i.RepairDetails, - &i.LabourHours, - &i.CompletedBy, - &i.Created, - &i.PartID, - &i.PartNumber, - &i.QuantityNeeded, - &i.InvoiceNumber, - &i.Description, - ) - return i, err +func (q *Queries) GetWarrantyByID(ctx context.Context, id string) ([]GetWarrantyByIDRow, error) { + rows, err := q.db.QueryContext(ctx, getWarrantyByID, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetWarrantyByIDRow + for rows.Next() { + var i GetWarrantyByIDRow + if err := rows.Scan( + &i.ID, + &i.Dealer, + &i.DealerContact, + &i.OwnerName, + &i.MachineModel, + &i.SerialNumber, + &i.InstallDate, + &i.FailureDate, + &i.RepairDate, + &i.FailureDetails, + &i.RepairDetails, + &i.LabourHours, + &i.CompletedBy, + &i.Created, + &i.PartID, + &i.PartNumber, + &i.QuantityNeeded, + &i.InvoiceNumber, + &i.Description, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil } const updateWarranty = `-- name: UpdateWarranty :exec From 52ed9b28efc0034720bd95f0618d0053ff09f0d7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:01:44 +0100 Subject: [PATCH 100/248] get warranties --- server/stores/warrantyStore.go | 134 ++++++++++++++++----------------- 1 file changed, 63 insertions(+), 71 deletions(-) diff --git a/server/stores/warrantyStore.go b/server/stores/warrantyStore.go index 6823038..a36a078 100644 --- a/server/stores/warrantyStore.go +++ b/server/stores/warrantyStore.go @@ -1,106 +1,98 @@ package stores import ( + "context" "database/sql" "fmt" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type WarrantyStore interface { - GetWarranties() ([]types.DealerOwnerInfo, error) - GetWarrantyById(id string) (*types.WarrantyClaim, []types.PartsRequired, error) - CreateWarranty(warranty *types.WarrantyClaim, parts []types.PartsRequired) error - UpdateWarranty(id string, warranty *types.WarrantyClaim, parts []types.PartsRequired) error - DeleteWarranty(id string) error + GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) + GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) + CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error + UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error + DeleteWarranty(ctx context.Context, id string) error } type WarrantyStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewWarrantyStore(database *sql.DB) *WarrantyStoreImpl { - return &WarrantyStoreImpl{database: database} +func NewWarrantyStore(sql *sql.DB) *WarrantyStoreImpl { + queries := db.New(sql) + return &WarrantyStoreImpl{queries: queries} } -func (store *WarrantyStoreImpl) GetWarranties() ([]types.DealerOwnerInfo, error) { - var warranties []types.DealerOwnerInfo - - query := `SELECT "id", "dealer", "owner_name" FROM "WarrantyClaim" ORDER BY "created" DESC` - rows, err := store.database.Query(query) +func (store *WarrantyStoreImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { + warranties, err := store.queries.GetWarranties(ctx) if err != nil { - return nil, fmt.Errorf("error occurred while querying database: %w", err) + return nil, fmt.Errorf("an error occurred while getting warranties: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var warranty types.DealerOwnerInfo - if err := rows.Scan(&warranty.ID, &warranty.Dealer, &warranty.OwnerName); err != nil { - return nil, fmt.Errorf("error occurred while interating over rows: %w", err) - } - - warranties = append(warranties, warranty) - } - - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after interating over rows: %w", err) + var result []types.DealerOwnerInfo + for _, warranty := range warranties { + result = append(result, types.DealerOwnerInfo{ + ID: warranty.ID, + Dealer: warranty.Dealer, + OwnerName: warranty.OwnerName, + }) } - - return warranties, nil + return result, nil } -func (store *WarrantyStoreImpl) GetWarrantyById(id string) (*types.WarrantyClaim, []types.PartsRequired, error) { - var warranty types.WarrantyClaim - var parts []types.PartsRequired - - warrantyQuery := `SELECT * FROM "WarrantyClaim" WHERE "id" = ?` - - row := store.database.QueryRow(warrantyQuery, id) - - if err := row.Scan(&warranty.ID, &warranty.Dealer, &warranty.DealerContact, &warranty.OwnerName, - &warranty.MachineModel, &warranty.SerialNumber, &warranty.InstallDate, &warranty.FailureDate, &warranty.RepairDate, - &warranty.FailureDetails, &warranty.RepairDetails, &warranty.LabourHours, &warranty.CompletedBy, &warranty.Created, - ); err != nil { - return nil, nil, fmt.Errorf("error while querying database: %w", err) - } - - partsQuery := `SELECT * FROM "PartsRequired" WHERE "warranty_id" = ?` - rows, err := store.database.Query(partsQuery, id) +func (store *WarrantyStoreImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { + rows, err := store.queries.GetWarrantyByID(ctx, id) if err != nil { - return nil, nil, fmt.Errorf("error querying parts required from database: %w", err) - } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) + return nil, nil, fmt.Errorf("error occurred while getting warranty from the db: %w", err) + } + + var warranty *db.WarrantyClaim + var parts []db.PartsRequired + + for _, row := range rows { + if warranty == nil { + warranty = &db.WarrantyClaim{ + ID: row.ID, + Dealer: row.Dealer, + DealerContact: row.DealerContact, + OwnerName: row.OwnerName, + MachineModel: row.MachineModel, + SerialNumber: row.SerialNumber, + InstallDate: row.InstallDate, + FailureDate: row.FailureDate, + RepairDate: row.RepairDate, + FailureDetails: row.FailureDetails, + RepairDetails: row.RepairDetails, + LabourHours: row.LabourHours, + CompletedBy: row.CompletedBy, + Created: row.Created, + } } - }() - - for rows.Next() { - var part types.PartsRequired - - if err := rows.Scan(&part.ID, &part.WarrantyID, &part.PartNumber, &part.QuantityNeeded, &part.InvoiceNumber, &part.Description); err != nil { - return nil, nil, fmt.Errorf("error while iterating over rows") + if row.PartID.Valid { + parts = append(parts, db.PartsRequired{ + ID: row.PartID.String, + WarrantyID: row.ID, + PartNumber: row.PartNumber, + QuantityNeeded: row.QuantityNeeded.String, + InvoiceNumber: row.InvoiceNumber, + Description: row.Description, + }) } - - parts = append(parts, part) } - if err := rows.Err(); err != nil { - return nil, nil, fmt.Errorf("error iterating over parts required rows: %w", err) + if warranty == nil { + return nil, nil, fmt.Errorf("warranty with id %s not found", id) } - - return &warranty, parts, nil + return warranty, parts, nil } -func (store *WarrantyStoreImpl) CreateWarranty(warranty *types.WarrantyClaim, parts []types.PartsRequired) error { +func (store *WarrantyStoreImpl) CreateWarranty(warranty *db.WarrantyClaim, parts []db.PartsRequired) error { warranty.ID = uuid.NewString() warranty.Created = time.Now().String() @@ -150,7 +142,7 @@ func (store *WarrantyStoreImpl) CreateWarranty(warranty *types.WarrantyClaim, pa return nil } -func (store *WarrantyStoreImpl) UpdateWarranty(id string, warranty *types.WarrantyClaim, parts []types.PartsRequired) error { +func (store *WarrantyStoreImpl) UpdateWarranty(id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { transaction, err := store.database.Begin() if err != nil { return err From ac77976849b598c105272a0f14956d1e3a6d6780 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:04:43 +0100 Subject: [PATCH 101/248] warranty delete query --- server/sql/queries/warranty.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/sql/queries/warranty.sql b/server/sql/queries/warranty.sql index eb36ff0..d2b7b80 100644 --- a/server/sql/queries/warranty.sql +++ b/server/sql/queries/warranty.sql @@ -60,5 +60,7 @@ from PartsRequired where warranty_id = ?; -- name: DeleteWarranty :exec -delete from PartsRequired where warranty_id = ?; delete from WarrantyClaim where id = ?; + +-- name: DeletePartsRequired :exec +delete from PartsRequired where warranty_id = ?; From d68eb0b5cd3f1f56f42051a4135bf5e57535f840 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:04:56 +0100 Subject: [PATCH 102/248] warranty gen code --- server/db/warranty.sql.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/db/warranty.sql.go b/server/db/warranty.sql.go index 9dba75b..ec2244c 100644 --- a/server/db/warranty.sql.go +++ b/server/db/warranty.sql.go @@ -91,12 +91,21 @@ func (q *Queries) DeletePartRequired(ctx context.Context, warrantyID string) err return err } -const deleteWarranty = `-- name: DeleteWarranty :exec +const deletePartsRequired = `-- name: DeletePartsRequired :exec delete from PartsRequired where warranty_id = ? ` -func (q *Queries) DeleteWarranty(ctx context.Context, warrantyID string) error { - _, err := q.db.ExecContext(ctx, deleteWarranty, warrantyID) +func (q *Queries) DeletePartsRequired(ctx context.Context, warrantyID string) error { + _, err := q.db.ExecContext(ctx, deletePartsRequired, warrantyID) + return err +} + +const deleteWarranty = `-- name: DeleteWarranty :exec +delete from WarrantyClaim where id = ? +` + +func (q *Queries) DeleteWarranty(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteWarranty, id) return err } From d38035d1ad503104342a966081a8cde1cdebf64f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:11:05 +0100 Subject: [PATCH 103/248] create warranty --- server/stores/warrantyStore.go | 74 ++++++++++++++++------------------ 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/server/stores/warrantyStore.go b/server/stores/warrantyStore.go index a36a078..5dcda37 100644 --- a/server/stores/warrantyStore.go +++ b/server/stores/warrantyStore.go @@ -92,53 +92,47 @@ func (store *WarrantyStoreImpl) GetWarrantyById(ctx context.Context, id string) return warranty, parts, nil } -func (store *WarrantyStoreImpl) CreateWarranty(warranty *db.WarrantyClaim, parts []db.PartsRequired) error { +func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { warranty.ID = uuid.NewString() - warranty.Created = time.Now().String() - - transaction, err := store.database.Begin() - if err != nil { - return err - } - - warrantyQuery := `INSERT INTO "WarrantyClaim" - (id, dealer, dealer_contact, owner_name, machine_model, serial_number, install_date, failure_date, repair_date, failure_details, repair_details, labour_hours, completed_by, created) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` - - _, err = transaction.Exec( - warrantyQuery, warranty.ID, warranty.Dealer, warranty.DealerContact, warranty.OwnerName, - warranty.MachineModel, warranty.SerialNumber, warranty.InstallDate, warranty.FailureDate, warranty.RepairDate, - warranty.FailureDetails, warranty.RepairDetails, warranty.LabourHours, warranty.CompletedBy, warranty.Created, - ) - if err != nil { - err := transaction.Rollback() - if err != nil { - return err - } - return err + warranty.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, + } + + params := db.CreateWarrantyParams{ + ID: warranty.ID, + Dealer: warranty.Dealer, + DealerContact: warranty.DealerContact, + OwnerName: warranty.OwnerName, + MachineModel: warranty.MachineModel, + SerialNumber: warranty.SerialNumber, + InstallDate: warranty.InstallDate, + FailureDate: warranty.FailureDate, + RepairDate: warranty.RepairDate, + FailureDetails: warranty.FailureDetails, + RepairDetails: warranty.RepairDetails, + LabourHours: warranty.LabourHours, + CompletedBy: warranty.CompletedBy, + Created: warranty.Created, + } + if err := store.queries.CreateWarranty(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating warranty: %w", err) } - partsQuery := `INSERT INTO "PartsRequired" - (id, "warranty_id", part_number, quantity_needed, invoice_number, description) VALUES (?, ?, ?, ?, ?, ?)` - for _, part := range parts { part.ID = uuid.NewString() - - _, err := transaction.Exec(partsQuery, part.ID, warranty.ID, part.PartNumber, part.QuantityNeeded, part.InvoiceNumber, part.Description) - if err != nil { - err := transaction.Rollback() - if err != nil { - return err - } - return err + params := db.CreatePartsRequiredParams{ + ID: part.ID, + WarrantyID: part.WarrantyID, + PartNumber: part.PartNumber, + QuantityNeeded: part.QuantityNeeded, + InvoiceNumber: part.InvoiceNumber, + Description: part.Description, + } + if err := store.queries.CreatePartsRequired(ctx, params); err != nil { + return fmt.Errorf("an error occurred while creating the part: %w", err) } - - } - - if err := transaction.Commit(); err != nil { - return err } - return nil } From f5cd70c74ddea7064cf51357385e68a8a2db188f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:17:32 +0100 Subject: [PATCH 104/248] tranaction for warrranty creation --- server/stores/warrantyStore.go | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/server/stores/warrantyStore.go b/server/stores/warrantyStore.go index 5dcda37..bf8f53c 100644 --- a/server/stores/warrantyStore.go +++ b/server/stores/warrantyStore.go @@ -22,11 +22,12 @@ type WarrantyStore interface { type WarrantyStoreImpl struct { queries *db.Queries + db *sql.DB } -func NewWarrantyStore(sql *sql.DB) *WarrantyStoreImpl { - queries := db.New(sql) - return &WarrantyStoreImpl{queries: queries} +func NewWarrantyStore(sqlDB *sql.DB) *WarrantyStoreImpl { + queries := db.New(sqlDB) + return &WarrantyStoreImpl{queries: queries, db: sqlDB} } func (store *WarrantyStoreImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { @@ -93,6 +94,19 @@ func (store *WarrantyStoreImpl) GetWarrantyById(ctx context.Context, id string) } func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { + tx, err := store.db.BeginTx(ctx, nil) + if err != nil { + return fmt.Errorf("failed to begin transaction: %w", err) + } + defer func(tx *sql.Tx) { + err := tx.Rollback() + if err != nil { + return + } + }(tx) + + qtx := store.queries.WithTx(tx) + warranty.ID = uuid.NewString() warranty.Created = sql.NullString{ String: time.Now().String(), @@ -115,7 +129,7 @@ func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db CompletedBy: warranty.CompletedBy, Created: warranty.Created, } - if err := store.queries.CreateWarranty(ctx, params); err != nil { + if err := qtx.CreateWarranty(ctx, params); err != nil { return fmt.Errorf("error occurred while creating warranty: %w", err) } @@ -123,19 +137,23 @@ func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db part.ID = uuid.NewString() params := db.CreatePartsRequiredParams{ ID: part.ID, - WarrantyID: part.WarrantyID, + WarrantyID: warranty.ID, PartNumber: part.PartNumber, QuantityNeeded: part.QuantityNeeded, InvoiceNumber: part.InvoiceNumber, Description: part.Description, } - if err := store.queries.CreatePartsRequired(ctx, params); err != nil { + if err := qtx.CreatePartsRequired(ctx, params); err != nil { return fmt.Errorf("an error occurred while creating the part: %w", err) } } + + if err := tx.Commit(); err != nil { + return fmt.Errorf("failed to commit transaction: %w", err) + } + return nil } - func (store *WarrantyStoreImpl) UpdateWarranty(id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { transaction, err := store.database.Begin() if err != nil { From bc5f2b8d2bd5e465a7dbb6d7642371ce6b3a5b30 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:34:51 +0100 Subject: [PATCH 105/248] warranty sql --- server/sql/queries/warranty.sql | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/sql/queries/warranty.sql b/server/sql/queries/warranty.sql index d2b7b80..e8b5f1b 100644 --- a/server/sql/queries/warranty.sql +++ b/server/sql/queries/warranty.sql @@ -54,11 +54,6 @@ set dealer = ?, completed_by = ? where id = ?; --- name: DeletePartRequired :exec -delete -from PartsRequired -where warranty_id = ?; - -- name: DeleteWarranty :exec delete from WarrantyClaim where id = ?; From 28ac3083b89311c0d1954c1fab28bf43577263f6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:35:04 +0100 Subject: [PATCH 106/248] sql gen code warranty --- server/db/warranty.sql.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/server/db/warranty.sql.go b/server/db/warranty.sql.go index ec2244c..13f5ed3 100644 --- a/server/db/warranty.sql.go +++ b/server/db/warranty.sql.go @@ -80,17 +80,6 @@ func (q *Queries) CreateWarranty(ctx context.Context, arg CreateWarrantyParams) return err } -const deletePartRequired = `-- name: DeletePartRequired :exec -delete -from PartsRequired -where warranty_id = ? -` - -func (q *Queries) DeletePartRequired(ctx context.Context, warrantyID string) error { - _, err := q.db.ExecContext(ctx, deletePartRequired, warrantyID) - return err -} - const deletePartsRequired = `-- name: DeletePartsRequired :exec delete from PartsRequired where warranty_id = ? ` From 22622f244319b303a01ad8f074b1afcac85ff804 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:37:44 +0100 Subject: [PATCH 107/248] update warranty transaction --- server/stores/warrantyStore.go | 82 +++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/server/stores/warrantyStore.go b/server/stores/warrantyStore.go index bf8f53c..7f8a8e6 100644 --- a/server/stores/warrantyStore.go +++ b/server/stores/warrantyStore.go @@ -154,64 +154,64 @@ func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db return nil } -func (store *WarrantyStoreImpl) UpdateWarranty(id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { - transaction, err := store.database.Begin() +func (store *WarrantyStoreImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { + tx, err := store.db.BeginTx(ctx, nil) if err != nil { - return err + return fmt.Errorf("failed to begin transaction: %w", err) } - - warrantyQuery := `UPDATE "WarrantyClaim" SET - dealer = ?, dealer_contact = ?, owner_name = ?, machine_model = ?, serial_number = ?, - install_date = ?, failure_date = ?, repair_date = ?, failure_details = ?, repair_details = ?, - labour_hours = ?, completed_by = ?, created = ? WHERE id = ?` - - _, err = transaction.Exec( - warrantyQuery, id, warranty.Dealer, warranty.DealerContact, warranty.OwnerName, - warranty.MachineModel, warranty.SerialNumber, warranty.InstallDate, warranty.FailureDate, warranty.RepairDate, - warranty.FailureDetails, warranty.RepairDetails, warranty.LabourHours, warranty.CompletedBy, warranty.Created, - ) - if err != nil { - err := transaction.Rollback() + defer func(tx *sql.Tx) { + err := tx.Rollback() if err != nil { - return err + return } - return err - } + }(tx) + qtx := store.queries.WithTx(tx) - deleteQuery := `DELETE FROM "PartsRequired" WHERE warranty_id = ?` - _, err = transaction.Exec(deleteQuery, id) - if err != nil { - err := transaction.Rollback() - if err != nil { - return err - } - return err + params := db.UpdateWarrantyParams{ + Dealer: warranty.Dealer, + DealerContact: warranty.DealerContact, + OwnerName: warranty.OwnerName, + MachineModel: warranty.MachineModel, + SerialNumber: warranty.SerialNumber, + InstallDate: warranty.InstallDate, + FailureDate: warranty.FailureDate, + RepairDate: warranty.RepairDate, + FailureDetails: warranty.FailureDetails, + RepairDetails: warranty.RepairDetails, + LabourHours: warranty.LabourHours, + CompletedBy: warranty.CompletedBy, + ID: id, + } + if err := qtx.UpdateWarranty(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating warranty: %w", err) + } + if err = qtx.DeletePartsRequired(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting parts required: %w", err) } - - partsQuery := `INSERT INTO "PartsRequired" - (id, warranty_id, part_number, quantity_needed, invoice_number, description) VALUES (?, ?, ?, ?, ?, ?)` for _, part := range parts { part.ID = uuid.NewString() - - _, err := transaction.Exec(partsQuery, part.ID, warranty.ID, part.PartNumber, part.QuantityNeeded, part.InvoiceNumber, part.Description) - if err != nil { - err := transaction.Rollback() - if err != nil { - return err - } - return err + params := db.CreatePartsRequiredParams{ + ID: part.ID, + WarrantyID: warranty.ID, + PartNumber: part.PartNumber, + QuantityNeeded: part.QuantityNeeded, + InvoiceNumber: part.InvoiceNumber, + Description: part.Description, + } + if err := qtx.CreatePartsRequired(ctx, params); err != nil { + return fmt.Errorf("an error occurred while creating the part: %w", err) } } - if err := transaction.Commit(); err != nil { - return err + if err := tx.Commit(); err != nil { + return fmt.Errorf("failed to commit transaction: %w", err) } return nil } -func (store *WarrantyStoreImpl) DeleteWarranty(id string) error { +func (store *WarrantyStoreImpl) DeleteWarranty(ctx context.Context, id string) error { transaction, err := store.database.Begin() if err != nil { return err From f71e3086cf3013664af220e4ad2d0ab8bfe60c30 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 1 Sep 2024 21:40:39 +0100 Subject: [PATCH 108/248] delete warranty --- server/stores/warrantyStore.go | 39 ++++++++++++---------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/server/stores/warrantyStore.go b/server/stores/warrantyStore.go index 7f8a8e6..d4c9989 100644 --- a/server/stores/warrantyStore.go +++ b/server/stores/warrantyStore.go @@ -5,7 +5,6 @@ import ( "database/sql" "fmt" "github.com/sean-david-welch/farmec-v2/server/types" - "log" "time" "github.com/google/uuid" @@ -212,36 +211,26 @@ func (store *WarrantyStoreImpl) UpdateWarranty(ctx context.Context, id string, w } func (store *WarrantyStoreImpl) DeleteWarranty(ctx context.Context, id string) error { - transaction, err := store.database.Begin() + tx, err := store.db.BeginTx(ctx, nil) if err != nil { - return err + return fmt.Errorf("failed to begin transaction: %w", err) } - - deleteParts := `DELETE FROM "PartsRequired" WHERE "warranty_id" = ?` - _, err = transaction.Exec(deleteParts, id) - if err != nil { - err := transaction.Rollback() + defer func(tx *sql.Tx) { + err := tx.Rollback() if err != nil { - return err + return } - log.Printf("error occurred while deleting parts from warranty: %v", err) - return err - } + }(tx) + qtx := store.queries.WithTx(tx) - deleteWarranty := `DELETE FROM "WarrantyClaim" WHERE "id" = ?` - _, err = transaction.Exec(deleteWarranty, id) - if err != nil { - err := transaction.Rollback() - if err != nil { - return err - } - log.Printf("error occurred while deleting warranty claim: %v", err) - return err + if err = qtx.DeletePartsRequired(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting parts required: %w", err) } - - if err := transaction.Commit(); err != nil { - return err + if err = qtx.DeleteWarranty(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting warranty: %w", err) + } + if err := tx.Commit(); err != nil { + return fmt.Errorf("failed to commit transaction: %w", err) } - return nil } From e890e98e2ff54ef962c5b1d2241dac8f03e21072 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 19:38:41 +0100 Subject: [PATCH 109/248] registration store --- server/stores/registrationStore.go | 90 ++++++++++++++---------------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/server/stores/registrationStore.go b/server/stores/registrationStore.go index dd5e666..0c80115 100644 --- a/server/stores/registrationStore.go +++ b/server/stores/registrationStore.go @@ -1,72 +1,66 @@ package stores import ( + "context" "database/sql" "fmt" - "log" + "github.com/sean-david-welch/farmec-v2/server/db" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" ) type RegistrationStore interface { - GetRegistrations() ([]types.MachineRegistration, error) - GetRegistrationById(id string) (*types.MachineRegistration, error) - CreateRegistration(registration *types.MachineRegistration) error - UpdateRegistration(id string, registration *types.MachineRegistration) error - DeleteRegistration(id string) error + GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) + GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) + CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error + UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error + DeleteRegistration(ctx context.Context, id string) error } type RegistrationStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewRegistrationStore(database *sql.DB) *RegistrationStoreImpl { - return &RegistrationStoreImpl{database: database} +func NewRegistrationStore(sql *sql.DB) *RegistrationStoreImpl { + queries := db.New(sql) + return &RegistrationStoreImpl{queries: queries} } -func (store *RegistrationStoreImpl) GetRegistrations() ([]types.MachineRegistration, error) { - var registrations []types.MachineRegistration - - query := `SELECT * FROM "MachineRegistration" ORDER BY "created" DESC` - rows, err := store.database.Query(query) +func (store *RegistrationStoreImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { + registrations, err := store.queries.GetRegistrations(ctx) if err != nil { - return nil, fmt.Errorf("error while querying database: %w", err) - } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var registration types.MachineRegistration - - err := rows.Scan( - ®istration.ID, ®istration.DealerName, ®istration.DealerAddress, - ®istration.OwnerName, ®istration.OwnerAddress, ®istration.MachineModel, - ®istration.SerialNumber, ®istration.InstallDate, ®istration.InvoiceNumber, - ®istration.CompleteSupply, ®istration.PdiComplete, ®istration.PtoCorrect, - ®istration.MachineTestRun, ®istration.SafetyInduction, ®istration.OperatorHandbook, - ®istration.Date, ®istration.CompletedBy, ®istration.Created, - ) - if err != nil { - return nil, fmt.Errorf("error occurred while iterating over rows: %w", err) - } - - registrations = append(registrations, registration) + return nil, fmt.Errorf("error occurred while getting registration from the db: %w", err) } - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over rows: %w", err) + var result []db.MachineRegistration + for _, registration := range registrations { + result = append(result, db.MachineRegistration{ + ID: registration.ID, + DealerName: registration.DealerName, + DealerAddress: registration.DealerAddress, + OwnerName: registration.OwnerName, + OwnerAddress: registration.OwnerAddress, + MachineModel: registration.MachineModel, + SerialNumber: registration.SerialNumber, + InstallDate: registration.InstallDate, + InvoiceNumber: registration.InvoiceNumber, + CompleteSupply: registration.CompleteSupply, + PdiComplete: registration.PdiComplete, + PtoCorrect: registration.PtoCorrect, + MachineTestRun: registration.MachineTestRun, + SafetyInduction: registration.SafetyInduction, + OperatorHandbook: registration.OperatorHandbook, + Date: registration.Date, + CompletedBy: registration.CompletedBy, + Created: registration.Created, + }) } - - return registrations, nil + return result, nil } -func (store *RegistrationStoreImpl) GetRegistrationById(id string) (*types.MachineRegistration, error) { - var registration types.MachineRegistration +func (store *RegistrationStoreImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { + var registration db.MachineRegistration query := `SELECT * FROM "MachineRegistration" WHERE "id" = ?` row := store.database.QueryRow(query, id) @@ -85,7 +79,7 @@ func (store *RegistrationStoreImpl) GetRegistrationById(id string) (*types.Machi return ®istration, nil } -func (store *RegistrationStoreImpl) CreateRegistration(registration *types.MachineRegistration) error { +func (store *RegistrationStoreImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { registration.ID = uuid.NewString() registration.Created = time.Now().String() @@ -112,7 +106,7 @@ func (store *RegistrationStoreImpl) CreateRegistration(registration *types.Machi return nil } -func (store *RegistrationStoreImpl) UpdateRegistration(id string, registration *types.MachineRegistration) error { +func (store *RegistrationStoreImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { query := `UPDATE "MachineRegistration" SET "dealer_name" = ?, "dealer_address" = ?, "owner_name" = ?, "owner_address" = ?, "machine_model" = ?, "serial_number" = ?, "install_date" = ?, "invoice_number" = ?, @@ -136,7 +130,7 @@ func (store *RegistrationStoreImpl) UpdateRegistration(id string, registration * return nil } -func (store *RegistrationStoreImpl) DeleteRegistration(id string) error { +func (store *RegistrationStoreImpl) DeleteRegistration(ctx context.Context, id string) error { query := `DELETE FROM "MachineRegistration" WHERE "id" = ?` _, err := store.database.Exec(query, id) From bcd981c0e2c28d448eb3435ca9226a1de4d77936 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 19:50:22 +0100 Subject: [PATCH 110/248] registration create --- server/stores/registrationStore.go | 64 ++++++++++++++---------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/server/stores/registrationStore.go b/server/stores/registrationStore.go index 0c80115..be5dd5a 100644 --- a/server/stores/registrationStore.go +++ b/server/stores/registrationStore.go @@ -60,49 +60,43 @@ func (store *RegistrationStoreImpl) GetRegistrations(ctx context.Context) ([]db. } func (store *RegistrationStoreImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { - var registration db.MachineRegistration - - query := `SELECT * FROM "MachineRegistration" WHERE "id" = ?` - row := store.database.QueryRow(query, id) - - if err := row.Scan( - ®istration.ID, ®istration.DealerName, ®istration.DealerAddress, - ®istration.OwnerName, ®istration.OwnerAddress, ®istration.MachineModel, - ®istration.SerialNumber, ®istration.InstallDate, ®istration.InvoiceNumber, - ®istration.CompleteSupply, ®istration.PdiComplete, ®istration.PtoCorrect, - ®istration.MachineTestRun, ®istration.SafetyInduction, ®istration.OperatorHandbook, - ®istration.Date, ®istration.CompletedBy, ®istration.Created, - ); err != nil { - return nil, fmt.Errorf("error occurred while iterating over row: %w", err) + registration, err := store.queries.GetRegistrationsByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("error occurred while getting a registration: %w", err) } - return ®istration, nil } func (store *RegistrationStoreImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { registration.ID = uuid.NewString() - registration.Created = time.Now().String() - - query := `INSERT INTO "MachineRegistration" ( - "id", "dealer_name", "dealer_address", "owner_name", "owner_address", "machine_model", - "serial_number", "install_date", "invoice_number", "complete_supply", "pdi_complete", - "pto_correct", "machine_test_run", "safety_induction", "operator_handbook", "date", - "completed_by", "created" - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` - - _, err := store.database.Exec( - query, - registration.ID, registration.DealerName, registration.DealerAddress, registration.OwnerName, - registration.OwnerAddress, registration.MachineModel, registration.SerialNumber, - registration.InstallDate, registration.InvoiceNumber, registration.CompleteSupply, - registration.PdiComplete, registration.PtoCorrect, registration.MachineTestRun, - registration.SafetyInduction, registration.OperatorHandbook, registration.Date, - registration.CompletedBy, registration.Created, - ) - if err != nil { - return fmt.Errorf("error occurred while creating machine registration: %w", err) + registration.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, } + params := db.CreateRegistrationParams{ + ID: registration.ID, + DealerName: registration.DealerName, + DealerAddress: registration.DealerAddress, + OwnerName: registration.OwnerName, + OwnerAddress: registration.OwnerAddress, + MachineModel: registration.MachineModel, + SerialNumber: registration.SerialNumber, + InstallDate: registration.InstallDate, + InvoiceNumber: registration.InvoiceNumber, + CompleteSupply: registration.CompleteSupply, + PdiComplete: registration.PdiComplete, + PtoCorrect: registration.PtoCorrect, + MachineTestRun: registration.MachineTestRun, + SafetyInduction: registration.SafetyInduction, + OperatorHandbook: registration.OperatorHandbook, + Date: registration.Date, + CompletedBy: registration.CompletedBy, + Created: registration.Created, + } + if err := store.queries.CreateRegistration(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating a registration: %w", err) + } return nil } From 91312b4879f9d7a0379851b233fe2baaadc74a21 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 19:52:19 +0100 Subject: [PATCH 111/248] registration update --- server/stores/registrationStore.go | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/server/stores/registrationStore.go b/server/stores/registrationStore.go index be5dd5a..c029a74 100644 --- a/server/stores/registrationStore.go +++ b/server/stores/registrationStore.go @@ -101,24 +101,27 @@ func (store *RegistrationStoreImpl) CreateRegistration(ctx context.Context, regi } func (store *RegistrationStoreImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { - query := `UPDATE "MachineRegistration" SET - "dealer_name" = ?, "dealer_address" = ?, "owner_name" = ?, "owner_address" = ?, - "machine_model" = ?, "serial_number" = ?, "install_date" = ?, "invoice_number" = ?, - "complete_supply" = ?, "pdi_complete" = ?, "pto_correct" = ?, "machine_test_run" = ?, - "safety_induction" = ?, "operator_handbook" = ?, "date" = ?, "completed_by" = ? - WHERE "id" = ?` - - _, err := store.database.Exec( - query, - id, registration.DealerName, registration.DealerAddress, registration.OwnerName, - registration.OwnerAddress, registration.MachineModel, registration.SerialNumber, - registration.InstallDate, registration.InvoiceNumber, registration.CompleteSupply, - registration.PdiComplete, registration.PtoCorrect, registration.MachineTestRun, - registration.SafetyInduction, registration.OperatorHandbook, registration.Date, - registration.CompletedBy, - ) - if err != nil { - return fmt.Errorf("error occurred while updating registration") + params := db.UpdateRegistrationParams{ + DealerName: registration.DealerName, + DealerAddress: registration.DealerAddress, + OwnerName: registration.OwnerName, + OwnerAddress: registration.OwnerAddress, + MachineModel: registration.MachineModel, + SerialNumber: registration.SerialNumber, + InstallDate: registration.InstallDate, + InvoiceNumber: registration.InvoiceNumber, + CompleteSupply: registration.CompleteSupply, + PdiComplete: registration.PdiComplete, + PtoCorrect: registration.PtoCorrect, + MachineTestRun: registration.MachineTestRun, + SafetyInduction: registration.SafetyInduction, + OperatorHandbook: registration.OperatorHandbook, + Date: registration.Date, + CompletedBy: registration.CompletedBy, + ID: id, + } + if err := store.queries.UpdateRegistration(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating registration: %w", err) } return nil From e9760990188da5a1f96fc0baf1206d9ebe31e157 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 19:55:28 +0100 Subject: [PATCH 112/248] fix --- server/stores/registrationStore.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/stores/registrationStore.go b/server/stores/registrationStore.go index c029a74..aff4281 100644 --- a/server/stores/registrationStore.go +++ b/server/stores/registrationStore.go @@ -128,12 +128,8 @@ func (store *RegistrationStoreImpl) UpdateRegistration(ctx context.Context, id s } func (store *RegistrationStoreImpl) DeleteRegistration(ctx context.Context, id string) error { - query := `DELETE FROM "MachineRegistration" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error occurred while deleting registration") + if err := store.queries.DeleteRegistration(ctx, id); err != nil { + return fmt.Errorf("an error occurred while deleting a registration: %w", err) } - return nil } From 773c843680b666ba230989ae99024074878c23ac Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:15:20 +0100 Subject: [PATCH 113/248] line item --- server/stores/lineitemStore.go | 70 ++++++++++++++-------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/server/stores/lineitemStore.go b/server/stores/lineitemStore.go index 9fa952e..c4c642f 100644 --- a/server/stores/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -1,71 +1,59 @@ package stores import ( + "context" "database/sql" "errors" "fmt" + "github.com/sean-david-welch/farmec-v2/server/db" "log" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" ) type LineItemStore interface { - GetLineItems() ([]types.LineItem, error) - GetLineItemById(id string) (*types.LineItem, error) - CreateLineItem(lineItem *types.LineItem) error - UpdateLineItem(id string, lineItem *types.LineItem) error - DeleteLineItem(id string) error + GetLineItems(ctx context.Context) ([]db.LineItem, error) + GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) + CreateLineItem(ctx context.Context, lineItem *db.LineItem) error + UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error + DeleteLineItem(ctx context.Context, id string) error } type LineItemStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewLineItemStore(database *sql.DB) *LineItemStoreImpl { - return &LineItemStoreImpl{database: database} +func NewLineItemStore(sql *sql.DB) *LineItemStoreImpl { + queries := db.New(sql) + return &LineItemStoreImpl{queries: queries} } -func (store *LineItemStoreImpl) GetLineItems() ([]types.LineItem, error) { - var lineItems []types.LineItem - - query := `SELECT * FROM "LineItems"` - rows, err := store.database.Query(query) +func (store *LineItemStoreImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { + lineItems, err := store.queries.GetLineItems(ctx) if err != nil { - return nil, fmt.Errorf("error occurred while querying database: %w", err) + return nil, fmt.Errorf("error occurred while getting line items: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var lineItem types.LineItem - - if err := rows.Scan(&lineItem.ID, &lineItem.Name, &lineItem.Price, &lineItem.Image); err != nil { - return nil, fmt.Errorf("error occurred while scanning line item: %w", err) - } - - lineItems = append(lineItems, lineItem) - } - - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over rows: %w", err) + var result []db.LineItem + for _, lineItem := range lineItems { + result = append(result, db.LineItem{ + ID: lineItem.ID, + Name: lineItem.Name, + Price: lineItem.Price, + Image: lineItem.Image, + }) } - - return lineItems, nil + return result, nil } -func (store *LineItemStoreImpl) GetLineItemById(id string) (*types.LineItem, error) { - var lineItem types.LineItem +func (store *LineItemStoreImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { + var lineItem db.LineItem query := `SELECT * FROM "LineItems" WHERE "id" = ?` row := store.database.QueryRow(query, id) if err := row.Scan(&lineItem.ID, &lineItem.Name, &lineItem.Price, &lineItem.Image); err != nil { - if errors.Is(err, sql.ErrNoRows) { + if errors.Is(err, ctx context.Context, sql.ErrNoRows) { return nil, fmt.Errorf("error item found with the given id: %w", err) } @@ -75,7 +63,7 @@ func (store *LineItemStoreImpl) GetLineItemById(id string) (*types.LineItem, err return &lineItem, nil } -func (store *LineItemStoreImpl) CreateLineItem(lineItem *types.LineItem) error { +func (store *LineItemStoreImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error { lineItem.ID = uuid.NewString() query := `INSERT INTO "LineItems" (id, name, price, image) VALUES (?, ?, ?, ?)` @@ -88,7 +76,7 @@ func (store *LineItemStoreImpl) CreateLineItem(lineItem *types.LineItem) error { return nil } -func (store *LineItemStoreImpl) UpdateLineItem(id string, lineItem *types.LineItem) error { +func (store *LineItemStoreImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error { query := `UPDATE "LineItems" SET "name" = ?, "price" = ? WHERE "id" = ?` args := []interface{}{id, lineItem.Name, lineItem.Price} @@ -105,7 +93,7 @@ func (store *LineItemStoreImpl) UpdateLineItem(id string, lineItem *types.LineIt return nil } -func (store *LineItemStoreImpl) DeleteLineItem(id string) error { +func (store *LineItemStoreImpl) DeleteLineItem(ctx context.Context, id string) error { query := `DELETE FROM "LineItems" WHERE "id" = ?` _, err := store.database.Exec(query, id) From e9538ac40f6bd05c26aa6d1641d860aa54cc2c02 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:16:48 +0100 Subject: [PATCH 114/248] line item by id --- server/stores/lineitemStore.go | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/server/stores/lineitemStore.go b/server/stores/lineitemStore.go index c4c642f..3d2d25a 100644 --- a/server/stores/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -3,12 +3,9 @@ package stores import ( "context" "database/sql" - "errors" "fmt" - "github.com/sean-david-welch/farmec-v2/server/db" - "log" - "github.com/google/uuid" + "github.com/sean-david-welch/farmec-v2/server/db" ) type LineItemStore interface { @@ -36,8 +33,8 @@ func (store *LineItemStoreImpl) GetLineItems(ctx context.Context) ([]db.LineItem var result []db.LineItem for _, lineItem := range lineItems { result = append(result, db.LineItem{ - ID: lineItem.ID, - Name: lineItem.Name, + ID: lineItem.ID, + Name: lineItem.Name, Price: lineItem.Price, Image: lineItem.Image, }) @@ -46,20 +43,10 @@ func (store *LineItemStoreImpl) GetLineItems(ctx context.Context) ([]db.LineItem } func (store *LineItemStoreImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { - var lineItem db.LineItem - - query := `SELECT * FROM "LineItems" WHERE "id" = ?` - row := store.database.QueryRow(query, id) - - if err := row.Scan(&lineItem.ID, &lineItem.Name, &lineItem.Price, &lineItem.Image); err != nil { - - if errors.Is(err, ctx context.Context, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error occurrred while scanning line item: %w", err) + lineItem, err := store.queries.GetLineItemByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("error occurred while getting line items from db: %w", err) } - return &lineItem, nil } From 02ea8e5ff79f8f74c69b4027309aedfd05beda59 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:18:15 +0100 Subject: [PATCH 115/248] create line item --- server/stores/lineitemStore.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/stores/lineitemStore.go b/server/stores/lineitemStore.go index 3d2d25a..fc261a5 100644 --- a/server/stores/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -53,13 +53,15 @@ func (store *LineItemStoreImpl) GetLineItemById(ctx context.Context, id string) func (store *LineItemStoreImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error { lineItem.ID = uuid.NewString() - query := `INSERT INTO "LineItems" (id, name, price, image) VALUES (?, ?, ?, ?)` - - _, err := store.database.Exec(query, lineItem.ID, lineItem.Name, lineItem.Price, lineItem.Image) - if err != nil { - return fmt.Errorf("error occurred while creating line item: %w", err) + params := db.CreateLineItemParams{ + ID: lineItem.ID, + Name: lineItem.Name, + Price: lineItem.Price, + Image: lineItem.Image, + } + if err := store.queries.CreateLineItem(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating line items: %w", err) } - return nil } From d50af31c58c123094044804c305a894214c6d372 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:21:30 +0100 Subject: [PATCH 116/248] update line item --- server/stores/lineitemStore.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/server/stores/lineitemStore.go b/server/stores/lineitemStore.go index fc261a5..f975b0c 100644 --- a/server/stores/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -66,19 +66,26 @@ func (store *LineItemStoreImpl) CreateLineItem(ctx context.Context, lineItem *db } func (store *LineItemStoreImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error { - query := `UPDATE "LineItems" SET "name" = ?, "price" = ? WHERE "id" = ?` - args := []interface{}{id, lineItem.Name, lineItem.Price} - - if lineItem.Image != "" && lineItem.Image != "null" { - query = `UPDATE "LineItems" SET "name" = ?, "price" = ?, "image" = ? WHERE "id" = ?` - args = []interface{}{id, lineItem.Name, lineItem.Price, lineItem.Image} - } - - _, err := store.database.Exec(query, args...) - if err != nil { - return fmt.Errorf("error occurred while updating line item: %w", err) + if lineItem.Image.Valid { + params := db.UpdateLineItemParams{ + Name: lineItem.Name, + Price: lineItem.Price, + Image: lineItem.Image, + ID: id, + } + if err := store.queries.UpdateLineItem(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a line item: %w", err) + } + } else { + params := db.UpdateLineItemNoImageParams{ + Name: lineItem.Name, + Price: lineItem.Price, + ID: id, + } + if err := store.queries.UpdateLineItemNoImage(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a line item: %w", err) + } } - return nil } From 95355f59dfee210e43d42b5951f6ebd5006661bc Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:23:08 +0100 Subject: [PATCH 117/248] delete line item --- server/stores/lineitemStore.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/stores/lineitemStore.go b/server/stores/lineitemStore.go index f975b0c..9f446dc 100644 --- a/server/stores/lineitemStore.go +++ b/server/stores/lineitemStore.go @@ -90,12 +90,8 @@ func (store *LineItemStoreImpl) UpdateLineItem(ctx context.Context, id string, l } func (store *LineItemStoreImpl) DeleteLineItem(ctx context.Context, id string) error { - query := `DELETE FROM "LineItems" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error occurred while deleting line items: %w", err) + if err := store.queries.DeleteLineItem(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting a line item: %w", err) } - return nil } From bfb99cecbfacd790401f513e4b52bfe35e0e7d18 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:30:52 +0100 Subject: [PATCH 118/248] parts store --- server/stores/partsStore.go | 87 +++++++++++++------------------------ 1 file changed, 30 insertions(+), 57 deletions(-) diff --git a/server/stores/partsStore.go b/server/stores/partsStore.go index 46dc0de..4084246 100644 --- a/server/stores/partsStore.go +++ b/server/stores/partsStore.go @@ -1,86 +1,59 @@ package stores import ( + "context" "database/sql" "errors" "fmt" "log" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type PartsStore interface { - GetParts(id string) ([]types.Sparepart, error) - GetPartById(id string) (*types.Sparepart, error) - CreatePart(part *types.Sparepart) error - UpdatePart(id string, part *types.Sparepart) error - DeletePart(id string) error + GetParts(ctx context.Context, id string) ([]db.SparePart, error) + GetPartById(ctx context.Context, id string) (*db.SparePart, error) + CreatePart(ctx context.Context, part *db.SparePart) error + UpdatePart(ctx context.Context, id string, part *db.SparePart) error + DeletePart(ctx context.Context, id string) error } type PartsStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewPartsStore(database *sql.DB) *PartsStoreImpl { - return &PartsStoreImpl{database: database} +func NewPartsStore(sql *sql.DB) *PartsStoreImpl { + queries := db.New(sql) + return &PartsStoreImpl{queries: queries} } -func ScanParts(row interface{}, part *types.Sparepart) error { - var scanner interface { - Scan(dest ...interface{}) error - } - - switch value := row.(type) { - case *sql.Row: - scanner = value - case *sql.Rows: - scanner = value - default: - return fmt.Errorf("unsupported type: %T", value) - } - - return scanner.Scan(&part.ID, &part.SupplierID, &part.Name, &part.PartsImage, &part.SparePartsLink) -} - -func (store *PartsStoreImpl) GetParts(id string) ([]types.Sparepart, error) { - var parts []types.Sparepart - - query := `SELECT * FROM "SpareParts" WHERE "supplier_id" = ?` - rows, err := store.database.Query(query, id) +func (store *PartsStoreImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { + parts, err := store.queries.GetParts(ctx, id) if err != nil { - return nil, fmt.Errorf("error executing query: %w", err) + return nil, fmt.Errorf("error occurred while getting spare parts: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var part types.Sparepart - - if err := ScanParts(rows, &part); err != nil { - return nil, fmt.Errorf("error scanning row: %w", err) - } - parts = append(parts, part) + var result []db.SparePart + for _, part := range parts { + result = append(result, db.SparePart{ + ID: part.ID, + SupplierID: part.SupplierID, + Name: part.Name, + PartsImage: part.PartsImage, + SparePartsLink: part.SparePartsLink, + }) } - - if err = rows.Err(); err != nil { - return nil, fmt.Errorf("error after iterating over rows: %w", err) - } - - return parts, nil + return result, nil } -func (store *PartsStoreImpl) GetPartById(id string) (*types.Sparepart, error) { +func (store *PartsStoreImpl) GetPartById(ctx context.Context, id string) (*db.SparePart, error) { query := `SELECT * FROM "SpareParts" WHERE id = ?` row := store.database.QueryRow(query, id) - var part types.Sparepart + var part dbSparePart. if err := ScanParts(row, &part); err != nil { - if errors.Is(err, sql.ErrNoRows) { + if errors.Is(err, sqlctx context.Context, .ErrNoRows) { return nil, fmt.Errorf("error item found with the given id: %w", err) } return nil, fmt.Errorf("error scanning row: %w", err) @@ -89,7 +62,7 @@ func (store *PartsStoreImpl) GetPartById(id string) (*types.Sparepart, error) { return &part, nil } -func (store *PartsStoreImpl) CreatePart(part *types.Sparepart) error { +func (store *PartsStoreImpl) CreatePart(ctx context.Context, part *db.SparePart) error { part.ID = uuid.NewString() query := `INSERT INTO "SpareParts" (id, supplier_id, name, parts_image, spare_parts_link) @@ -104,7 +77,7 @@ func (store *PartsStoreImpl) CreatePart(part *types.Sparepart) error { return nil } -func (store *PartsStoreImpl) UpdatePart(id string, part *types.Sparepart) error { +func (store *PartsStoreImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) error { query := `UPDATE "SpareParts" SET supplier_id = ?, name = ?, spare_parts_link = ? WHERE ID = ?` args := []interface{}{id, part.SupplierID, part.Name, part.SparePartsLink} @@ -121,7 +94,7 @@ func (store *PartsStoreImpl) UpdatePart(id string, part *types.Sparepart) error return nil } -func (store *PartsStoreImpl) DeletePart(id string) error { +func (store *PartsStoreImpl) DeletePart(ctx context.Context, id string) error { query := `DELETE FROM "SpareParts" WHERE id = ?` _, err := store.database.Exec(query, id) From ff868149403d6702eec4d93d321de66054ab946f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:32:32 +0100 Subject: [PATCH 119/248] parts store by id --- server/stores/partsStore.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/server/stores/partsStore.go b/server/stores/partsStore.go index 4084246..e9b0da4 100644 --- a/server/stores/partsStore.go +++ b/server/stores/partsStore.go @@ -3,10 +3,7 @@ package stores import ( "context" "database/sql" - "errors" "fmt" - "log" - "github.com/google/uuid" "github.com/sean-david-welch/farmec-v2/server/db" ) @@ -36,10 +33,10 @@ func (store *PartsStoreImpl) GetParts(ctx context.Context, id string) ([]db.Spar var result []db.SparePart for _, part := range parts { result = append(result, db.SparePart{ - ID: part.ID, - SupplierID: part.SupplierID, - Name: part.Name, - PartsImage: part.PartsImage, + ID: part.ID, + SupplierID: part.SupplierID, + Name: part.Name, + PartsImage: part.PartsImage, SparePartsLink: part.SparePartsLink, }) } @@ -47,19 +44,11 @@ func (store *PartsStoreImpl) GetParts(ctx context.Context, id string) ([]db.Spar } func (store *PartsStoreImpl) GetPartById(ctx context.Context, id string) (*db.SparePart, error) { - query := `SELECT * FROM "SpareParts" WHERE id = ?` - row := store.database.QueryRow(query, id) - - var part dbSparePart. - - if err := ScanParts(row, &part); err != nil { - if errors.Is(err, sqlctx context.Context, .ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - return nil, fmt.Errorf("error scanning row: %w", err) + part, err := store.queries.GetPartByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("error occurred while getting part from the db: %w", err) } - - return &part, nil + return &part, err } func (store *PartsStoreImpl) CreatePart(ctx context.Context, part *db.SparePart) error { From a1d4af5c5ea44381045b74b59d266c5347097e27 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:34:50 +0100 Subject: [PATCH 120/248] create part --- server/stores/partsStore.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/stores/partsStore.go b/server/stores/partsStore.go index e9b0da4..521469f 100644 --- a/server/stores/partsStore.go +++ b/server/stores/partsStore.go @@ -54,15 +54,16 @@ func (store *PartsStoreImpl) GetPartById(ctx context.Context, id string) (*db.Sp func (store *PartsStoreImpl) CreatePart(ctx context.Context, part *db.SparePart) error { part.ID = uuid.NewString() - query := `INSERT INTO "SpareParts" (id, supplier_id, name, parts_image, spare_parts_link) - VALUES (?, ?, ?, ?, ?)` - - _, err := store.database.Exec(query, part.ID, part.SupplierID, part.Name, part.PartsImage, part.SparePartsLink) - - if err != nil { - return fmt.Errorf("error creating spare part: %w", err) + params := db.CreateSparePartParams{ + ID: part.ID, + SupplierID: part.SupplierID, + Name: part.Name, + PartsImage: part.PartsImage, + SparePartsLink: part.SparePartsLink, + } + if err := store.queries.CreateSparePart(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating spare parts: %w", err) } - return nil } From 09a697351525c81b065b0768d9caf32df0a2d817 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:38:36 +0100 Subject: [PATCH 121/248] update part --- server/stores/partsStore.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/server/stores/partsStore.go b/server/stores/partsStore.go index 521469f..3d82a51 100644 --- a/server/stores/partsStore.go +++ b/server/stores/partsStore.go @@ -68,19 +68,28 @@ func (store *PartsStoreImpl) CreatePart(ctx context.Context, part *db.SparePart) } func (store *PartsStoreImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) error { - query := `UPDATE "SpareParts" SET supplier_id = ?, name = ?, spare_parts_link = ? WHERE ID = ?` - args := []interface{}{id, part.SupplierID, part.Name, part.SparePartsLink} - - if part.PartsImage != "" && part.PartsImage != "null" { - query = `UPDATE "SpareParts" SET supplier_id = ?, name = ?, parts_image = ?, spare_parts_link = ? WHERE ID = ?` - args = []interface{}{id, part.SupplierID, part.Name, part.PartsImage, part.SparePartsLink} - } - - _, err := store.database.Exec(query, args...) - if err != nil { - return fmt.Errorf("error updating part: %w", err) + if part.PartsImage.Valid { + params := db.UpdateSparePartParams{ + SupplierID: part.SupplierID, + Name: part.Name, + PartsImage: part.PartsImage, + SparePartsLink: part.SparePartsLink, + ID: id, + } + if err := store.queries.UpdateSparePart(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a spare part: %w", err) + } + } else { + params := db.UpdateSparePartNoImageParams{ + SupplierID: part.SupplierID, + Name: part.Name, + SparePartsLink: part.SparePartsLink, + ID: id, + } + if err := store.queries.UpdateSparePartNoImage(ctx, params); err != nil { + return fmt.Errorf("error occurred while updating a spare part: %w", err) + } } - return nil } From d083b8316f748c8fe9b6f5932d8e116609fbeeb4 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:39:33 +0100 Subject: [PATCH 122/248] delete part --- server/stores/partsStore.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/stores/partsStore.go b/server/stores/partsStore.go index 3d82a51..3bc44e0 100644 --- a/server/stores/partsStore.go +++ b/server/stores/partsStore.go @@ -94,12 +94,8 @@ func (store *PartsStoreImpl) UpdatePart(ctx context.Context, id string, part *db } func (store *PartsStoreImpl) DeletePart(ctx context.Context, id string) error { - query := `DELETE FROM "SpareParts" WHERE id = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error deleting part: %w", err) + if err := store.queries.DeleteSparePart(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting a spare part: %w", err) } - return nil } From 36d679561f59439b6a0a3eecfc4e004b7668546a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:42:50 +0100 Subject: [PATCH 123/248] privacy store --- server/stores/privacyStore.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/server/stores/privacyStore.go b/server/stores/privacyStore.go index 95cab0b..0cb3e5e 100644 --- a/server/stores/privacyStore.go +++ b/server/stores/privacyStore.go @@ -1,32 +1,34 @@ package stores import ( + "context" "database/sql" "fmt" "log" "time" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type PrivacyStore interface { - GetPrivacy() ([]types.Privacy, error) - CreatePrivacy(privacy *types.Privacy) error - UpdatePrivacy(id string, privacy *types.Privacy) error - DeletePrivacy(id string) error + GetPrivacy(ctx context.Context) ([]db.Privacy, error) + CreatePrivacy(ctx context.Context, privacy *db.Privacy) error + UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error + DeletePrivacy(ctx context.Context, id string) error } type PrivacyStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewPrivacyStore(database *sql.DB) *PrivacyStoreImpl { - return &PrivacyStoreImpl{database: database} +func NewPrivacyStore(sql *sql.DB) *PrivacyStoreImpl { + queries := db.New(sql) + return &PrivacyStoreImpl{queries: queries} } -func (store *PrivacyStoreImpl) GetPrivacy() ([]types.Privacy, error) { - var privacyTerms []types.Privacy +func (store *PrivacyStoreImpl) GetPrivacy() ([]db.Privacy, error) { + var privacyTerms []db.Privacy query := `SELECT * FROM "Privacy"` rows, err := store.database.Query(query) @@ -40,7 +42,7 @@ func (store *PrivacyStoreImpl) GetPrivacy() ([]types.Privacy, error) { }() for rows.Next() { - var privacyTerm types.Privacy + var privacyTerm db.Privacy if err := rows.Scan(&privacyTerm.ID, &privacyTerm.Title, &privacyTerm.Body, &privacyTerm.Created); err != nil { return nil, fmt.Errorf("error occurred while scanning row: %w", err) @@ -56,7 +58,7 @@ func (store *PrivacyStoreImpl) GetPrivacy() ([]types.Privacy, error) { return privacyTerms, err } -func (store *PrivacyStoreImpl) CreatePrivacy(privacy *types.Privacy) error { +func (store *PrivacyStoreImpl) CreatePrivacy(privacy *db.Privacy) error { privacy.ID = uuid.NewString() privacy.Created = time.Now().String() @@ -70,7 +72,7 @@ func (store *PrivacyStoreImpl) CreatePrivacy(privacy *types.Privacy) error { return nil } -func (store *PrivacyStoreImpl) UpdatePrivacy(id string, privacy *types.Privacy) error { +func (store *PrivacyStoreImpl) UpdatePrivacy(id string, privacy *db.Privacy) error { query := `UPDATE "Privacy" SET title = ?, body = ? where id = ?` _, err := store.database.Exec(query, privacy.Title, privacy.Body, id) From 1a00f32e1df7bb94c93b0338aa9d286b14162605 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:48:53 +0100 Subject: [PATCH 124/248] privacy create --- server/stores/privacyStore.go | 64 +++++++++++++++-------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/server/stores/privacyStore.go b/server/stores/privacyStore.go index 0cb3e5e..f193d50 100644 --- a/server/stores/privacyStore.go +++ b/server/stores/privacyStore.go @@ -4,7 +4,6 @@ import ( "context" "database/sql" "fmt" - "log" "time" "github.com/google/uuid" @@ -27,52 +26,43 @@ func NewPrivacyStore(sql *sql.DB) *PrivacyStoreImpl { return &PrivacyStoreImpl{queries: queries} } -func (store *PrivacyStoreImpl) GetPrivacy() ([]db.Privacy, error) { - var privacyTerms []db.Privacy - - query := `SELECT * FROM "Privacy"` - rows, err := store.database.Query(query) +func (store *PrivacyStoreImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, error) { + privacies, err := store.queries.GetPrivacies(ctx) if err != nil { - return nil, err + return nil, fmt.Errorf("an error occurred while getting privacy policy: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var privacyTerm db.Privacy - - if err := rows.Scan(&privacyTerm.ID, &privacyTerm.Title, &privacyTerm.Body, &privacyTerm.Created); err != nil { - return nil, fmt.Errorf("error occurred while scanning row: %w", err) - } - - privacyTerms = append(privacyTerms, privacyTerm) - - if err := rows.Err(); err != nil { - return nil, fmt.Errorf("error occurred after iterating over rows: %w", err) - } + var result []db.Privacy + for _, privacy := range privacies { + result = append(result, db.Privacy{ + ID: privacy.ID, + Title: privacy.Title, + Body: privacy.Body, + Created: privacy.Created, + }) } - - return privacyTerms, err + return result, nil } -func (store *PrivacyStoreImpl) CreatePrivacy(privacy *db.Privacy) error { +func (store *PrivacyStoreImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { privacy.ID = uuid.NewString() - privacy.Created = time.Now().String() - - query := `INSERT INTO "Privacy" (id, title, body, created) VALUES (?, ?, ?, ?)` - - _, err := store.database.Exec(query, privacy.ID, privacy.Title, privacy.Body, privacy.Created) - if err != nil { - return fmt.Errorf("error occurred while creating privacy term: %w", err) + privacy.Created = sql.NullString{ + String: time.Now().String(), + Valid: true, } + params := db.CreatePrivacyParams{ + ID: privacy.ID, + Title: privacy.Title, + Body: privacy.Body, + Created: privacy.Created, + } + if err := store.queries.CreatePrivacy(ctx, params); err != nil { + return fmt.Errorf("error occurred while creating policy: %w", err) + } return nil } -func (store *PrivacyStoreImpl) UpdatePrivacy(id string, privacy *db.Privacy) error { +func (store *PrivacyStoreImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { query := `UPDATE "Privacy" SET title = ?, body = ? where id = ?` _, err := store.database.Exec(query, privacy.Title, privacy.Body, id) @@ -83,7 +73,7 @@ func (store *PrivacyStoreImpl) UpdatePrivacy(id string, privacy *db.Privacy) err return nil } -func (store *PrivacyStoreImpl) DeletePrivacy(id string) error { +func (store *PrivacyStoreImpl) DeletePrivacy(ctx context.Context, id string) error { query := `DELETE FROM "Privacy" WHERE "id" = ?` _, err := store.database.Exec(query, id) From 4c6e945410b8281072b575a1a79c20ad08a502e8 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 20:53:53 +0100 Subject: [PATCH 125/248] update and delete --- server/stores/privacyStore.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/server/stores/privacyStore.go b/server/stores/privacyStore.go index f193d50..8133757 100644 --- a/server/stores/privacyStore.go +++ b/server/stores/privacyStore.go @@ -63,23 +63,20 @@ func (store *PrivacyStoreImpl) CreatePrivacy(ctx context.Context, privacy *db.Pr } func (store *PrivacyStoreImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { - query := `UPDATE "Privacy" SET title = ?, body = ? where id = ?` - - _, err := store.database.Exec(query, privacy.Title, privacy.Body, id) - if err != nil { - return fmt.Errorf("error occurred while updating privacy term: %w", err) + params := db.UpdatePrivacyParams{ + Title: privacy.Title, + Body: privacy.Body, + ID: id, + } + if err := store.queries.UpdatePrivacy(ctx, params); err != nil { + return fmt.Errorf("an error occurred while") } - return nil } func (store *PrivacyStoreImpl) DeletePrivacy(ctx context.Context, id string) error { - query := `DELETE FROM "Privacy" WHERE "id" = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error occurred while deleting privacy term: %w", err) + if err := store.queries.DeletePrivacy(ctx, id); err != nil { + return fmt.Errorf("an error occurred while deleting privacy: %w", err) } - return nil } From ac860cea85a3edb519892968125c4315d9d563bf Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:00:00 +0100 Subject: [PATCH 126/248] product store --- server/stores/productStore.go | 89 ++++++++++++----------------------- 1 file changed, 31 insertions(+), 58 deletions(-) diff --git a/server/stores/productStore.go b/server/stores/productStore.go index 6801af7..889e6bc 100644 --- a/server/stores/productStore.go +++ b/server/stores/productStore.go @@ -1,88 +1,61 @@ package stores import ( + "context" "database/sql" "errors" "fmt" "log" "github.com/google/uuid" - "github.com/sean-david-welch/farmec-v2/server/types" + "github.com/sean-david-welch/farmec-v2/server/db" ) type ProductStore interface { - GetProducts(id string) ([]types.Product, error) - GetProductById(id string) (*types.Product, error) - CreateProduct(product *types.Product) error - UpdateProduct(id string, product *types.Product) error - DeleteProduct(id string) error + GetProducts(ctx context.Context, id string) ([]db.Product, error) + GetProductById(ctx context.Context, id string) (*db.Product, error) + CreateProduct(ctx context.Context, product *db.Product) error + UpdateProduct(ctx context.Context, id string, product *db.Product) error + DeleteProduct(ctx context.Context, id string) error } type ProductStoreImpl struct { - database *sql.DB + queries *db.Queries } -func NewProductStore(database *sql.DB) *ProductStoreImpl { - return &ProductStoreImpl{database: database} +func NewProductStore(sql *sql.DB) *ProductStoreImpl { + queries := db.New(sql) + return &ProductStoreImpl{queries: queries} } -func ScanProduct(row interface{}, product *types.Product) error { - var scanner interface { - Scan(dest ...interface{}) error - } - - switch value := row.(type) { - case *sql.Row: - scanner = value - case *sql.Rows: - scanner = value - default: - return fmt.Errorf("unsupported type: %T", value) - } - - return scanner.Scan(&product.ID, &product.MachineID, &product.Name, &product.ProductImage, &product.Description, &product.ProductLink) -} - -func (store *ProductStoreImpl) GetProducts(id string) ([]types.Product, error) { - var products []types.Product - - query := `SELECT * FROM "Product" WHERE "machine_id" = ?` - rows, err := store.database.Query(query, id) +func (store *ProductStoreImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { + products, err := store.queries.GetProducts(context, id) if err != nil { - return nil, fmt.Errorf("error executing query: %w", err) + return nil, fmt.Errorf("an error occurred while getting products: %w", err) } - defer func() { - if err := rows.Close(); err != nil { - log.Fatal("Failed to close database: ", err) - } - }() - - for rows.Next() { - var product types.Product - - if err := ScanProduct(rows, &product); err != nil { - return nil, fmt.Errorf("error scanning row: %w", err) - } - - products = append(products, product) + var result []db.Product + for _, product := range products { + result = append(result, db.Product{ + ID: product.ID, + MachineID: product.MachineID, + Name: product.Name, + ProductImage: product.ProductImage, + Description: product.Description, + ProductLink: product.ProductLink, + }) } - - if err = rows.Err(); err != nil { - return nil, fmt.Errorf("error after iterating over rows: %w", err) - } - - return products, nil + return result, nil } -func (store *ProductStoreImpl) GetProductById(id string) (*types.Product, error) { +func (store *ProductStoreImpl) GetProductById(ctx context.Context, id string) (*db.Product, error) { query := `SELECT * FROM "Product" WHERE "id" = ?` row := store.database.QueryRow(query, id) - var product types.Product + var product db.Product if err := ScanProduct(row, &product); err != nil { - if errors.Is(err, sql.ErrNoRows) { + if errors.Is(err, ctx context.Context, sql.ErrNoRows) { return nil, fmt.Errorf("error item found with the given id: %w", err) } @@ -92,7 +65,7 @@ func (store *ProductStoreImpl) GetProductById(id string) (*types.Product, error) return &product, nil } -func (store *ProductStoreImpl) CreateProduct(product *types.Product) error { +func (store *ProductStoreImpl) CreateProduct(ctx context.Context, product *db.Product) error { product.ID = uuid.NewString() query := `INSERT INTO "Product" (id, machine_id, name, product_image, description, product_link) @@ -107,7 +80,7 @@ func (store *ProductStoreImpl) CreateProduct(product *types.Product) error { return nil } -func (store *ProductStoreImpl) UpdateProduct(id string, product *types.Product) error { +func (store *ProductStoreImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) error { query := `UPDATE "Product" SET machine_id = ?, name = ?, description = ?, product_link = ? WHERE id = ?` args := []interface{}{product.MachineID, product.Name, product.Description, product.ProductLink, id} @@ -126,7 +99,7 @@ func (store *ProductStoreImpl) UpdateProduct(id string, product *types.Product) return nil } -func (store *ProductStoreImpl) DeleteProduct(id string) error { +func (store *ProductStoreImpl) DeleteProduct(ctx context.Context, id string) error { query := `DELETE FROM "Product" WHERE id = ?` _, err := store.database.Exec(query, id) From 8616831053998d95cb47a4a9c5fd4d29d321d7b5 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:02:07 +0100 Subject: [PATCH 127/248] sql product --- server/sql/queries/product.sql | 2 +- server/stores/productStore.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/sql/queries/product.sql b/server/sql/queries/product.sql index f7eb610..da9a459 100644 --- a/server/sql/queries/product.sql +++ b/server/sql/queries/product.sql @@ -1,6 +1,6 @@ -- name: GetProducts :many select id, machine_id, name, product_image, description, product_link -from Product; +from Product where machine_id = ?; -- name: GetProductByID :one select id, machine_id, name, product_image, description, product_link diff --git a/server/stores/productStore.go b/server/stores/productStore.go index 889e6bc..2b379df 100644 --- a/server/stores/productStore.go +++ b/server/stores/productStore.go @@ -29,7 +29,7 @@ func NewProductStore(sql *sql.DB) *ProductStoreImpl { } func (store *ProductStoreImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { - products, err := store.queries.GetProducts(context, id) + products, err := store.queries.GetProducts(ctx, id) if err != nil { return nil, fmt.Errorf("an error occurred while getting products: %w", err) } From 25f2eb85e25bde85981a6ca373a91118664021a7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:02:24 +0100 Subject: [PATCH 128/248] sql gen code product --- server/db/product.sql.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/db/product.sql.go b/server/db/product.sql.go index 911b4dd..27115c5 100644 --- a/server/db/product.sql.go +++ b/server/db/product.sql.go @@ -69,11 +69,11 @@ func (q *Queries) GetProductByID(ctx context.Context, id string) (Product, error const getProducts = `-- name: GetProducts :many select id, machine_id, name, product_image, description, product_link -from Product +from Product where machine_id = ? ` -func (q *Queries) GetProducts(ctx context.Context) ([]Product, error) { - rows, err := q.db.QueryContext(ctx, getProducts) +func (q *Queries) GetProducts(ctx context.Context, machineID string) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getProducts, machineID) if err != nil { return nil, err } From e9c2de087a879f555c09411cfe8691f4ce6c483e Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:06:38 +0100 Subject: [PATCH 129/248] create product --- server/stores/productStore.go | 46 ++++++++++++++--------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/server/stores/productStore.go b/server/stores/productStore.go index 2b379df..86a1ae2 100644 --- a/server/stores/productStore.go +++ b/server/stores/productStore.go @@ -3,10 +3,7 @@ package stores import ( "context" "database/sql" - "errors" "fmt" - "log" - "github.com/google/uuid" "github.com/sean-david-welch/farmec-v2/server/db" ) @@ -37,44 +34,37 @@ func (store *ProductStoreImpl) GetProducts(ctx context.Context, id string) ([]db var result []db.Product for _, product := range products { result = append(result, db.Product{ - ID: product.ID, - MachineID: product.MachineID, - Name: product.Name, + ID: product.ID, + MachineID: product.MachineID, + Name: product.Name, ProductImage: product.ProductImage, - Description: product.Description, - ProductLink: product.ProductLink, + Description: product.Description, + ProductLink: product.ProductLink, }) } return result, nil } func (store *ProductStoreImpl) GetProductById(ctx context.Context, id string) (*db.Product, error) { - query := `SELECT * FROM "Product" WHERE "id" = ?` - row := store.database.QueryRow(query, id) - - var product db.Product - - if err := ScanProduct(row, &product); err != nil { - if errors.Is(err, ctx context.Context, sql.ErrNoRows) { - return nil, fmt.Errorf("error item found with the given id: %w", err) - } - - return nil, fmt.Errorf("error scanning row: %w", err) + product, err := store.queries.GetProductByID(ctx, id) + if err != nil { + return nil, fmt.Errorf("an error occurred while getting product: %w", err) } - return &product, nil } func (store *ProductStoreImpl) CreateProduct(ctx context.Context, product *db.Product) error { product.ID = uuid.NewString() - - query := `INSERT INTO "Product" (id, machine_id, name, product_image, description, product_link) - VALUES (?, ?, ?, ?, ?, ?)` - - _, err := store.database.Exec(query, product.ID, product.MachineID, product.Name, product.ProductImage, product.Description, product.ProductLink) - - if err != nil { - return fmt.Errorf("error creating product: %w", err) + params := db.CreateProductParams{ + ID: product.ID, + MachineID: product.MachineID, + Name: product.Name, + ProductImage: product.ProductImage, + Description: product.Description, + ProductLink: product.ProductLink, + } + if err := store.queries.CreateProduct(ctx, params); err != nil { + return fmt.Errorf("an error occurred while creating a product: %w", err) } return nil From 9c562f112ff528e1fe6e499d7ab6cd573503535c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:10:23 +0100 Subject: [PATCH 130/248] update product --- server/stores/productStore.go | 38 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/server/stores/productStore.go b/server/stores/productStore.go index 86a1ae2..102032e 100644 --- a/server/stores/productStore.go +++ b/server/stores/productStore.go @@ -66,26 +66,34 @@ func (store *ProductStoreImpl) CreateProduct(ctx context.Context, product *db.Pr if err := store.queries.CreateProduct(ctx, params); err != nil { return fmt.Errorf("an error occurred while creating a product: %w", err) } - return nil } func (store *ProductStoreImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) error { - query := `UPDATE "Product" SET machine_id = ?, name = ?, description = ?, product_link = ? WHERE id = ?` - args := []interface{}{product.MachineID, product.Name, product.Description, product.ProductLink, id} - - if product.ProductImage != "" && product.ProductImage != "null" { - query = `UPDATE "Product" SET machine_id = ?, name = ?, product_image = ?, description = ?, product_link = ? WHERE id = ?` - args = []interface{}{product.MachineID, product.Name, product.ProductImage, product.Description, product.ProductLink, id} - - } - - _, err := store.database.Exec(query, args...) - - if err != nil { - return fmt.Errorf("error updating product: %w", err) + if product.ProductImage.Valid { + params := db.UpdateProductParams{ + MachineID: product.MachineID, + Name: product.Name, + ProductImage: product.ProductImage, + Description: product.Description, + ProductLink: product.ProductLink, + ID: id, + } + if err := store.queries.UpdateProduct(ctx, params); err != nil { + return fmt.Errorf("an error occurred while updating product: %w", err) + } + } else { + params := db.UpdateProductNoImageParams{ + MachineID: product.MachineID, + Name: product.Name, + Description: product.Description, + ProductLink: product.ProductLink, + ID: id, + } + if err := store.queries.UpdateProductNoImage(ctx, params); err != nil { + return fmt.Errorf("an error occurred while updating product: %w", err) + } } - return nil } From 0e74bd56141ef4c49e5b5b206c89e487c3a8fd36 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:14:14 +0100 Subject: [PATCH 131/248] delete product --- server/stores/productStore.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/stores/productStore.go b/server/stores/productStore.go index 102032e..6079a83 100644 --- a/server/stores/productStore.go +++ b/server/stores/productStore.go @@ -98,12 +98,8 @@ func (store *ProductStoreImpl) UpdateProduct(ctx context.Context, id string, pro } func (store *ProductStoreImpl) DeleteProduct(ctx context.Context, id string) error { - query := `DELETE FROM "Product" WHERE id = ?` - - _, err := store.database.Exec(query, id) - if err != nil { - return fmt.Errorf("error deleting product: %w", err) + if err := store.queries.DeleteProduct(ctx, id); err != nil { + return fmt.Errorf("error occurred while deleting a product: %w", err) } - return nil } From 8499a847379cbfb0bb44294ff89e73b671a3b95b Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:23:31 +0100 Subject: [PATCH 132/248] handler --- server/handlers/blogHandler.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/handlers/blogHandler.go b/server/handlers/blogHandler.go index f9b1531..612ded2 100644 --- a/server/handlers/blogHandler.go +++ b/server/handlers/blogHandler.go @@ -18,7 +18,8 @@ func NewBlogHandler(service services.BlogService) *BlogHandler { } func (handler *BlogHandler) GetBlogs(context *gin.Context) { - blogs, err := handler.service.GetBlogs() + ctx := context.Request.Context() + blogs, err := handler.service.GetBlogs(ctx) if err != nil { log.Printf("error getting blogs: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting blogs"}) @@ -29,8 +30,9 @@ func (handler *BlogHandler) GetBlogs(context *gin.Context) { } func (handler *BlogHandler) GetBlogByID(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - blog, err := handler.service.GetBlogsByID(id) + blog, err := handler.service.GetBlogsByID(ctx, id) if err != nil { log.Printf("error getting blog: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting blog"}) @@ -41,6 +43,7 @@ func (handler *BlogHandler) GetBlogByID(context *gin.Context) { } func (handler *BlogHandler) CreateBlog(context *gin.Context) { + ctx := context.Request.Context() var blog db.Blog if err := context.ShouldBindJSON(&blog); err != nil { @@ -49,7 +52,7 @@ func (handler *BlogHandler) CreateBlog(context *gin.Context) { return } - result, err := handler.service.CreateBlog(&blog) + result, err := handler.service.CreateBlog(ctx, &blog) if err != nil { log.Printf("error while creating blog: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating blog"}) @@ -62,6 +65,7 @@ func (handler *BlogHandler) CreateBlog(context *gin.Context) { } func (handler *BlogHandler) UpdateBlog(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") var blog db.Blog @@ -72,7 +76,7 @@ func (handler *BlogHandler) UpdateBlog(context *gin.Context) { return } - result, err := handler.service.UpdateBlog(id, &blog) + result, err := handler.service.UpdateBlog(ctx, id, &blog) if err != nil { log.Printf("error while updating blog: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating blog"}) @@ -85,9 +89,10 @@ func (handler *BlogHandler) UpdateBlog(context *gin.Context) { } func (handler *BlogHandler) DeleteBlog(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteBlog(id); err != nil { + if err := handler.service.DeleteBlog(ctx, id); err != nil { log.Printf("error while deleting blog: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while deleting blog"}) return From 28d6168cb848150e3c41a9191f2e5835a602ba14 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:26:37 +0100 Subject: [PATCH 133/248] blog service --- server/services/blogService.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/server/services/blogService.go b/server/services/blogService.go index a19fd6f..c7044d4 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -1,6 +1,7 @@ package services import ( + "context" "database/sql" "errors" "github.com/sean-david-welch/farmec-v2/server/db" @@ -12,11 +13,11 @@ import ( ) type BlogService interface { - GetBlogs() ([]db.Blog, error) - GetBlogsByID(id string) (*db.Blog, error) - CreateBlog(blog *db.Blog) (*types.ModelResult, error) - UpdateBlog(id string, blog *db.Blog) (*types.ModelResult, error) - DeleteBlog(id string) error + GetBlogs(ctx context.Context) ([]db.Blog, error) + GetBlogsByID(ctx context.Context, id string) (*db.Blog, error) + CreateBlog(ctx context.Context, blog *db.Blog) (*types.ModelResult, error) + UpdateBlog(ctx context.Context, id string, blog *db.Blog) (*types.ModelResult, error) + DeleteBlog(ctx context.Context, id string) error } type BlogServiceImpl struct { @@ -29,8 +30,8 @@ func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *BlogServiceImpl) GetBlogs() ([]db.Blog, error) { - blogs, err := service.store.GetBlogs() +func (service *BlogServiceImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { + blogs, err := service.store.GetBlogs(ctx) if err != nil { return nil, err } @@ -38,8 +39,8 @@ func (service *BlogServiceImpl) GetBlogs() ([]db.Blog, error) { return blogs, nil } -func (service *BlogServiceImpl) GetBlogsByID(id string) (*db.Blog, error) { - blog, err := service.store.GetBlogById(id) +func (service *BlogServiceImpl) GetBlogsByID(ctx context.Context, id string) (*db.Blog, error) { + blog, err := service.store.GetBlogById(ctx, id) if err != nil { return nil, err } @@ -47,7 +48,7 @@ func (service *BlogServiceImpl) GetBlogsByID(id string) (*db.Blog, error) { return blog, nil } -func (service *BlogServiceImpl) CreateBlog(blog *db.Blog) (*types.ModelResult, error) { +func (service *BlogServiceImpl) CreateBlog(ctx context.Context, blog *db.Blog) (*types.ModelResult, error) { image := blog.MainImage if !image.Valid { @@ -62,7 +63,7 @@ func (service *BlogServiceImpl) CreateBlog(blog *db.Blog) (*types.ModelResult, e blog.MainImage = sql.NullString{String: imageUrl, Valid: true} - if err := service.store.CreateBlog(blog); err != nil { + if err := service.store.CreateBlog(ctx, blog); err != nil { return nil, err } @@ -74,7 +75,7 @@ func (service *BlogServiceImpl) CreateBlog(blog *db.Blog) (*types.ModelResult, e return result, nil } -func (service *BlogServiceImpl) UpdateBlog(id string, blog *db.Blog) (*types.ModelResult, error) { +func (service *BlogServiceImpl) UpdateBlog(ctx context.Context, id string, blog *db.Blog) (*types.ModelResult, error) { image := blog.MainImage var presignedUrl, imageUrl string @@ -89,7 +90,7 @@ func (service *BlogServiceImpl) UpdateBlog(id string, blog *db.Blog) (*types.Mod blog.MainImage = sql.NullString{String: imageUrl, Valid: true} } - if err := service.store.UpdateBlog(id, blog); err != nil { + if err := service.store.UpdateBlog(ctx, id, blog); err != nil { return nil, err } @@ -101,8 +102,8 @@ func (service *BlogServiceImpl) UpdateBlog(id string, blog *db.Blog) (*types.Mod return result, nil } -func (service *BlogServiceImpl) DeleteBlog(id string) error { - blog, err := service.store.GetBlogById(id) +func (service *BlogServiceImpl) DeleteBlog(ctx context.Context, id string) error { + blog, err := service.store.GetBlogById(ctx, id) if err != nil { return err } @@ -111,7 +112,7 @@ func (service *BlogServiceImpl) DeleteBlog(id string) error { return err } - if err := service.store.DeleteBlog(id); err != nil { + if err := service.store.DeleteBlog(ctx, id); err != nil { return err } From 31baa1c5ad8a2715ba31e0eb6fa3c455d46aee6c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:47:42 +0100 Subject: [PATCH 134/248] carousel service --- server/services/carouselService.go | 55 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/server/services/carouselService.go b/server/services/carouselService.go index f64d0ba..bd0fec3 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -1,19 +1,22 @@ package services import ( + "database/sql" "errors" "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" + "golang.org/x/net/context" "log" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" ) type CarouselService interface { - GetCarousels() ([]types.Carousel, error) - CreateCarousel(carousel *types.Carousel) (*types.ModelResult, error) - UpdateCarousel(id string, carousel *types.Carousel) (*types.ModelResult, error) - DeleteCarousel(id string) error + GetCarousels(ctx context.Context) ([]db.Carousel, error) + CreateCarousel(ctx context.Context, carousel *db.Carousel) (*types.ModelResult, error) + UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) (*types.ModelResult, error) + DeleteCarousel(ctx context.Context, id string) error } type CarouselServiceImpl struct { @@ -30,26 +33,33 @@ func NewCarouselService(store stores.CarouselStore, s3Client lib.S3Client, folde } } -func (service *CarouselServiceImpl) GetCarousels() ([]types.Carousel, error) { - return service.store.GetCarousels() +func (service *CarouselServiceImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { + carousels, err := service.store.GetCarousels(ctx) + if err != nil { + return nil, err + } + return carousels, nil } -func (service *CarouselServiceImpl) CreateCarousel(carousel *types.Carousel) (*types.ModelResult, error) { +func (service *CarouselServiceImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) (*types.ModelResult, error) { image := carousel.Image - if image == "" || image == "null" { + if image.Valid { return nil, errors.New("image is empty") } - presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image) + presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - carousel.Image = imageUrl + carousel.Image = sql.NullString{ + String: imageUrl, + Valid: true, + } - if err := service.store.CreateCarousel(carousel); err != nil { + if err := service.store.CreateCarousel(ctx, carousel); err != nil { return nil, err } @@ -61,22 +71,25 @@ func (service *CarouselServiceImpl) CreateCarousel(carousel *types.Carousel) (*t return result, nil } -func (service *CarouselServiceImpl) UpdateCarousel(id string, carousel *types.Carousel) (*types.ModelResult, error) { +func (service *CarouselServiceImpl) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) (*types.ModelResult, error) { image := carousel.Image var presignedUrl, imageUrl string var err error - if image != "" && image != "null" { - presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image) + if image.Valid { + presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - carousel.Image = imageUrl + carousel.Image = sql.NullString{ + String: imageUrl, + Valid: true, + } } - if err := service.store.UpdateCarousel(id, carousel); err != nil { + if err := service.store.UpdateCarousel(ctx, id, carousel); err != nil { return nil, err } @@ -88,17 +101,17 @@ func (service *CarouselServiceImpl) UpdateCarousel(id string, carousel *types.Ca return result, nil } -func (service *CarouselServiceImpl) DeleteCarousel(id string) error { - carousel, err := service.store.GetCarouselById(id) +func (service *CarouselServiceImpl) DeleteCarousel(ctx context.Context, id string) error { + carousel, err := service.store.GetCarouselById(ctx, id) if err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(carousel.Image); err != nil { + if err := service.s3Client.DeleteImageFromS3(carousel.Image.String); err != nil { return err } - if err := service.store.DeleteCarousel(id); err != nil { + if err := service.store.DeleteCarousel(ctx, id); err != nil { return err } From 28327b94a1f5bc7a3ea8d8085199b88316d5a274 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:49:55 +0100 Subject: [PATCH 135/248] carousel handler --- server/handlers/carouselHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/carouselHandler.go b/server/handlers/carouselHandler.go index b0b7319..7505158 100644 --- a/server/handlers/carouselHandler.go +++ b/server/handlers/carouselHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type CarouselHandler struct { @@ -18,7 +18,8 @@ func NewCarouselHandler(carouselService services.CarouselService) *CarouselHandl } func (handler *CarouselHandler) GetCarousels(context *gin.Context) { - carousels, err := handler.carouselService.GetCarousels() + ctx := context.Request.Context() + carousels, err := handler.carouselService.GetCarousels(ctx) if err != nil { log.Printf("error getting carousels: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting carousel images"}) @@ -29,14 +30,15 @@ func (handler *CarouselHandler) GetCarousels(context *gin.Context) { } func (handler *CarouselHandler) CreateCarousel(context *gin.Context) { - var carousel types.Carousel + ctx := context.Request.Context() + var carousel db.Carousel if err := context.ShouldBindJSON(&carousel); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - result, err := handler.carouselService.CreateCarousel(&carousel) + result, err := handler.carouselService.CreateCarousel(ctx, &carousel) if err != nil { log.Printf("Error creating carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating carousel", "details": err.Error()}) @@ -53,16 +55,17 @@ func (handler *CarouselHandler) CreateCarousel(context *gin.Context) { } func (handler *CarouselHandler) UpdateCarousel(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var carousel types.Carousel + var carousel db.Carousel if err := context.ShouldBindJSON(&carousel); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - result, err := handler.carouselService.UpdateCarousel(id, &carousel) + result, err := handler.carouselService.UpdateCarousel(ctx, id, &carousel) if err != nil { log.Printf("Error updating carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating carousel", "details": err.Error()}) @@ -79,9 +82,10 @@ func (handler *CarouselHandler) UpdateCarousel(context *gin.Context) { } func (handler *CarouselHandler) DeleteCarousel(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.carouselService.DeleteCarousel(id); err != nil { + if err := handler.carouselService.DeleteCarousel(ctx, id); err != nil { log.Printf("Error deleting carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting machine", "details": err.Error()}) return From 6f6755c165fc23c94bc25db87d0b205f098acfe2 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:52:01 +0100 Subject: [PATCH 136/248] checkout --- server/handlers/checkoutHandler.go | 3 ++- server/services/checkoutService.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/handlers/checkoutHandler.go b/server/handlers/checkoutHandler.go index 4708ea2..199ec69 100644 --- a/server/handlers/checkoutHandler.go +++ b/server/handlers/checkoutHandler.go @@ -17,9 +17,10 @@ func NewCheckoutHandler(service services.CheckoutService) *CheckoutHandler { } func (handler *CheckoutHandler) CreateCheckoutSession(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - sess, err := handler.service.CreateCheckoutSession(id) + sess, err := handler.service.CreateCheckoutSession(ctx, id) if err != nil { log.Printf("error occurred in checkout service: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred when trying to create checkout session"}) diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 3e9e250..123c90e 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -2,6 +2,7 @@ package services import ( "github.com/sean-david-welch/farmec-v2/server/lib" + "golang.org/x/net/context" "log" "github.com/sean-david-welch/farmec-v2/server/stores" @@ -10,7 +11,7 @@ import ( ) type CheckoutService interface { - CreateCheckoutSession(id string) (*stripe.CheckoutSession, error) + CreateCheckoutSession(ctx context.Context, id string) (*stripe.CheckoutSession, error) RetrieveCheckoutSession(sessionId string) (*stripe.CheckoutSession, error) } @@ -22,12 +23,12 @@ type CheckoutServiceImpl struct { func NewCheckoutService(secrets *lib.Secrets, store stores.LineItemStore) *CheckoutServiceImpl { return &CheckoutServiceImpl{secrets: secrets, store: store} } -func (service *CheckoutServiceImpl) CreateCheckoutSession(id string) (*stripe.CheckoutSession, error) { +func (service *CheckoutServiceImpl) CreateCheckoutSession(ctx context.Context, id string) (*stripe.CheckoutSession, error) { stripe.Key = service.secrets.StripeSecretKey log.Printf("Creating checkout session for product ID: %s", id) - product, err := service.store.GetLineItemById(id) + product, err := service.store.GetLineItemById(ctx, id) if err != nil { log.Printf("Error retrieving product by ID: %v", err) return nil, err @@ -45,7 +46,7 @@ func (service *CheckoutServiceImpl) CreateCheckoutSession(id string) (*stripe.Ch Currency: stripe.String("eur"), ProductData: &stripe.CheckoutSessionLineItemPriceDataProductDataParams{ Name: stripe.String(product.Name), - Images: stripe.StringSlice([]string{product.Image}), + Images: stripe.StringSlice([]string{product.Image.String}), }, UnitAmount: stripe.Int64(int64(product.Price * 100)), }, From 7a2012915fbedf7c9866fcfc9ceebdc6440a5773 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:56:53 +0100 Subject: [PATCH 137/248] employee service --- server/services/employeeService.go | 49 ++++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 68f49cb..83b746d 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -1,7 +1,10 @@ package services import ( + "context" + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -10,10 +13,10 @@ import ( ) type EmployeeService interface { - GetEmployees() ([]types.Employee, error) - CreateEmployee(employee *types.Employee) (*types.ModelResult, error) - UpdateEmployee(id string, employee *types.Employee) (*types.ModelResult, error) - DeleteEmployee(id string) error + GetEmployees(ctx context.Context) ([]db.Employee, error) + CreateEmployee(ctx context.Context, employee *db.Employee) (*types.ModelResult, error) + UpdateEmployee(ctx context.Context, id string, employee *db.Employee) (*types.ModelResult, error) + DeleteEmployee(ctx context.Context, id string) error } type EmployeeServiceImpl struct { @@ -26,8 +29,8 @@ func NewEmployeeService(store stores.EmployeeStore, s3Client lib.S3Client, folde return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *EmployeeServiceImpl) GetEmployees() ([]types.Employee, error) { - employees, err := service.store.GetEmployees() +func (service *EmployeeServiceImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { + employees, err := service.store.GetEmployees(ctx) if err != nil { return nil, err } @@ -35,22 +38,25 @@ func (service *EmployeeServiceImpl) GetEmployees() ([]types.Employee, error) { return employees, nil } -func (service *EmployeeServiceImpl) CreateEmployee(employee *types.Employee) (*types.ModelResult, error) { +func (service *EmployeeServiceImpl) CreateEmployee(ctx context.Context, employee *db.Employee) (*types.ModelResult, error) { image := employee.ProfileImage - if image == "" || image == "null" { + if image.Valid { return nil, errors.New("image is empty") } - PresignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image) + PresignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - employee.ProfileImage = imageUrl + employee.ProfileImage = sql.NullString{ + String: imageUrl, + Valid: true, + } - if err := service.store.CreateEmployee(employee); err != nil { + if err := service.store.CreateEmployee(ctx, employee); err != nil { return nil, err } @@ -62,22 +68,25 @@ func (service *EmployeeServiceImpl) CreateEmployee(employee *types.Employee) (*t return result, nil } -func (service *EmployeeServiceImpl) UpdateEmployee(id string, employee *types.Employee) (*types.ModelResult, error) { +func (service *EmployeeServiceImpl) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) (*types.ModelResult, error) { image := employee.ProfileImage var PresignedUrl, imageUrl string var err error - if image != "" && image != "null" { - PresignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image) + if image.Valid { + PresignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - employee.ProfileImage = imageUrl + employee.ProfileImage = sql.NullString{ + String: imageUrl, + Valid: true, + } } - if err := service.store.UpdateEmployee(id, employee); err != nil { + if err := service.store.UpdateEmployee(ctx, id, employee); err != nil { return nil, err } @@ -89,17 +98,17 @@ func (service *EmployeeServiceImpl) UpdateEmployee(id string, employee *types.Em return result, nil } -func (service *EmployeeServiceImpl) DeleteEmployee(id string) error { - employee, err := service.store.GetEmployeeById(id) +func (service *EmployeeServiceImpl) DeleteEmployee(ctx context.Context, id string) error { + employee, err := service.store.GetEmployeeById(ctx, id) if err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(employee.ProfileImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(employee.ProfileImage.String); err != nil { return err } - if err := service.store.DeleteEmployee(id); err != nil { + if err := service.store.DeleteEmployee(ctx, id); err != nil { return err } From 58ff3b529feb086941685bedd9ffd340ebf6ed4c Mon Sep 17 00:00:00 2001 From: seanwelch Date: Mon, 2 Sep 2024 21:59:01 +0100 Subject: [PATCH 138/248] employee handler --- server/handlers/employeeHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/employeeHandler.go b/server/handlers/employeeHandler.go index d16b11c..bc806eb 100644 --- a/server/handlers/employeeHandler.go +++ b/server/handlers/employeeHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type EmployeeHandler struct { @@ -18,7 +18,8 @@ func NewEmployeeHandler(service services.EmployeeService) *EmployeeHandler { } func (handler *EmployeeHandler) GetEmployees(context *gin.Context) { - employees, err := handler.service.GetEmployees() + ctx := context.Request.Context() + employees, err := handler.service.GetEmployees(ctx) if err != nil { log.Printf("error getting employees: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting employees"}) @@ -29,7 +30,8 @@ func (handler *EmployeeHandler) GetEmployees(context *gin.Context) { } func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { - var employee types.Employee + ctx := context.Request.Context() + var employee db.Employee if err := context.ShouldBindJSON(&employee); err != nil { log.Printf("Error creating employee: %v", err) @@ -37,7 +39,7 @@ func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { return } - result, err := handler.service.CreateEmployee(&employee) + result, err := handler.service.CreateEmployee(ctx, &employee) if err != nil { log.Printf("Error creating employee: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating employee", "details": err.Error()}) @@ -54,8 +56,9 @@ func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { } func (handler *EmployeeHandler) UpdateEmployee(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var employee types.Employee + var employee db.Employee if err := context.ShouldBindJSON(&employee); err != nil { log.Printf("Error creating employee: %v", err) @@ -63,7 +66,7 @@ func (handler *EmployeeHandler) UpdateEmployee(context *gin.Context) { return } - result, err := handler.service.UpdateEmployee(id, &employee) + result, err := handler.service.UpdateEmployee(ctx, id, &employee) if err != nil { log.Printf("Error creating employee: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating employee", "details": err.Error()}) @@ -80,9 +83,10 @@ func (handler *EmployeeHandler) UpdateEmployee(context *gin.Context) { } func (handler *EmployeeHandler) DeleteEmployee(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteEmployee(id); err != nil { + if err := handler.service.DeleteEmployee(ctx, id); err != nil { log.Printf("Error deleting employee: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting employee", "details": err.Error()}) return From b90d0acae04b64e5b98f1f69d18e9e77626102f9 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 10:40:50 +0100 Subject: [PATCH 139/248] exhibitions service context --- server/services/exhibitionService.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index 50e5a42..04b8f50 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -1,15 +1,16 @@ package services import ( + "context" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" ) type ExhibitionService interface { - GetExhibitions() ([]types.Exhibition, error) - CreateExhibition(exhibition *types.Exhibition) error - UpdateExhibition(id string, exhibition *types.Exhibition) error - DeleteExhibition(id string) error + GetExhibitions(ctx context.Context) ([]db.Exhibition, error) + CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error + UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error + DeleteExhibition(ctx context.Context, id string) error } type ExhibitionServiceImpl struct { @@ -20,8 +21,8 @@ func NewExhibitionService(store stores.ExhibitionStore) *ExhibitionServiceImpl { return &ExhibitionServiceImpl{store: store} } -func (service *ExhibitionServiceImpl) GetExhibitions() ([]types.Exhibition, error) { - exhibitions, err := service.store.GetExhibitions() +func (service *ExhibitionServiceImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { + exhibitions, err := service.store.GetExhibitions(ctx) if err != nil { return nil, err } @@ -29,24 +30,24 @@ func (service *ExhibitionServiceImpl) GetExhibitions() ([]types.Exhibition, erro return exhibitions, nil } -func (service *ExhibitionServiceImpl) CreateExhibition(exhibition *types.Exhibition) error { - if err := service.store.CreateExhibition(exhibition); err != nil { +func (service *ExhibitionServiceImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { + if err := service.store.CreateExhibition(ctx, exhibition); err != nil { return err } return nil } -func (service *ExhibitionServiceImpl) UpdateExhibition(id string, exhibition *types.Exhibition) error { - if err := service.store.UpdateExhibition(id, exhibition); err != nil { +func (service *ExhibitionServiceImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { + if err := service.store.UpdateExhibition(ctx, id, exhibition); err != nil { return err } return nil } -func (service *ExhibitionServiceImpl) DeleteExhibition(id string) error { - if err := service.store.DeleteExhibition(id); err != nil { +func (service *ExhibitionServiceImpl) DeleteExhibition(ctx context.Context, id string) error { + if err := service.store.DeleteExhibition(ctx, id); err != nil { return err } From 71eaf55968eed36c9417457e0f7bc6a669b1819b Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 10:44:20 +0100 Subject: [PATCH 140/248] exhibitions handler context --- server/handlers/exhibitionHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/exhibitionHandler.go b/server/handlers/exhibitionHandler.go index 0c9820d..1521379 100644 --- a/server/handlers/exhibitionHandler.go +++ b/server/handlers/exhibitionHandler.go @@ -5,8 +5,8 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type ExhibitionHandler struct { @@ -18,7 +18,8 @@ func NewExhibitionHandler(service services.ExhibitionService) *ExhibitionHandler } func (handler *ExhibitionHandler) GetExhibitions(context *gin.Context) { - exhibitions, err := handler.service.GetExhibitions() + ctx := context.Request.Context() + exhibitions, err := handler.service.GetExhibitions(ctx) if err != nil { log.Printf("error getting exhibitions: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting exhibitions"}) @@ -29,14 +30,15 @@ func (handler *ExhibitionHandler) GetExhibitions(context *gin.Context) { } func (handler *ExhibitionHandler) CreateExhibition(context *gin.Context) { - var exhibition *types.Exhibition + ctx := context.Request.Context() + var exhibition *db.Exhibition if err := context.ShouldBindJSON(&exhibition); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreateExhibition(exhibition); err != nil { + if err := handler.service.CreateExhibition(ctx, exhibition); err != nil { log.Printf("error occurred while creating exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating exhibition", "details": err.Error()}) return @@ -46,16 +48,17 @@ func (handler *ExhibitionHandler) CreateExhibition(context *gin.Context) { } func (handler *ExhibitionHandler) UpdateExhibition(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var exhibition *types.Exhibition + var exhibition *db.Exhibition if err := context.ShouldBindJSON(&exhibition); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdateExhibition(id, exhibition); err != nil { + if err := handler.service.UpdateExhibition(ctx, id, exhibition); err != nil { log.Printf("error occurred while updating exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating exhibition", "details": err.Error()}) return @@ -65,9 +68,10 @@ func (handler *ExhibitionHandler) UpdateExhibition(context *gin.Context) { } func (handler *ExhibitionHandler) DeleteExhibition(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteExhibition(id); err != nil { + if err := handler.service.DeleteExhibition(ctx, id); err != nil { log.Printf("error occurred while deleting exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while deleting exhibition"}) return From 7698c5905d25d2a5c92e2a45cd8de5c3af0dedfb Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 10:53:49 +0100 Subject: [PATCH 141/248] line item service --- server/services/lineItemService.go | 55 +++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index 1a94295..f5f7c71 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -1,7 +1,10 @@ package services import ( + "context" + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -10,11 +13,11 @@ import ( ) type LineItemService interface { - GetLineItems() ([]types.LineItem, error) - GetLineItemById(id string) (*types.LineItem, error) - CreateLineItem(lineItem *types.LineItem) (*types.ModelResult, error) - UpdateLineItem(id string, lineItem *types.LineItem) (*types.ModelResult, error) - DeleteLineItem(id string) error + GetLineItems(ctx context.Context) ([]db.LineItem, error) + GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) + CreateLineItem(ctx context.Context, lineItem *db.LineItem) (*types.ModelResult, error) + UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) (*types.ModelResult, error) + DeleteLineItem(ctx context.Context, id string) error } type LineItemServiceImpl struct { @@ -27,8 +30,8 @@ func NewLineItemService(store stores.LineItemStore, s3Client lib.S3Client, folde return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *LineItemServiceImpl) GetLineItems() ([]types.LineItem, error) { - lineItems, err := service.store.GetLineItems() +func (service *LineItemServiceImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { + lineItems, err := service.store.GetLineItems(ctx) if err != nil { return nil, err } @@ -36,8 +39,8 @@ func (service *LineItemServiceImpl) GetLineItems() ([]types.LineItem, error) { return lineItems, nil } -func (service *LineItemServiceImpl) GetLineItemById(id string) (*types.LineItem, error) { - lineItem, err := service.store.GetLineItemById(id) +func (service *LineItemServiceImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { + lineItem, err := service.store.GetLineItemById(ctx, id) if err != nil { return nil, err } @@ -45,22 +48,25 @@ func (service *LineItemServiceImpl) GetLineItemById(id string) (*types.LineItem, return lineItem, nil } -func (service *LineItemServiceImpl) CreateLineItem(lineItem *types.LineItem) (*types.ModelResult, error) { +func (service *LineItemServiceImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) (*types.ModelResult, error) { image := lineItem.Image - if image == "" || image == "null" { + if image.Valid { return nil, errors.New("image is empty") } - PresignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image) + PresignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - lineItem.Image = imageUrl + lineItem.Image = sql.NullString{ + String: imageUrl, + Valid: true, + } - if err := service.store.CreateLineItem(lineItem); err != nil { + if err := service.store.CreateLineItem(ctx, lineItem); err != nil { return nil, err } @@ -72,22 +78,25 @@ func (service *LineItemServiceImpl) CreateLineItem(lineItem *types.LineItem) (*t return result, nil } -func (service *LineItemServiceImpl) UpdateLineItem(id string, lineItem *types.LineItem) (*types.ModelResult, error) { +func (service *LineItemServiceImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) (*types.ModelResult, error) { image := lineItem.Image var PresignedUrl, imageUrl string var err error - if image != "" && image != "null" { - PresignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image) + if image.Valid { + PresignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, image.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - lineItem.Image = imageUrl + lineItem.Image = sql.NullString{ + String: imageUrl, + Valid: true, + } } - if err := service.store.UpdateLineItem(id, lineItem); err != nil { + if err := service.store.UpdateLineItem(ctx, id, lineItem); err != nil { return nil, err } @@ -99,17 +108,17 @@ func (service *LineItemServiceImpl) UpdateLineItem(id string, lineItem *types.Li return result, nil } -func (service *LineItemServiceImpl) DeleteLineItem(id string) error { - lineItem, err := service.store.GetLineItemById(id) +func (service *LineItemServiceImpl) DeleteLineItem(ctx context.Context, id string) error { + lineItem, err := service.store.GetLineItemById(ctx, id) if err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(lineItem.Image); err != nil { + if err := service.s3Client.DeleteImageFromS3(lineItem.Image.String); err != nil { return err } - if err := service.store.DeleteLineItem(id); err != nil { + if err := service.store.DeleteLineItem(ctx, id); err != nil { return err } From 5da8922e63509d31f835ec3da5c662eb8c16a8ef Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 10:57:25 +0100 Subject: [PATCH 142/248] line item handler --- server/handlers/lineItemHandler.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/handlers/lineItemHandler.go b/server/handlers/lineItemHandler.go index 9845bac..a79191f 100644 --- a/server/handlers/lineItemHandler.go +++ b/server/handlers/lineItemHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type LineItemHandler struct { @@ -18,7 +18,8 @@ func NewLineItemHandler(service services.LineItemService) *LineItemHandler { } func (handler *LineItemHandler) GetLineItems(context *gin.Context) { - lineItems, err := handler.service.GetLineItems() + ctx := context.Request.Context() + lineItems, err := handler.service.GetLineItems(ctx) if err != nil { log.Printf("error occurred while getting lineItems: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting LineItem"}) @@ -29,7 +30,8 @@ func (handler *LineItemHandler) GetLineItems(context *gin.Context) { } func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { - var lineItem types.LineItem + ctx := context.Request.Context() + var lineItem db.LineItem if err := context.ShouldBindJSON(&lineItem); err != nil { log.Printf("error when creating lineItem: %v", err) @@ -37,7 +39,7 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { return } - result, err := handler.service.CreateLineItem(&lineItem) + result, err := handler.service.CreateLineItem(ctx, &lineItem) if err != nil { log.Printf("error when creating lineItem: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when creating lineItem"}) @@ -53,9 +55,10 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { } func (handler *LineItemHandler) GetLineItemById(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - lineItem, err := handler.service.GetLineItemById(id) + lineItem, err := handler.service.GetLineItemById(ctx, id) if err != nil { log.Printf("error occurred while getting lineItem: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting lineItem"}) @@ -66,8 +69,9 @@ func (handler *LineItemHandler) GetLineItemById(context *gin.Context) { } func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var lineItem types.LineItem + var lineItem db.LineItem if err := context.ShouldBindJSON(&lineItem); err != nil { log.Printf("error when updating lineItem: %v", err) @@ -75,7 +79,7 @@ func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { return } - result, err := handler.service.UpdateLineItem(id, &lineItem) + result, err := handler.service.UpdateLineItem(ctx, id, &lineItem) if err != nil { log.Printf("error when updating lineItem: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when updating lineItem"}) @@ -91,9 +95,10 @@ func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { } func (handler *LineItemHandler) DeleteLineItem(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteLineItem(id); err != nil { + if err := handler.service.DeleteLineItem(ctx, id); err != nil { log.Printf("error occurred while deleting lineItem: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error while deleting lineItem"}) } From 6f59fcb8d6a0b619f03ed845ab1277b1bc924fc2 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 11:06:16 +0100 Subject: [PATCH 143/248] machine service --- server/services/machineService.go | 55 ++++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/server/services/machineService.go b/server/services/machineService.go index 568d279..64d90d5 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -1,7 +1,10 @@ package services import ( + "context" + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -10,11 +13,11 @@ import ( ) type MachineService interface { - GetMachines(id string) ([]types.Machine, error) - GetMachineById(id string) (*types.Machine, error) - CreateMachine(machine *types.Machine) (*types.ModelResult, error) - UpdateMachine(id string, machine *types.Machine) (*types.ModelResult, error) - DeleteMachine(id string) error + GetMachines(ctx context.Context, id string) ([]db.Machine, error) + GetMachineById(ctx context.Context, id string) (*db.Machine, error) + CreateMachine(ctx context.Context, machine *db.Machine) (*types.ModelResult, error) + UpdateMachine(ctx context.Context, id string, machine *db.Machine) (*types.ModelResult, error) + DeleteMachine(ctx context.Context, id string) error } type MachineServiceImpl struct { @@ -31,8 +34,8 @@ func NewMachineService(store stores.MachineStore, s3Client lib.S3Client, folder } } -func (service *MachineServiceImpl) GetMachines(id string) ([]types.Machine, error) { - machines, err := service.store.GetMachines(id) +func (service *MachineServiceImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { + machines, err := service.store.GetMachines(ctx, id) if err != nil { return nil, errors.New("machines with supplier_id not foud") } @@ -40,8 +43,8 @@ func (service *MachineServiceImpl) GetMachines(id string) ([]types.Machine, erro return machines, nil } -func (service *MachineServiceImpl) GetMachineById(id string) (*types.Machine, error) { - machine, err := service.store.GetMachineById(id) +func (service *MachineServiceImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { + machine, err := service.store.GetMachineById(ctx, id) if err != nil { return nil, errors.New("machine with id not found") } @@ -49,21 +52,24 @@ func (service *MachineServiceImpl) GetMachineById(id string) (*types.Machine, er return machine, nil } -func (service *MachineServiceImpl) CreateMachine(machine *types.Machine) (*types.ModelResult, error) { +func (service *MachineServiceImpl) CreateMachine(ctx context.Context, machine *db.Machine) (*types.ModelResult, error) { machineImage := machine.MachineImage - if machineImage == "" { + if !machineImage.Valid { return nil, errors.New("machine image is empty") } - presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, machineImage) + presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, machineImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - machine.MachineImage = imageUrl + machine.MachineImage = sql.NullString{ + String: imageUrl, + Valid: true, + } - err = service.store.CreateMachine(machine) + err = service.store.CreateMachine(ctx, machine) if err != nil { return nil, err } @@ -76,22 +82,25 @@ func (service *MachineServiceImpl) CreateMachine(machine *types.Machine) (*types return result, nil } -func (service *MachineServiceImpl) UpdateMachine(id string, machine *types.Machine) (*types.ModelResult, error) { +func (service *MachineServiceImpl) UpdateMachine(ctx context.Context, id string, machine *db.Machine) (*types.ModelResult, error) { machineImage := machine.MachineImage var presignedUrl, imageUrl string var err error - if machineImage != "" && machineImage != "null" { - presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, machineImage) + if machineImage.Valid { + presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, machineImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - machine.MachineImage = imageUrl + machine.MachineImage = sql.NullString{ + String: imageUrl, + Valid: true, + } } - err = service.store.UpdateMachine(id, machine) + err = service.store.UpdateMachine(ctx, id, machine) if err != nil { return nil, err } @@ -104,17 +113,17 @@ func (service *MachineServiceImpl) UpdateMachine(id string, machine *types.Machi return result, nil } -func (service *MachineServiceImpl) DeleteMachine(id string) error { - machine, err := service.store.GetMachineById(id) +func (service *MachineServiceImpl) DeleteMachine(ctx context.Context, id string) error { + machine, err := service.store.GetMachineById(ctx, id) if err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(machine.MachineImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(machine.MachineImage.String); err != nil { return err } - if err := service.store.DeleteMachine(id); err != nil { + if err := service.store.DeleteMachine(ctx, id); err != nil { return err } From 7a4e32cc966ae53fa2546b6d15e5d3fb3eb7dabd Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 11:06:30 +0100 Subject: [PATCH 144/248] rename !valid --- server/services/carouselService.go | 2 +- server/services/employeeService.go | 2 +- server/services/lineItemService.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/services/carouselService.go b/server/services/carouselService.go index bd0fec3..38ddaf6 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -44,7 +44,7 @@ func (service *CarouselServiceImpl) GetCarousels(ctx context.Context) ([]db.Caro func (service *CarouselServiceImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) (*types.ModelResult, error) { image := carousel.Image - if image.Valid { + if !image.Valid { return nil, errors.New("image is empty") } diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 83b746d..28cf429 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -41,7 +41,7 @@ func (service *EmployeeServiceImpl) GetEmployees(ctx context.Context) ([]db.Empl func (service *EmployeeServiceImpl) CreateEmployee(ctx context.Context, employee *db.Employee) (*types.ModelResult, error) { image := employee.ProfileImage - if image.Valid { + if !image.Valid { return nil, errors.New("image is empty") } diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index f5f7c71..fbbf91b 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -51,7 +51,7 @@ func (service *LineItemServiceImpl) GetLineItemById(ctx context.Context, id stri func (service *LineItemServiceImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) (*types.ModelResult, error) { image := lineItem.Image - if image.Valid { + if !image.Valid { return nil, errors.New("image is empty") } From 5e43a83407721aed973b0477ab4c3869d947c268 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 11:09:00 +0100 Subject: [PATCH 145/248] machine handler --- server/handlers/machineHandler.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/handlers/machineHandler.go b/server/handlers/machineHandler.go index 0400806..a533c9f 100644 --- a/server/handlers/machineHandler.go +++ b/server/handlers/machineHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type MachineHandler struct { @@ -18,9 +18,10 @@ func NewMachineHandler(machineService services.MachineService) *MachineHandler { } func (handler *MachineHandler) GetMachines(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - machines, err := handler.machineService.GetMachines(id) + machines, err := handler.machineService.GetMachines(ctx, id) if err != nil { log.Printf("Error getting machines: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting machines"}) @@ -31,9 +32,10 @@ func (handler *MachineHandler) GetMachines(context *gin.Context) { } func (handler *MachineHandler) GetMachineById(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - machine, err := handler.machineService.GetMachineById(id) + machine, err := handler.machineService.GetMachineById(ctx, id) if err != nil { log.Printf("Error getting machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting machine"}) @@ -44,7 +46,8 @@ func (handler *MachineHandler) GetMachineById(context *gin.Context) { } func (handler *MachineHandler) CreateMachine(context *gin.Context) { - var machine types.Machine + ctx := context.Request.Context() + var machine db.Machine if err := context.ShouldBindJSON(&machine); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) @@ -56,7 +59,7 @@ func (handler *MachineHandler) CreateMachine(context *gin.Context) { return } - result, err := handler.machineService.CreateMachine(&machine) + result, err := handler.machineService.CreateMachine(ctx, &machine) if err != nil { log.Printf("Error creating machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating machine", "details": err.Error()}) @@ -73,9 +76,10 @@ func (handler *MachineHandler) CreateMachine(context *gin.Context) { } func (handler *MachineHandler) UpdateMachine(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var machine types.Machine + var machine db.Machine if err := context.ShouldBindJSON(&machine); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) @@ -87,7 +91,7 @@ func (handler *MachineHandler) UpdateMachine(context *gin.Context) { return } - result, err := handler.machineService.UpdateMachine(id, &machine) + result, err := handler.machineService.UpdateMachine(ctx, id, &machine) if err != nil { log.Printf("Error updating machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) @@ -104,9 +108,10 @@ func (handler *MachineHandler) UpdateMachine(context *gin.Context) { } func (handler *MachineHandler) DeleteMachine(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.machineService.DeleteMachine(id); err != nil { + if err := handler.machineService.DeleteMachine(ctx, id); err != nil { log.Printf("Error deleting machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting machine", "details": err.Error()}) return From 84e62611f7a951a6dc9b895ac2e7612130940881 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 11:21:08 +0100 Subject: [PATCH 146/248] parts service --- server/services/partsService.go | 86 +++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 30 deletions(-) diff --git a/server/services/partsService.go b/server/services/partsService.go index 5d4bf32..e77fcd7 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -1,7 +1,10 @@ package services import ( + "context" + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" url2 "net/url" @@ -11,10 +14,10 @@ import ( ) type PartsService interface { - GetParts(id string) ([]types.Sparepart, error) - CreatePart(part *types.Sparepart) (*types.PartsModelResult, error) - UpdatePart(id string, part *types.Sparepart) (*types.PartsModelResult, error) - DeletePart(id string) error + GetParts(ctx context.Context, id string) ([]db.SparePart, error) + CreatePart(ctx context.Context, part *db.SparePart) (*types.PartsModelResult, error) + UpdatePart(ctx context.Context, id string, part *db.SparePart) (*types.PartsModelResult, error) + DeletePart(ctx context.Context, id string) error } type PartsServiceImpl struct { @@ -31,29 +34,40 @@ func NewPartsService(store stores.PartsStore, s3Client lib.S3Client, folder stri } } -func (service *PartsServiceImpl) GetParts(id string) ([]types.Sparepart, error) { - return service.store.GetParts(id) +func (service *PartsServiceImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { + parts, err := service.store.GetParts(ctx, id) + if err != nil { + return nil, err + } + return parts, nil } -func (service *PartsServiceImpl) CreatePart(part *types.Sparepart) (*types.PartsModelResult, error) { +func (service *PartsServiceImpl) CreatePart(ctx context.Context, part *db.SparePart) (*types.PartsModelResult, error) { partsImage := part.PartsImage - if partsImage == "" || partsImage == "null" { + if !partsImage.Valid { return nil, errors.New("image is empty") } - presignedImageUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, partsImage) + + presignedImageUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, partsImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - part.PartsImage = imageUrl + part.PartsImage = sql.NullString{ + String: imageUrl, + Valid: true, + } var partsLinkUrl, presignedLinkUrl string - partsLink := part.SparePartsLink - u, err := url2.Parse(partsLink) + partsLink := sql.NullString{ + String: part.SparePartsLink.String, + Valid: true, + } + u, err := url2.Parse(partsLink.String) if err == nil && u.Scheme != "" && u.Host != "" { - partsLinkUrl = partsLink + partsLinkUrl = partsLink.String } else { - presignedUrl, linkUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, partsLink) + presignedUrl, linkUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, partsLink.String) if err != nil { log.Printf("error occurred while generating presigned url for link: %v", err) return nil, err @@ -61,9 +75,12 @@ func (service *PartsServiceImpl) CreatePart(part *types.Sparepart) (*types.Parts partsLinkUrl = linkUrl presignedLinkUrl = presignedUrl } - part.SparePartsLink = partsLinkUrl + part.SparePartsLink = sql.NullString{ + String: partsLinkUrl, + Valid: true, + } - err = service.store.CreatePart(part) + err = service.store.CreatePart(ctx, part) if err != nil { log.Printf("Failed to create part: %v", err) return nil, err @@ -78,28 +95,34 @@ func (service *PartsServiceImpl) CreatePart(part *types.Sparepart) (*types.Parts return result, nil } -func (service *PartsServiceImpl) UpdatePart(id string, part *types.Sparepart) (*types.PartsModelResult, error) { +func (service *PartsServiceImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) (*types.PartsModelResult, error) { partsImage := part.PartsImage var presignedUrl, imageUrl string var err error - if partsImage != "" && partsImage != "null" { - presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, partsImage) + if partsImage.Valid { + presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, partsImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - part.PartsImage = imageUrl + part.PartsImage = sql.NullString{ + String: imageUrl, + Valid: true, + } } var partsLinkUrl, presignedLinkUrl string - partsLink := part.SparePartsLink + partsLink := sql.NullString{ + String: part.SparePartsLink.String, + Valid: true, + } - u, err := url2.Parse(partsLink) + u, err := url2.Parse(partsLink.String) if err == nil && u.Scheme != "" && u.Host != "" { - partsLinkUrl = partsLink + partsLinkUrl = partsLink.String } else { - presignedUrl, linkUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, partsLink) + presignedUrl, linkUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, partsLink.String) if err != nil { log.Printf("error occurred while generating presigned url for link: %v", err) return nil, err @@ -107,9 +130,12 @@ func (service *PartsServiceImpl) UpdatePart(id string, part *types.Sparepart) (* partsLinkUrl = linkUrl presignedLinkUrl = presignedUrl } - part.SparePartsLink = partsLinkUrl + part.SparePartsLink = sql.NullString{ + String: partsLinkUrl, + Valid: true, + } - err = service.store.UpdatePart(id, part) + err = service.store.UpdatePart(ctx, id, part) if err != nil { log.Printf("Failed to update part: %v", err) return nil, err @@ -124,17 +150,17 @@ func (service *PartsServiceImpl) UpdatePart(id string, part *types.Sparepart) (* return result, nil } -func (service *PartsServiceImpl) DeletePart(id string) error { - part, err := service.store.GetPartById(id) +func (service *PartsServiceImpl) DeletePart(ctx context.Context, id string) error { + part, err := service.store.GetPartById(ctx, id) if err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(part.PartsImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(part.PartsImage.String); err != nil { return err } - if err := service.store.DeletePart(id); err != nil { + if err := service.store.DeletePart(ctx, id); err != nil { return err } From 939f81a1557c0fab4bee3e2e97f8b4aed871e74a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 11:27:08 +0100 Subject: [PATCH 147/248] parts handler --- server/handlers/partsHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/partsHandler.go b/server/handlers/partsHandler.go index 7892970..c7caff3 100644 --- a/server/handlers/partsHandler.go +++ b/server/handlers/partsHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type PartsHandler struct { @@ -18,9 +18,10 @@ func NewPartsHandler(partsService services.PartsService) *PartsHandler { } func (handler *PartsHandler) GetParts(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - parts, err := handler.partsService.GetParts(id) + parts, err := handler.partsService.GetParts(ctx, id) if err != nil { log.Printf("Error getting parts: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting parts"}) @@ -31,7 +32,8 @@ func (handler *PartsHandler) GetParts(context *gin.Context) { } func (handler *PartsHandler) CreateParts(context *gin.Context) { - var part types.Sparepart + ctx := context.Request.Context() + var part db.SparePart if err := context.ShouldBindJSON(&part); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Ivalid request body", "details": err.Error()}) @@ -43,7 +45,7 @@ func (handler *PartsHandler) CreateParts(context *gin.Context) { return } - result, err := handler.partsService.CreatePart(&part) + result, err := handler.partsService.CreatePart(ctx, &part) if err != nil { log.Printf("Error creating part: %v", err) context.JSON(http.StatusInternalServerError, @@ -62,9 +64,10 @@ func (handler *PartsHandler) CreateParts(context *gin.Context) { } func (handler *PartsHandler) UpdateParts(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var part types.Sparepart + var part db.SparePart if err := context.ShouldBindJSON(&part); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "details": err.Error()}) @@ -76,7 +79,7 @@ func (handler *PartsHandler) UpdateParts(context *gin.Context) { return } - result, err := handler.partsService.UpdatePart(id, &part) + result, err := handler.partsService.UpdatePart(ctx, id, &part) if err != nil { log.Printf("Error updating part: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) @@ -94,9 +97,10 @@ func (handler *PartsHandler) UpdateParts(context *gin.Context) { } func (handler *PartsHandler) DeletePart(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.partsService.DeletePart(id); err != nil { + if err := handler.partsService.DeletePart(ctx, id); err != nil { log.Printf("Erroir deleting part: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurrrd while deleting part", "details": err.Error()}) return From b1980f8ca15117613c7b929dbc705b13aa886d3a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:23:34 +0100 Subject: [PATCH 148/248] privacy service --- server/services/privacyService.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/server/services/privacyService.go b/server/services/privacyService.go index a7ce5d6..a70a7cc 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -1,15 +1,16 @@ package services import ( + "context" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" ) type PrivacyService interface { - GetPrivacys() ([]types.Privacy, error) - CreatePrivacy(privacy *types.Privacy) error - UpdatePrivacy(id string, privacy *types.Privacy) error - DeletePrivacy(id string) error + GetPrivacys(ctx context.Context) ([]db.Privacy, error) + CreatePrivacy(ctx context.Context, privacy *db.Privacy) error + UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error + DeletePrivacy(ctx context.Context, id string) error } type PrivacyServiceImpl struct { @@ -20,8 +21,8 @@ func NewPrivacyService(store stores.PrivacyStore) *PrivacyServiceImpl { return &PrivacyServiceImpl{store: store} } -func (service *PrivacyServiceImpl) GetPrivacys() ([]types.Privacy, error) { - privacys, err := service.store.GetPrivacy() +func (service *PrivacyServiceImpl) GetPrivacys(ctx context.Context) ([]db.Privacy, error) { + privacys, err := service.store.GetPrivacy(ctx) if err != nil { return nil, err } @@ -29,24 +30,24 @@ func (service *PrivacyServiceImpl) GetPrivacys() ([]types.Privacy, error) { return privacys, nil } -func (service *PrivacyServiceImpl) CreatePrivacy(privacy *types.Privacy) error { - if err := service.store.CreatePrivacy(privacy); err != nil { +func (service *PrivacyServiceImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { + if err := service.store.CreatePrivacy(ctx, privacy); err != nil { return err } return nil } -func (service *PrivacyServiceImpl) UpdatePrivacy(id string, privacy *types.Privacy) error { - if err := service.store.UpdatePrivacy(id, privacy); err != nil { +func (service *PrivacyServiceImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { + if err := service.store.UpdatePrivacy(ctx, id, privacy); err != nil { return err } return nil } -func (service *PrivacyServiceImpl) DeletePrivacy(id string) error { - if err := service.store.DeletePrivacy(id); err != nil { +func (service *PrivacyServiceImpl) DeletePrivacy(ctx context.Context, id string) error { + if err := service.store.DeletePrivacy(ctx, id); err != nil { return err } From c0a990c30674e439a0ee35534b49efa552dbbc3d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:25:01 +0100 Subject: [PATCH 149/248] privacy handler --- server/handlers/privacyHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/privacyHandler.go b/server/handlers/privacyHandler.go index e47805f..f88d97f 100644 --- a/server/handlers/privacyHandler.go +++ b/server/handlers/privacyHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type PrivacyHandler struct { @@ -18,7 +18,8 @@ func NewPrivacyHandler(service services.PrivacyService) *PrivacyHandler { } func (handler *PrivacyHandler) GetPrivacys(context *gin.Context) { - privacys, err := handler.service.GetPrivacys() + ctx := context.Request.Context() + privacys, err := handler.service.GetPrivacys(ctx) if err != nil { log.Printf("error getting privacys: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting privacy"}) @@ -29,14 +30,15 @@ func (handler *PrivacyHandler) GetPrivacys(context *gin.Context) { } func (handler *PrivacyHandler) CreatePrivacy(context *gin.Context) { - var privacy types.Privacy + ctx := context.Request.Context() + var privacy db.Privacy if err := context.ShouldBindJSON(&privacy); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreatePrivacy(&privacy); err != nil { + if err := handler.service.CreatePrivacy(ctx, &privacy); err != nil { log.Printf("error while creating privacy: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating privacy", "details": err.Error()}) return @@ -46,15 +48,16 @@ func (handler *PrivacyHandler) CreatePrivacy(context *gin.Context) { } func (handler *PrivacyHandler) UpdatePrivacy(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var privacy types.Privacy + var privacy db.Privacy if err := context.ShouldBindJSON(&privacy); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdatePrivacy(id, &privacy); err != nil { + if err := handler.service.UpdatePrivacy(ctx, id, &privacy); err != nil { log.Printf("error while updating privacy: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating privacy", "details": err.Error()}) return @@ -64,9 +67,10 @@ func (handler *PrivacyHandler) UpdatePrivacy(context *gin.Context) { } func (handler *PrivacyHandler) DeletePrivacy(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeletePrivacy(id); err != nil { + if err := handler.service.DeletePrivacy(ctx, id); err != nil { log.Printf("Error deleting privacy: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting privacy", "details": err.Error()}) return From f72560fe353a30b6c8d708e08af3313a7dbf8e5a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:30:24 +0100 Subject: [PATCH 150/248] product service --- server/services/productService.go | 53 +++++++++++++++++++------------ 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/server/services/productService.go b/server/services/productService.go index bec0423..d4d47a9 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -1,7 +1,10 @@ package services import ( + "context" + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -10,10 +13,10 @@ import ( ) type ProductService interface { - GetProducts(id string) ([]types.Product, error) - CreateProduct(product *types.Product) (*types.ModelResult, error) - UpdateProduct(id string, product *types.Product) (*types.ModelResult, error) - DeleteProduct(id string) error + GetProducts(ctx context.Context, id string) ([]db.Product, error) + CreateProduct(ctx context.Context, product *db.Product) (*types.ModelResult, error) + UpdateProduct(ctx context.Context, id string, product *db.Product) (*types.ModelResult, error) + DeleteProduct(ctx context.Context, id string) error } type ProductServiceImpl struct { @@ -30,25 +33,32 @@ func NewProductService(store stores.ProductStore, s3Client lib.S3Client, folder } } -func (service *ProductServiceImpl) GetProducts(id string) ([]types.Product, error) { - return service.store.GetProducts(id) +func (service *ProductServiceImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { + products, err := service.store.GetProducts(ctx, id) + if err != nil { + return nil, err + } + return products, nil } -func (service *ProductServiceImpl) CreateProduct(product *types.Product) (*types.ModelResult, error) { +func (service *ProductServiceImpl) CreateProduct(ctx context.Context, product *db.Product) (*types.ModelResult, error) { productImage := product.ProductImage - if productImage == "" || productImage == "null" { + if !productImage.Valid { return nil, errors.New("image is empty") } - presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, productImage) + presignedUrl, imageUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, productImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - product.ProductImage = imageUrl + product.ProductImage = sql.NullString{ + String: imageUrl, + Valid: true, + } - err = service.store.CreateProduct(product) + err = service.store.CreateProduct(ctx, product) if err != nil { return nil, err } @@ -61,22 +71,25 @@ func (service *ProductServiceImpl) CreateProduct(product *types.Product) (*types return result, nil } -func (service *ProductServiceImpl) UpdateProduct(id string, product *types.Product) (*types.ModelResult, error) { +func (service *ProductServiceImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) (*types.ModelResult, error) { productImage := product.ProductImage var presignedUrl, imageUrl string var err error - if productImage != "" && productImage != "null" { - presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, productImage) + if productImage.Valid { + presignedUrl, imageUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, productImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - product.ProductImage = imageUrl + product.ProductImage = sql.NullString{ + String: imageUrl, + Valid: true, + } } - err = service.store.UpdateProduct(id, product) + err = service.store.UpdateProduct(ctx, id, product) if err != nil { return nil, err } @@ -89,17 +102,17 @@ func (service *ProductServiceImpl) UpdateProduct(id string, product *types.Produ return result, err } -func (service *ProductServiceImpl) DeleteProduct(id string) error { - product, err := service.store.GetProductById(id) +func (service *ProductServiceImpl) DeleteProduct(ctx context.Context, id string) error { + product, err := service.store.GetProductById(ctx, id) if err != nil { return nil } - if err := service.s3Client.DeleteImageFromS3(product.ProductImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(product.ProductImage.String); err != nil { return err } - if err := service.store.DeleteProduct(id); err != nil { + if err := service.store.DeleteProduct(ctx, id); err != nil { return err } From 64a4b18ba1725171705360963e1ab134773a3d89 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:31:55 +0100 Subject: [PATCH 151/248] product handler --- server/handlers/productHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/productHandler.go b/server/handlers/productHandler.go index b6210fd..ed65243 100644 --- a/server/handlers/productHandler.go +++ b/server/handlers/productHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type ProductHandler struct { @@ -18,9 +18,10 @@ func NewProductHandler(productService services.ProductService) *ProductHandler { } func (handler *ProductHandler) GetProducts(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - products, err := handler.productService.GetProducts(id) + products, err := handler.productService.GetProducts(ctx, id) if err != nil { log.Printf("Error getting machines: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occured while getting products"}) @@ -31,7 +32,8 @@ func (handler *ProductHandler) GetProducts(context *gin.Context) { } func (handler *ProductHandler) CreateProduct(context *gin.Context) { - var product types.Product + ctx := context.Request.Context() + var product db.Product if err := context.ShouldBindJSON(&product); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) @@ -43,7 +45,7 @@ func (handler *ProductHandler) CreateProduct(context *gin.Context) { return } - result, err := handler.productService.CreateProduct(&product) + result, err := handler.productService.CreateProduct(ctx, &product) if err != nil { log.Printf("Error creating product: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating product", "details": err.Error()}) @@ -60,9 +62,10 @@ func (handler *ProductHandler) CreateProduct(context *gin.Context) { } func (handler *ProductHandler) UpdateProduct(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var product types.Product + var product db.Product if err := context.ShouldBindJSON(&product); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "details": err.Error()}) @@ -74,7 +77,7 @@ func (handler *ProductHandler) UpdateProduct(context *gin.Context) { return } - result, err := handler.productService.UpdateProduct(id, &product) + result, err := handler.productService.UpdateProduct(ctx, id, &product) if err != nil { log.Printf("Error updating product: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) @@ -91,9 +94,10 @@ func (handler *ProductHandler) UpdateProduct(context *gin.Context) { } func (handler *ProductHandler) DeleteProduct(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.productService.DeleteProduct(id); err != nil { + if err := handler.productService.DeleteProduct(ctx, id); err != nil { log.Printf("Error deleting machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting machine", "details": err.Error()}) return From 166a8cda5d67dc41bbb7599293b0f0a9953816a7 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:34:28 +0100 Subject: [PATCH 152/248] registration service --- server/services/registrationService.go | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/server/services/registrationService.go b/server/services/registrationService.go index d3a0e84..fe9ba54 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -1,6 +1,8 @@ package services import ( + "context" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" @@ -8,11 +10,11 @@ import ( ) type RegistrationService interface { - GetRegistrations() ([]types.MachineRegistration, error) - GetRegistrationById(id string) (*types.MachineRegistration, error) - CreateRegistration(registration *types.MachineRegistration) error - UpdateRegistration(id string, registration *types.MachineRegistration) error - DeleteRegistration(id string) error + GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) + GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) + CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error + UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error + DeleteRegistration(ctx context.Context, id string) error } type RegistrationServiceImpl struct { @@ -24,8 +26,8 @@ func NewRegistrationService(store stores.RegistrationStore, smtpClient lib.SMTPC return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} } -func (service *RegistrationServiceImpl) GetRegistrations() ([]types.MachineRegistration, error) { - registrations, err := service.store.GetRegistrations() +func (service *RegistrationServiceImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { + registrations, err := service.store.GetRegistrations(ctx) if err != nil { return nil, err } @@ -33,8 +35,8 @@ func (service *RegistrationServiceImpl) GetRegistrations() ([]types.MachineRegis return registrations, nil } -func (service *RegistrationServiceImpl) GetRegistrationById(id string) (*types.MachineRegistration, error) { - registration, err := service.store.GetRegistrationById(id) +func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { + registration, err := service.store.GetRegistrationById(ctx, id) if err != nil { return nil, err } @@ -42,8 +44,8 @@ func (service *RegistrationServiceImpl) GetRegistrationById(id string) (*types.M return registration, nil } -func (service *RegistrationServiceImpl) CreateRegistration(registration *types.MachineRegistration) error { - if err := service.store.CreateRegistration(registration); err != nil { +func (service *RegistrationServiceImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { + if err := service.store.CreateRegistration(ctx, registration); err != nil { return err } @@ -71,8 +73,8 @@ func (service *RegistrationServiceImpl) CreateRegistration(registration *types.M return nil } -func (service *RegistrationServiceImpl) UpdateRegistration(id string, registration *types.MachineRegistration) error { - if err := service.store.UpdateRegistration(id, registration); err != nil { +func (service *RegistrationServiceImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { + if err := service.store.UpdateRegistration(ctx, id, registration); err != nil { return err } @@ -100,8 +102,8 @@ func (service *RegistrationServiceImpl) UpdateRegistration(id string, registrati return nil } -func (service *RegistrationServiceImpl) DeleteRegistration(id string) error { - if err := service.store.DeleteRegistration(id); err != nil { +func (service *RegistrationServiceImpl) DeleteRegistration(ctx context.Context, id string) error { + if err := service.store.DeleteRegistration(ctx, id); err != nil { return err } From b11c433038dbbc6f0f169c26da50c6cfdd9eaa91 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:35:48 +0100 Subject: [PATCH 153/248] registration handler --- server/handlers/registrationHandler.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/handlers/registrationHandler.go b/server/handlers/registrationHandler.go index 1e06770..a3fd1b6 100644 --- a/server/handlers/registrationHandler.go +++ b/server/handlers/registrationHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type RegistrationHandler struct { @@ -18,7 +18,8 @@ func NewRegistrationHandler(service services.RegistrationService) *RegistrationH } func (handler *RegistrationHandler) GetRegistrations(context *gin.Context) { - registrations, err := handler.service.GetRegistrations() + ctx := context.Request.Context() + registrations, err := handler.service.GetRegistrations(ctx) if err != nil { log.Printf("error occurred while getting registrations: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting registration"}) @@ -29,9 +30,10 @@ func (handler *RegistrationHandler) GetRegistrations(context *gin.Context) { } func (handler *RegistrationHandler) GetRegistrationById(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - registration, err := handler.service.GetRegistrationById(id) + registration, err := handler.service.GetRegistrationById(ctx, id) if err != nil { log.Printf("error occurred while getting registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting registration"}) @@ -42,7 +44,8 @@ func (handler *RegistrationHandler) GetRegistrationById(context *gin.Context) { } func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { - var registration *types.MachineRegistration + ctx := context.Request.Context() + var registration *db.MachineRegistration if err := context.ShouldBindJSON(®istration); err != nil { log.Printf("error when creating registration: %v", err) @@ -50,7 +53,7 @@ func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { return } - if err := handler.service.CreateRegistration(registration); err != nil { + if err := handler.service.CreateRegistration(ctx, registration); err != nil { log.Printf("error when creating registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when creating registration"}) } @@ -59,8 +62,9 @@ func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { } func (handler *RegistrationHandler) UpdateRegistration(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var registration *types.MachineRegistration + var registration *db.MachineRegistration if err := context.ShouldBindJSON(®istration); err != nil { log.Printf("error when updating registration: %v", err) @@ -68,7 +72,7 @@ func (handler *RegistrationHandler) UpdateRegistration(context *gin.Context) { return } - if err := handler.service.UpdateRegistration(id, registration); err != nil { + if err := handler.service.UpdateRegistration(ctx, id, registration); err != nil { log.Printf("error when updating registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when updating registration"}) } @@ -77,9 +81,10 @@ func (handler *RegistrationHandler) UpdateRegistration(context *gin.Context) { } func (handler *RegistrationHandler) DeleteRegistration(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteRegistration(id); err != nil { + if err := handler.service.DeleteRegistration(ctx, id); err != nil { log.Printf("error occurred while deleting registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error while deleting registration"}) } From c7d498e4eeb214e70083923ae5a5e7e68ba35ead Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:46:29 +0100 Subject: [PATCH 154/248] supplier service --- server/services/supplierService.go | 85 +++++++++++++++++++----------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 52781ea..9744dcd 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -1,7 +1,10 @@ package services import ( + "context" + "database/sql" "errors" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "log" @@ -10,11 +13,11 @@ import ( ) type SupplierService interface { - GetSuppliers() ([]types.Supplier, error) - CreateSupplier(supplier *types.Supplier) (*types.SupplierResult, error) - GetSupplierById(id string) (*types.Supplier, error) - UpdateSupplier(id string, supplier *types.Supplier) (*types.SupplierResult, error) - DeleteSupplier(id string) error + GetSuppliers(ctx context.Context) ([]db.Supplier, error) + CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) + GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) + UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) (*types.SupplierResult, error) + DeleteSupplier(ctx context.Context, id string) error } type SupplierServiceImpl struct { @@ -31,34 +34,52 @@ func NewSupplierService(store stores.SupplierStore, s3Client lib.S3Client, folde } } -func (service *SupplierServiceImpl) GetSuppliers() ([]types.Supplier, error) { - return service.store.GetSuppliers() +func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { + suppliers, err := service.store.GetSuppliers(ctx) + if err != nil { + return nil, err + } + return suppliers, nil +} + +func (service *SupplierServiceImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { + supplier, err := service.store.GetSupplierById(ctx, id) + if err != nil { + return nil, err + } + return supplier, nil } -func (service *SupplierServiceImpl) CreateSupplier(supplier *types.Supplier) (*types.SupplierResult, error) { +func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) { logoImage := supplier.LogoImage marketingImage := supplier.MarketingImage - if logoImage == "" || logoImage == "null" { + if !logoImage.Valid || !marketingImage.Valid { return nil, errors.New("image is empty") } - presignedLogo, logoUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, logoImage) + presignedLogo, logoUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, logoImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - presignedMarketing, marketingUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, marketingImage) + presignedMarketing, marketingUrl, err := service.s3Client.GeneratePresignedUrl(service.folder, marketingImage.String) if err != nil { log.Printf("error occurred while generating presigned url: %v", err) return nil, err } - supplier.LogoImage = logoUrl - supplier.MarketingImage = marketingUrl + supplier.LogoImage = sql.NullString{ + String: logoUrl, + Valid: true, + } + supplier.MarketingImage = sql.NullString{ + String: marketingUrl, + Valid: true, + } - err = service.store.CreateSupplier(supplier) + err = service.store.CreateSupplier(ctx, supplier) if err != nil { return nil, err } @@ -73,34 +94,36 @@ func (service *SupplierServiceImpl) CreateSupplier(supplier *types.Supplier) (*t return result, nil } -func (service *SupplierServiceImpl) GetSupplierById(id string) (*types.Supplier, error) { - return service.store.GetSupplierById(id) -} - -func (service *SupplierServiceImpl) UpdateSupplier(id string, supplier *types.Supplier) (*types.SupplierResult, error) { +func (service *SupplierServiceImpl) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) (*types.SupplierResult, error) { logoImage := supplier.LogoImage marketingImage := supplier.MarketingImage var presignedLogo, logoUrl, presignedMarketing, marketingUrl string var err error - if logoImage != "" && logoImage != "null" { - presignedLogo, logoUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, logoImage) + if logoImage.Valid { + presignedLogo, logoUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, logoImage.String) if err != nil { return nil, err } - supplier.LogoImage = logoUrl + supplier.LogoImage = sql.NullString{ + String: logoUrl, + Valid: true, + } } - if marketingImage != "" && marketingImage != "null" { - presignedMarketing, marketingUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, marketingImage) + if marketingImage.Valid { + presignedMarketing, marketingUrl, err = service.s3Client.GeneratePresignedUrl(service.folder, marketingImage.String) if err != nil { return nil, err } - supplier.MarketingImage = marketingUrl + supplier.MarketingImage = sql.NullString{ + String: marketingUrl, + Valid: true, + } } - err = service.store.UpdateSupplier(id, supplier) + err = service.store.UpdateSupplier(ctx, id, supplier) if err != nil { return nil, err } @@ -115,21 +138,21 @@ func (service *SupplierServiceImpl) UpdateSupplier(id string, supplier *types.Su return result, nil } -func (service *SupplierServiceImpl) DeleteSupplier(id string) error { - supplier, err := service.store.GetSupplierById(id) +func (service *SupplierServiceImpl) DeleteSupplier(ctx context.Context, id string) error { + supplier, err := service.store.GetSupplierById(ctx, id) if err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(supplier.LogoImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(supplier.LogoImage.String); err != nil { return err } - if err := service.s3Client.DeleteImageFromS3(supplier.MarketingImage); err != nil { + if err := service.s3Client.DeleteImageFromS3(supplier.MarketingImage.String); err != nil { return err } - if err := service.store.DeleteSupplier(id); err != nil { + if err := service.store.DeleteSupplier(ctx, id); err != nil { return err } From 81d228b714d8a6d422ce8d672085f0c91b527dd8 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:47:52 +0100 Subject: [PATCH 155/248] supplier handler --- server/handlers/supplierHandler.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index 1dbe9e4..171adb3 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type SupplierHandler struct { @@ -18,7 +18,8 @@ func NewSupplierContoller(supplierService services.SupplierService) *SupplierHan } func (handler *SupplierHandler) GetSuppliers(context *gin.Context) { - suppliers, err := handler.supplierService.GetSuppliers() + ctx := context.Request.Context() + suppliers, err := handler.supplierService.GetSuppliers(ctx) if err != nil { log.Printf("Error getting suppliers: %v", err) @@ -29,14 +30,15 @@ func (handler *SupplierHandler) GetSuppliers(context *gin.Context) { } func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { - var supplier types.Supplier + ctx := context.Request.Context() + var supplier db.Supplier if err := context.ShouldBindJSON(&supplier); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - result, err := handler.supplierService.CreateSupplier(&supplier) + result, err := handler.supplierService.CreateSupplier(ctx, &supplier) if err != nil { log.Printf("Error creating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating supplier", "details": err.Error()}) @@ -55,8 +57,9 @@ func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { } func (handler *SupplierHandler) GetSupplierByID(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - supplier, err := handler.supplierService.GetSupplierById(id) + supplier, err := handler.supplierService.GetSupplierById(ctx, id) if err != nil { log.Printf("Error getting suppliers: %v", err) @@ -68,16 +71,17 @@ func (handler *SupplierHandler) GetSupplierByID(context *gin.Context) { } func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var supplier types.Supplier + var supplier db.Supplier if err := context.ShouldBindJSON(&supplier); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - result, err := handler.supplierService.UpdateSupplier(id, &supplier) + result, err := handler.supplierService.UpdateSupplier(ctx, id, &supplier) if err != nil { log.Printf("Error updating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating supplier", "details": err.Error()}) @@ -96,9 +100,10 @@ func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { } func (handler *SupplierHandler) DeleteSupplier(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - err := handler.supplierService.DeleteSupplier(id) + err := handler.supplierService.DeleteSupplier(ctx, id) if err != nil { log.Printf("Error deleting supplier: %v", err) From 95cf42255f46cd6a33bca06f121ebe6f504b711b Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:50:55 +0100 Subject: [PATCH 156/248] terms service --- server/services/termsService.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/server/services/termsService.go b/server/services/termsService.go index e3eb97d..bb5cb79 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -1,15 +1,16 @@ package services import ( + "context" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" ) type TermsService interface { - GetTerms() ([]types.Terms, error) - CreateTerm(term *types.Terms) error - UpdateTerm(id string, term *types.Terms) error - DeleteTerm(id string) error + GetTerms(ctx context.Context) ([]db.Term, error) + CreateTerm(ctx context.Context, term *db.Term) error + UpdateTerm(ctx context.Context, id string, term *db.Term) error + DeleteTerm(ctx context.Context, id string) error } type TermsServiceImpl struct { @@ -20,35 +21,31 @@ func NewTermsService(store stores.TermsStore) *TermsServiceImpl { return &TermsServiceImpl{store: store} } -func (service *TermsServiceImpl) GetTerms() ([]types.Terms, error) { - terms, err := service.store.GetTerms() +func (service *TermsServiceImpl) GetTerms(ctx context.Context) ([]db.Term, error) { + terms, err := service.store.GetTerms(ctx) if err != nil { return nil, err } - return terms, nil } -func (service *TermsServiceImpl) CreateTerm(term *types.Terms) error { - if err := service.store.CreateTerm(term); err != nil { +func (service *TermsServiceImpl) CreateTerm(ctx context.Context, term *db.Term) error { + if err := service.store.CreateTerm(ctx, term); err != nil { return err } - return nil } -func (service *TermsServiceImpl) UpdateTerm(id string, term *types.Terms) error { - if err := service.store.UpdateTerm(id, term); err != nil { +func (service *TermsServiceImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { + if err := service.store.UpdateTerm(ctx, id, term); err != nil { return err } - return nil } -func (service *TermsServiceImpl) DeleteTerm(id string) error { - if err := service.store.DeleteTerm(id); err != nil { +func (service *TermsServiceImpl) DeleteTerm(ctx context.Context, id string) error { + if err := service.store.DeleteTerm(ctx, id); err != nil { return err } - return nil } From 149ae30a1bd4e710de341e3f48a5c7696233eec1 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:52:49 +0100 Subject: [PATCH 157/248] terms handler --- server/handlers/termsHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/termsHandler.go b/server/handlers/termsHandler.go index 040b5d9..54baadb 100644 --- a/server/handlers/termsHandler.go +++ b/server/handlers/termsHandler.go @@ -5,8 +5,8 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type TermsHandler struct { @@ -18,7 +18,8 @@ func NewTermsHandler(service services.TermsService) *TermsHandler { } func (handler *TermsHandler) GetTerms(context *gin.Context) { - terms, err := handler.service.GetTerms() + ctx := context.Request.Context() + terms, err := handler.service.GetTerms(ctx) if err != nil { log.Printf("error getting terms: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting term"}) @@ -29,14 +30,15 @@ func (handler *TermsHandler) GetTerms(context *gin.Context) { } func (handler *TermsHandler) CreateTerm(context *gin.Context) { - var term types.Terms + ctx := context.Request.Context() + var term db.Term if err := context.ShouldBindJSON(&term); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreateTerm(&term); err != nil { + if err := handler.service.CreateTerm(ctx, &term); err != nil { log.Printf("error while creating term: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating term", "details": err.Error()}) return @@ -46,15 +48,16 @@ func (handler *TermsHandler) CreateTerm(context *gin.Context) { } func (handler *TermsHandler) UpdateTerm(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var term types.Terms + var term db.Term if err := context.ShouldBindJSON(&term); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdateTerm(id, &term); err != nil { + if err := handler.service.UpdateTerm(ctx, id, &term); err != nil { log.Printf("error while updating term: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating term", "details": err.Error()}) return @@ -64,9 +67,10 @@ func (handler *TermsHandler) UpdateTerm(context *gin.Context) { } func (handler *TermsHandler) DeleteTerm(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteTerm(id); err != nil { + if err := handler.service.DeleteTerm(ctx, id); err != nil { log.Printf("Error deleting term: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting term", "details": err.Error()}) return From aa0ebf2d05dcd2b5b2b44cb1640b9f8b41f786d6 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:54:48 +0100 Subject: [PATCH 158/248] timeline service --- server/services/timelineService.go | 31 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/server/services/timelineService.go b/server/services/timelineService.go index fe873ca..41fae2a 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -1,15 +1,16 @@ package services import ( + "context" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" ) type TimelineService interface { - GetTimelines() ([]types.Timeline, error) - CreateTimeline(timeline *types.Timeline) error - UpdateTimeline(id string, timeline *types.Timeline) error - DeleteTimeline(id string) error + GetTimelines(ctx context.Context) ([]db.Timeline, error) + CreateTimeline(ctx context.Context, timeline *db.Timeline) error + UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error + DeleteTimeline(ctx context.Context, id string) error } type TimelineServiceImpl struct { @@ -20,35 +21,31 @@ func NewTimelineService(store stores.TimelineStore) *TimelineServiceImpl { return &TimelineServiceImpl{store: store} } -func (service *TimelineServiceImpl) GetTimelines() ([]types.Timeline, error) { - timelines, err := service.store.GetTimelines() +func (service *TimelineServiceImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { + timelines, err := service.store.GetTimelines(ctx) if err != nil { return nil, err } - return timelines, nil } -func (service *TimelineServiceImpl) CreateTimeline(timeline *types.Timeline) error { - if err := service.store.CreateTimeline(timeline); err != nil { +func (service *TimelineServiceImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { + if err := service.store.CreateTimeline(ctx, timeline); err != nil { return err } - return nil } -func (service *TimelineServiceImpl) UpdateTimeline(id string, timeline *types.Timeline) error { - if err := service.store.UpdateTimeline(id, timeline); err != nil { +func (service *TimelineServiceImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { + if err := service.store.UpdateTimeline(ctx, id, timeline); err != nil { return err } - return nil } -func (service *TimelineServiceImpl) DeleteTimeline(id string) error { - if err := service.store.DeleteTimeline(id); err != nil { +func (service *TimelineServiceImpl) DeleteTimeline(ctx context.Context, id string) error { + if err := service.store.DeleteTimeline(ctx, id); err != nil { return err } - return nil } From 95babbef30933f5b728e80a86d861c621fd52a4f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 12:56:02 +0100 Subject: [PATCH 159/248] timeline handler --- server/handlers/timelineHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/timelineHandler.go b/server/handlers/timelineHandler.go index 4fab5ec..9e63e04 100644 --- a/server/handlers/timelineHandler.go +++ b/server/handlers/timelineHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type TimelineHandler struct { @@ -18,7 +18,8 @@ func NewTimelineHandler(service services.TimelineService) *TimelineHandler { } func (handler *TimelineHandler) GetTimelines(context *gin.Context) { - timelines, err := handler.service.GetTimelines() + ctx := context.Request.Context() + timelines, err := handler.service.GetTimelines(ctx) if err != nil { log.Printf("error getting timelines: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting timeline"}) @@ -29,14 +30,15 @@ func (handler *TimelineHandler) GetTimelines(context *gin.Context) { } func (handler *TimelineHandler) CreateTimeline(context *gin.Context) { - var timeline types.Timeline + ctx := context.Request.Context() + var timeline db.Timeline if err := context.ShouldBindJSON(&timeline); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreateTimeline(&timeline); err != nil { + if err := handler.service.CreateTimeline(ctx, &timeline); err != nil { log.Printf("error while creating timeline: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating timeline", "details": err.Error()}) return @@ -46,15 +48,16 @@ func (handler *TimelineHandler) CreateTimeline(context *gin.Context) { } func (handler *TimelineHandler) UpdateTimeline(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var timeline types.Timeline + var timeline db.Timeline if err := context.ShouldBindJSON(&timeline); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdateTimeline(id, &timeline); err != nil { + if err := handler.service.UpdateTimeline(ctx, id, &timeline); err != nil { log.Printf("error while updating timeline: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating timeline", "details": err.Error()}) return @@ -64,9 +67,10 @@ func (handler *TimelineHandler) UpdateTimeline(context *gin.Context) { } func (handler *TimelineHandler) DeleteTimeline(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteTimeline(id); err != nil { + if err := handler.service.DeleteTimeline(ctx, id); err != nil { log.Printf("Error deleting timeline: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting timeline", "details": err.Error()}) return From ea2812fcfbac18e5b8c4d91b49887e6e831b000d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:14:50 +0100 Subject: [PATCH 160/248] video service transform data --- server/services/videoService.go | 54 +++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/server/services/videoService.go b/server/services/videoService.go index 6934538..68c8071 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -1,20 +1,22 @@ package services import ( + "context" + "database/sql" "fmt" + "github.com/sean-david-welch/farmec-v2/server/db" "strings" "github.com/sean-david-welch/farmec-v2/server/stores" - "github.com/sean-david-welch/farmec-v2/server/types" "google.golang.org/api/youtube/v3" ) type VideoService interface { - TransformData(video *types.Video) (*types.Video, error) - GetVideos(id string) ([]types.Video, error) - CreateVideo(video *types.Video) error - UpdateVideo(id string, video *types.Video) error - DeleteVideo(id string) error + TransformData(video *db.Video) (*db.Video, error) + GetVideos(ctx context.Context, id string) ([]db.Video, error) + CreateVideo(ctx context.Context, video *db.Video) error + UpdateVideo(ctx context.Context, id string, video *db.Video) error + DeleteVideo(ctx context.Context, id string) error } type VideoServiceImpl struct { @@ -29,8 +31,8 @@ func NewVideoService(store stores.VideoStore, youtubeService *youtube.Service) * } } -func (service *VideoServiceImpl) TransformData(video *types.Video) (*types.Video, error) { - splits := strings.Split(video.WebURL, "v=") +func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, error) { + splits := strings.Split(video.WebUrl.String, "v=") if len(splits) < 2 { return nil, fmt.Errorf("invalid web_url format") } @@ -53,25 +55,37 @@ func (service *VideoServiceImpl) TransformData(video *types.Video) (*types.Video } item := response.Items[0] - videoData := &types.Video{ - ID: video.ID, - SupplierID: video.SupplierID, - WebURL: video.WebURL, - Title: &item.Snippet.Title, - Description: &item.Snippet.Description, - VideoID: &item.Id, - ThumbnailURL: &item.Snippet.Thumbnails.Medium.Url, - Created: video.Created, + videoData := &db.Video{ + ID: video.ID, + SupplierID: video.SupplierID, + WebUrl: video.WebUrl, + Title: sql.NullString{ + String: item.Snippet.Title, + Valid: true, + }, + Description: sql.NullString{ + String: item.Snippet.Description, + Valid: true, + }, + VideoID: sql.NullString{ + String: item.Id, + Valid: true, + }, + ThumbnailUrl: sql.NullString{ + String: item.Snippet.Thumbnails.Medium.Url, + Valid: true, + }, + Created: video.Created, } return videoData, nil } -func (service *VideoServiceImpl) GetVideos(id string) ([]types.Video, error) { +func (service *VideoServiceImpl) GetVideos(id string) ([]db.Video, error) { return service.store.GetVideos(id) } -func (service *VideoServiceImpl) CreateVideo(video *types.Video) error { +func (service *VideoServiceImpl) CreateVideo(video *db.Video) error { videoData, err := service.TransformData(video) if err != nil { return err @@ -85,7 +99,7 @@ func (service *VideoServiceImpl) CreateVideo(video *types.Video) error { return nil } -func (service *VideoServiceImpl) UpdateVideo(id string, video *types.Video) error { +func (service *VideoServiceImpl) UpdateVideo(id string, video *db.Video) error { videoData, err := service.TransformData(video) if err != nil { return err From c8403eeaac327e62a8750fb208d7b1bd90498241 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:16:16 +0100 Subject: [PATCH 161/248] video service --- server/services/videoService.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/services/videoService.go b/server/services/videoService.go index 68c8071..b6dd756 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -81,17 +81,21 @@ func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, erro return videoData, nil } -func (service *VideoServiceImpl) GetVideos(id string) ([]db.Video, error) { - return service.store.GetVideos(id) +func (service *VideoServiceImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { + videos, err := service.store.GetVideos(ctx, id) + if err != nil { + return nil, err + } + return videos, nil } -func (service *VideoServiceImpl) CreateVideo(video *db.Video) error { +func (service *VideoServiceImpl) CreateVideo(ctx context.Context, video *db.Video) error { videoData, err := service.TransformData(video) if err != nil { return err } - err = service.store.CreateVideo(videoData) + err = service.store.CreateVideo(ctx, videoData) if err != nil { return err } @@ -99,13 +103,13 @@ func (service *VideoServiceImpl) CreateVideo(video *db.Video) error { return nil } -func (service *VideoServiceImpl) UpdateVideo(id string, video *db.Video) error { +func (service *VideoServiceImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { videoData, err := service.TransformData(video) if err != nil { return err } - err = service.store.UpdateVideo(id, videoData) + err = service.store.UpdateVideo(ctx, id, videoData) if err != nil { return err } @@ -113,8 +117,8 @@ func (service *VideoServiceImpl) UpdateVideo(id string, video *db.Video) error { return nil } -func (service *VideoServiceImpl) DeleteVideo(id string) error { - err := service.store.DeleteVideo(id) +func (service *VideoServiceImpl) DeleteVideo(ctx context.Context, id string) error { + err := service.store.DeleteVideo(ctx, id) if err != nil { return err } From ae5368d096c1be3179e00e88badbc77b8f2182c3 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:17:34 +0100 Subject: [PATCH 162/248] video handler --- server/handlers/videoHandler.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index 0cdf217..86b06ac 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -1,12 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/types" ) type VideoHandler struct { @@ -18,9 +18,10 @@ func NewVideoHandler(videoService services.VideoService) *VideoHandler { } func (handler *VideoHandler) GetVideos(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - videos, err := handler.videoService.GetVideos(id) + videos, err := handler.videoService.GetVideos(ctx, id) if err != nil { log.Printf("Error getting suppliers: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting suppliers"}) @@ -31,14 +32,15 @@ func (handler *VideoHandler) GetVideos(context *gin.Context) { } func (handler *VideoHandler) CreateVideo(context *gin.Context) { - var video types.Video + ctx := context.Request.Context() + var video db.Video if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } - if err := handler.videoService.CreateVideo(&video); err != nil { + if err := handler.videoService.CreateVideo(ctx, &video); err != nil { log.Printf("Error creating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating video", "details": err.Error()}) return @@ -48,16 +50,17 @@ func (handler *VideoHandler) CreateVideo(context *gin.Context) { } func (handler *VideoHandler) UpdateVideo(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var video types.Video + var video db.Video if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } - if err := handler.videoService.UpdateVideo(id, &video); err != nil { + if err := handler.videoService.UpdateVideo(ctx, id, &video); err != nil { log.Printf("Error updating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating video", "details": err.Error()}) return @@ -67,9 +70,10 @@ func (handler *VideoHandler) UpdateVideo(context *gin.Context) { } func (handler *VideoHandler) DeleteVideo(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.videoService.DeleteVideo(id); err != nil { + if err := handler.videoService.DeleteVideo(ctx, id); err != nil { log.Printf("Error deleting video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Erropr occurred while deleting supplier", "details": err.Error()}) return From 89d6fc37b623efd525d16e3ec41c6d813953e1b3 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:22:32 +0100 Subject: [PATCH 163/248] warranty service --- server/services/warrantyService.go | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index bce9595..9b5f41d 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -1,6 +1,8 @@ package services import ( + "context" + "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/stores" "github.com/sean-david-welch/farmec-v2/server/types" @@ -8,11 +10,11 @@ import ( ) type WarrantyService interface { - GetWarranties() ([]types.DealerOwnerInfo, error) - GetWarrantyById(id string) (*types.WarrantyClaim, []types.PartsRequired, error) - CreateWarranty(warranty *types.WarrantyClaim, parts []types.PartsRequired) error - UpdateWarranty(id string, warranty *types.WarrantyClaim, parts []types.PartsRequired) error - DeleteWarranty(id string) error + GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) + GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) + CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error + UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error + DeleteWarranty(ctx context.Context, id string) error } type WarrantyServiceImpl struct { @@ -24,8 +26,8 @@ func NewWarrantyService(store stores.WarrantyStore, smtpClient lib.SMTPClient) * return &WarrantyServiceImpl{store: store, smtpClient: smtpClient} } -func (service *WarrantyServiceImpl) GetWarranties() ([]types.DealerOwnerInfo, error) { - warranties, err := service.store.GetWarranties() +func (service *WarrantyServiceImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { + warranties, err := service.store.GetWarranties(ctx) if err != nil { return nil, err } @@ -33,8 +35,8 @@ func (service *WarrantyServiceImpl) GetWarranties() ([]types.DealerOwnerInfo, er return warranties, nil } -func (service *WarrantyServiceImpl) GetWarrantyById(id string) (*types.WarrantyClaim, []types.PartsRequired, error) { - warranty, partsRequired, err := service.store.GetWarrantyById(id) +func (service *WarrantyServiceImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { + warranty, partsRequired, err := service.store.GetWarrantyById(ctx, id) if err != nil { return nil, nil, err } @@ -42,8 +44,8 @@ func (service *WarrantyServiceImpl) GetWarrantyById(id string) (*types.WarrantyC return warranty, partsRequired, nil } -func (service *WarrantyServiceImpl) CreateWarranty(warranty *types.WarrantyClaim, parts []types.PartsRequired) error { - if err := service.store.CreateWarranty(warranty, parts); err != nil { +func (service *WarrantyServiceImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { + if err := service.store.CreateWarranty(ctx, warranty, parts); err != nil { return err } @@ -59,9 +61,9 @@ func (service *WarrantyServiceImpl) CreateWarranty(warranty *types.WarrantyClaim }(client) data := &types.EmailData{ - Name: *warranty.OwnerName, + Name: warranty.OwnerName, Email: warranty.Dealer, - Message: *warranty.MachineModel, + Message: warranty.MachineModel, } if err := service.smtpClient.SendFormNotification(client, data, "Warranty"); err != nil { @@ -71,8 +73,8 @@ func (service *WarrantyServiceImpl) CreateWarranty(warranty *types.WarrantyClaim return nil } -func (service *WarrantyServiceImpl) UpdateWarranty(id string, warranty *types.WarrantyClaim, parts []types.PartsRequired) error { - if err := service.store.UpdateWarranty(id, warranty, parts); err != nil { +func (service *WarrantyServiceImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { + if err := service.store.UpdateWarranty(ctx, id, warranty, parts); err != nil { return err } @@ -88,9 +90,9 @@ func (service *WarrantyServiceImpl) UpdateWarranty(id string, warranty *types.Wa }(client) data := &types.EmailData{ - Name: *warranty.OwnerName, + Name: warranty.OwnerName, Email: warranty.Dealer, - Message: *warranty.MachineModel, + Message: warranty.MachineModel, } if err := service.smtpClient.SendFormNotification(client, data, "Warranty"); err != nil { @@ -100,8 +102,8 @@ func (service *WarrantyServiceImpl) UpdateWarranty(id string, warranty *types.Wa return nil } -func (service *WarrantyServiceImpl) DeleteWarranty(id string) error { - if err := service.store.DeleteWarranty(id); err != nil { +func (service *WarrantyServiceImpl) DeleteWarranty(ctx context.Context, id string) error { + if err := service.store.DeleteWarranty(ctx, id); err != nil { return err } From 26e5dc4f18cda07cb7426048d30f55587ec71c0d Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:30:41 +0100 Subject: [PATCH 164/248] warranty handler --- server/handlers/warrantyHandler.go | 20 +++++++++++++------- server/types/miscTypes.go | 6 ++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/server/handlers/warrantyHandler.go b/server/handlers/warrantyHandler.go index d22cab9..6f91240 100644 --- a/server/handlers/warrantyHandler.go +++ b/server/handlers/warrantyHandler.go @@ -1,6 +1,7 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/db" "log" "net/http" @@ -18,7 +19,8 @@ func NewWarrantyHandler(service services.WarrantyService) *WarrantyHandler { } func (handler *WarrantyHandler) GetWarranties(context *gin.Context) { - warranties, err := handler.service.GetWarranties() + ctx := context.Request.Context() + warranties, err := handler.service.GetWarranties(ctx) if err != nil { log.Printf("error occurred while getting warranties: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting warranties"}) @@ -29,9 +31,10 @@ func (handler *WarrantyHandler) GetWarranties(context *gin.Context) { } func (handler *WarrantyHandler) GetWarrantyById(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - warranty, parts, err := handler.service.GetWarrantyById(id) + warranty, parts, err := handler.service.GetWarrantyById(ctx, id) if err != nil { log.Printf("error occurred while getting warrantiy and adjoining parts: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting warrantiy and adjoining parts"}) @@ -47,6 +50,7 @@ func (handler *WarrantyHandler) GetWarrantyById(context *gin.Context) { } func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { + ctx := context.Request.Context() var warrantyParts types.WarranrtyParts if err := context.ShouldBindJSON(&warrantyParts); err != nil { @@ -55,7 +59,7 @@ func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { return } - if err := handler.service.CreateWarranty(warrantyParts.Warranty, warrantyParts.Parts); err != nil { + if err := handler.service.CreateWarranty(ctx, warrantyParts.Warranty, warrantyParts.Parts); err != nil { log.Printf("error occurred while creating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating warranty claim"}) return @@ -65,10 +69,11 @@ func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { } func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - var warranty *types.WarrantyClaim - var parts []types.PartsRequired + var warranty *db.WarrantyClaim + var parts []db.PartsRequired body := gin.H{ "warranty": warranty, @@ -81,7 +86,7 @@ func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { return } - if err := handler.service.UpdateWarranty(id, warranty, parts); err != nil { + if err := handler.service.UpdateWarranty(ctx, id, warranty, parts); err != nil { log.Printf("error occurred while updating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating warranty claim"}) return @@ -91,9 +96,10 @@ func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { } func (handler *WarrantyHandler) DeleteWarranty(context *gin.Context) { + ctx := context.Request.Context() id := context.Param("id") - if err := handler.service.DeleteWarranty(id); err != nil { + if err := handler.service.DeleteWarranty(ctx, id); err != nil { log.Printf("error occurred while deleting warranty: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred while deleting warranty"}) return diff --git a/server/types/miscTypes.go b/server/types/miscTypes.go index dc0d91c..d964e5f 100644 --- a/server/types/miscTypes.go +++ b/server/types/miscTypes.go @@ -1,5 +1,7 @@ package types +import "github.com/sean-david-welch/farmec-v2/server/db" + type Carousel struct { ID string `json:"id"` Name string `json:"name"` @@ -40,8 +42,8 @@ type PartsRequired struct { } type WarranrtyParts struct { - Warranty *WarrantyClaim - Parts []PartsRequired + Warranty *db.WarrantyClaim + Parts []db.PartsRequired } type WarrantyClaimPDF struct { From a73cc7128ea94191da4e4eda1b89050e00a1bc6e Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:44:19 +0100 Subject: [PATCH 165/248] fix types in pdf service --- server/services/pdfService.go | 2 +- server/types/miscTypes.go | 37 +++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/server/services/pdfService.go b/server/services/pdfService.go index ebbb71c..df700b2 100644 --- a/server/services/pdfService.go +++ b/server/services/pdfService.go @@ -68,7 +68,7 @@ func (service *PdfServiceImpl) RenderRegistrationPdf(registration *types.Machine } func (service *PdfServiceImpl) RenderWarrantyClaimPdf(warranty *types.WarranrtyParts) ([]byte, error) { - pdf, err := service.InitPdf("Warranty Claim " + "-- " + *warranty.Warranty.OwnerName) + pdf, err := service.InitPdf("Warranty Claim " + "-- " + warranty.Warranty.OwnerName) if err != nil { return nil, err } diff --git a/server/types/miscTypes.go b/server/types/miscTypes.go index d964e5f..f22c74d 100644 --- a/server/types/miscTypes.go +++ b/server/types/miscTypes.go @@ -1,6 +1,9 @@ package types -import "github.com/sean-david-welch/farmec-v2/server/db" +import ( + "database/sql" + "github.com/sean-david-welch/farmec-v2/server/db" +) type Carousel struct { ID string `json:"id"` @@ -47,25 +50,25 @@ type WarranrtyParts struct { } type WarrantyClaimPDF struct { - Dealer string `json:"dealer"` - DealerContact *string `json:"dealer_contact"` - OwnerName *string `json:"owner_name"` - MachineModel *string `json:"machine_model"` - SerialNumber *string `json:"serial_number"` - InstallDate *string `json:"install_date"` - FailureDate *string `json:"failure_date"` - RepairDate *string `json:"repair_date"` - FailureDetails *string `json:"failure_details"` - RepairDetails *string `json:"repair_details"` - LabourHours *string `json:"labour_hours"` - CompletedBy *string `json:"completed_by"` + Dealer string `json:"dealer"` + DealerContact sql.NullString `json:"dealer_contact"` + OwnerName string `json:"owner_name"` + MachineModel string `json:"machine_model"` + SerialNumber string `json:"serial_number"` + InstallDate sql.NullString `json:"install_date"` + FailureDate sql.NullString `json:"failure_date"` + RepairDate sql.NullString `json:"repair_date"` + FailureDetails sql.NullString `json:"failure_details"` + RepairDetails sql.NullString `json:"repair_details"` + LabourHours sql.NullString `json:"labour_hours"` + CompletedBy sql.NullString `json:"completed_by"` } type PartsRequiredPDF struct { - PartNumber string `json:"part_number"` - QuantityNeeded string `json:"quantity_needed"` - InvoiceNumber string `json:"invoice_number"` - Description string `json:"description"` + PartNumber sql.NullString `json:"part_number"` + QuantityNeeded string `json:"quantity_needed"` + InvoiceNumber sql.NullString `json:"invoice_number"` + Description sql.NullString `json:"description"` } type MachineRegistration struct { From c659812b274460646147e1c608e3ef78338c9c63 Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:45:48 +0100 Subject: [PATCH 166/248] fix error in pdf handler --- server/handlers/pdfHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handlers/pdfHandler.go b/server/handlers/pdfHandler.go index f75ac06..8bba545 100644 --- a/server/handlers/pdfHandler.go +++ b/server/handlers/pdfHandler.go @@ -66,7 +66,7 @@ func (handler *PdfHandler) RenderWarrantyClaimPdf(context *gin.Context) { fileName := fmt.Sprintf("%s-%s.warranty.pdf", strings.ReplaceAll(warranty.Warranty.Dealer, " ", ""), - strings.ReplaceAll(*warranty.Warranty.OwnerName, " ", "")) + strings.ReplaceAll(warranty.Warranty.OwnerName, " ", "")) contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"", fileName) From 459fe42ef314aad6bd28794b34c368adcb1881fc Mon Sep 17 00:00:00 2001 From: seanwelch Date: Thu, 5 Sep 2024 13:46:57 +0100 Subject: [PATCH 167/248] handle errors --- server/services/pdfService.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/services/pdfService.go b/server/services/pdfService.go index df700b2..12cbc7f 100644 --- a/server/services/pdfService.go +++ b/server/services/pdfService.go @@ -137,7 +137,10 @@ func (service *PdfServiceImpl) InitPdf(model string) (*gopdf.GoPdf, error) { title := model pdf.AddHeader(func() { - pdf.Text(title) + err := pdf.Text(title) + if err != nil { + return + } }) if err := pdf.Text(title); err != nil { @@ -187,7 +190,10 @@ func (service *PdfServiceImpl) RenderStruct(pdf *gopdf.GoPdf, data interface{}, if field.Kind() == reflect.Ptr { if field.IsNil() { - pdf.Text(fieldName + ": ") + err := pdf.Text(fieldName + ": ") + if err != nil { + return err + } } else { field = field.Elem() } From 9fdb3f5a0b0216975979c1f1a5fc849d2c7c534f Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 8 Sep 2024 12:58:46 -0400 Subject: [PATCH 168/248] return type --- server/services/supplierService.go | 40 +++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 9744dcd..91cb352 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -34,20 +34,52 @@ func NewSupplierService(store stores.SupplierStore, s3Client lib.S3Client, folde } } -func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { +func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]types.Supplier, error) { suppliers, err := service.store.GetSuppliers(ctx) if err != nil { return nil, err } - return suppliers, nil + + var result []types.Supplier + for _, supplier := range suppliers { + result = append(result, types.Supplier{ + ID: supplier.ID, + Name: supplier.Name, + LogoImage: supplier.LogoImage.String, + MarketingImage: supplier.MarketingImage.String, + Description: supplier.Description.String, + SocialFacebook: &supplier.SocialFacebook.String, + SocialInstagram: &supplier.SocialInstagram.String, + SocialLinkedin: &supplier.SocialLinkedin.String, + SocialTwitter: &supplier.SocialTwitter.String, + SocialYoutube: &supplier.SocialYoutube.String, + SocialWebsite: &supplier.SocialWebsite.String, + Created: supplier.Created.String, + }) + } + return result, nil } -func (service *SupplierServiceImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { +func (service *SupplierServiceImpl) GetSupplierById(ctx context.Context, id string) (*types.Supplier, error) { supplier, err := service.store.GetSupplierById(ctx, id) if err != nil { return nil, err } - return supplier, nil + result := &types.Supplier{ + ID: supplier.ID, + Name: supplier.Name, + LogoImage: supplier.LogoImage.String, + MarketingImage: supplier.MarketingImage.String, + Description: supplier.Description.String, + SocialFacebook: &supplier.SocialFacebook.String, + SocialInstagram: &supplier.SocialInstagram.String, + SocialLinkedin: &supplier.SocialLinkedin.String, + SocialTwitter: &supplier.SocialTwitter.String, + SocialYoutube: &supplier.SocialYoutube.String, + SocialWebsite: &supplier.SocialWebsite.String, + Created: supplier.Created.String, + } + return result, nil } func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) { From 3bb134afa8db708638b9629601a61c631837406a Mon Sep 17 00:00:00 2001 From: seanwelch Date: Sun, 8 Sep 2024 14:08:48 -0400 Subject: [PATCH 169/248] fixes for supplier service types --- server/services/supplierService.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 91cb352..318cd34 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -13,9 +13,9 @@ import ( ) type SupplierService interface { - GetSuppliers(ctx context.Context) ([]db.Supplier, error) + GetSuppliers(ctx context.Context) ([]types.Supplier, error) CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) - GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) + GetSupplierById(ctx context.Context, id string) (*types.Supplier, error) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) (*types.SupplierResult, error) DeleteSupplier(ctx context.Context, id string) error } From 6518377400e6fdb51b4ff186f786bb7868e8215c Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 14:39:27 +0100 Subject: [PATCH 170/248] sqlc --- server/sql/sqlc.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml index 85ee997..6b17f12 100644 --- a/server/sql/sqlc.yaml +++ b/server/sql/sqlc.yaml @@ -8,3 +8,13 @@ sql: package: "db" out: "../db" emit_json_tags: true + overrides: + - db_type: "TEXT" + nullable: true + go_type: "*string" + - db_type: "INTEGER" + nullable: true + go_type: "*int64" + - db_type: "TIMESTAMP" + nullable: true + go_type: "*time.Time" \ No newline at end of file From 42c279398fb3dd8a677265e8e1a5d60c2f2b3626 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 14:39:33 +0100 Subject: [PATCH 171/248] fmt sql --- server/sql/queries/blogs.sql | 14 +- server/sql/queries/carousel.sql | 24 ++- server/sql/queries/employees.sql | 20 ++- server/sql/queries/exhibition.sql | 20 ++- server/sql/queries/machines.sql | 4 +- server/sql/queries/privacy.sql | 19 ++- server/sql/queries/product.sql | 3 +- server/sql/queries/suppliers.sql | 57 +++++-- server/sql/queries/video.sql | 4 +- server/sql/queries/warranty.sql | 8 +- server/sql/schema.sql | 254 ++++++++++++++++-------------- 11 files changed, 267 insertions(+), 160 deletions(-) diff --git a/server/sql/queries/blogs.sql b/server/sql/queries/blogs.sql index d130b4c..2bade2e 100644 --- a/server/sql/queries/blogs.sql +++ b/server/sql/queries/blogs.sql @@ -14,14 +14,22 @@ values (?, ?, ?, ?, ?, ?, ?); -- name: UpdateBlogNoImage :exec update Blog -set title = ?, date = ?, subheading = ?, body = ? +set title = ?, + date = ?, + subheading = ?, + body = ? where id = ?; -- name: UpdateBlog :exec update Blog -set title = ?, date = ?, main_image = ?, subheading = ?, body = ? +set title = ?, + date = ?, + main_image = ?, + subheading = ?, + body = ? where id = ?; -- name: DeleteBlog :exec -delete from Blog +delete +from Blog where id = ?; diff --git a/server/sql/queries/carousel.sql b/server/sql/queries/carousel.sql index f2fd22a..490cd57 100644 --- a/server/sql/queries/carousel.sql +++ b/server/sql/queries/carousel.sql @@ -1,17 +1,29 @@ -- name: GetCarousels :many -select id, name, image, created from Carousel order by created desc; +select id, name, image, created +from Carousel +order by created desc; -- name: GetCarouselByID :one -select id, name, image, created from Carousel where id = ?; +select id, name, image, created +from Carousel +where id = ?; -- name: CreateCarousel :exec -insert into Carousel (id, name, image, created) VALUES (?, ?, ?, ?); +insert into Carousel (id, name, image, created) +VALUES (?, ?, ?, ?); -- name: UpdateCarousel :exec -update Carousel set name = ?, image = ? where id = ?; +update Carousel +set name = ?, + image = ? +where id = ?; -- name: UpdateCarouselNoImage :exec -update Carousel set name = ? where id = ?; +update Carousel +set name = ? +where id = ?; -- name: DeleteCarousel :exec -delete from Carousel where id = ?; \ No newline at end of file +delete +from Carousel +where id = ?; \ No newline at end of file diff --git a/server/sql/queries/employees.sql b/server/sql/queries/employees.sql index 34f209c..b95fa3b 100644 --- a/server/sql/queries/employees.sql +++ b/server/sql/queries/employees.sql @@ -1,9 +1,12 @@ -- name: GetEmployees :many select id, name, email, role, profile_image, created -from Employee order by created desc; +from Employee +order by created desc; -- name: GetEmployee :one -select id, name, email, role, profile_image, created from Employee where id = ?; +select id, name, email, role, profile_image, created +from Employee +where id = ?; -- name: CreateEmployee :exec insert into Employee (id, name, email, role, profile_image, created) @@ -11,13 +14,20 @@ values (?, ?, ?, ?, ?, ?); -- name: UpdateEmployeeNoImage :exec update Employee -set name = ?, email = ?, role = ? +set name = ?, + email = ?, + role = ? where id = ?; -- name: UpdateEmployee :exec update Employee -set name = ?, email = ?, role = ?, profile_image = ? +set name = ?, + email = ?, + role = ?, + profile_image = ? where id = ?; -- name: DeleteEmployee :exec -delete from Employee where id = ?; +delete +from Employee +where id = ?; diff --git a/server/sql/queries/exhibition.sql b/server/sql/queries/exhibition.sql index 459e372..5396847 100644 --- a/server/sql/queries/exhibition.sql +++ b/server/sql/queries/exhibition.sql @@ -1,16 +1,26 @@ -- name: GetExhibitions :many -select id, title, date, location, info, created from Exhibition order by created desc; +select id, title, date, location, info, created +from Exhibition +order by created desc; -- name: GetExhibitionByID :one -select id, title, date, location, info, created from Exhibition where id = ?; +select id, title, date, location, info, created +from Exhibition +where id = ?; -- name: CreateExhibition :exec -insert into Exhibition (id, title, date, location, info, created) values (?, ?, ?, ?, ?, ?); +insert into Exhibition (id, title, date, location, info, created) +values (?, ?, ?, ?, ?, ?); -- name: UpdateExhibition :exec update Exhibition -set title = ?, date = ?, location = ?, info = ? +set title = ?, + date = ?, + location = ?, + info = ? where id = ?; -- name: DeleteExhibition :exec -delete from Exhibition where id = ?; \ No newline at end of file +delete +from Exhibition +where id = ?; \ No newline at end of file diff --git a/server/sql/queries/machines.sql b/server/sql/queries/machines.sql index 10f7430..51c9382 100644 --- a/server/sql/queries/machines.sql +++ b/server/sql/queries/machines.sql @@ -30,4 +30,6 @@ set supplier_id = ?, where id = ?; -- name: DeleteMachine :exec -delete from Machine where id = ?; \ No newline at end of file +delete +from Machine +where id = ?; \ No newline at end of file diff --git a/server/sql/queries/privacy.sql b/server/sql/queries/privacy.sql index 418b260..4f10196 100644 --- a/server/sql/queries/privacy.sql +++ b/server/sql/queries/privacy.sql @@ -1,14 +1,23 @@ -- name: GetPrivacies :many -select id, title, body, created from Privacy; +select id, title, body, created +from Privacy; -- name: GetPrivacyByID :one -select id, title, body, created from Privacy where id = ?; +select id, title, body, created +from Privacy +where id = ?; -- name: CreatePrivacy :exec -insert into Privacy (id, title, body, created) VALUES (?, ?, ?, ?); +insert into Privacy (id, title, body, created) +VALUES (?, ?, ?, ?); -- name: UpdatePrivacy :exec -update Privacy set title = ?, body = ? where id = ?; +update Privacy +set title = ?, + body = ? +where id = ?; -- name: DeletePrivacy :exec -delete from Privacy where id = ?; \ No newline at end of file +delete +from Privacy +where id = ?; \ No newline at end of file diff --git a/server/sql/queries/product.sql b/server/sql/queries/product.sql index da9a459..d3aa0e7 100644 --- a/server/sql/queries/product.sql +++ b/server/sql/queries/product.sql @@ -1,6 +1,7 @@ -- name: GetProducts :many select id, machine_id, name, product_image, description, product_link -from Product where machine_id = ?; +from Product +where machine_id = ?; -- name: GetProductByID :one select id, machine_id, name, product_image, description, product_link diff --git a/server/sql/queries/suppliers.sql b/server/sql/queries/suppliers.sql index 2b2bd47..6577226 100644 --- a/server/sql/queries/suppliers.sql +++ b/server/sql/queries/suppliers.sql @@ -1,14 +1,32 @@ -- name: GetSuppliers :many -select id, name, logo_image, marketing_image, - description, social_facebook, social_instagram, - social_linkedin, social_twitter, social_youtube, social_website, created +select id, + name, + logo_image, + marketing_image, + description, + social_facebook, + social_instagram, + social_linkedin, + social_twitter, + social_youtube, + social_website, + created from Supplier order by created desc; -- name: GetSupplierByID :one -select id, name, logo_image, marketing_image, - description, social_facebook, social_instagram, - social_linkedin, social_twitter, social_youtube, social_website, created +select id, + name, + logo_image, + marketing_image, + description, + social_facebook, + social_instagram, + social_linkedin, + social_twitter, + social_youtube, + social_website, + created from Supplier where id = ?; @@ -20,16 +38,31 @@ values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); -- name: UpdateSupplierNoImage :exec update Supplier -set name = ?, description = ?, social_facebook = ?, social_twitter = ?, - social_instagram = ?, social_youtube = ?, social_linkedin = ?, social_website = ? +set name = ?, + description = ?, + social_facebook = ?, + social_twitter = ?, + social_instagram = ?, + social_youtube = ?, + social_linkedin = ?, + social_website = ? where id = ?; -- name: UpdateSupplier :exec update Supplier -set name = ?, logo_image = ?, marketing_image = ?, description = ?, - social_facebook = ?, social_twitter = ?, social_instagram = ?, social_youtube = ?, - social_linkedin = ?, social_website = ? +set name = ?, + logo_image = ?, + marketing_image = ?, + description = ?, + social_facebook = ?, + social_twitter = ?, + social_instagram = ?, + social_youtube = ?, + social_linkedin = ?, + social_website = ? where id = ?; -- name: DeleteSupplier :exec -delete from Supplier where id = ? \ No newline at end of file +delete +from Supplier +where id = ? \ No newline at end of file diff --git a/server/sql/queries/video.sql b/server/sql/queries/video.sql index 0353d1f..94baec4 100644 --- a/server/sql/queries/video.sql +++ b/server/sql/queries/video.sql @@ -37,4 +37,6 @@ set supplier_id = ?, where id = ?; -- name: DeleteVideo :exec -delete from Video where id = ?; +delete +from Video +where id = ?; diff --git a/server/sql/queries/warranty.sql b/server/sql/queries/warranty.sql index e8b5f1b..3180d8d 100644 --- a/server/sql/queries/warranty.sql +++ b/server/sql/queries/warranty.sql @@ -55,7 +55,11 @@ set dealer = ?, where id = ?; -- name: DeleteWarranty :exec -delete from WarrantyClaim where id = ?; +delete +from WarrantyClaim +where id = ?; -- name: DeletePartsRequired :exec -delete from PartsRequired where warranty_id = ?; +delete +from PartsRequired +where warranty_id = ?; diff --git a/server/sql/schema.sql b/server/sql/schema.sql index e056889..8104766 100644 --- a/server/sql/schema.sql +++ b/server/sql/schema.sql @@ -5,171 +5,187 @@ PRAGMA foreign_keys = ON; PRAGMA journal_mode = wal; -- Create tables with safety features -CREATE TABLE IF NOT EXISTS Blog ( - id TEXT PRIMARY KEY, - title TEXT NOT NULL, - date TEXT, +CREATE TABLE IF NOT EXISTS Blog +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + date TEXT, main_image TEXT, subheading TEXT, - body TEXT, - created TEXT + body TEXT, + created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Carousel ( - id TEXT PRIMARY KEY, - name TEXT NOT NULL, - image TEXT, +CREATE TABLE IF NOT EXISTS Carousel +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + image TEXT, created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Employee ( - id TEXT PRIMARY KEY, - name TEXT NOT NULL, - email TEXT NOT NULL, - role TEXT NOT NULL, +CREATE TABLE IF NOT EXISTS Employee +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + email TEXT NOT NULL, + role TEXT NOT NULL, profile_image TEXT, - created TEXT + created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Exhibition ( - id TEXT PRIMARY KEY, - title TEXT NOT NULL, - date TEXT, +CREATE TABLE IF NOT EXISTS Exhibition +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + date TEXT, location TEXT, - info TEXT, - created TEXT + info TEXT, + created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS LineItems ( - id TEXT PRIMARY KEY, - name TEXT NOT NULL, +CREATE TABLE IF NOT EXISTS LineItems +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, price REAL NOT NULL, image TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Supplier ( - id TEXT PRIMARY KEY, - name TEXT NOT NULL, - logo_image TEXT, - marketing_image TEXT, - description TEXT, - social_facebook TEXT, - social_twitter TEXT, +CREATE TABLE IF NOT EXISTS Supplier +( + id TEXT PRIMARY KEY, + name TEXT NOT NULL, + logo_image TEXT, + marketing_image TEXT, + description TEXT, + social_facebook TEXT, + social_twitter TEXT, social_instagram TEXT, - social_youtube TEXT, - social_linkedin TEXT, - social_website TEXT, - created TEXT + social_youtube TEXT, + social_linkedin TEXT, + social_website TEXT, + created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Machine ( - id TEXT PRIMARY KEY, - supplier_id TEXT NOT NULL, - name TEXT NOT NULL, +CREATE TABLE IF NOT EXISTS Machine +( + id TEXT PRIMARY KEY, + supplier_id TEXT NOT NULL, + name TEXT NOT NULL, machine_image TEXT, - description TEXT, - machine_link TEXT, - created TEXT, - FOREIGN KEY (supplier_id) REFERENCES Supplier(id) ON DELETE CASCADE + description TEXT, + machine_link TEXT, + created TEXT, + FOREIGN KEY (supplier_id) REFERENCES Supplier (id) ON DELETE CASCADE ) STRICT; -CREATE TABLE IF NOT EXISTS MachineRegistration ( - id TEXT PRIMARY KEY, - dealer_name TEXT NOT NULL, - dealer_address TEXT, - owner_name TEXT NOT NULL, - owner_address TEXT, - machine_model TEXT NOT NULL, - serial_number TEXT NOT NULL, - install_date TEXT, - invoice_number TEXT, - complete_supply INTEGER, - pdi_complete INTEGER, - pto_correct INTEGER, - machine_test_run INTEGER, - safety_induction INTEGER, +CREATE TABLE IF NOT EXISTS MachineRegistration +( + id TEXT PRIMARY KEY, + dealer_name TEXT NOT NULL, + dealer_address TEXT, + owner_name TEXT NOT NULL, + owner_address TEXT, + machine_model TEXT NOT NULL, + serial_number TEXT NOT NULL, + install_date TEXT, + invoice_number TEXT, + complete_supply INTEGER, + pdi_complete INTEGER, + pto_correct INTEGER, + machine_test_run INTEGER, + safety_induction INTEGER, operator_handbook INTEGER, - date TEXT, - completed_by TEXT, - created TEXT + date TEXT, + completed_by TEXT, + created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS WarrantyClaim ( - id TEXT PRIMARY KEY, - dealer TEXT NOT NULL, - dealer_contact TEXT, - owner_name TEXT NOT NULL, - machine_model TEXT NOT NULL, - serial_number TEXT NOT NULL, - install_date TEXT, - failure_date TEXT, - repair_date TEXT, +CREATE TABLE IF NOT EXISTS WarrantyClaim +( + id TEXT PRIMARY KEY, + dealer TEXT NOT NULL, + dealer_contact TEXT, + owner_name TEXT NOT NULL, + machine_model TEXT NOT NULL, + serial_number TEXT NOT NULL, + install_date TEXT, + failure_date TEXT, + repair_date TEXT, failure_details TEXT, - repair_details TEXT, - labour_hours TEXT, - completed_by TEXT, - created TEXT + repair_details TEXT, + labour_hours TEXT, + completed_by TEXT, + created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS PartsRequired ( - id TEXT PRIMARY KEY, - warranty_id TEXT NOT NULL, - part_number TEXT, +CREATE TABLE IF NOT EXISTS PartsRequired +( + id TEXT PRIMARY KEY, + warranty_id TEXT NOT NULL, + part_number TEXT, quantity_needed TEXT NOT NULL, - invoice_number TEXT, - description TEXT, - FOREIGN KEY (warranty_id) REFERENCES WarrantyClaim(id) ON DELETE CASCADE + invoice_number TEXT, + description TEXT, + FOREIGN KEY (warranty_id) REFERENCES WarrantyClaim (id) ON DELETE CASCADE ) STRICT; -CREATE TABLE IF NOT EXISTS Privacy ( - id TEXT PRIMARY KEY, - title TEXT NOT NULL, - body TEXT, +CREATE TABLE IF NOT EXISTS Privacy +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + body TEXT, created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Product ( - id TEXT PRIMARY KEY, - machine_id TEXT NOT NULL, - name TEXT NOT NULL, +CREATE TABLE IF NOT EXISTS Product +( + id TEXT PRIMARY KEY, + machine_id TEXT NOT NULL, + name TEXT NOT NULL, product_image TEXT, - description TEXT, - product_link TEXT, - FOREIGN KEY (machine_id) REFERENCES Machine(id) ON DELETE CASCADE + description TEXT, + product_link TEXT, + FOREIGN KEY (machine_id) REFERENCES Machine (id) ON DELETE CASCADE ) STRICT; -CREATE TABLE IF NOT EXISTS SpareParts ( - id TEXT PRIMARY KEY, - supplier_id TEXT NOT NULL, - name TEXT NOT NULL, - parts_image TEXT, +CREATE TABLE IF NOT EXISTS SpareParts +( + id TEXT PRIMARY KEY, + supplier_id TEXT NOT NULL, + name TEXT NOT NULL, + parts_image TEXT, spare_parts_link TEXT, - FOREIGN KEY (supplier_id) REFERENCES Supplier(id) ON DELETE CASCADE + FOREIGN KEY (supplier_id) REFERENCES Supplier (id) ON DELETE CASCADE ) STRICT; -CREATE TABLE IF NOT EXISTS Terms ( - id TEXT PRIMARY KEY, - title TEXT NOT NULL, - body TEXT, +CREATE TABLE IF NOT EXISTS Terms +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + body TEXT, created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Timeline ( - id TEXT PRIMARY KEY, - title TEXT NOT NULL, - date TEXT, - body TEXT, +CREATE TABLE IF NOT EXISTS Timeline +( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + date TEXT, + body TEXT, created TEXT ) STRICT; -CREATE TABLE IF NOT EXISTS Video ( - id TEXT PRIMARY KEY, - supplier_id TEXT NOT NULL, - web_url TEXT, - title TEXT, - description TEXT, - video_id TEXT, +CREATE TABLE IF NOT EXISTS Video +( + id TEXT PRIMARY KEY, + supplier_id TEXT NOT NULL, + web_url TEXT, + title TEXT, + description TEXT, + video_id TEXT, thumbnail_url TEXT, - created TEXT, - FOREIGN KEY (supplier_id) REFERENCES Supplier(id) ON DELETE CASCADE + created TEXT, + FOREIGN KEY (supplier_id) REFERENCES Supplier (id) ON DELETE CASCADE ) STRICT; \ No newline at end of file From 8e7fca30b41805884b85a76f0652d5f8337e0efb Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 14:45:21 +0100 Subject: [PATCH 172/248] fmt sqlc gen --- server/db/blogs.sql.go | 14 +++++++-- server/db/carousel.sql.go | 24 ++++++++++++---- server/db/employees.sql.go | 20 +++++++++---- server/db/exhibition.sql.go | 20 +++++++++---- server/db/machines.sql.go | 4 ++- server/db/privacy.sql.go | 19 +++++++++---- server/db/product.sql.go | 3 +- server/db/suppliers.sql.go | 57 +++++++++++++++++++++++++++++-------- server/db/video.sql.go | 4 ++- server/db/warranty.sql.go | 8 ++++-- 10 files changed, 132 insertions(+), 41 deletions(-) diff --git a/server/db/blogs.sql.go b/server/db/blogs.sql.go index 8eefc07..b603fde 100644 --- a/server/db/blogs.sql.go +++ b/server/db/blogs.sql.go @@ -39,7 +39,8 @@ func (q *Queries) CreateBlog(ctx context.Context, arg CreateBlogParams) error { } const deleteBlog = `-- name: DeleteBlog :exec -delete from Blog +delete +from Blog where id = ? ` @@ -108,7 +109,11 @@ func (q *Queries) GetBlogs(ctx context.Context) ([]Blog, error) { const updateBlog = `-- name: UpdateBlog :exec update Blog -set title = ?, date = ?, main_image = ?, subheading = ?, body = ? +set title = ?, + date = ?, + main_image = ?, + subheading = ?, + body = ? where id = ? ` @@ -135,7 +140,10 @@ func (q *Queries) UpdateBlog(ctx context.Context, arg UpdateBlogParams) error { const updateBlogNoImage = `-- name: UpdateBlogNoImage :exec update Blog -set title = ?, date = ?, subheading = ?, body = ? +set title = ?, + date = ?, + subheading = ?, + body = ? where id = ? ` diff --git a/server/db/carousel.sql.go b/server/db/carousel.sql.go index ed1091f..0a1413e 100644 --- a/server/db/carousel.sql.go +++ b/server/db/carousel.sql.go @@ -11,7 +11,8 @@ import ( ) const createCarousel = `-- name: CreateCarousel :exec -insert into Carousel (id, name, image, created) VALUES (?, ?, ?, ?) +insert into Carousel (id, name, image, created) +VALUES (?, ?, ?, ?) ` type CreateCarouselParams struct { @@ -32,7 +33,9 @@ func (q *Queries) CreateCarousel(ctx context.Context, arg CreateCarouselParams) } const deleteCarousel = `-- name: DeleteCarousel :exec -delete from Carousel where id = ? +delete +from Carousel +where id = ? ` func (q *Queries) DeleteCarousel(ctx context.Context, id string) error { @@ -41,7 +44,9 @@ func (q *Queries) DeleteCarousel(ctx context.Context, id string) error { } const getCarouselByID = `-- name: GetCarouselByID :one -select id, name, image, created from Carousel where id = ? +select id, name, image, created +from Carousel +where id = ? ` func (q *Queries) GetCarouselByID(ctx context.Context, id string) (Carousel, error) { @@ -57,7 +62,9 @@ func (q *Queries) GetCarouselByID(ctx context.Context, id string) (Carousel, err } const getCarousels = `-- name: GetCarousels :many -select id, name, image, created from Carousel order by created desc +select id, name, image, created +from Carousel +order by created desc ` func (q *Queries) GetCarousels(ctx context.Context) ([]Carousel, error) { @@ -89,7 +96,10 @@ func (q *Queries) GetCarousels(ctx context.Context) ([]Carousel, error) { } const updateCarousel = `-- name: UpdateCarousel :exec -update Carousel set name = ?, image = ? where id = ? +update Carousel +set name = ?, + image = ? +where id = ? ` type UpdateCarouselParams struct { @@ -104,7 +114,9 @@ func (q *Queries) UpdateCarousel(ctx context.Context, arg UpdateCarouselParams) } const updateCarouselNoImage = `-- name: UpdateCarouselNoImage :exec -update Carousel set name = ? where id = ? +update Carousel +set name = ? +where id = ? ` type UpdateCarouselNoImageParams struct { diff --git a/server/db/employees.sql.go b/server/db/employees.sql.go index 55e20cb..0ea623b 100644 --- a/server/db/employees.sql.go +++ b/server/db/employees.sql.go @@ -37,7 +37,9 @@ func (q *Queries) CreateEmployee(ctx context.Context, arg CreateEmployeeParams) } const deleteEmployee = `-- name: DeleteEmployee :exec -delete from Employee where id = ? +delete +from Employee +where id = ? ` func (q *Queries) DeleteEmployee(ctx context.Context, id string) error { @@ -46,7 +48,9 @@ func (q *Queries) DeleteEmployee(ctx context.Context, id string) error { } const getEmployee = `-- name: GetEmployee :one -select id, name, email, role, profile_image, created from Employee where id = ? +select id, name, email, role, profile_image, created +from Employee +where id = ? ` func (q *Queries) GetEmployee(ctx context.Context, id string) (Employee, error) { @@ -65,7 +69,8 @@ func (q *Queries) GetEmployee(ctx context.Context, id string) (Employee, error) const getEmployees = `-- name: GetEmployees :many select id, name, email, role, profile_image, created -from Employee order by created desc +from Employee +order by created desc ` func (q *Queries) GetEmployees(ctx context.Context) ([]Employee, error) { @@ -100,7 +105,10 @@ func (q *Queries) GetEmployees(ctx context.Context) ([]Employee, error) { const updateEmployee = `-- name: UpdateEmployee :exec update Employee -set name = ?, email = ?, role = ?, profile_image = ? +set name = ?, + email = ?, + role = ?, + profile_image = ? where id = ? ` @@ -125,7 +133,9 @@ func (q *Queries) UpdateEmployee(ctx context.Context, arg UpdateEmployeeParams) const updateEmployeeNoImage = `-- name: UpdateEmployeeNoImage :exec update Employee -set name = ?, email = ?, role = ? +set name = ?, + email = ?, + role = ? where id = ? ` diff --git a/server/db/exhibition.sql.go b/server/db/exhibition.sql.go index 5560445..07605c0 100644 --- a/server/db/exhibition.sql.go +++ b/server/db/exhibition.sql.go @@ -11,7 +11,8 @@ import ( ) const createExhibition = `-- name: CreateExhibition :exec -insert into Exhibition (id, title, date, location, info, created) values (?, ?, ?, ?, ?, ?) +insert into Exhibition (id, title, date, location, info, created) +values (?, ?, ?, ?, ?, ?) ` type CreateExhibitionParams struct { @@ -36,7 +37,9 @@ func (q *Queries) CreateExhibition(ctx context.Context, arg CreateExhibitionPara } const deleteExhibition = `-- name: DeleteExhibition :exec -delete from Exhibition where id = ? +delete +from Exhibition +where id = ? ` func (q *Queries) DeleteExhibition(ctx context.Context, id string) error { @@ -45,7 +48,9 @@ func (q *Queries) DeleteExhibition(ctx context.Context, id string) error { } const getExhibitionByID = `-- name: GetExhibitionByID :one -select id, title, date, location, info, created from Exhibition where id = ? +select id, title, date, location, info, created +from Exhibition +where id = ? ` func (q *Queries) GetExhibitionByID(ctx context.Context, id string) (Exhibition, error) { @@ -63,7 +68,9 @@ func (q *Queries) GetExhibitionByID(ctx context.Context, id string) (Exhibition, } const getExhibitions = `-- name: GetExhibitions :many -select id, title, date, location, info, created from Exhibition order by created desc +select id, title, date, location, info, created +from Exhibition +order by created desc ` func (q *Queries) GetExhibitions(ctx context.Context) ([]Exhibition, error) { @@ -98,7 +105,10 @@ func (q *Queries) GetExhibitions(ctx context.Context) ([]Exhibition, error) { const updateExhibition = `-- name: UpdateExhibition :exec update Exhibition -set title = ?, date = ?, location = ?, info = ? +set title = ?, + date = ?, + location = ?, + info = ? where id = ? ` diff --git a/server/db/machines.sql.go b/server/db/machines.sql.go index 7ac2186..5320ef5 100644 --- a/server/db/machines.sql.go +++ b/server/db/machines.sql.go @@ -39,7 +39,9 @@ func (q *Queries) CreateMachine(ctx context.Context, arg CreateMachineParams) er } const deleteMachine = `-- name: DeleteMachine :exec -delete from Machine where id = ? +delete +from Machine +where id = ? ` func (q *Queries) DeleteMachine(ctx context.Context, id string) error { diff --git a/server/db/privacy.sql.go b/server/db/privacy.sql.go index bc619d3..1edd33c 100644 --- a/server/db/privacy.sql.go +++ b/server/db/privacy.sql.go @@ -11,7 +11,8 @@ import ( ) const createPrivacy = `-- name: CreatePrivacy :exec -insert into Privacy (id, title, body, created) VALUES (?, ?, ?, ?) +insert into Privacy (id, title, body, created) +VALUES (?, ?, ?, ?) ` type CreatePrivacyParams struct { @@ -32,7 +33,9 @@ func (q *Queries) CreatePrivacy(ctx context.Context, arg CreatePrivacyParams) er } const deletePrivacy = `-- name: DeletePrivacy :exec -delete from Privacy where id = ? +delete +from Privacy +where id = ? ` func (q *Queries) DeletePrivacy(ctx context.Context, id string) error { @@ -41,7 +44,8 @@ func (q *Queries) DeletePrivacy(ctx context.Context, id string) error { } const getPrivacies = `-- name: GetPrivacies :many -select id, title, body, created from Privacy +select id, title, body, created +from Privacy ` func (q *Queries) GetPrivacies(ctx context.Context) ([]Privacy, error) { @@ -73,7 +77,9 @@ func (q *Queries) GetPrivacies(ctx context.Context) ([]Privacy, error) { } const getPrivacyByID = `-- name: GetPrivacyByID :one -select id, title, body, created from Privacy where id = ? +select id, title, body, created +from Privacy +where id = ? ` func (q *Queries) GetPrivacyByID(ctx context.Context, id string) (Privacy, error) { @@ -89,7 +95,10 @@ func (q *Queries) GetPrivacyByID(ctx context.Context, id string) (Privacy, error } const updatePrivacy = `-- name: UpdatePrivacy :exec -update Privacy set title = ?, body = ? where id = ? +update Privacy +set title = ?, + body = ? +where id = ? ` type UpdatePrivacyParams struct { diff --git a/server/db/product.sql.go b/server/db/product.sql.go index 27115c5..bf2abf4 100644 --- a/server/db/product.sql.go +++ b/server/db/product.sql.go @@ -69,7 +69,8 @@ func (q *Queries) GetProductByID(ctx context.Context, id string) (Product, error const getProducts = `-- name: GetProducts :many select id, machine_id, name, product_image, description, product_link -from Product where machine_id = ? +from Product +where machine_id = ? ` func (q *Queries) GetProducts(ctx context.Context, machineID string) ([]Product, error) { diff --git a/server/db/suppliers.sql.go b/server/db/suppliers.sql.go index c18c694..036108c 100644 --- a/server/db/suppliers.sql.go +++ b/server/db/suppliers.sql.go @@ -51,7 +51,9 @@ func (q *Queries) CreateSupplier(ctx context.Context, arg CreateSupplierParams) } const deleteSupplier = `-- name: DeleteSupplier :exec -delete from Supplier where id = ? +delete +from Supplier +where id = ? ` func (q *Queries) DeleteSupplier(ctx context.Context, id string) error { @@ -60,9 +62,18 @@ func (q *Queries) DeleteSupplier(ctx context.Context, id string) error { } const getSupplierByID = `-- name: GetSupplierByID :one -select id, name, logo_image, marketing_image, - description, social_facebook, social_instagram, - social_linkedin, social_twitter, social_youtube, social_website, created +select id, + name, + logo_image, + marketing_image, + description, + social_facebook, + social_instagram, + social_linkedin, + social_twitter, + social_youtube, + social_website, + created from Supplier where id = ? ` @@ -103,9 +114,18 @@ func (q *Queries) GetSupplierByID(ctx context.Context, id string) (GetSupplierBy } const getSuppliers = `-- name: GetSuppliers :many -select id, name, logo_image, marketing_image, - description, social_facebook, social_instagram, - social_linkedin, social_twitter, social_youtube, social_website, created +select id, + name, + logo_image, + marketing_image, + description, + social_facebook, + social_instagram, + social_linkedin, + social_twitter, + social_youtube, + social_website, + created from Supplier order by created desc ` @@ -163,9 +183,16 @@ func (q *Queries) GetSuppliers(ctx context.Context) ([]GetSuppliersRow, error) { const updateSupplier = `-- name: UpdateSupplier :exec update Supplier -set name = ?, logo_image = ?, marketing_image = ?, description = ?, - social_facebook = ?, social_twitter = ?, social_instagram = ?, social_youtube = ?, - social_linkedin = ?, social_website = ? +set name = ?, + logo_image = ?, + marketing_image = ?, + description = ?, + social_facebook = ?, + social_twitter = ?, + social_instagram = ?, + social_youtube = ?, + social_linkedin = ?, + social_website = ? where id = ? ` @@ -202,8 +229,14 @@ func (q *Queries) UpdateSupplier(ctx context.Context, arg UpdateSupplierParams) const updateSupplierNoImage = `-- name: UpdateSupplierNoImage :exec update Supplier -set name = ?, description = ?, social_facebook = ?, social_twitter = ?, - social_instagram = ?, social_youtube = ?, social_linkedin = ?, social_website = ? +set name = ?, + description = ?, + social_facebook = ?, + social_twitter = ?, + social_instagram = ?, + social_youtube = ?, + social_linkedin = ?, + social_website = ? where id = ? ` diff --git a/server/db/video.sql.go b/server/db/video.sql.go index b387289..c1a6988 100644 --- a/server/db/video.sql.go +++ b/server/db/video.sql.go @@ -41,7 +41,9 @@ func (q *Queries) CreateVideo(ctx context.Context, arg CreateVideoParams) error } const deleteVideo = `-- name: DeleteVideo :exec -delete from Video where id = ? +delete +from Video +where id = ? ` func (q *Queries) DeleteVideo(ctx context.Context, id string) error { diff --git a/server/db/warranty.sql.go b/server/db/warranty.sql.go index 13f5ed3..2bfb206 100644 --- a/server/db/warranty.sql.go +++ b/server/db/warranty.sql.go @@ -81,7 +81,9 @@ func (q *Queries) CreateWarranty(ctx context.Context, arg CreateWarrantyParams) } const deletePartsRequired = `-- name: DeletePartsRequired :exec -delete from PartsRequired where warranty_id = ? +delete +from PartsRequired +where warranty_id = ? ` func (q *Queries) DeletePartsRequired(ctx context.Context, warrantyID string) error { @@ -90,7 +92,9 @@ func (q *Queries) DeletePartsRequired(ctx context.Context, warrantyID string) er } const deleteWarranty = `-- name: DeleteWarranty :exec -delete from WarrantyClaim where id = ? +delete +from WarrantyClaim +where id = ? ` func (q *Queries) DeleteWarranty(ctx context.Context, id string) error { From 10f307ba645f74bca39227f1980349b5ddbc61a2 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 14:49:20 +0100 Subject: [PATCH 173/248] going to be hell to pay for this --- server/sql/sqlc.yaml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/server/sql/sqlc.yaml b/server/sql/sqlc.yaml index 6b17f12..b7a4d9f 100644 --- a/server/sql/sqlc.yaml +++ b/server/sql/sqlc.yaml @@ -7,14 +7,4 @@ sql: go: package: "db" out: "../db" - emit_json_tags: true - overrides: - - db_type: "TEXT" - nullable: true - go_type: "*string" - - db_type: "INTEGER" - nullable: true - go_type: "*int64" - - db_type: "TIMESTAMP" - nullable: true - go_type: "*time.Time" \ No newline at end of file + emit_json_tags: true \ No newline at end of file From edde795194b3499289336c60748aec9a7138dbb4 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 15:20:21 +0100 Subject: [PATCH 174/248] conversions code --- server/lib/conversions.go | 208 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 server/lib/conversions.go diff --git a/server/lib/conversions.go b/server/lib/conversions.go new file mode 100644 index 0000000..842276d --- /dev/null +++ b/server/lib/conversions.go @@ -0,0 +1,208 @@ +package lib + +import ( + "database/sql" + "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/types" +) + +func int64ToBool(i sql.NullInt64) bool { + val := i.Int64 != 0 + return val +} + +func convertSupplier(supplier db.Supplier) types.Supplier { + return types.Supplier{ + ID: supplier.ID, + Name: supplier.Name, + LogoImage: supplier.LogoImage.String, + MarketingImage: supplier.MarketingImage.String, + Description: supplier.Description.String, + SocialFacebook: &supplier.SocialFacebook.String, + SocialInstagram: &supplier.SocialInstagram.String, + SocialLinkedin: &supplier.SocialLinkedin.String, + SocialTwitter: &supplier.SocialTwitter.String, + SocialYoutube: &supplier.SocialYoutube.String, + SocialWebsite: &supplier.SocialWebsite.String, + Created: supplier.Created.String, + } +} + +func convertBlog(blog db.Blog) types.Blog { + return types.Blog{ + ID: blog.ID, + Title: blog.Title, + Date: blog.Date.String, + MainImage: blog.MainImage.String, + Subheading: blog.Subheading.String, + Body: blog.Body.String, + Created: blog.Created.String, + } +} + +func convertCarousel(carousel db.Carousel) types.Carousel { + return types.Carousel{ + ID: carousel.ID, + Name: carousel.Name, + Image: carousel.Image.String, + Created: carousel.Created.String, + } +} + +func convertEmployee(employee db.Employee) types.Employee { + return types.Employee{ + ID: employee.ID, + Name: employee.Name, + Email: employee.Email, + Role: employee.Role, + ProfileImage: employee.ProfileImage.String, + Created: employee.Created.String, + } +} + +func convertExhibition(exhibition db.Exhibition) types.Exhibition { + return types.Exhibition{ + ID: exhibition.ID, + Title: exhibition.Title, + Date: exhibition.Date.String, + Location: exhibition.Location.String, + Info: exhibition.Info.String, + Created: exhibition.Created.String, + } +} + +func convertLineItem(lineItem db.LineItem) types.LineItem { + return types.LineItem{ + ID: lineItem.ID, + Name: lineItem.Name, + Price: lineItem.Price, + Image: lineItem.Image.String, + } +} + +func convertMachine(machine db.Machine) types.Machine { + return types.Machine{ + ID: machine.ID, + SupplierID: machine.SupplierID, + Name: machine.Name, + MachineImage: machine.MachineImage.String, + Description: &machine.Description.String, + MachineLink: &machine.MachineLink.String, + Created: machine.Created.String, + } +} + +func convertMachineRegistration(reg db.MachineRegistration) types.MachineRegistration { + return types.MachineRegistration{ + ID: reg.ID, + DealerName: reg.DealerName, + DealerAddress: reg.DealerAddress.String, + OwnerName: reg.OwnerName, + OwnerAddress: reg.OwnerAddress.String, + MachineModel: reg.MachineModel, + SerialNumber: reg.SerialNumber, + InstallDate: reg.InstallDate.String, + InvoiceNumber: reg.InvoiceNumber.String, + CompleteSupply: int64ToBool(reg.CompleteSupply), + PdiComplete: int64ToBool(reg.PdiComplete), + PtoCorrect: int64ToBool(reg.PtoCorrect), + MachineTestRun: int64ToBool(reg.MachineTestRun), + SafetyInduction: int64ToBool(reg.SafetyInduction), + OperatorHandbook: int64ToBool(reg.OperatorHandbook), + Date: reg.Date.String, + CompletedBy: reg.CompletedBy.String, + Created: reg.Created.String, + } +} + +func convertPartsRequired(parts db.PartsRequired) types.PartsRequired { + return types.PartsRequired{ + ID: parts.ID, + WarrantyID: parts.WarrantyID, + PartNumber: parts.PartNumber.String, + QuantityNeeded: parts.QuantityNeeded, + InvoiceNumber: parts.InvoiceNumber.String, + Description: parts.Description.String, + } +} + +func convertPrivacy(privacy db.Privacy) types.Privacy { + return types.Privacy{ + ID: privacy.ID, + Title: privacy.Title, + Body: privacy.Body.String, + Created: privacy.Created.String, + } +} + +func convertProduct(product db.Product) types.Product { + return types.Product{ + ID: product.ID, + MachineID: product.MachineID, + Name: product.Name, + ProductImage: product.ProductImage.String, + Description: product.Description.String, + ProductLink: product.ProductLink.String, + } +} + +func convertSparePart(sparePart db.SparePart) types.Sparepart { + return types.Sparepart{ + ID: sparePart.ID, + SupplierID: sparePart.SupplierID, + Name: sparePart.Name, + PartsImage: sparePart.PartsImage.String, + SparePartsLink: sparePart.SparePartsLink.String, + } +} + +func convertTerm(term db.Term) types.Terms { + return types.Terms{ + ID: term.ID, + Title: term.Title, + Body: term.Body.String, + Created: term.Created.String, + } +} + +func convertTimeline(timeline db.Timeline) types.Timeline { + return types.Timeline{ + ID: timeline.ID, + Title: timeline.Title, + Date: timeline.Date.String, + Body: timeline.Body.String, + Created: timeline.Created.String, + } +} + +func convertVideo(video db.Video) types.Video { + return types.Video{ + ID: video.ID, + SupplierID: video.SupplierID, + WebURL: video.WebUrl.String, + Title: &video.Title.String, + Description: &video.Description.String, + VideoID: &video.VideoID.String, + ThumbnailURL: &video.ThumbnailUrl.String, + Created: video.Created.String, + } +} + +func convertWarrantyClaim(claim db.WarrantyClaim) types.WarrantyClaim { + return types.WarrantyClaim{ + ID: claim.ID, + Dealer: claim.Dealer, + DealerContact: &claim.DealerContact.String, + OwnerName: &claim.OwnerName, + MachineModel: &claim.MachineModel, + SerialNumber: &claim.SerialNumber, + InstallDate: &claim.InstallDate.String, + FailureDate: &claim.FailureDate.String, + RepairDate: &claim.RepairDate.String, + FailureDetails: &claim.FailureDetails.String, + RepairDetails: &claim.RepairDetails.String, + LabourHours: &claim.LabourHours.String, + CompletedBy: &claim.CompletedBy.String, + Created: claim.Created.String, + } +} From 1f658b5a6029a670aa2b0db62be2985c73b5c43f Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 15:23:32 +0100 Subject: [PATCH 175/248] converstions public --- server/lib/conversions.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/server/lib/conversions.go b/server/lib/conversions.go index 842276d..28c4cbe 100644 --- a/server/lib/conversions.go +++ b/server/lib/conversions.go @@ -11,7 +11,7 @@ func int64ToBool(i sql.NullInt64) bool { return val } -func convertSupplier(supplier db.Supplier) types.Supplier { +func ConvertSupplier(supplier db.Supplier) types.Supplier { return types.Supplier{ ID: supplier.ID, Name: supplier.Name, @@ -28,7 +28,7 @@ func convertSupplier(supplier db.Supplier) types.Supplier { } } -func convertBlog(blog db.Blog) types.Blog { +func ConvertBlog(blog db.Blog) types.Blog { return types.Blog{ ID: blog.ID, Title: blog.Title, @@ -40,7 +40,7 @@ func convertBlog(blog db.Blog) types.Blog { } } -func convertCarousel(carousel db.Carousel) types.Carousel { +func ConvertCarousel(carousel db.Carousel) types.Carousel { return types.Carousel{ ID: carousel.ID, Name: carousel.Name, @@ -49,7 +49,7 @@ func convertCarousel(carousel db.Carousel) types.Carousel { } } -func convertEmployee(employee db.Employee) types.Employee { +func ConvertEmployee(employee db.Employee) types.Employee { return types.Employee{ ID: employee.ID, Name: employee.Name, @@ -60,7 +60,7 @@ func convertEmployee(employee db.Employee) types.Employee { } } -func convertExhibition(exhibition db.Exhibition) types.Exhibition { +func ConvertExhibition(exhibition db.Exhibition) types.Exhibition { return types.Exhibition{ ID: exhibition.ID, Title: exhibition.Title, @@ -71,7 +71,7 @@ func convertExhibition(exhibition db.Exhibition) types.Exhibition { } } -func convertLineItem(lineItem db.LineItem) types.LineItem { +func ConvertLineItem(lineItem db.LineItem) types.LineItem { return types.LineItem{ ID: lineItem.ID, Name: lineItem.Name, @@ -80,7 +80,7 @@ func convertLineItem(lineItem db.LineItem) types.LineItem { } } -func convertMachine(machine db.Machine) types.Machine { +func ConvertMachine(machine db.Machine) types.Machine { return types.Machine{ ID: machine.ID, SupplierID: machine.SupplierID, @@ -92,7 +92,7 @@ func convertMachine(machine db.Machine) types.Machine { } } -func convertMachineRegistration(reg db.MachineRegistration) types.MachineRegistration { +func ConvertMachineRegistration(reg db.MachineRegistration) types.MachineRegistration { return types.MachineRegistration{ ID: reg.ID, DealerName: reg.DealerName, @@ -115,7 +115,7 @@ func convertMachineRegistration(reg db.MachineRegistration) types.MachineRegistr } } -func convertPartsRequired(parts db.PartsRequired) types.PartsRequired { +func ConvertPartsRequired(parts db.PartsRequired) types.PartsRequired { return types.PartsRequired{ ID: parts.ID, WarrantyID: parts.WarrantyID, @@ -126,7 +126,7 @@ func convertPartsRequired(parts db.PartsRequired) types.PartsRequired { } } -func convertPrivacy(privacy db.Privacy) types.Privacy { +func ConvertPrivacy(privacy db.Privacy) types.Privacy { return types.Privacy{ ID: privacy.ID, Title: privacy.Title, @@ -135,7 +135,7 @@ func convertPrivacy(privacy db.Privacy) types.Privacy { } } -func convertProduct(product db.Product) types.Product { +func ConvertProduct(product db.Product) types.Product { return types.Product{ ID: product.ID, MachineID: product.MachineID, @@ -146,7 +146,7 @@ func convertProduct(product db.Product) types.Product { } } -func convertSparePart(sparePart db.SparePart) types.Sparepart { +func ConvertSparePart(sparePart db.SparePart) types.Sparepart { return types.Sparepart{ ID: sparePart.ID, SupplierID: sparePart.SupplierID, @@ -156,7 +156,7 @@ func convertSparePart(sparePart db.SparePart) types.Sparepart { } } -func convertTerm(term db.Term) types.Terms { +func ConvertTerm(term db.Term) types.Terms { return types.Terms{ ID: term.ID, Title: term.Title, @@ -165,7 +165,7 @@ func convertTerm(term db.Term) types.Terms { } } -func convertTimeline(timeline db.Timeline) types.Timeline { +func ConvertTimeline(timeline db.Timeline) types.Timeline { return types.Timeline{ ID: timeline.ID, Title: timeline.Title, @@ -175,7 +175,7 @@ func convertTimeline(timeline db.Timeline) types.Timeline { } } -func convertVideo(video db.Video) types.Video { +func ConvertVideo(video db.Video) types.Video { return types.Video{ ID: video.ID, SupplierID: video.SupplierID, @@ -188,7 +188,7 @@ func convertVideo(video db.Video) types.Video { } } -func convertWarrantyClaim(claim db.WarrantyClaim) types.WarrantyClaim { +func ConvertWarrantyClaim(claim db.WarrantyClaim) types.WarrantyClaim { return types.WarrantyClaim{ ID: claim.ID, Dealer: claim.Dealer, From 856b546b5f7fe11591b8a8ad2a294d0c399e63a2 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 15:26:13 +0100 Subject: [PATCH 176/248] use supplier conversion --- server/services/supplierService.go | 32 +++--------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 318cd34..843dbec 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -42,20 +42,7 @@ func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]types.S var result []types.Supplier for _, supplier := range suppliers { - result = append(result, types.Supplier{ - ID: supplier.ID, - Name: supplier.Name, - LogoImage: supplier.LogoImage.String, - MarketingImage: supplier.MarketingImage.String, - Description: supplier.Description.String, - SocialFacebook: &supplier.SocialFacebook.String, - SocialInstagram: &supplier.SocialInstagram.String, - SocialLinkedin: &supplier.SocialLinkedin.String, - SocialTwitter: &supplier.SocialTwitter.String, - SocialYoutube: &supplier.SocialYoutube.String, - SocialWebsite: &supplier.SocialWebsite.String, - Created: supplier.Created.String, - }) + result = append(result, lib.ConvertSupplier(supplier)) } return result, nil } @@ -65,21 +52,8 @@ func (service *SupplierServiceImpl) GetSupplierById(ctx context.Context, id stri if err != nil { return nil, err } - result := &types.Supplier{ - ID: supplier.ID, - Name: supplier.Name, - LogoImage: supplier.LogoImage.String, - MarketingImage: supplier.MarketingImage.String, - Description: supplier.Description.String, - SocialFacebook: &supplier.SocialFacebook.String, - SocialInstagram: &supplier.SocialInstagram.String, - SocialLinkedin: &supplier.SocialLinkedin.String, - SocialTwitter: &supplier.SocialTwitter.String, - SocialYoutube: &supplier.SocialYoutube.String, - SocialWebsite: &supplier.SocialWebsite.String, - Created: supplier.Created.String, - } - return result, nil + result := lib.ConvertSupplier(*supplier) + return &result, nil } func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) { From 2b50b285c75e23e79d92f3f44a5e653ae07a2211 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 15:45:35 +0100 Subject: [PATCH 177/248] serializers --- server/lib/{conversions.go => serializers.go} | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) rename server/lib/{conversions.go => serializers.go} (83%) diff --git a/server/lib/conversions.go b/server/lib/serializers.go similarity index 83% rename from server/lib/conversions.go rename to server/lib/serializers.go index 28c4cbe..5987ed6 100644 --- a/server/lib/conversions.go +++ b/server/lib/serializers.go @@ -11,7 +11,7 @@ func int64ToBool(i sql.NullInt64) bool { return val } -func ConvertSupplier(supplier db.Supplier) types.Supplier { +func SerializeSupplier(supplier db.Supplier) types.Supplier { return types.Supplier{ ID: supplier.ID, Name: supplier.Name, @@ -28,7 +28,7 @@ func ConvertSupplier(supplier db.Supplier) types.Supplier { } } -func ConvertBlog(blog db.Blog) types.Blog { +func SerializeBlog(blog db.Blog) types.Blog { return types.Blog{ ID: blog.ID, Title: blog.Title, @@ -40,7 +40,7 @@ func ConvertBlog(blog db.Blog) types.Blog { } } -func ConvertCarousel(carousel db.Carousel) types.Carousel { +func SerializeCarousel(carousel db.Carousel) types.Carousel { return types.Carousel{ ID: carousel.ID, Name: carousel.Name, @@ -49,7 +49,7 @@ func ConvertCarousel(carousel db.Carousel) types.Carousel { } } -func ConvertEmployee(employee db.Employee) types.Employee { +func SerializeEmployee(employee db.Employee) types.Employee { return types.Employee{ ID: employee.ID, Name: employee.Name, @@ -60,7 +60,7 @@ func ConvertEmployee(employee db.Employee) types.Employee { } } -func ConvertExhibition(exhibition db.Exhibition) types.Exhibition { +func SerializeExhibition(exhibition db.Exhibition) types.Exhibition { return types.Exhibition{ ID: exhibition.ID, Title: exhibition.Title, @@ -71,7 +71,7 @@ func ConvertExhibition(exhibition db.Exhibition) types.Exhibition { } } -func ConvertLineItem(lineItem db.LineItem) types.LineItem { +func SerializeLineItem(lineItem db.LineItem) types.LineItem { return types.LineItem{ ID: lineItem.ID, Name: lineItem.Name, @@ -80,7 +80,7 @@ func ConvertLineItem(lineItem db.LineItem) types.LineItem { } } -func ConvertMachine(machine db.Machine) types.Machine { +func SerializeMachine(machine db.Machine) types.Machine { return types.Machine{ ID: machine.ID, SupplierID: machine.SupplierID, @@ -92,7 +92,7 @@ func ConvertMachine(machine db.Machine) types.Machine { } } -func ConvertMachineRegistration(reg db.MachineRegistration) types.MachineRegistration { +func SerializeMachineRegistration(reg db.MachineRegistration) types.MachineRegistration { return types.MachineRegistration{ ID: reg.ID, DealerName: reg.DealerName, @@ -115,7 +115,7 @@ func ConvertMachineRegistration(reg db.MachineRegistration) types.MachineRegistr } } -func ConvertPartsRequired(parts db.PartsRequired) types.PartsRequired { +func SerializePartsRequired(parts db.PartsRequired) types.PartsRequired { return types.PartsRequired{ ID: parts.ID, WarrantyID: parts.WarrantyID, @@ -126,7 +126,7 @@ func ConvertPartsRequired(parts db.PartsRequired) types.PartsRequired { } } -func ConvertPrivacy(privacy db.Privacy) types.Privacy { +func SerializePrivacy(privacy db.Privacy) types.Privacy { return types.Privacy{ ID: privacy.ID, Title: privacy.Title, @@ -135,7 +135,7 @@ func ConvertPrivacy(privacy db.Privacy) types.Privacy { } } -func ConvertProduct(product db.Product) types.Product { +func SerializeProduct(product db.Product) types.Product { return types.Product{ ID: product.ID, MachineID: product.MachineID, @@ -146,7 +146,7 @@ func ConvertProduct(product db.Product) types.Product { } } -func ConvertSparePart(sparePart db.SparePart) types.Sparepart { +func SerializeSparePart(sparePart db.SparePart) types.Sparepart { return types.Sparepart{ ID: sparePart.ID, SupplierID: sparePart.SupplierID, @@ -156,7 +156,7 @@ func ConvertSparePart(sparePart db.SparePart) types.Sparepart { } } -func ConvertTerm(term db.Term) types.Terms { +func SerializeTerm(term db.Term) types.Terms { return types.Terms{ ID: term.ID, Title: term.Title, @@ -165,7 +165,7 @@ func ConvertTerm(term db.Term) types.Terms { } } -func ConvertTimeline(timeline db.Timeline) types.Timeline { +func SerializeTimeline(timeline db.Timeline) types.Timeline { return types.Timeline{ ID: timeline.ID, Title: timeline.Title, @@ -175,7 +175,7 @@ func ConvertTimeline(timeline db.Timeline) types.Timeline { } } -func ConvertVideo(video db.Video) types.Video { +func SerializeVideo(video db.Video) types.Video { return types.Video{ ID: video.ID, SupplierID: video.SupplierID, @@ -188,7 +188,7 @@ func ConvertVideo(video db.Video) types.Video { } } -func ConvertWarrantyClaim(claim db.WarrantyClaim) types.WarrantyClaim { +func SerializeWarrantyClaim(claim db.WarrantyClaim) types.WarrantyClaim { return types.WarrantyClaim{ ID: claim.ID, Dealer: claim.Dealer, From 6fd44eb04f6949e232c6a9bd7f6b84fe22071240 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 15:46:04 +0100 Subject: [PATCH 178/248] deserializers --- server/lib/deserializers.go | 210 ++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 server/lib/deserializers.go diff --git a/server/lib/deserializers.go b/server/lib/deserializers.go new file mode 100644 index 0000000..81f42c3 --- /dev/null +++ b/server/lib/deserializers.go @@ -0,0 +1,210 @@ +package lib + +import ( + "database/sql" + "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/types" +) + +func boolToInt64(b bool) sql.NullInt64 { + if b { + return sql.NullInt64{Int64: 1, Valid: true} + } + return sql.NullInt64{Int64: 0, Valid: true} +} + +func DeserializeSupplier(supplier types.Supplier) db.Supplier { + return db.Supplier{ + ID: supplier.ID, + Name: supplier.Name, + LogoImage: sql.NullString{String: supplier.LogoImage, Valid: supplier.LogoImage != ""}, + MarketingImage: sql.NullString{String: supplier.MarketingImage, Valid: supplier.MarketingImage != ""}, + Description: sql.NullString{String: supplier.Description, Valid: supplier.Description != ""}, + SocialFacebook: sql.NullString{String: *supplier.SocialFacebook, Valid: supplier.SocialFacebook != nil}, + SocialInstagram: sql.NullString{String: *supplier.SocialInstagram, Valid: supplier.SocialInstagram != nil}, + SocialLinkedin: sql.NullString{String: *supplier.SocialLinkedin, Valid: supplier.SocialLinkedin != nil}, + SocialTwitter: sql.NullString{String: *supplier.SocialTwitter, Valid: supplier.SocialTwitter != nil}, + SocialYoutube: sql.NullString{String: *supplier.SocialYoutube, Valid: supplier.SocialYoutube != nil}, + SocialWebsite: sql.NullString{String: *supplier.SocialWebsite, Valid: supplier.SocialWebsite != nil}, + Created: sql.NullString{String: supplier.Created, Valid: supplier.Created != ""}, + } +} + +func DeserializeBlog(blog types.Blog) db.Blog { + return db.Blog{ + ID: blog.ID, + Title: blog.Title, + Date: sql.NullString{String: blog.Date, Valid: blog.Date != ""}, + MainImage: sql.NullString{String: blog.MainImage, Valid: blog.MainImage != ""}, + Subheading: sql.NullString{String: blog.Subheading, Valid: blog.Subheading != ""}, + Body: sql.NullString{String: blog.Body, Valid: blog.Body != ""}, + Created: sql.NullString{String: blog.Created, Valid: blog.Created != ""}, + } +} + +func DeserializeCarousel(carousel types.Carousel) db.Carousel { + return db.Carousel{ + ID: carousel.ID, + Name: carousel.Name, + Image: sql.NullString{String: carousel.Image, Valid: carousel.Image != ""}, + Created: sql.NullString{String: carousel.Created, Valid: carousel.Created != ""}, + } +} + +func DeserializeEmployee(employee types.Employee) db.Employee { + return db.Employee{ + ID: employee.ID, + Name: employee.Name, + Email: employee.Email, + Role: employee.Role, + ProfileImage: sql.NullString{String: employee.ProfileImage, Valid: employee.ProfileImage != ""}, + Created: sql.NullString{String: employee.Created, Valid: employee.Created != ""}, + } +} + +func DeserializeExhibition(exhibition types.Exhibition) db.Exhibition { + return db.Exhibition{ + ID: exhibition.ID, + Title: exhibition.Title, + Date: sql.NullString{String: exhibition.Date, Valid: exhibition.Date != ""}, + Location: sql.NullString{String: exhibition.Location, Valid: exhibition.Location != ""}, + Info: sql.NullString{String: exhibition.Info, Valid: exhibition.Info != ""}, + Created: sql.NullString{String: exhibition.Created, Valid: exhibition.Created != ""}, + } +} + +func DeserializeLineItem(lineItem types.LineItem) db.LineItem { + return db.LineItem{ + ID: lineItem.ID, + Name: lineItem.Name, + Price: lineItem.Price, + Image: sql.NullString{String: lineItem.Image, Valid: lineItem.Image != ""}, + } +} + +func DeserializeMachine(machine types.Machine) db.Machine { + return db.Machine{ + ID: machine.ID, + SupplierID: machine.SupplierID, + Name: machine.Name, + MachineImage: sql.NullString{String: machine.MachineImage, Valid: machine.MachineImage != ""}, + Description: sql.NullString{String: *machine.Description, Valid: machine.Description != nil}, + MachineLink: sql.NullString{String: *machine.MachineLink, Valid: machine.MachineLink != nil}, + Created: sql.NullString{String: machine.Created, Valid: machine.Created != ""}, + } +} + +func DeserializeMachineRegistration(reg types.MachineRegistration) db.MachineRegistration { + return db.MachineRegistration{ + ID: reg.ID, + DealerName: reg.DealerName, + DealerAddress: sql.NullString{String: reg.DealerAddress, Valid: reg.DealerAddress != ""}, + OwnerName: reg.OwnerName, + OwnerAddress: sql.NullString{String: reg.OwnerAddress, Valid: reg.OwnerAddress != ""}, + MachineModel: reg.MachineModel, + SerialNumber: reg.SerialNumber, + InstallDate: sql.NullString{String: reg.InstallDate, Valid: reg.InstallDate != ""}, + InvoiceNumber: sql.NullString{String: reg.InvoiceNumber, Valid: reg.InvoiceNumber != ""}, + CompleteSupply: boolToInt64(reg.CompleteSupply), + PdiComplete: boolToInt64(reg.PdiComplete), + PtoCorrect: boolToInt64(reg.PtoCorrect), + MachineTestRun: boolToInt64(reg.MachineTestRun), + SafetyInduction: boolToInt64(reg.SafetyInduction), + OperatorHandbook: boolToInt64(reg.OperatorHandbook), + Date: sql.NullString{String: reg.Date, Valid: reg.Date != ""}, + CompletedBy: sql.NullString{String: reg.CompletedBy, Valid: reg.CompletedBy != ""}, + Created: sql.NullString{String: reg.Created, Valid: reg.Created != ""}, + } +} + +func DeserializePartsRequired(parts types.PartsRequired) db.PartsRequired { + return db.PartsRequired{ + ID: parts.ID, + WarrantyID: parts.WarrantyID, + PartNumber: sql.NullString{String: parts.PartNumber, Valid: parts.PartNumber != ""}, + QuantityNeeded: parts.QuantityNeeded, + InvoiceNumber: sql.NullString{String: parts.InvoiceNumber, Valid: parts.InvoiceNumber != ""}, + Description: sql.NullString{String: parts.Description, Valid: parts.Description != ""}, + } +} + +func DeserializePrivacy(privacy types.Privacy) db.Privacy { + return db.Privacy{ + ID: privacy.ID, + Title: privacy.Title, + Body: sql.NullString{String: privacy.Body, Valid: privacy.Body != ""}, + Created: sql.NullString{String: privacy.Created, Valid: privacy.Created != ""}, + } +} + +func DeserializeProduct(product types.Product) db.Product { + return db.Product{ + ID: product.ID, + MachineID: product.MachineID, + Name: product.Name, + ProductImage: sql.NullString{String: product.ProductImage, Valid: product.ProductImage != ""}, + Description: sql.NullString{String: product.Description, Valid: product.Description != ""}, + ProductLink: sql.NullString{String: product.ProductLink, Valid: product.ProductLink != ""}, + } +} + +func DeserializeSparePart(sparePart types.Sparepart) db.SparePart { + return db.SparePart{ + ID: sparePart.ID, + SupplierID: sparePart.SupplierID, + Name: sparePart.Name, + PartsImage: sql.NullString{String: sparePart.PartsImage, Valid: sparePart.PartsImage != ""}, + SparePartsLink: sql.NullString{String: sparePart.SparePartsLink, Valid: sparePart.SparePartsLink != ""}, + } +} + +func DeserializeTerm(term types.Terms) db.Term { + return db.Term{ + ID: term.ID, + Title: term.Title, + Body: sql.NullString{String: term.Body, Valid: term.Body != ""}, + Created: sql.NullString{String: term.Created, Valid: term.Created != ""}, + } +} + +func DeserializeTimeline(timeline types.Timeline) db.Timeline { + return db.Timeline{ + ID: timeline.ID, + Title: timeline.Title, + Date: sql.NullString{String: timeline.Date, Valid: timeline.Date != ""}, + Body: sql.NullString{String: timeline.Body, Valid: timeline.Body != ""}, + Created: sql.NullString{String: timeline.Created, Valid: timeline.Created != ""}, + } +} + +func DeserializeVideo(video types.Video) db.Video { + return db.Video{ + ID: video.ID, + SupplierID: video.SupplierID, + WebUrl: sql.NullString{String: video.WebURL, Valid: video.WebURL != ""}, + Title: sql.NullString{String: *video.Title, Valid: video.Title != nil}, + Description: sql.NullString{String: *video.Description, Valid: video.Description != nil}, + VideoID: sql.NullString{String: *video.VideoID, Valid: video.VideoID != nil}, + ThumbnailUrl: sql.NullString{String: *video.ThumbnailURL, Valid: video.ThumbnailURL != nil}, + Created: sql.NullString{String: video.Created, Valid: video.Created != ""}, + } +} + +func DeserializeWarrantyClaim(claim types.WarrantyClaim) db.WarrantyClaim { + return db.WarrantyClaim{ + ID: claim.ID, + Dealer: claim.Dealer, + DealerContact: sql.NullString{String: *claim.DealerContact, Valid: claim.DealerContact != nil}, + OwnerName: *claim.OwnerName, + MachineModel: *claim.MachineModel, + SerialNumber: *claim.SerialNumber, + InstallDate: sql.NullString{String: *claim.InstallDate, Valid: claim.InstallDate != nil}, + FailureDate: sql.NullString{String: *claim.FailureDate, Valid: claim.FailureDate != nil}, + RepairDate: sql.NullString{String: *claim.RepairDate, Valid: claim.RepairDate != nil}, + FailureDetails: sql.NullString{String: *claim.FailureDetails, Valid: claim.FailureDetails != nil}, + RepairDetails: sql.NullString{String: *claim.RepairDetails, Valid: claim.RepairDetails != nil}, + LabourHours: sql.NullString{String: *claim.LabourHours, Valid: claim.LabourHours != nil}, + CompletedBy: sql.NullString{String: *claim.CompletedBy, Valid: claim.CompletedBy != nil}, + Created: sql.NullString{String: claim.Created, Valid: claim.Created != ""}, + } +} From 6e1a72b9ab11c2a1b8a43bcc6a1e056160684ca1 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 15:49:47 +0100 Subject: [PATCH 179/248] fix create supplier --- server/handlers/supplierHandler.go | 7 +++++-- server/services/supplierService.go | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index 171adb3..d70b261 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -2,6 +2,8 @@ package handlers import ( "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -31,14 +33,15 @@ func (handler *SupplierHandler) GetSuppliers(context *gin.Context) { func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { ctx := context.Request.Context() - var supplier db.Supplier + var supplier types.Supplier + dbSupplier := lib.DeserializeSupplier(supplier) if err := context.ShouldBindJSON(&supplier); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - result, err := handler.supplierService.CreateSupplier(ctx, &supplier) + result, err := handler.supplierService.CreateSupplier(ctx, &dbSupplier) if err != nil { log.Printf("Error creating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating supplier", "details": err.Error()}) diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 843dbec..b177896 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -42,7 +42,7 @@ func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]types.S var result []types.Supplier for _, supplier := range suppliers { - result = append(result, lib.ConvertSupplier(supplier)) + result = append(result, lib.SerializeSupplier(supplier)) } return result, nil } @@ -52,11 +52,11 @@ func (service *SupplierServiceImpl) GetSupplierById(ctx context.Context, id stri if err != nil { return nil, err } - result := lib.ConvertSupplier(*supplier) + result := lib.SerializeSupplier(*supplier) return &result, nil } -func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) { +func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier db.Supplier) (*types.SupplierResult, error) { logoImage := supplier.LogoImage marketingImage := supplier.MarketingImage @@ -85,7 +85,7 @@ func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier Valid: true, } - err = service.store.CreateSupplier(ctx, supplier) + err = service.store.CreateSupplier(ctx, &supplier) if err != nil { return nil, err } From f59c2810c6d5be813d729edf508c5e82a922e491 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:05:22 +0100 Subject: [PATCH 180/248] move --- server/handlers/supplierHandler.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index d70b261..38696e8 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -31,6 +31,20 @@ func (handler *SupplierHandler) GetSuppliers(context *gin.Context) { context.JSON(http.StatusOK, suppliers) } +func (handler *SupplierHandler) GetSupplierByID(context *gin.Context) { + ctx := context.Request.Context() + id := context.Param("id") + supplier, err := handler.supplierService.GetSupplierById(ctx, id) + + if err != nil { + log.Printf("Error getting suppliers: %v", err) + context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting suppliers"}) + return + } + + context.JSON(http.StatusOK, supplier) +} + func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { ctx := context.Request.Context() var supplier types.Supplier @@ -59,25 +73,12 @@ func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { context.JSON(http.StatusCreated, response) } -func (handler *SupplierHandler) GetSupplierByID(context *gin.Context) { - ctx := context.Request.Context() - id := context.Param("id") - supplier, err := handler.supplierService.GetSupplierById(ctx, id) - - if err != nil { - log.Printf("Error getting suppliers: %v", err) - context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting suppliers"}) - return - } - - context.JSON(http.StatusOK, supplier) -} - func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") var supplier db.Supplier + dbSupplier := lib.DeserializeSupplier(supplier) if err := context.ShouldBindJSON(&supplier); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) From b0141229ba2c6e08bdfdb969ceafc41157a8cf0c Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:08:12 +0100 Subject: [PATCH 181/248] fix supplier handler --- server/handlers/supplierHandler.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index 38696e8..b59cf8e 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -1,7 +1,6 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/types" "log" @@ -77,7 +76,7 @@ func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var supplier db.Supplier + var supplier types.Supplier dbSupplier := lib.DeserializeSupplier(supplier) if err := context.ShouldBindJSON(&supplier); err != nil { @@ -85,7 +84,7 @@ func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { return } - result, err := handler.supplierService.UpdateSupplier(ctx, id, &supplier) + result, err := handler.supplierService.UpdateSupplier(ctx, id, &dbSupplier) if err != nil { log.Printf("Error updating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating supplier", "details": err.Error()}) From eaf84405cdbfae6fc07530bddf0760636086e894 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:24:49 +0100 Subject: [PATCH 182/248] fix blogs --- server/handlers/blogHandler.go | 13 ++++++++----- server/services/blogService.go | 17 +++++++++++------ server/services/supplierService.go | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/server/handlers/blogHandler.go b/server/handlers/blogHandler.go index 612ded2..940f3cb 100644 --- a/server/handlers/blogHandler.go +++ b/server/handlers/blogHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -44,7 +45,8 @@ func (handler *BlogHandler) GetBlogByID(context *gin.Context) { func (handler *BlogHandler) CreateBlog(context *gin.Context) { ctx := context.Request.Context() - var blog db.Blog + var blog types.Blog + dbBlog := lib.DeserializeBlog(blog) if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while creating blog: %v", err) @@ -52,7 +54,7 @@ func (handler *BlogHandler) CreateBlog(context *gin.Context) { return } - result, err := handler.service.CreateBlog(ctx, &blog) + result, err := handler.service.CreateBlog(ctx, &dbBlog) if err != nil { log.Printf("error while creating blog: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating blog"}) @@ -68,7 +70,8 @@ func (handler *BlogHandler) UpdateBlog(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var blog db.Blog + var blog types.Blog + dbBlog := lib.DeserializeBlog(blog) if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while updating blog: %v", err) @@ -76,7 +79,7 @@ func (handler *BlogHandler) UpdateBlog(context *gin.Context) { return } - result, err := handler.service.UpdateBlog(ctx, id, &blog) + result, err := handler.service.UpdateBlog(ctx, id, &dbBlog) if err != nil { log.Printf("error while updating blog: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating blog"}) diff --git a/server/services/blogService.go b/server/services/blogService.go index c7044d4..472c7ae 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -13,8 +13,8 @@ import ( ) type BlogService interface { - GetBlogs(ctx context.Context) ([]db.Blog, error) - GetBlogsByID(ctx context.Context, id string) (*db.Blog, error) + GetBlogs(ctx context.Context) ([]types.Blog, error) + GetBlogsByID(ctx context.Context, id string) (*types.Blog, error) CreateBlog(ctx context.Context, blog *db.Blog) (*types.ModelResult, error) UpdateBlog(ctx context.Context, id string, blog *db.Blog) (*types.ModelResult, error) DeleteBlog(ctx context.Context, id string) error @@ -30,22 +30,27 @@ func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *BlogServiceImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { +func (service *BlogServiceImpl) GetBlogs(ctx context.Context) ([]types.Blog, error) { blogs, err := service.store.GetBlogs(ctx) if err != nil { return nil, err } - return blogs, nil + var result []types.Blog + for _, blog := range blogs { + result = append(result, lib.SerializeBlog(blog)) + } + return result, nil } -func (service *BlogServiceImpl) GetBlogsByID(ctx context.Context, id string) (*db.Blog, error) { +func (service *BlogServiceImpl) GetBlogsByID(ctx context.Context, id string) (*types.Blog, error) { blog, err := service.store.GetBlogById(ctx, id) if err != nil { return nil, err } + result := lib.SerializeBlog(*blog) - return blog, nil + return &result, nil } func (service *BlogServiceImpl) CreateBlog(ctx context.Context, blog *db.Blog) (*types.ModelResult, error) { diff --git a/server/services/supplierService.go b/server/services/supplierService.go index b177896..c0d00de 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -14,8 +14,8 @@ import ( type SupplierService interface { GetSuppliers(ctx context.Context) ([]types.Supplier, error) - CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) GetSupplierById(ctx context.Context, id string) (*types.Supplier, error) + CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) (*types.SupplierResult, error) DeleteSupplier(ctx context.Context, id string) error } From a586e80ed993c3ac7e87f71bf0330eb5e4066ad5 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:46:08 +0100 Subject: [PATCH 183/248] carousel handler --- server/services/carouselService.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/services/carouselService.go b/server/services/carouselService.go index 38ddaf6..3d3ddd0 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -13,7 +13,7 @@ import ( ) type CarouselService interface { - GetCarousels(ctx context.Context) ([]db.Carousel, error) + GetCarousels(ctx context.Context) ([]types.Carousel, error) CreateCarousel(ctx context.Context, carousel *db.Carousel) (*types.ModelResult, error) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) (*types.ModelResult, error) DeleteCarousel(ctx context.Context, id string) error @@ -33,12 +33,16 @@ func NewCarouselService(store stores.CarouselStore, s3Client lib.S3Client, folde } } -func (service *CarouselServiceImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { +func (service *CarouselServiceImpl) GetCarousels(ctx context.Context) ([]types.Carousel, error) { carousels, err := service.store.GetCarousels(ctx) if err != nil { return nil, err } - return carousels, nil + var result []types.Carousel + for _, carousel := range carousels { + result = append(result, lib.SerializeCarousel(carousel)) + } + return result, nil } func (service *CarouselServiceImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) (*types.ModelResult, error) { From 17989430e37f06577f28fa01c490f1621d148501 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:48:15 +0100 Subject: [PATCH 184/248] carouselHandler.go --- server/handlers/carouselHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/carouselHandler.go b/server/handlers/carouselHandler.go index 7505158..989da70 100644 --- a/server/handlers/carouselHandler.go +++ b/server/handlers/carouselHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -31,14 +32,15 @@ func (handler *CarouselHandler) GetCarousels(context *gin.Context) { func (handler *CarouselHandler) CreateCarousel(context *gin.Context) { ctx := context.Request.Context() - var carousel db.Carousel + var carousel types.Carousel + dbCarousel := lib.DeserializeCarousel(carousel) if err := context.ShouldBindJSON(&carousel); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - result, err := handler.carouselService.CreateCarousel(ctx, &carousel) + result, err := handler.carouselService.CreateCarousel(ctx, &dbCarousel) if err != nil { log.Printf("Error creating carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating carousel", "details": err.Error()}) @@ -58,14 +60,15 @@ func (handler *CarouselHandler) UpdateCarousel(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var carousel db.Carousel + var carousel types.Carousel + dbCarousel := lib.DeserializeCarousel(carousel) if err := context.ShouldBindJSON(&carousel); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - result, err := handler.carouselService.UpdateCarousel(ctx, id, &carousel) + result, err := handler.carouselService.UpdateCarousel(ctx, id, &dbCarousel) if err != nil { log.Printf("Error updating carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating carousel", "details": err.Error()}) From d8a436c93fe16eec2beb813541d44970a4f10388 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:51:41 +0100 Subject: [PATCH 185/248] employeeService.go --- server/services/checkoutService.go | 1 + server/services/employeeService.go | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 123c90e..5eb20fc 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -23,6 +23,7 @@ type CheckoutServiceImpl struct { func NewCheckoutService(secrets *lib.Secrets, store stores.LineItemStore) *CheckoutServiceImpl { return &CheckoutServiceImpl{secrets: secrets, store: store} } + func (service *CheckoutServiceImpl) CreateCheckoutSession(ctx context.Context, id string) (*stripe.CheckoutSession, error) { stripe.Key = service.secrets.StripeSecretKey diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 28cf429..728da73 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -13,7 +13,7 @@ import ( ) type EmployeeService interface { - GetEmployees(ctx context.Context) ([]db.Employee, error) + GetEmployees(ctx context.Context) ([]types.Employee, error) CreateEmployee(ctx context.Context, employee *db.Employee) (*types.ModelResult, error) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) (*types.ModelResult, error) DeleteEmployee(ctx context.Context, id string) error @@ -29,13 +29,16 @@ func NewEmployeeService(store stores.EmployeeStore, s3Client lib.S3Client, folde return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *EmployeeServiceImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { +func (service *EmployeeServiceImpl) GetEmployees(ctx context.Context) ([]types.Employee, error) { employees, err := service.store.GetEmployees(ctx) if err != nil { return nil, err } - - return employees, nil + var result []types.Employee + for _, employee := range employees { + result = append(result, lib.SerializeEmployee(employee)) + } + return result, nil } func (service *EmployeeServiceImpl) CreateEmployee(ctx context.Context, employee *db.Employee) (*types.ModelResult, error) { From 7bd9b4da588cfb75fc2df4621dd22b08ed811788 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:53:26 +0100 Subject: [PATCH 186/248] employeeHandler.go --- server/handlers/employeeHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/employeeHandler.go b/server/handlers/employeeHandler.go index bc806eb..ff1e6af 100644 --- a/server/handlers/employeeHandler.go +++ b/server/handlers/employeeHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -31,7 +32,8 @@ func (handler *EmployeeHandler) GetEmployees(context *gin.Context) { func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { ctx := context.Request.Context() - var employee db.Employee + var employee types.Employee + dbEmployee := lib.DeserializeEmployee(employee) if err := context.ShouldBindJSON(&employee); err != nil { log.Printf("Error creating employee: %v", err) @@ -39,7 +41,7 @@ func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { return } - result, err := handler.service.CreateEmployee(ctx, &employee) + result, err := handler.service.CreateEmployee(ctx, &dbEmployee) if err != nil { log.Printf("Error creating employee: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating employee", "details": err.Error()}) @@ -58,7 +60,8 @@ func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { func (handler *EmployeeHandler) UpdateEmployee(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var employee db.Employee + var employee types.Employee + dbEmployee := lib.DeserializeEmployee(employee) if err := context.ShouldBindJSON(&employee); err != nil { log.Printf("Error creating employee: %v", err) @@ -66,7 +69,7 @@ func (handler *EmployeeHandler) UpdateEmployee(context *gin.Context) { return } - result, err := handler.service.UpdateEmployee(ctx, id, &employee) + result, err := handler.service.UpdateEmployee(ctx, id, &dbEmployee) if err != nil { log.Printf("Error creating employee: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating employee", "details": err.Error()}) From 9256eb79921ed16f051c26f435233e32bbd11c49 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:57:21 +0100 Subject: [PATCH 187/248] exhibitionService.go --- server/services/exhibitionService.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index 04b8f50..2b849c6 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -3,11 +3,13 @@ package services import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/types" ) type ExhibitionService interface { - GetExhibitions(ctx context.Context) ([]db.Exhibition, error) + GetExhibitions(ctx context.Context) ([]types.Exhibition, error) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error DeleteExhibition(ctx context.Context, id string) error @@ -21,13 +23,16 @@ func NewExhibitionService(store stores.ExhibitionStore) *ExhibitionServiceImpl { return &ExhibitionServiceImpl{store: store} } -func (service *ExhibitionServiceImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { +func (service *ExhibitionServiceImpl) GetExhibitions(ctx context.Context) ([]types.Exhibition, error) { exhibitions, err := service.store.GetExhibitions(ctx) if err != nil { return nil, err } - - return exhibitions, nil + var result []types.Exhibition + for _, exhibition := range exhibitions { + result = append(result, lib.SerializeExhibition(exhibition)) + } + return result, nil } func (service *ExhibitionServiceImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { From a28486b80c9fc075980384be640460043269c2fb Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 16:59:54 +0100 Subject: [PATCH 188/248] exhibitionHandler.go --- server/handlers/exhibitionHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/exhibitionHandler.go b/server/handlers/exhibitionHandler.go index 1521379..326b1a4 100644 --- a/server/handlers/exhibitionHandler.go +++ b/server/handlers/exhibitionHandler.go @@ -1,11 +1,12 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" "github.com/gin-gonic/gin" - "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/services" ) @@ -31,14 +32,15 @@ func (handler *ExhibitionHandler) GetExhibitions(context *gin.Context) { func (handler *ExhibitionHandler) CreateExhibition(context *gin.Context) { ctx := context.Request.Context() - var exhibition *db.Exhibition + var exhibition types.Exhibition + dbExhibition := lib.DeserializeExhibition(exhibition) if err := context.ShouldBindJSON(&exhibition); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreateExhibition(ctx, exhibition); err != nil { + if err := handler.service.CreateExhibition(ctx, &dbExhibition); err != nil { log.Printf("error occurred while creating exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating exhibition", "details": err.Error()}) return @@ -51,14 +53,15 @@ func (handler *ExhibitionHandler) UpdateExhibition(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var exhibition *db.Exhibition + var exhibition types.Exhibition + dbExhibition := lib.DeserializeExhibition(exhibition) if err := context.ShouldBindJSON(&exhibition); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdateExhibition(ctx, id, exhibition); err != nil { + if err := handler.service.UpdateExhibition(ctx, id, &dbExhibition); err != nil { log.Printf("error occurred while updating exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating exhibition", "details": err.Error()}) return From e898f987dd5dd82e7267afeae3758fe66935c1bc Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 17:02:14 +0100 Subject: [PATCH 189/248] lineItemService.go --- server/services/lineItemService.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index fbbf91b..ae3c8fb 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -13,8 +13,8 @@ import ( ) type LineItemService interface { - GetLineItems(ctx context.Context) ([]db.LineItem, error) - GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) + GetLineItems(ctx context.Context) ([]types.LineItem, error) + GetLineItemById(ctx context.Context, id string) (*types.LineItem, error) CreateLineItem(ctx context.Context, lineItem *db.LineItem) (*types.ModelResult, error) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) (*types.ModelResult, error) DeleteLineItem(ctx context.Context, id string) error @@ -30,22 +30,25 @@ func NewLineItemService(store stores.LineItemStore, s3Client lib.S3Client, folde return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} } -func (service *LineItemServiceImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { +func (service *LineItemServiceImpl) GetLineItems(ctx context.Context) ([]types.LineItem, error) { lineItems, err := service.store.GetLineItems(ctx) if err != nil { return nil, err } - - return lineItems, nil + var result []types.LineItem + for _, lineItem := range lineItems { + result = append(result, lib.SerializeLineItem(lineItem)) + } + return result, nil } -func (service *LineItemServiceImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { +func (service *LineItemServiceImpl) GetLineItemById(ctx context.Context, id string) (*types.LineItem, error) { lineItem, err := service.store.GetLineItemById(ctx, id) if err != nil { return nil, err } - - return lineItem, nil + result := lib.SerializeLineItem(*lineItem) + return &result, nil } func (service *LineItemServiceImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) (*types.ModelResult, error) { From 44ed71871fa9d4fb881d21c5abda01a52bd41961 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 17:02:56 +0100 Subject: [PATCH 190/248] move --- server/handlers/lineItemHandler.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/server/handlers/lineItemHandler.go b/server/handlers/lineItemHandler.go index a79191f..ba8ada3 100644 --- a/server/handlers/lineItemHandler.go +++ b/server/handlers/lineItemHandler.go @@ -29,6 +29,20 @@ func (handler *LineItemHandler) GetLineItems(context *gin.Context) { context.JSON(http.StatusOK, lineItems) } +func (handler *LineItemHandler) GetLineItemById(context *gin.Context) { + ctx := context.Request.Context() + id := context.Param("id") + + lineItem, err := handler.service.GetLineItemById(ctx, id) + if err != nil { + log.Printf("error occurred while getting lineItem: %v", err) + context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting lineItem"}) + return + } + + context.JSON(http.StatusOK, lineItem) +} + func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { ctx := context.Request.Context() var lineItem db.LineItem @@ -54,20 +68,6 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { context.JSON(http.StatusCreated, response) } -func (handler *LineItemHandler) GetLineItemById(context *gin.Context) { - ctx := context.Request.Context() - id := context.Param("id") - - lineItem, err := handler.service.GetLineItemById(ctx, id) - if err != nil { - log.Printf("error occurred while getting lineItem: %v", err) - context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting lineItem"}) - return - } - - context.JSON(http.StatusOK, lineItem) -} - func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") From 90807aae1b8f1d0a83f21cb4548323df16d1dfa3 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 17:04:32 +0100 Subject: [PATCH 191/248] lineItemHandler.go --- server/handlers/lineItemHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/lineItemHandler.go b/server/handlers/lineItemHandler.go index ba8ada3..69175d2 100644 --- a/server/handlers/lineItemHandler.go +++ b/server/handlers/lineItemHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -45,7 +46,8 @@ func (handler *LineItemHandler) GetLineItemById(context *gin.Context) { func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { ctx := context.Request.Context() - var lineItem db.LineItem + var lineItem types.LineItem + dbLineItem := lib.DeserializeLineItem(lineItem) if err := context.ShouldBindJSON(&lineItem); err != nil { log.Printf("error when creating lineItem: %v", err) @@ -53,7 +55,7 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { return } - result, err := handler.service.CreateLineItem(ctx, &lineItem) + result, err := handler.service.CreateLineItem(ctx, &dbLineItem) if err != nil { log.Printf("error when creating lineItem: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when creating lineItem"}) @@ -71,7 +73,8 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var lineItem db.LineItem + var lineItem types.LineItem + dbLineItem := lib.DeserializeLineItem(lineItem) if err := context.ShouldBindJSON(&lineItem); err != nil { log.Printf("error when updating lineItem: %v", err) @@ -79,7 +82,7 @@ func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { return } - result, err := handler.service.UpdateLineItem(ctx, id, &lineItem) + result, err := handler.service.UpdateLineItem(ctx, id, &dbLineItem) if err != nil { log.Printf("error when updating lineItem: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when updating lineItem"}) From af15315ecf6db0dd4abdb06af14859fcdd96950b Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 17:09:02 +0100 Subject: [PATCH 192/248] machineService.go --- server/services/machineService.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/services/machineService.go b/server/services/machineService.go index 64d90d5..b570b9c 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -13,8 +13,8 @@ import ( ) type MachineService interface { - GetMachines(ctx context.Context, id string) ([]db.Machine, error) - GetMachineById(ctx context.Context, id string) (*db.Machine, error) + GetMachines(ctx context.Context, id string) ([]types.Machine, error) + GetMachineById(ctx context.Context, id string) (*types.Machine, error) CreateMachine(ctx context.Context, machine *db.Machine) (*types.ModelResult, error) UpdateMachine(ctx context.Context, id string, machine *db.Machine) (*types.ModelResult, error) DeleteMachine(ctx context.Context, id string) error @@ -34,22 +34,26 @@ func NewMachineService(store stores.MachineStore, s3Client lib.S3Client, folder } } -func (service *MachineServiceImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { +func (service *MachineServiceImpl) GetMachines(ctx context.Context, id string) ([]types.Machine, error) { machines, err := service.store.GetMachines(ctx, id) if err != nil { return nil, errors.New("machines with supplier_id not foud") } - - return machines, nil + var result []types.Machine + for _, machine := range machines { + result = append(result, lib.SerializeMachine(machine)) + } + return result, nil } -func (service *MachineServiceImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { +func (service *MachineServiceImpl) GetMachineById(ctx context.Context, id string) (*types.Machine, error) { machine, err := service.store.GetMachineById(ctx, id) if err != nil { return nil, errors.New("machine with id not found") } + result := lib.SerializeMachine(*machine) - return machine, nil + return &result, nil } func (service *MachineServiceImpl) CreateMachine(ctx context.Context, machine *db.Machine) (*types.ModelResult, error) { From 2a067adc5e999441d04d39e7ed120534d921e6df Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 17:10:21 +0100 Subject: [PATCH 193/248] machineHandler.go --- server/handlers/machineHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/machineHandler.go b/server/handlers/machineHandler.go index a533c9f..6a7d6d0 100644 --- a/server/handlers/machineHandler.go +++ b/server/handlers/machineHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -47,7 +48,8 @@ func (handler *MachineHandler) GetMachineById(context *gin.Context) { func (handler *MachineHandler) CreateMachine(context *gin.Context) { ctx := context.Request.Context() - var machine db.Machine + var machine types.Machine + dbMachine := lib.DeserializeMachine(machine) if err := context.ShouldBindJSON(&machine); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) @@ -59,7 +61,7 @@ func (handler *MachineHandler) CreateMachine(context *gin.Context) { return } - result, err := handler.machineService.CreateMachine(ctx, &machine) + result, err := handler.machineService.CreateMachine(ctx, &dbMachine) if err != nil { log.Printf("Error creating machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating machine", "details": err.Error()}) @@ -79,7 +81,8 @@ func (handler *MachineHandler) UpdateMachine(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var machine db.Machine + var machine types.Machine + dbMachine := lib.DeserializeMachine(machine) if err := context.ShouldBindJSON(&machine); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) @@ -91,7 +94,7 @@ func (handler *MachineHandler) UpdateMachine(context *gin.Context) { return } - result, err := handler.machineService.UpdateMachine(ctx, id, &machine) + result, err := handler.machineService.UpdateMachine(ctx, id, &dbMachine) if err != nil { log.Printf("Error updating machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) From 2da7547db68ef448bc5a9ed85ae40dc2b73e16e4 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:32:59 +0100 Subject: [PATCH 194/248] partsService.go --- server/services/partsService.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/services/partsService.go b/server/services/partsService.go index e77fcd7..7484784 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -14,7 +14,7 @@ import ( ) type PartsService interface { - GetParts(ctx context.Context, id string) ([]db.SparePart, error) + GetParts(ctx context.Context, id string) ([]types.Sparepart, error) CreatePart(ctx context.Context, part *db.SparePart) (*types.PartsModelResult, error) UpdatePart(ctx context.Context, id string, part *db.SparePart) (*types.PartsModelResult, error) DeletePart(ctx context.Context, id string) error @@ -34,12 +34,16 @@ func NewPartsService(store stores.PartsStore, s3Client lib.S3Client, folder stri } } -func (service *PartsServiceImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { +func (service *PartsServiceImpl) GetParts(ctx context.Context, id string) ([]types.Sparepart, error) { parts, err := service.store.GetParts(ctx, id) if err != nil { return nil, err } - return parts, nil + var result []types.Sparepart + for _, part := range parts { + result = append(result, lib.SerializeSparePart(part)) + } + return result, nil } func (service *PartsServiceImpl) CreatePart(ctx context.Context, part *db.SparePart) (*types.PartsModelResult, error) { From cdd93aece0686e1398867687f738e28fd2e0d187 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:34:01 +0100 Subject: [PATCH 195/248] partsHandler.go --- server/handlers/partsHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/partsHandler.go b/server/handlers/partsHandler.go index c7caff3..0b29052 100644 --- a/server/handlers/partsHandler.go +++ b/server/handlers/partsHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -33,7 +34,8 @@ func (handler *PartsHandler) GetParts(context *gin.Context) { func (handler *PartsHandler) CreateParts(context *gin.Context) { ctx := context.Request.Context() - var part db.SparePart + var part types.Sparepart + dbPart := lib.DeserializeSparePart(part) if err := context.ShouldBindJSON(&part); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Ivalid request body", "details": err.Error()}) @@ -45,7 +47,7 @@ func (handler *PartsHandler) CreateParts(context *gin.Context) { return } - result, err := handler.partsService.CreatePart(ctx, &part) + result, err := handler.partsService.CreatePart(ctx, &dbPart) if err != nil { log.Printf("Error creating part: %v", err) context.JSON(http.StatusInternalServerError, @@ -67,7 +69,8 @@ func (handler *PartsHandler) UpdateParts(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var part db.SparePart + var part types.Sparepart + dbPart := lib.DeserializeSparePart(part) if err := context.ShouldBindJSON(&part); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "details": err.Error()}) @@ -79,7 +82,7 @@ func (handler *PartsHandler) UpdateParts(context *gin.Context) { return } - result, err := handler.partsService.UpdatePart(ctx, id, &part) + result, err := handler.partsService.UpdatePart(ctx, id, &dbPart) if err != nil { log.Printf("Error updating part: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) From e71fa08d3de293f685a7b2dd377f9c072a450da2 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:36:45 +0100 Subject: [PATCH 196/248] privacyService.go --- server/services/privacyService.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/services/privacyService.go b/server/services/privacyService.go index a70a7cc..5f6c09d 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -3,11 +3,13 @@ package services import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/types" ) type PrivacyService interface { - GetPrivacys(ctx context.Context) ([]db.Privacy, error) + GetPrivacys(ctx context.Context) ([]types.Privacy, error) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error DeletePrivacy(ctx context.Context, id string) error @@ -21,13 +23,16 @@ func NewPrivacyService(store stores.PrivacyStore) *PrivacyServiceImpl { return &PrivacyServiceImpl{store: store} } -func (service *PrivacyServiceImpl) GetPrivacys(ctx context.Context) ([]db.Privacy, error) { +func (service *PrivacyServiceImpl) GetPrivacys(ctx context.Context) ([]types.Privacy, error) { privacys, err := service.store.GetPrivacy(ctx) if err != nil { return nil, err } - - return privacys, nil + var result []types.Privacy + for _, privacy := range privacys { + result = append(result, lib.SerializePrivacy(privacy)) + } + return result, nil } func (service *PrivacyServiceImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { From 068522ae1ee8444cae83373cafc09c96588fc980 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:37:53 +0100 Subject: [PATCH 197/248] privacyHandler.go --- server/handlers/privacyHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/privacyHandler.go b/server/handlers/privacyHandler.go index f88d97f..ba5bc88 100644 --- a/server/handlers/privacyHandler.go +++ b/server/handlers/privacyHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -31,14 +32,15 @@ func (handler *PrivacyHandler) GetPrivacys(context *gin.Context) { func (handler *PrivacyHandler) CreatePrivacy(context *gin.Context) { ctx := context.Request.Context() - var privacy db.Privacy + var privacy types.Privacy + dbPrivacy := lib.DeserializePrivacy(privacy) if err := context.ShouldBindJSON(&privacy); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreatePrivacy(ctx, &privacy); err != nil { + if err := handler.service.CreatePrivacy(ctx, &dbPrivacy); err != nil { log.Printf("error while creating privacy: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating privacy", "details": err.Error()}) return @@ -50,14 +52,15 @@ func (handler *PrivacyHandler) CreatePrivacy(context *gin.Context) { func (handler *PrivacyHandler) UpdatePrivacy(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var privacy db.Privacy + var privacy types.Privacy + dbPrivacy := lib.DeserializePrivacy(privacy) if err := context.ShouldBindJSON(&privacy); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdatePrivacy(ctx, id, &privacy); err != nil { + if err := handler.service.UpdatePrivacy(ctx, id, &dbPrivacy); err != nil { log.Printf("error while updating privacy: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating privacy", "details": err.Error()}) return From 1e3422a5317c261542b5b5fd5144481100af3997 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:39:59 +0100 Subject: [PATCH 198/248] product service --- server/services/productService.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/services/productService.go b/server/services/productService.go index d4d47a9..ec783af 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -13,7 +13,7 @@ import ( ) type ProductService interface { - GetProducts(ctx context.Context, id string) ([]db.Product, error) + GetProducts(ctx context.Context, id string) ([]types.Product, error) CreateProduct(ctx context.Context, product *db.Product) (*types.ModelResult, error) UpdateProduct(ctx context.Context, id string, product *db.Product) (*types.ModelResult, error) DeleteProduct(ctx context.Context, id string) error @@ -33,12 +33,16 @@ func NewProductService(store stores.ProductStore, s3Client lib.S3Client, folder } } -func (service *ProductServiceImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { +func (service *ProductServiceImpl) GetProducts(ctx context.Context, id string) ([]types.Product, error) { products, err := service.store.GetProducts(ctx, id) if err != nil { return nil, err } - return products, nil + var result []types.Product + for _, product := range products { + result = append(result, lib.SerializeProduct(product)) + } + return result, nil } func (service *ProductServiceImpl) CreateProduct(ctx context.Context, product *db.Product) (*types.ModelResult, error) { From 7709b94c15221e2bab6c979f67b51be11fa7acc4 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:41:47 +0100 Subject: [PATCH 199/248] db product --- server/handlers/productHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/productHandler.go b/server/handlers/productHandler.go index ed65243..4d06449 100644 --- a/server/handlers/productHandler.go +++ b/server/handlers/productHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -33,7 +34,8 @@ func (handler *ProductHandler) GetProducts(context *gin.Context) { func (handler *ProductHandler) CreateProduct(context *gin.Context) { ctx := context.Request.Context() - var product db.Product + var product types.Product + dbProduct := lib.DeserializeProduct(product) if err := context.ShouldBindJSON(&product); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) @@ -45,7 +47,7 @@ func (handler *ProductHandler) CreateProduct(context *gin.Context) { return } - result, err := handler.productService.CreateProduct(ctx, &product) + result, err := handler.productService.CreateProduct(ctx, &dbProduct) if err != nil { log.Printf("Error creating product: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating product", "details": err.Error()}) @@ -65,7 +67,8 @@ func (handler *ProductHandler) UpdateProduct(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var product db.Product + var product types.Product + dbProduct := lib.DeserializeProduct(product) if err := context.ShouldBindJSON(&product); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "details": err.Error()}) @@ -77,7 +80,7 @@ func (handler *ProductHandler) UpdateProduct(context *gin.Context) { return } - result, err := handler.productService.UpdateProduct(ctx, id, &product) + result, err := handler.productService.UpdateProduct(ctx, id, &dbProduct) if err != nil { log.Printf("Error updating product: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) From cb83fe128beced3b2c39ac6d3b7cd44bc39a4341 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 19:45:11 +0100 Subject: [PATCH 200/248] registrationService.go --- server/services/registrationService.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/services/registrationService.go b/server/services/registrationService.go index fe9ba54..4f4c509 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -10,8 +10,8 @@ import ( ) type RegistrationService interface { - GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) - GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) + GetRegistrations(ctx context.Context) ([]types.MachineRegistration, error) + GetRegistrationById(ctx context.Context, id string) (*types.MachineRegistration, error) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error DeleteRegistration(ctx context.Context, id string) error @@ -26,22 +26,25 @@ func NewRegistrationService(store stores.RegistrationStore, smtpClient lib.SMTPC return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} } -func (service *RegistrationServiceImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { +func (service *RegistrationServiceImpl) GetRegistrations(ctx context.Context) ([]types.MachineRegistration, error) { registrations, err := service.store.GetRegistrations(ctx) if err != nil { return nil, err } - - return registrations, nil + var result []types.MachineRegistration + for _, reg := range registrations { + result = append(result, lib.SerializeMachineRegistration(reg)) + } + return result, nil } -func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { +func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, id string) (*types.MachineRegistration, error) { registration, err := service.store.GetRegistrationById(ctx, id) if err != nil { return nil, err } - - return registration, nil + result := lib.SerializeMachineRegistration(*registration) + return &result, nil } func (service *RegistrationServiceImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { From e02587492621675616df54e358d2c79e4a4654e8 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:36:55 +0100 Subject: [PATCH 201/248] registrationHandler.go --- server/handlers/registrationHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/registrationHandler.go b/server/handlers/registrationHandler.go index a3fd1b6..db94bc7 100644 --- a/server/handlers/registrationHandler.go +++ b/server/handlers/registrationHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -45,7 +46,8 @@ func (handler *RegistrationHandler) GetRegistrationById(context *gin.Context) { func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { ctx := context.Request.Context() - var registration *db.MachineRegistration + var registration types.MachineRegistration + dbRegistration := lib.DeserializeMachineRegistration(registration) if err := context.ShouldBindJSON(®istration); err != nil { log.Printf("error when creating registration: %v", err) @@ -53,7 +55,7 @@ func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { return } - if err := handler.service.CreateRegistration(ctx, registration); err != nil { + if err := handler.service.CreateRegistration(ctx, &dbRegistration); err != nil { log.Printf("error when creating registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when creating registration"}) } @@ -64,7 +66,8 @@ func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { func (handler *RegistrationHandler) UpdateRegistration(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var registration *db.MachineRegistration + var registration types.MachineRegistration + dbRegistration := lib.DeserializeMachineRegistration(registration) if err := context.ShouldBindJSON(®istration); err != nil { log.Printf("error when updating registration: %v", err) @@ -72,7 +75,7 @@ func (handler *RegistrationHandler) UpdateRegistration(context *gin.Context) { return } - if err := handler.service.UpdateRegistration(ctx, id, registration); err != nil { + if err := handler.service.UpdateRegistration(ctx, id, &dbRegistration); err != nil { log.Printf("error when updating registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when updating registration"}) } From ad0f66a5a313b93b5d38ed367e649143a46c437f Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:42:56 +0100 Subject: [PATCH 202/248] termsService.go --- server/services/termsService.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/services/termsService.go b/server/services/termsService.go index bb5cb79..f0044bc 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -3,11 +3,13 @@ package services import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/types" ) type TermsService interface { - GetTerms(ctx context.Context) ([]db.Term, error) + GetTerms(ctx context.Context) ([]types.Terms, error) CreateTerm(ctx context.Context, term *db.Term) error UpdateTerm(ctx context.Context, id string, term *db.Term) error DeleteTerm(ctx context.Context, id string) error @@ -21,12 +23,16 @@ func NewTermsService(store stores.TermsStore) *TermsServiceImpl { return &TermsServiceImpl{store: store} } -func (service *TermsServiceImpl) GetTerms(ctx context.Context) ([]db.Term, error) { +func (service *TermsServiceImpl) GetTerms(ctx context.Context) ([]types.Terms, error) { terms, err := service.store.GetTerms(ctx) if err != nil { return nil, err } - return terms, nil + var result []types.Terms + for _, term := range terms { + result = append(result, lib.SerializeTerm(term)) + } + return result, nil } func (service *TermsServiceImpl) CreateTerm(ctx context.Context, term *db.Term) error { From a2d5b174472e6466655c37f4245e3cc792116381 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:45:16 +0100 Subject: [PATCH 203/248] termsHandler.go --- server/handlers/termsHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/termsHandler.go b/server/handlers/termsHandler.go index 54baadb..9aaa14c 100644 --- a/server/handlers/termsHandler.go +++ b/server/handlers/termsHandler.go @@ -1,12 +1,13 @@ package handlers import ( + "github.com/sean-david-welch/farmec-v2/server/lib" "log" "net/http" "github.com/gin-gonic/gin" - "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/services" + "github.com/sean-david-welch/farmec-v2/server/types" ) type TermsHandler struct { @@ -31,14 +32,15 @@ func (handler *TermsHandler) GetTerms(context *gin.Context) { func (handler *TermsHandler) CreateTerm(context *gin.Context) { ctx := context.Request.Context() - var term db.Term + var term types.Terms + dbTerm := lib.DeserializeTerm(term) if err := context.ShouldBindJSON(&term); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreateTerm(ctx, &term); err != nil { + if err := handler.service.CreateTerm(ctx, &dbTerm); err != nil { log.Printf("error while creating term: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating term", "details": err.Error()}) return @@ -50,14 +52,15 @@ func (handler *TermsHandler) CreateTerm(context *gin.Context) { func (handler *TermsHandler) UpdateTerm(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var term db.Term + var term types.Terms + dbTerm := lib.DeserializeTerm(term) if err := context.ShouldBindJSON(&term); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdateTerm(ctx, id, &term); err != nil { + if err := handler.service.UpdateTerm(ctx, id, &dbTerm); err != nil { log.Printf("error while updating term: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating term", "details": err.Error()}) return From 2c191d4b34a2cb2e13fbbfa9161cabce6b92411e Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:48:07 +0100 Subject: [PATCH 204/248] timelineService.go --- server/services/timelineService.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/services/timelineService.go b/server/services/timelineService.go index 41fae2a..4335614 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -3,11 +3,13 @@ package services import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/types" ) type TimelineService interface { - GetTimelines(ctx context.Context) ([]db.Timeline, error) + GetTimelines(ctx context.Context) ([]types.Timeline, error) CreateTimeline(ctx context.Context, timeline *db.Timeline) error UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error DeleteTimeline(ctx context.Context, id string) error @@ -21,12 +23,16 @@ func NewTimelineService(store stores.TimelineStore) *TimelineServiceImpl { return &TimelineServiceImpl{store: store} } -func (service *TimelineServiceImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { +func (service *TimelineServiceImpl) GetTimelines(ctx context.Context) ([]types.Timeline, error) { timelines, err := service.store.GetTimelines(ctx) if err != nil { return nil, err } - return timelines, nil + var result []types.Timeline + for _, event := range timelines { + result = append(result, lib.SerializeTimeline(event)) + } + return result, nil } func (service *TimelineServiceImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { From 8c7a8b8f3dd0d7345af9220a490c74898129fd20 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:51:32 +0100 Subject: [PATCH 205/248] timelineHandler.go --- server/handlers/timelineHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/timelineHandler.go b/server/handlers/timelineHandler.go index 9e63e04..3b6b2f9 100644 --- a/server/handlers/timelineHandler.go +++ b/server/handlers/timelineHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -31,14 +32,15 @@ func (handler *TimelineHandler) GetTimelines(context *gin.Context) { func (handler *TimelineHandler) CreateTimeline(context *gin.Context) { ctx := context.Request.Context() - var timeline db.Timeline + var timeline types.Timeline + dbTimeline := lib.DeserializeTimeline(timeline) if err := context.ShouldBindJSON(&timeline); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.CreateTimeline(ctx, &timeline); err != nil { + if err := handler.service.CreateTimeline(ctx, &dbTimeline); err != nil { log.Printf("error while creating timeline: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating timeline", "details": err.Error()}) return @@ -50,14 +52,15 @@ func (handler *TimelineHandler) CreateTimeline(context *gin.Context) { func (handler *TimelineHandler) UpdateTimeline(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var timeline db.Timeline + var timeline types.Timeline + dbTimeline := lib.DeserializeTimeline(timeline) if err := context.ShouldBindJSON(&timeline); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } - if err := handler.service.UpdateTimeline(ctx, id, &timeline); err != nil { + if err := handler.service.UpdateTimeline(ctx, id, &dbTimeline); err != nil { log.Printf("error while updating timeline: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating timeline", "details": err.Error()}) return From dc72bd70967b2371999d9384b99c06454411602d Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:55:56 +0100 Subject: [PATCH 206/248] videoService.go --- server/services/videoService.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/services/videoService.go b/server/services/videoService.go index b6dd756..c1de067 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -5,6 +5,8 @@ import ( "database/sql" "fmt" "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "strings" "github.com/sean-david-welch/farmec-v2/server/stores" @@ -13,7 +15,7 @@ import ( type VideoService interface { TransformData(video *db.Video) (*db.Video, error) - GetVideos(ctx context.Context, id string) ([]db.Video, error) + GetVideos(ctx context.Context, id string) ([]types.Video, error) CreateVideo(ctx context.Context, video *db.Video) error UpdateVideo(ctx context.Context, id string, video *db.Video) error DeleteVideo(ctx context.Context, id string) error @@ -81,12 +83,16 @@ func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, erro return videoData, nil } -func (service *VideoServiceImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { +func (service *VideoServiceImpl) GetVideos(ctx context.Context, id string) ([]types.Video, error) { videos, err := service.store.GetVideos(ctx, id) if err != nil { return nil, err } - return videos, nil + var result []types.Video + for _, video := range videos { + result = append(result, lib.SerializeVideo(video)) + } + return result, nil } func (service *VideoServiceImpl) CreateVideo(ctx context.Context, video *db.Video) error { From b53e402ecc3750e8c5c59b9f3669e49393213457 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 20:58:27 +0100 Subject: [PATCH 207/248] videoHandler.go --- server/handlers/videoHandler.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index 86b06ac..c8395ee 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -1,7 +1,8 @@ package handlers import ( - "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/types" "log" "net/http" @@ -33,14 +34,15 @@ func (handler *VideoHandler) GetVideos(context *gin.Context) { func (handler *VideoHandler) CreateVideo(context *gin.Context) { ctx := context.Request.Context() - var video db.Video + var video types.Video + dbVideo := lib.DeserializeVideo(video) if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } - if err := handler.videoService.CreateVideo(ctx, &video); err != nil { + if err := handler.videoService.CreateVideo(ctx, &dbVideo); err != nil { log.Printf("Error creating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating video", "details": err.Error()}) return @@ -53,14 +55,15 @@ func (handler *VideoHandler) UpdateVideo(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var video db.Video + var video types.Video + dbVideo := lib.DeserializeVideo(video) if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } - if err := handler.videoService.UpdateVideo(ctx, id, &video); err != nil { + if err := handler.videoService.UpdateVideo(ctx, id, &dbVideo); err != nil { log.Printf("Error updating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating video", "details": err.Error()}) return From 13f8a1e83fedf4faf8c9f7eb6039f5730da2cfeb Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:02:54 +0100 Subject: [PATCH 208/248] warrantyService.go --- server/services/warrantyService.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index 9b5f41d..dd5ba75 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -11,7 +11,7 @@ import ( type WarrantyService interface { GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) - GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) + GetWarrantyById(ctx context.Context, id string) (types.WarrantyClaim, []types.PartsRequired, error) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error DeleteWarranty(ctx context.Context, id string) error @@ -35,13 +35,17 @@ func (service *WarrantyServiceImpl) GetWarranties(ctx context.Context) ([]types. return warranties, nil } -func (service *WarrantyServiceImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { +func (service *WarrantyServiceImpl) GetWarrantyById(ctx context.Context, id string) (*types.WarrantyClaim, []types.PartsRequired, error) { warranty, partsRequired, err := service.store.GetWarrantyById(ctx, id) if err != nil { return nil, nil, err } - - return warranty, partsRequired, nil + warrantyClaim := lib.SerializeWarrantyClaim(*warranty) + var result []types.PartsRequired + for _, part := range partsRequired { + result = append(result, lib.SerializePartsRequired(part)) + } + return &warrantyClaim, result, nil } func (service *WarrantyServiceImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { From f80c056f170b8d4f152ca1fd61609537ec1eea44 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:04:08 +0100 Subject: [PATCH 209/248] types --- server/types/miscTypes.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/types/miscTypes.go b/server/types/miscTypes.go index f22c74d..c40b26d 100644 --- a/server/types/miscTypes.go +++ b/server/types/miscTypes.go @@ -45,6 +45,10 @@ type PartsRequired struct { } type WarranrtyParts struct { + Warranty *WarrantyClaim + Parts []PartsRequired +} +type WarranrtyPartsDB struct { Warranty *db.WarrantyClaim Parts []db.PartsRequired } From d8ce689dd6ebe6add7caf8b4f6a3b5ce16e9f159 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:10:27 +0100 Subject: [PATCH 210/248] warrantyHandler.go --- server/handlers/warrantyHandler.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/server/handlers/warrantyHandler.go b/server/handlers/warrantyHandler.go index 6f91240..7689f1d 100644 --- a/server/handlers/warrantyHandler.go +++ b/server/handlers/warrantyHandler.go @@ -2,6 +2,7 @@ package handlers import ( "github.com/sean-david-welch/farmec-v2/server/db" + "github.com/sean-david-welch/farmec-v2/server/lib" "log" "net/http" @@ -52,6 +53,11 @@ func (handler *WarrantyHandler) GetWarrantyById(context *gin.Context) { func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { ctx := context.Request.Context() var warrantyParts types.WarranrtyParts + warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) + var parts []db.PartsRequired + for _, part := range warrantyParts.Parts { + parts = append(parts, lib.DeserializePartsRequired(part)) + } if err := context.ShouldBindJSON(&warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) @@ -59,7 +65,7 @@ func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { return } - if err := handler.service.CreateWarranty(ctx, warrantyParts.Warranty, warrantyParts.Parts); err != nil { + if err := handler.service.CreateWarranty(ctx, &warranty, parts); err != nil { log.Printf("error occurred while creating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating warranty claim"}) return @@ -71,28 +77,26 @@ func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - - var warranty *db.WarrantyClaim + var warrantyParts types.WarranrtyParts + warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) var parts []db.PartsRequired - - body := gin.H{ - "warranty": warranty, - "parts": parts, + for _, part := range warrantyParts.Parts { + parts = append(parts, lib.DeserializePartsRequired(part)) } - if err := context.ShouldBindJSON(body); err != nil { + if err := context.ShouldBindJSON(warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred bad request"}) return } - if err := handler.service.UpdateWarranty(ctx, id, warranty, parts); err != nil { + if err := handler.service.UpdateWarranty(ctx, id, &warranty, parts); err != nil { log.Printf("error occurred while updating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating warranty claim"}) return } - context.JSON(http.StatusAccepted, body) + context.JSON(http.StatusAccepted, warrantyParts) } func (handler *WarrantyHandler) DeleteWarranty(context *gin.Context) { From be2173a5d514a79cac185dde0aab3d2ae3f0234c Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:18:55 +0100 Subject: [PATCH 211/248] fixes --- server/services/pdfService.go | 6 +++++- server/types/miscTypes.go | 33 ++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/server/services/pdfService.go b/server/services/pdfService.go index 12cbc7f..c4adb93 100644 --- a/server/services/pdfService.go +++ b/server/services/pdfService.go @@ -68,7 +68,11 @@ func (service *PdfServiceImpl) RenderRegistrationPdf(registration *types.Machine } func (service *PdfServiceImpl) RenderWarrantyClaimPdf(warranty *types.WarranrtyParts) ([]byte, error) { - pdf, err := service.InitPdf("Warranty Claim " + "-- " + warranty.Warranty.OwnerName) + ownerName := "" + if warranty.Warranty.OwnerName != nil { + ownerName = *warranty.Warranty.OwnerName + } + pdf, err := service.InitPdf("Warranty Claim " + "-- " + ownerName) if err != nil { return nil, err } diff --git a/server/types/miscTypes.go b/server/types/miscTypes.go index c40b26d..b686167 100644 --- a/server/types/miscTypes.go +++ b/server/types/miscTypes.go @@ -1,7 +1,6 @@ package types import ( - "database/sql" "github.com/sean-david-welch/farmec-v2/server/db" ) @@ -54,25 +53,25 @@ type WarranrtyPartsDB struct { } type WarrantyClaimPDF struct { - Dealer string `json:"dealer"` - DealerContact sql.NullString `json:"dealer_contact"` - OwnerName string `json:"owner_name"` - MachineModel string `json:"machine_model"` - SerialNumber string `json:"serial_number"` - InstallDate sql.NullString `json:"install_date"` - FailureDate sql.NullString `json:"failure_date"` - RepairDate sql.NullString `json:"repair_date"` - FailureDetails sql.NullString `json:"failure_details"` - RepairDetails sql.NullString `json:"repair_details"` - LabourHours sql.NullString `json:"labour_hours"` - CompletedBy sql.NullString `json:"completed_by"` + Dealer string `json:"dealer"` + DealerContact *string `json:"dealer_contact"` + OwnerName *string `json:"owner_name"` + MachineModel *string `json:"machine_model"` + SerialNumber *string `json:"serial_number"` + InstallDate *string `json:"install_date"` + FailureDate *string `json:"failure_date"` + RepairDate *string `json:"repair_date"` + FailureDetails *string `json:"failure_details"` + RepairDetails *string `json:"repair_details"` + LabourHours *string `json:"labour_hours"` + CompletedBy *string `json:"completed_by"` } type PartsRequiredPDF struct { - PartNumber sql.NullString `json:"part_number"` - QuantityNeeded string `json:"quantity_needed"` - InvoiceNumber sql.NullString `json:"invoice_number"` - Description sql.NullString `json:"description"` + PartNumber string `json:"part_number"` + QuantityNeeded string `json:"quantity_needed"` + InvoiceNumber string `json:"invoice_number"` + Description string `json:"description"` } type MachineRegistration struct { From 8a6fb33cde65ed817468312a0726614d4131c7ee Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:21:08 +0100 Subject: [PATCH 212/248] fixes --- server/handlers/pdfHandler.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/handlers/pdfHandler.go b/server/handlers/pdfHandler.go index 8bba545..f4ffca7 100644 --- a/server/handlers/pdfHandler.go +++ b/server/handlers/pdfHandler.go @@ -66,7 +66,13 @@ func (handler *PdfHandler) RenderWarrantyClaimPdf(context *gin.Context) { fileName := fmt.Sprintf("%s-%s.warranty.pdf", strings.ReplaceAll(warranty.Warranty.Dealer, " ", ""), - strings.ReplaceAll(warranty.Warranty.OwnerName, " ", "")) + func(ownerName *string) string { + if ownerName != nil { + return strings.ReplaceAll(*ownerName, " ", "") + } + return "unknown_owner" + }(warranty.Warranty.OwnerName), + ) contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"", fileName) From 4500e47781eb13da1aa1f351cafa17984a8cb247 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:24:01 +0100 Subject: [PATCH 213/248] fixes --- server/services/supplierService.go | 2 +- server/services/warrantyService.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/services/supplierService.go b/server/services/supplierService.go index c0d00de..6e6102b 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -15,7 +15,7 @@ import ( type SupplierService interface { GetSuppliers(ctx context.Context) ([]types.Supplier, error) GetSupplierById(ctx context.Context, id string) (*types.Supplier, error) - CreateSupplier(ctx context.Context, supplier *db.Supplier) (*types.SupplierResult, error) + CreateSupplier(ctx context.Context, supplier db.Supplier) (*types.SupplierResult, error) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) (*types.SupplierResult, error) DeleteSupplier(ctx context.Context, id string) error } diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index dd5ba75..86a9660 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -11,7 +11,7 @@ import ( type WarrantyService interface { GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) - GetWarrantyById(ctx context.Context, id string) (types.WarrantyClaim, []types.PartsRequired, error) + GetWarrantyById(ctx context.Context, id string) (*types.WarrantyClaim, []types.PartsRequired, error) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error DeleteWarranty(ctx context.Context, id string) error From 57cb2925dd8c4c9c1fcf0d8a5b3bb028535b40dc Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 13 Oct 2024 21:25:37 +0100 Subject: [PATCH 214/248] another fix --- server/handlers/supplierHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index b59cf8e..a8be0f9 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -54,7 +54,7 @@ func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { return } - result, err := handler.supplierService.CreateSupplier(ctx, &dbSupplier) + result, err := handler.supplierService.CreateSupplier(ctx, dbSupplier) if err != nil { log.Printf("Error creating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating supplier", "details": err.Error()}) From bb5e83b5264d8f1212e08daacafde122c8903650 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:01:32 +0100 Subject: [PATCH 215/248] handler --- server/handlers/supplierHandler.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index a8be0f9..b1756ef 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -47,12 +47,11 @@ func (handler *SupplierHandler) GetSupplierByID(context *gin.Context) { func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { ctx := context.Request.Context() var supplier types.Supplier - dbSupplier := lib.DeserializeSupplier(supplier) - if err := context.ShouldBindJSON(&supplier); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } + dbSupplier := lib.DeserializeSupplier(supplier) result, err := handler.supplierService.CreateSupplier(ctx, dbSupplier) if err != nil { From 3c92d814d3b6ffe04c5062ae2648c1dbf0d5496d Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:02:48 +0100 Subject: [PATCH 216/248] store -> repo --- server/{stores => repository}/blogStore.go | 2 +- server/{stores => repository}/carouselStore.go | 2 +- server/{stores => repository}/employeeStore.go | 2 +- server/{stores => repository}/exhibitionStore.go | 2 +- server/{stores => repository}/lineitemStore.go | 2 +- server/{stores => repository}/machineStore.go | 2 +- server/{stores => repository}/partsStore.go | 2 +- server/{stores => repository}/privacyStore.go | 2 +- server/{stores => repository}/productStore.go | 2 +- server/{stores => repository}/registrationStore.go | 2 +- server/{stores => repository}/supplierStore.go | 2 +- server/{stores => repository}/termsStore.go | 2 +- server/{stores => repository}/timelineStore.go | 2 +- server/{stores => repository}/videoStore.go | 2 +- server/{stores => repository}/warrantyStore.go | 2 +- server/routes/blogRoutes.go | 4 ++-- server/routes/carouselRoutes.go | 4 ++-- server/routes/checkoutRoutes.go | 4 ++-- server/routes/employeeRoutes.go | 4 ++-- server/routes/exhibitionRoutes.go | 4 ++-- server/routes/lineItemRoutes.go | 4 ++-- server/routes/machineRoutes.go | 4 ++-- server/routes/partsRoutes.go | 4 ++-- server/routes/privacyRoutes.go | 4 ++-- server/routes/productRoutes.go | 4 ++-- server/routes/registrationRoutes.go | 4 ++-- server/routes/supplierRoutes.go | 4 ++-- server/routes/termsRoutes.go | 4 ++-- server/routes/timelineRoutes.go | 4 ++-- server/routes/videoRoutes.go | 4 ++-- server/routes/warrantyRoutes.go | 4 ++-- server/services/blogService.go | 6 +++--- server/services/carouselService.go | 6 +++--- server/services/checkoutService.go | 6 +++--- server/services/employeeService.go | 6 +++--- server/services/exhibitionService.go | 6 +++--- server/services/lineItemService.go | 6 +++--- server/services/machineService.go | 6 +++--- server/services/partsService.go | 6 +++--- server/services/privacyService.go | 6 +++--- server/services/productService.go | 6 +++--- server/services/registrationService.go | 6 +++--- server/services/supplierService.go | 6 +++--- server/services/termsService.go | 6 +++--- server/services/timelineService.go | 6 +++--- server/services/videoService.go | 6 +++--- server/services/warrantyService.go | 6 +++--- server/tests/blog_test.go | 4 ++-- 48 files changed, 97 insertions(+), 97 deletions(-) rename server/{stores => repository}/blogStore.go (99%) rename server/{stores => repository}/carouselStore.go (99%) rename server/{stores => repository}/employeeStore.go (99%) rename server/{stores => repository}/exhibitionStore.go (99%) rename server/{stores => repository}/lineitemStore.go (99%) rename server/{stores => repository}/machineStore.go (99%) rename server/{stores => repository}/partsStore.go (99%) rename server/{stores => repository}/privacyStore.go (99%) rename server/{stores => repository}/productStore.go (99%) rename server/{stores => repository}/registrationStore.go (99%) rename server/{stores => repository}/supplierStore.go (99%) rename server/{stores => repository}/termsStore.go (99%) rename server/{stores => repository}/timelineStore.go (99%) rename server/{stores => repository}/videoStore.go (99%) rename server/{stores => repository}/warrantyStore.go (99%) diff --git a/server/stores/blogStore.go b/server/repository/blogStore.go similarity index 99% rename from server/stores/blogStore.go rename to server/repository/blogStore.go index 37f34af..ec76519 100644 --- a/server/stores/blogStore.go +++ b/server/repository/blogStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/carouselStore.go b/server/repository/carouselStore.go similarity index 99% rename from server/stores/carouselStore.go rename to server/repository/carouselStore.go index c813489..de7f20e 100644 --- a/server/stores/carouselStore.go +++ b/server/repository/carouselStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/employeeStore.go b/server/repository/employeeStore.go similarity index 99% rename from server/stores/employeeStore.go rename to server/repository/employeeStore.go index 60725c7..222ca04 100644 --- a/server/stores/employeeStore.go +++ b/server/repository/employeeStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/exhibitionStore.go b/server/repository/exhibitionStore.go similarity index 99% rename from server/stores/exhibitionStore.go rename to server/repository/exhibitionStore.go index f3bde1e..f262e5a 100644 --- a/server/stores/exhibitionStore.go +++ b/server/repository/exhibitionStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/lineitemStore.go b/server/repository/lineitemStore.go similarity index 99% rename from server/stores/lineitemStore.go rename to server/repository/lineitemStore.go index 9f446dc..c95d2b3 100644 --- a/server/stores/lineitemStore.go +++ b/server/repository/lineitemStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/machineStore.go b/server/repository/machineStore.go similarity index 99% rename from server/stores/machineStore.go rename to server/repository/machineStore.go index 06e307b..7fb36fb 100644 --- a/server/stores/machineStore.go +++ b/server/repository/machineStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/partsStore.go b/server/repository/partsStore.go similarity index 99% rename from server/stores/partsStore.go rename to server/repository/partsStore.go index 3bc44e0..a47b8ff 100644 --- a/server/stores/partsStore.go +++ b/server/repository/partsStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/privacyStore.go b/server/repository/privacyStore.go similarity index 99% rename from server/stores/privacyStore.go rename to server/repository/privacyStore.go index 8133757..2eab77f 100644 --- a/server/stores/privacyStore.go +++ b/server/repository/privacyStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/productStore.go b/server/repository/productStore.go similarity index 99% rename from server/stores/productStore.go rename to server/repository/productStore.go index 6079a83..21ca2e9 100644 --- a/server/stores/productStore.go +++ b/server/repository/productStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/registrationStore.go b/server/repository/registrationStore.go similarity index 99% rename from server/stores/registrationStore.go rename to server/repository/registrationStore.go index aff4281..5533d14 100644 --- a/server/stores/registrationStore.go +++ b/server/repository/registrationStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/supplierStore.go b/server/repository/supplierStore.go similarity index 99% rename from server/stores/supplierStore.go rename to server/repository/supplierStore.go index 85b6507..c888765 100644 --- a/server/stores/supplierStore.go +++ b/server/repository/supplierStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/termsStore.go b/server/repository/termsStore.go similarity index 99% rename from server/stores/termsStore.go rename to server/repository/termsStore.go index b2e30ce..af45f9b 100644 --- a/server/stores/termsStore.go +++ b/server/repository/termsStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/timelineStore.go b/server/repository/timelineStore.go similarity index 99% rename from server/stores/timelineStore.go rename to server/repository/timelineStore.go index 6cf485a..1dff5a7 100644 --- a/server/stores/timelineStore.go +++ b/server/repository/timelineStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/videoStore.go b/server/repository/videoStore.go similarity index 99% rename from server/stores/videoStore.go rename to server/repository/videoStore.go index d8da917..975fb0f 100644 --- a/server/stores/videoStore.go +++ b/server/repository/videoStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/stores/warrantyStore.go b/server/repository/warrantyStore.go similarity index 99% rename from server/stores/warrantyStore.go rename to server/repository/warrantyStore.go index d4c9989..445026a 100644 --- a/server/stores/warrantyStore.go +++ b/server/repository/warrantyStore.go @@ -1,4 +1,4 @@ -package stores +package repository import ( "context" diff --git a/server/routes/blogRoutes.go b/server/routes/blogRoutes.go index 2a7c58c..3c642ef 100644 --- a/server/routes/blogRoutes.go +++ b/server/routes/blogRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitBlogs(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - blogStore := stores.NewBlogStore(database) + blogStore := repository.NewBlogStore(database) service := services.NewBlogService(blogStore, s3Client, "Blogs") handler := handlers.NewBlogHandler(service) diff --git a/server/routes/carouselRoutes.go b/server/routes/carouselRoutes.go index cd818d4..5190710 100644 --- a/server/routes/carouselRoutes.go +++ b/server/routes/carouselRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitCarousel(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleare *middleware.AdminMiddleware) { - carouselStore := stores.NewCarouselStore(database) + carouselStore := repository.NewCarouselStore(database) carouselService := services.NewCarouselService(carouselStore, s3Client, "Carousels") carouselHandler := handlers.NewCarouselHandler(carouselService) diff --git a/server/routes/checkoutRoutes.go b/server/routes/checkoutRoutes.go index 3f8e6ae..6c5a2a9 100644 --- a/server/routes/checkoutRoutes.go +++ b/server/routes/checkoutRoutes.go @@ -6,12 +6,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitCheckout(router *gin.Engine, database *sql.DB, secrets *lib.Secrets) { - itemStore := stores.NewLineItemStore(database) + itemStore := repository.NewLineItemStore(database) service := services.NewCheckoutService(secrets, itemStore) handler := handlers.NewCheckoutHandler(service) diff --git a/server/routes/employeeRoutes.go b/server/routes/employeeRoutes.go index dbaee87..7a5b20f 100644 --- a/server/routes/employeeRoutes.go +++ b/server/routes/employeeRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitializeEmployee(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - employeeStore := stores.NewEmployeeStore(database) + employeeStore := repository.NewEmployeeStore(database) service := services.NewEmployeeService(employeeStore, s3Client, "Employees") handler := handlers.NewEmployeeHandler(service) diff --git a/server/routes/exhibitionRoutes.go b/server/routes/exhibitionRoutes.go index 755ae0e..ffe098e 100644 --- a/server/routes/exhibitionRoutes.go +++ b/server/routes/exhibitionRoutes.go @@ -6,12 +6,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitExhibitions(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - exhibitionStore := stores.NewExhibitionStore(database) + exhibitionStore := repository.NewExhibitionStore(database) service := services.NewExhibitionService(exhibitionStore) handler := handlers.NewExhibitionHandler(service) diff --git a/server/routes/lineItemRoutes.go b/server/routes/lineItemRoutes.go index 36fa7ad..9384ace 100644 --- a/server/routes/lineItemRoutes.go +++ b/server/routes/lineItemRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitLineItems(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - itemStore := stores.NewLineItemStore(database) + itemStore := repository.NewLineItemStore(database) service := services.NewLineItemService(itemStore, s3Client, "Lineitems") handler := handlers.NewLineItemHandler(service) diff --git a/server/routes/machineRoutes.go b/server/routes/machineRoutes.go index 4eb6426..6387e52 100644 --- a/server/routes/machineRoutes.go +++ b/server/routes/machineRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitMachines(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - machineStore := stores.NewMachineStore(database) + machineStore := repository.NewMachineStore(database) machineService := services.NewMachineService(machineStore, s3Client, "Machines") machineHandler := handlers.NewMachineHandler(machineService) diff --git a/server/routes/partsRoutes.go b/server/routes/partsRoutes.go index a39201b..c4d5e3c 100644 --- a/server/routes/partsRoutes.go +++ b/server/routes/partsRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitParts(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - partsStore := stores.NewPartsStore(database) + partsStore := repository.NewPartsStore(database) partsService := services.NewPartsService(partsStore, s3Client, "Spareparts") partsHandler := handlers.NewPartsHandler(partsService) diff --git a/server/routes/privacyRoutes.go b/server/routes/privacyRoutes.go index 8202231..ff20d1b 100644 --- a/server/routes/privacyRoutes.go +++ b/server/routes/privacyRoutes.go @@ -6,12 +6,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitPrivacy(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - privacyStore := stores.NewPrivacyStore(database) + privacyStore := repository.NewPrivacyStore(database) service := services.NewPrivacyService(privacyStore) handler := handlers.NewPrivacyHandler(service) diff --git a/server/routes/productRoutes.go b/server/routes/productRoutes.go index ffcaec0..7ca358e 100644 --- a/server/routes/productRoutes.go +++ b/server/routes/productRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitProduct(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - productStore := stores.NewProductStore(database) + productStore := repository.NewProductStore(database) productService := services.NewProductService(productStore, s3Client, "Products") productHandler := handlers.NewProductHandler(productService) diff --git a/server/routes/registrationRoutes.go b/server/routes/registrationRoutes.go index 4112a99..ec75df5 100644 --- a/server/routes/registrationRoutes.go +++ b/server/routes/registrationRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitRegistrations(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - store := stores.NewRegistrationStore(database) + store := repository.NewRegistrationStore(database) service := services.NewRegistrationService(store, smtp) handler := handlers.NewRegistrationHandler(service) diff --git a/server/routes/supplierRoutes.go b/server/routes/supplierRoutes.go index eeb86cf..d1a4f83 100644 --- a/server/routes/supplierRoutes.go +++ b/server/routes/supplierRoutes.go @@ -8,12 +8,12 @@ import ( "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitSuppliers(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - supplierStore := stores.NewSupplierStore(database) + supplierStore := repository.NewSupplierStore(database) supplierService := services.NewSupplierService(supplierStore, s3Client, "Suppliers") supplierHandler := handlers.NewSupplierContoller(supplierService) diff --git a/server/routes/termsRoutes.go b/server/routes/termsRoutes.go index cd27699..6b17c66 100644 --- a/server/routes/termsRoutes.go +++ b/server/routes/termsRoutes.go @@ -6,12 +6,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitTerms(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - termsStore := stores.NewTermsStore(database) + termsStore := repository.NewTermsStore(database) service := services.NewTermsService(termsStore) handler := handlers.NewTermsHandler(service) diff --git a/server/routes/timelineRoutes.go b/server/routes/timelineRoutes.go index 9e422d4..2004447 100644 --- a/server/routes/timelineRoutes.go +++ b/server/routes/timelineRoutes.go @@ -6,12 +6,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitTimelines(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - timelineStore := stores.NewTimelineStore(database) + timelineStore := repository.NewTimelineStore(database) service := services.NewTimelineService(timelineStore) handler := handlers.NewTimelineHandler(service) diff --git a/server/routes/videoRoutes.go b/server/routes/videoRoutes.go index 6ee7c34..dde733c 100644 --- a/server/routes/videoRoutes.go +++ b/server/routes/videoRoutes.go @@ -9,8 +9,8 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" "google.golang.org/api/option" "google.golang.org/api/youtube/v3" ) @@ -21,7 +21,7 @@ func InitVideos(router *gin.Engine, database *sql.DB, secrets *lib.Secrets, admi log.Fatal("error calling YouTube API: ", err) } - videoStore := stores.NewVideoStore(database) + videoStore := repository.NewVideoStore(database) videoService := services.NewVideoService(videoStore, youtubeService) videoHandler := handlers.NewVideoHandler(videoService) diff --git a/server/routes/warrantyRoutes.go b/server/routes/warrantyRoutes.go index fe7bfa3..77fff9f 100644 --- a/server/routes/warrantyRoutes.go +++ b/server/routes/warrantyRoutes.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/middleware" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) func InitWarranty(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - warrantyStore := stores.NewWarrantyStore(database) + warrantyStore := repository.NewWarrantyStore(database) service := services.NewWarrantyService(warrantyStore, smtp) handler := handlers.NewWarrantyHandler(service) diff --git a/server/services/blogService.go b/server/services/blogService.go index 472c7ae..39eb548 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -21,12 +21,12 @@ type BlogService interface { } type BlogServiceImpl struct { - store stores.BlogStore + store repository.BlogStore s3Client lib.S3Client folder string } -func NewBlogService(store stores.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { +func NewBlogService(store repository.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/carouselService.go b/server/services/carouselService.go index 3d3ddd0..d7e407d 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -9,7 +9,7 @@ import ( "log" "github.com/sean-david-welch/farmec-v2/server/db" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" ) type CarouselService interface { @@ -20,12 +20,12 @@ type CarouselService interface { } type CarouselServiceImpl struct { - store stores.CarouselStore + store repository.CarouselStore s3Client lib.S3Client folder string } -func NewCarouselService(store stores.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { +func NewCarouselService(store repository.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { return &CarouselServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 5eb20fc..5aa51ef 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/stripe/stripe-go/v76" "github.com/stripe/stripe-go/v76/checkout/session" ) @@ -17,10 +17,10 @@ type CheckoutService interface { type CheckoutServiceImpl struct { secrets *lib.Secrets - store stores.LineItemStore + store repository.LineItemStore } -func NewCheckoutService(secrets *lib.Secrets, store stores.LineItemStore) *CheckoutServiceImpl { +func NewCheckoutService(secrets *lib.Secrets, store repository.LineItemStore) *CheckoutServiceImpl { return &CheckoutServiceImpl{secrets: secrets, store: store} } diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 728da73..b85fc12 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -20,12 +20,12 @@ type EmployeeService interface { } type EmployeeServiceImpl struct { - store stores.EmployeeStore + store repository.EmployeeStore s3Client lib.S3Client folder string } -func NewEmployeeService(store stores.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { +func NewEmployeeService(store repository.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index 2b849c6..2f57320 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -16,10 +16,10 @@ type ExhibitionService interface { } type ExhibitionServiceImpl struct { - store stores.ExhibitionStore + store repository.ExhibitionStore } -func NewExhibitionService(store stores.ExhibitionStore) *ExhibitionServiceImpl { +func NewExhibitionService(store repository.ExhibitionStore) *ExhibitionServiceImpl { return &ExhibitionServiceImpl{store: store} } diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index ae3c8fb..7f5b92e 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -21,12 +21,12 @@ type LineItemService interface { } type LineItemServiceImpl struct { - store stores.LineItemStore + store repository.LineItemStore s3Client lib.S3Client folder string } -func NewLineItemService(store stores.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { +func NewLineItemService(store repository.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/machineService.go b/server/services/machineService.go index b570b9c..218241d 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -23,10 +23,10 @@ type MachineService interface { type MachineServiceImpl struct { folder string s3Client lib.S3Client - store stores.MachineStore + store repository.MachineStore } -func NewMachineService(store stores.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { +func NewMachineService(store repository.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { return &MachineServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/partsService.go b/server/services/partsService.go index 7484784..4b218d1 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -9,7 +9,7 @@ import ( "log" url2 "net/url" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -23,10 +23,10 @@ type PartsService interface { type PartsServiceImpl struct { folder string s3Client lib.S3Client - store stores.PartsStore + store repository.PartsStore } -func NewPartsService(store stores.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { +func NewPartsService(store repository.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { return &PartsServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/privacyService.go b/server/services/privacyService.go index 5f6c09d..701b91f 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -16,10 +16,10 @@ type PrivacyService interface { } type PrivacyServiceImpl struct { - store stores.PrivacyStore + store repository.PrivacyStore } -func NewPrivacyService(store stores.PrivacyStore) *PrivacyServiceImpl { +func NewPrivacyService(store repository.PrivacyStore) *PrivacyServiceImpl { return &PrivacyServiceImpl{store: store} } diff --git a/server/services/productService.go b/server/services/productService.go index ec783af..4c90e94 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -22,10 +22,10 @@ type ProductService interface { type ProductServiceImpl struct { folder string s3Client lib.S3Client - store stores.ProductStore + store repository.ProductStore } -func NewProductService(store stores.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { +func NewProductService(store repository.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { return &ProductServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/registrationService.go b/server/services/registrationService.go index 4f4c509..84803e9 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" "net/smtp" ) @@ -19,10 +19,10 @@ type RegistrationService interface { type RegistrationServiceImpl struct { smtpClient lib.SMTPClient - store stores.RegistrationStore + store repository.RegistrationStore } -func NewRegistrationService(store stores.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { +func NewRegistrationService(store repository.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 6e6102b..7d30717 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "log" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -23,10 +23,10 @@ type SupplierService interface { type SupplierServiceImpl struct { folder string s3Client lib.S3Client - store stores.SupplierStore + store repository.SupplierStore } -func NewSupplierService(store stores.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { +func NewSupplierService(store repository.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { return &SupplierServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/termsService.go b/server/services/termsService.go index f0044bc..7c1b04f 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -16,10 +16,10 @@ type TermsService interface { } type TermsServiceImpl struct { - store stores.TermsStore + store repository.TermsStore } -func NewTermsService(store stores.TermsStore) *TermsServiceImpl { +func NewTermsService(store repository.TermsStore) *TermsServiceImpl { return &TermsServiceImpl{store: store} } diff --git a/server/services/timelineService.go b/server/services/timelineService.go index 4335614..46e71c6 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" ) @@ -16,10 +16,10 @@ type TimelineService interface { } type TimelineServiceImpl struct { - store stores.TimelineStore + store repository.TimelineStore } -func NewTimelineService(store stores.TimelineStore) *TimelineServiceImpl { +func NewTimelineService(store repository.TimelineStore) *TimelineServiceImpl { return &TimelineServiceImpl{store: store} } diff --git a/server/services/videoService.go b/server/services/videoService.go index c1de067..34e8cb8 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -9,7 +9,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/types" "strings" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "google.golang.org/api/youtube/v3" ) @@ -22,11 +22,11 @@ type VideoService interface { } type VideoServiceImpl struct { - store stores.VideoStore + store repository.VideoStore youtubeService *youtube.Service } -func NewVideoService(store stores.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { +func NewVideoService(store repository.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { return &VideoServiceImpl{ store: store, youtubeService: youtubeService, diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index 86a9660..5f7d956 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -4,7 +4,7 @@ import ( "context" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/stores" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" "net/smtp" ) @@ -19,10 +19,10 @@ type WarrantyService interface { type WarrantyServiceImpl struct { smtpClient lib.SMTPClient - store stores.WarrantyStore + store repository.WarrantyStore } -func NewWarrantyService(store stores.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { +func NewWarrantyService(store repository.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { return &WarrantyServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index f4130a0..55870ad 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -17,8 +17,8 @@ import ( _ "github.com/mattn/go-sqlite3" "github.com/sean-david-welch/farmec-v2/server/handlers" "github.com/sean-david-welch/farmec-v2/server/lib" + "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/services" - "github.com/sean-david-welch/farmec-v2/server/stores" ) type BlogTestSuite struct { @@ -56,7 +56,7 @@ func (suite *BlogTestSuite) SetupTest() { suite.db = database suite.mock = mock - store := stores.NewBlogStore(database) + store := repository.NewBlogStore(database) s3Client := lib.NewNoOpS3Client() service := services.NewBlogService(store, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) From 7d8e5630deba1c7965f71855d1a49f1c1afdf747 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:03:54 +0100 Subject: [PATCH 217/248] store -> repo again --- server/repository/blogStore.go | 18 +++++++++--------- server/repository/carouselStore.go | 18 +++++++++--------- server/repository/employeeStore.go | 18 +++++++++--------- server/repository/exhibitionStore.go | 16 ++++++++-------- server/repository/lineitemStore.go | 18 +++++++++--------- server/repository/machineStore.go | 18 +++++++++--------- server/repository/partsStore.go | 18 +++++++++--------- server/repository/privacyStore.go | 16 ++++++++-------- server/repository/productStore.go | 18 +++++++++--------- server/repository/registrationStore.go | 18 +++++++++--------- server/repository/supplierStore.go | 18 +++++++++--------- server/repository/termsStore.go | 16 ++++++++-------- server/repository/timelineStore.go | 16 ++++++++-------- server/repository/videoStore.go | 16 ++++++++-------- server/repository/warrantyStore.go | 18 +++++++++--------- server/routes/blogRoutes.go | 4 ++-- server/routes/carouselRoutes.go | 4 ++-- server/routes/checkoutRoutes.go | 4 ++-- server/routes/employeeRoutes.go | 4 ++-- server/routes/exhibitionRoutes.go | 4 ++-- server/routes/lineItemRoutes.go | 4 ++-- server/routes/machineRoutes.go | 4 ++-- server/routes/partsRoutes.go | 4 ++-- server/routes/privacyRoutes.go | 4 ++-- server/routes/productRoutes.go | 4 ++-- server/routes/registrationRoutes.go | 2 +- server/routes/supplierRoutes.go | 4 ++-- server/routes/termsRoutes.go | 4 ++-- server/routes/timelineRoutes.go | 4 ++-- server/routes/videoRoutes.go | 4 ++-- server/routes/warrantyRoutes.go | 4 ++-- server/services/blogService.go | 4 ++-- server/services/carouselService.go | 4 ++-- server/services/checkoutService.go | 4 ++-- server/services/employeeService.go | 4 ++-- server/services/exhibitionService.go | 4 ++-- server/services/lineItemService.go | 4 ++-- server/services/machineService.go | 4 ++-- server/services/partsService.go | 4 ++-- server/services/privacyService.go | 4 ++-- server/services/productService.go | 4 ++-- server/services/registrationService.go | 4 ++-- server/services/supplierService.go | 4 ++-- server/services/termsService.go | 4 ++-- server/services/timelineService.go | 4 ++-- server/services/videoService.go | 4 ++-- server/services/warrantyService.go | 4 ++-- server/tests/blog_test.go | 2 +- 48 files changed, 194 insertions(+), 194 deletions(-) diff --git a/server/repository/blogStore.go b/server/repository/blogStore.go index ec76519..c37dc3b 100644 --- a/server/repository/blogStore.go +++ b/server/repository/blogStore.go @@ -9,7 +9,7 @@ import ( "time" ) -type BlogStore interface { +type BlogRepo interface { GetBlogs(ctx context.Context) ([]db.Blog, error) GetBlogById(ctx context.Context, id string) (*db.Blog, error) CreateBlog(ctx context.Context, blog *db.Blog) error @@ -17,18 +17,18 @@ type BlogStore interface { DeleteBlog(ctx context.Context, id string) error } -type BlogStoreImpl struct { +type BlogRepoImpl struct { queries *db.Queries } -func NewBlogStore(sql *sql.DB) *BlogStoreImpl { +func NewBlogRepo(sql *sql.DB) *BlogRepoImpl { queries := db.New(sql) - return &BlogStoreImpl{ + return &BlogRepoImpl{ queries: queries, } } -func (store *BlogStoreImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { +func (store *BlogRepoImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { blogs, err := store.queries.GetBlogs(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) @@ -50,7 +50,7 @@ func (store *BlogStoreImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { return result, nil } -func (store *BlogStoreImpl) GetBlogById(ctx context.Context, id string) (*db.Blog, error) { +func (store *BlogRepoImpl) GetBlogById(ctx context.Context, id string) (*db.Blog, error) { blog, err := store.queries.GetBlogByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) @@ -59,7 +59,7 @@ func (store *BlogStoreImpl) GetBlogById(ctx context.Context, id string) (*db.Blo return &blog, nil } -func (store *BlogStoreImpl) CreateBlog(ctx context.Context, blog *db.Blog) error { +func (store *BlogRepoImpl) CreateBlog(ctx context.Context, blog *db.Blog) error { blog.ID = uuid.NewString() blog.Created = sql.NullString{String: time.Now().String(), Valid: true} @@ -81,7 +81,7 @@ func (store *BlogStoreImpl) CreateBlog(ctx context.Context, blog *db.Blog) error return nil } -func (store *BlogStoreImpl) UpdateBlog(ctx context.Context, id string, blog *db.Blog) error { +func (store *BlogRepoImpl) UpdateBlog(ctx context.Context, id string, blog *db.Blog) error { if blog.MainImage.Valid { params := db.UpdateBlogParams{ Title: blog.Title, @@ -112,7 +112,7 @@ func (store *BlogStoreImpl) UpdateBlog(ctx context.Context, id string, blog *db. return nil } -func (store *BlogStoreImpl) DeleteBlog(ctx context.Context, id string) error { +func (store *BlogRepoImpl) DeleteBlog(ctx context.Context, id string) error { err := store.queries.DeleteBlog(ctx, id) if err != nil { return fmt.Errorf("error occurred while deleting blog: %w", err) diff --git a/server/repository/carouselStore.go b/server/repository/carouselStore.go index de7f20e..3deb8c0 100644 --- a/server/repository/carouselStore.go +++ b/server/repository/carouselStore.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" ) -type CarouselStore interface { +type CarouselRepo interface { GetCarousels(ctx context.Context) ([]db.Carousel, error) GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) CreateCarousel(ctx context.Context, carousel *db.Carousel) error @@ -18,16 +18,16 @@ type CarouselStore interface { DeleteCarousel(ctx context.Context, id string) error } -type CarouselStoreImpl struct { +type CarouselRepoImpl struct { queries *db.Queries } -func NewCarouselStore(sql *sql.DB) *CarouselStoreImpl { +func NewCarouselRepo(sql *sql.DB) *CarouselRepoImpl { queries := db.New(sql) - return &CarouselStoreImpl{queries: queries} + return &CarouselRepoImpl{queries: queries} } -func (store *CarouselStoreImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { +func (store *CarouselRepoImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { carousels, err := store.queries.GetCarousels(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for carousels: %w", err) @@ -45,7 +45,7 @@ func (store *CarouselStoreImpl) GetCarousels(ctx context.Context) ([]db.Carousel return result, nil } -func (store *CarouselStoreImpl) GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) { +func (store *CarouselRepoImpl) GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) { carousel, err := store.queries.GetCarouselByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for carousel: %w", err) @@ -54,7 +54,7 @@ func (store *CarouselStoreImpl) GetCarouselById(ctx context.Context, id string) return &carousel, nil } -func (store *CarouselStoreImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) error { +func (store *CarouselRepoImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) error { carousel.ID = uuid.NewString() carousel.Created = sql.NullString{ String: time.Now().String(), @@ -74,7 +74,7 @@ func (store *CarouselStoreImpl) CreateCarousel(ctx context.Context, carousel *db return nil } -func (store *CarouselStoreImpl) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) error { +func (store *CarouselRepoImpl) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) error { if carousel.Image.Valid { params := db.UpdateCarouselParams{ Name: carousel.Name, @@ -96,7 +96,7 @@ func (store *CarouselStoreImpl) UpdateCarousel(ctx context.Context, id string, c return nil } -func (store *CarouselStoreImpl) DeleteCarousel(ctx context.Context, id string) error { +func (store *CarouselRepoImpl) DeleteCarousel(ctx context.Context, id string) error { if err := store.queries.DeleteCarousel(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a carousel: %w", err) } diff --git a/server/repository/employeeStore.go b/server/repository/employeeStore.go index 222ca04..8f8d464 100644 --- a/server/repository/employeeStore.go +++ b/server/repository/employeeStore.go @@ -10,7 +10,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type EmployeeStore interface { +type EmployeeRepo interface { GetEmployees(ctx context.Context) ([]db.Employee, error) GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) CreateEmployee(ctx context.Context, employee *db.Employee) error @@ -18,16 +18,16 @@ type EmployeeStore interface { DeleteEmployee(ctx context.Context, id string) error } -type EmployeeStoreImpl struct { +type EmployeeRepoImpl struct { queries *db.Queries } -func NewEmployeeStore(sql *sql.DB) *EmployeeStoreImpl { +func NewEmployeeRepo(sql *sql.DB) *EmployeeRepoImpl { queries := db.New(sql) - return &EmployeeStoreImpl{queries: queries} + return &EmployeeRepoImpl{queries: queries} } -func (store *EmployeeStoreImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { +func (store *EmployeeRepoImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { employees, err := store.queries.GetEmployees(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying employees: %w", err) @@ -48,7 +48,7 @@ func (store *EmployeeStoreImpl) GetEmployees(ctx context.Context) ([]db.Employee return result, nil } -func (store *EmployeeStoreImpl) GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) { +func (store *EmployeeRepoImpl) GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) { employee, err := store.queries.GetEmployee(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for employee: %w", err) @@ -57,7 +57,7 @@ func (store *EmployeeStoreImpl) GetEmployeeById(ctx context.Context, id string) return &employee, nil } -func (store *EmployeeStoreImpl) CreateEmployee(ctx context.Context, employee *db.Employee) error { +func (store *EmployeeRepoImpl) CreateEmployee(ctx context.Context, employee *db.Employee) error { employee.ID = uuid.NewString() employee.Created = sql.NullString{ String: time.Now().String(), @@ -79,7 +79,7 @@ func (store *EmployeeStoreImpl) CreateEmployee(ctx context.Context, employee *db return nil } -func (store *EmployeeStoreImpl) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) error { +func (store *EmployeeRepoImpl) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) error { if employee.ProfileImage.Valid { params := db.UpdateEmployeeParams{ Name: employee.Name, @@ -105,7 +105,7 @@ func (store *EmployeeStoreImpl) UpdateEmployee(ctx context.Context, id string, e return nil } -func (store *EmployeeStoreImpl) DeleteEmployee(ctx context.Context, id string) error { +func (store *EmployeeRepoImpl) DeleteEmployee(ctx context.Context, id string) error { if err := store.queries.DeleteEmployee(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting employee: %w", err) } diff --git a/server/repository/exhibitionStore.go b/server/repository/exhibitionStore.go index f262e5a..e60ef65 100644 --- a/server/repository/exhibitionStore.go +++ b/server/repository/exhibitionStore.go @@ -10,23 +10,23 @@ import ( "github.com/google/uuid" ) -type ExhibitionStore interface { +type ExhibitionRepo interface { GetExhibitions(ctx context.Context) ([]db.Exhibition, error) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error DeleteExhibition(ctx context.Context, id string) error } -type ExhibitionStoreImpl struct { +type ExhibitionRepoImpl struct { queries *db.Queries } -func NewExhibitionStore(sql *sql.DB) *ExhibitionStoreImpl { +func NewExhibitionRepo(sql *sql.DB) *ExhibitionRepoImpl { queries := db.New(sql) - return &ExhibitionStoreImpl{queries: queries} + return &ExhibitionRepoImpl{queries: queries} } -func (store *ExhibitionStoreImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { +func (store *ExhibitionRepoImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { exhibitions, err := store.queries.GetExhibitions(ctx) if err != nil { return nil, fmt.Errorf("an error occurred while querying the database for exhibitions: %w", err) @@ -47,7 +47,7 @@ func (store *ExhibitionStoreImpl) GetExhibitions(ctx context.Context) ([]db.Exhi return exhibitions, nil } -func (store *ExhibitionStoreImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { +func (store *ExhibitionRepoImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { exhibition.ID = uuid.NewString() exhibition.Created = sql.NullString{ String: time.Now().String(), @@ -70,7 +70,7 @@ func (store *ExhibitionStoreImpl) CreateExhibition(ctx context.Context, exhibiti return nil } -func (store *ExhibitionStoreImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { +func (store *ExhibitionRepoImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { params := db.UpdateExhibitionParams{ Title: exhibition.Title, Date: exhibition.Date, @@ -85,7 +85,7 @@ func (store *ExhibitionStoreImpl) UpdateExhibition(ctx context.Context, id strin return nil } -func (store *ExhibitionStoreImpl) DeleteExhibition(ctx context.Context, id string) error { +func (store *ExhibitionRepoImpl) DeleteExhibition(ctx context.Context, id string) error { if err := store.queries.DeleteExhibition(ctx, id); err != nil { return fmt.Errorf("error occurred while delting an exhibition: %w", err) } diff --git a/server/repository/lineitemStore.go b/server/repository/lineitemStore.go index c95d2b3..8ea29c6 100644 --- a/server/repository/lineitemStore.go +++ b/server/repository/lineitemStore.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type LineItemStore interface { +type LineItemRepo interface { GetLineItems(ctx context.Context) ([]db.LineItem, error) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error @@ -16,16 +16,16 @@ type LineItemStore interface { DeleteLineItem(ctx context.Context, id string) error } -type LineItemStoreImpl struct { +type LineItemRepoImpl struct { queries *db.Queries } -func NewLineItemStore(sql *sql.DB) *LineItemStoreImpl { +func NewLineItemRepo(sql *sql.DB) *LineItemRepoImpl { queries := db.New(sql) - return &LineItemStoreImpl{queries: queries} + return &LineItemRepoImpl{queries: queries} } -func (store *LineItemStoreImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { +func (store *LineItemRepoImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { lineItems, err := store.queries.GetLineItems(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting line items: %w", err) @@ -42,7 +42,7 @@ func (store *LineItemStoreImpl) GetLineItems(ctx context.Context) ([]db.LineItem return result, nil } -func (store *LineItemStoreImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { +func (store *LineItemRepoImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { lineItem, err := store.queries.GetLineItemByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting line items from db: %w", err) @@ -50,7 +50,7 @@ func (store *LineItemStoreImpl) GetLineItemById(ctx context.Context, id string) return &lineItem, nil } -func (store *LineItemStoreImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error { +func (store *LineItemRepoImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error { lineItem.ID = uuid.NewString() params := db.CreateLineItemParams{ @@ -65,7 +65,7 @@ func (store *LineItemStoreImpl) CreateLineItem(ctx context.Context, lineItem *db return nil } -func (store *LineItemStoreImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error { +func (store *LineItemRepoImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error { if lineItem.Image.Valid { params := db.UpdateLineItemParams{ Name: lineItem.Name, @@ -89,7 +89,7 @@ func (store *LineItemStoreImpl) UpdateLineItem(ctx context.Context, id string, l return nil } -func (store *LineItemStoreImpl) DeleteLineItem(ctx context.Context, id string) error { +func (store *LineItemRepoImpl) DeleteLineItem(ctx context.Context, id string) error { if err := store.queries.DeleteLineItem(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a line item: %w", err) } diff --git a/server/repository/machineStore.go b/server/repository/machineStore.go index 7fb36fb..84637aa 100644 --- a/server/repository/machineStore.go +++ b/server/repository/machineStore.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" ) -type MachineStore interface { +type MachineRepo interface { GetMachines(ctx context.Context, id string) ([]db.Machine, error) GetMachineById(ctx context.Context, id string) (*db.Machine, error) CreateMachine(ctx context.Context, machine *db.Machine) error @@ -18,16 +18,16 @@ type MachineStore interface { DeleteMachine(ctx context.Context, id string) error } -type MachineStoreImpl struct { +type MachineRepoImpl struct { queries *db.Queries } -func NewMachineStore(sql *sql.DB) *MachineStoreImpl { +func NewMachineRepo(sql *sql.DB) *MachineRepoImpl { queries := db.New(sql) - return &MachineStoreImpl{queries: queries} + return &MachineRepoImpl{queries: queries} } -func (store *MachineStoreImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { +func (store *MachineRepoImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { machines, err := store.queries.GetMachines(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) @@ -49,7 +49,7 @@ func (store *MachineStoreImpl) GetMachines(ctx context.Context, id string) ([]db return result, nil } -func (store *MachineStoreImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { +func (store *MachineRepoImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { machine, err := store.queries.GetMachineByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) @@ -58,7 +58,7 @@ func (store *MachineStoreImpl) GetMachineById(ctx context.Context, id string) (* return &machine, nil } -func (store *MachineStoreImpl) CreateMachine(ctx context.Context, machine *db.Machine) error { +func (store *MachineRepoImpl) CreateMachine(ctx context.Context, machine *db.Machine) error { machine.ID = uuid.NewString() machine.Created = sql.NullString{String: time.Now().String(), Valid: true} @@ -79,7 +79,7 @@ func (store *MachineStoreImpl) CreateMachine(ctx context.Context, machine *db.Ma return nil } -func (store *MachineStoreImpl) UpdateMachine(ctx context.Context, id string, machine *db.Machine) error { +func (store *MachineRepoImpl) UpdateMachine(ctx context.Context, id string, machine *db.Machine) error { if machine.MachineImage.Valid { params := db.UpdateMachineParams{ SupplierID: machine.SupplierID, @@ -107,7 +107,7 @@ func (store *MachineStoreImpl) UpdateMachine(ctx context.Context, id string, mac return nil } -func (store *MachineStoreImpl) DeleteMachine(ctx context.Context, id string) error { +func (store *MachineRepoImpl) DeleteMachine(ctx context.Context, id string) error { if err := store.queries.DeleteMachine(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting machine: %w", err) } diff --git a/server/repository/partsStore.go b/server/repository/partsStore.go index a47b8ff..a56b22d 100644 --- a/server/repository/partsStore.go +++ b/server/repository/partsStore.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type PartsStore interface { +type PartsRepo interface { GetParts(ctx context.Context, id string) ([]db.SparePart, error) GetPartById(ctx context.Context, id string) (*db.SparePart, error) CreatePart(ctx context.Context, part *db.SparePart) error @@ -16,16 +16,16 @@ type PartsStore interface { DeletePart(ctx context.Context, id string) error } -type PartsStoreImpl struct { +type PartsRepoImpl struct { queries *db.Queries } -func NewPartsStore(sql *sql.DB) *PartsStoreImpl { +func NewPartsRepo(sql *sql.DB) *PartsRepoImpl { queries := db.New(sql) - return &PartsStoreImpl{queries: queries} + return &PartsRepoImpl{queries: queries} } -func (store *PartsStoreImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { +func (store *PartsRepoImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { parts, err := store.queries.GetParts(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting spare parts: %w", err) @@ -43,7 +43,7 @@ func (store *PartsStoreImpl) GetParts(ctx context.Context, id string) ([]db.Spar return result, nil } -func (store *PartsStoreImpl) GetPartById(ctx context.Context, id string) (*db.SparePart, error) { +func (store *PartsRepoImpl) GetPartById(ctx context.Context, id string) (*db.SparePart, error) { part, err := store.queries.GetPartByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting part from the db: %w", err) @@ -51,7 +51,7 @@ func (store *PartsStoreImpl) GetPartById(ctx context.Context, id string) (*db.Sp return &part, err } -func (store *PartsStoreImpl) CreatePart(ctx context.Context, part *db.SparePart) error { +func (store *PartsRepoImpl) CreatePart(ctx context.Context, part *db.SparePart) error { part.ID = uuid.NewString() params := db.CreateSparePartParams{ @@ -67,7 +67,7 @@ func (store *PartsStoreImpl) CreatePart(ctx context.Context, part *db.SparePart) return nil } -func (store *PartsStoreImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) error { +func (store *PartsRepoImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) error { if part.PartsImage.Valid { params := db.UpdateSparePartParams{ SupplierID: part.SupplierID, @@ -93,7 +93,7 @@ func (store *PartsStoreImpl) UpdatePart(ctx context.Context, id string, part *db return nil } -func (store *PartsStoreImpl) DeletePart(ctx context.Context, id string) error { +func (store *PartsRepoImpl) DeletePart(ctx context.Context, id string) error { if err := store.queries.DeleteSparePart(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a spare part: %w", err) } diff --git a/server/repository/privacyStore.go b/server/repository/privacyStore.go index 2eab77f..69ca4c1 100644 --- a/server/repository/privacyStore.go +++ b/server/repository/privacyStore.go @@ -10,23 +10,23 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type PrivacyStore interface { +type PrivacyRepo interface { GetPrivacy(ctx context.Context) ([]db.Privacy, error) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error DeletePrivacy(ctx context.Context, id string) error } -type PrivacyStoreImpl struct { +type PrivacyRepoImpl struct { queries *db.Queries } -func NewPrivacyStore(sql *sql.DB) *PrivacyStoreImpl { +func NewPrivacyRepo(sql *sql.DB) *PrivacyRepoImpl { queries := db.New(sql) - return &PrivacyStoreImpl{queries: queries} + return &PrivacyRepoImpl{queries: queries} } -func (store *PrivacyStoreImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, error) { +func (store *PrivacyRepoImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, error) { privacies, err := store.queries.GetPrivacies(ctx) if err != nil { return nil, fmt.Errorf("an error occurred while getting privacy policy: %w", err) @@ -43,7 +43,7 @@ func (store *PrivacyStoreImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, er return result, nil } -func (store *PrivacyStoreImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { +func (store *PrivacyRepoImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { privacy.ID = uuid.NewString() privacy.Created = sql.NullString{ String: time.Now().String(), @@ -62,7 +62,7 @@ func (store *PrivacyStoreImpl) CreatePrivacy(ctx context.Context, privacy *db.Pr return nil } -func (store *PrivacyStoreImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { +func (store *PrivacyRepoImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { params := db.UpdatePrivacyParams{ Title: privacy.Title, Body: privacy.Body, @@ -74,7 +74,7 @@ func (store *PrivacyStoreImpl) UpdatePrivacy(ctx context.Context, id string, pri return nil } -func (store *PrivacyStoreImpl) DeletePrivacy(ctx context.Context, id string) error { +func (store *PrivacyRepoImpl) DeletePrivacy(ctx context.Context, id string) error { if err := store.queries.DeletePrivacy(ctx, id); err != nil { return fmt.Errorf("an error occurred while deleting privacy: %w", err) } diff --git a/server/repository/productStore.go b/server/repository/productStore.go index 21ca2e9..3005e73 100644 --- a/server/repository/productStore.go +++ b/server/repository/productStore.go @@ -8,7 +8,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type ProductStore interface { +type ProductRepo interface { GetProducts(ctx context.Context, id string) ([]db.Product, error) GetProductById(ctx context.Context, id string) (*db.Product, error) CreateProduct(ctx context.Context, product *db.Product) error @@ -16,16 +16,16 @@ type ProductStore interface { DeleteProduct(ctx context.Context, id string) error } -type ProductStoreImpl struct { +type ProductRepoImpl struct { queries *db.Queries } -func NewProductStore(sql *sql.DB) *ProductStoreImpl { +func NewProductRepo(sql *sql.DB) *ProductRepoImpl { queries := db.New(sql) - return &ProductStoreImpl{queries: queries} + return &ProductRepoImpl{queries: queries} } -func (store *ProductStoreImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { +func (store *ProductRepoImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { products, err := store.queries.GetProducts(ctx, id) if err != nil { return nil, fmt.Errorf("an error occurred while getting products: %w", err) @@ -45,7 +45,7 @@ func (store *ProductStoreImpl) GetProducts(ctx context.Context, id string) ([]db return result, nil } -func (store *ProductStoreImpl) GetProductById(ctx context.Context, id string) (*db.Product, error) { +func (store *ProductRepoImpl) GetProductById(ctx context.Context, id string) (*db.Product, error) { product, err := store.queries.GetProductByID(ctx, id) if err != nil { return nil, fmt.Errorf("an error occurred while getting product: %w", err) @@ -53,7 +53,7 @@ func (store *ProductStoreImpl) GetProductById(ctx context.Context, id string) (* return &product, nil } -func (store *ProductStoreImpl) CreateProduct(ctx context.Context, product *db.Product) error { +func (store *ProductRepoImpl) CreateProduct(ctx context.Context, product *db.Product) error { product.ID = uuid.NewString() params := db.CreateProductParams{ ID: product.ID, @@ -69,7 +69,7 @@ func (store *ProductStoreImpl) CreateProduct(ctx context.Context, product *db.Pr return nil } -func (store *ProductStoreImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) error { +func (store *ProductRepoImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) error { if product.ProductImage.Valid { params := db.UpdateProductParams{ MachineID: product.MachineID, @@ -97,7 +97,7 @@ func (store *ProductStoreImpl) UpdateProduct(ctx context.Context, id string, pro return nil } -func (store *ProductStoreImpl) DeleteProduct(ctx context.Context, id string) error { +func (store *ProductRepoImpl) DeleteProduct(ctx context.Context, id string) error { if err := store.queries.DeleteProduct(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a product: %w", err) } diff --git a/server/repository/registrationStore.go b/server/repository/registrationStore.go index 5533d14..05fdfc5 100644 --- a/server/repository/registrationStore.go +++ b/server/repository/registrationStore.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" ) -type RegistrationStore interface { +type RegistrationRepo interface { GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error @@ -18,16 +18,16 @@ type RegistrationStore interface { DeleteRegistration(ctx context.Context, id string) error } -type RegistrationStoreImpl struct { +type RegistrationRepoImpl struct { queries *db.Queries } -func NewRegistrationStore(sql *sql.DB) *RegistrationStoreImpl { +func NewRegistrationRepo(sql *sql.DB) *RegistrationRepoImpl { queries := db.New(sql) - return &RegistrationStoreImpl{queries: queries} + return &RegistrationRepoImpl{queries: queries} } -func (store *RegistrationStoreImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { +func (store *RegistrationRepoImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { registrations, err := store.queries.GetRegistrations(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting registration from the db: %w", err) @@ -59,7 +59,7 @@ func (store *RegistrationStoreImpl) GetRegistrations(ctx context.Context) ([]db. return result, nil } -func (store *RegistrationStoreImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { +func (store *RegistrationRepoImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { registration, err := store.queries.GetRegistrationsByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting a registration: %w", err) @@ -67,7 +67,7 @@ func (store *RegistrationStoreImpl) GetRegistrationById(ctx context.Context, id return ®istration, nil } -func (store *RegistrationStoreImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { +func (store *RegistrationRepoImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { registration.ID = uuid.NewString() registration.Created = sql.NullString{ String: time.Now().String(), @@ -100,7 +100,7 @@ func (store *RegistrationStoreImpl) CreateRegistration(ctx context.Context, regi return nil } -func (store *RegistrationStoreImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { +func (store *RegistrationRepoImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { params := db.UpdateRegistrationParams{ DealerName: registration.DealerName, DealerAddress: registration.DealerAddress, @@ -127,7 +127,7 @@ func (store *RegistrationStoreImpl) UpdateRegistration(ctx context.Context, id s return nil } -func (store *RegistrationStoreImpl) DeleteRegistration(ctx context.Context, id string) error { +func (store *RegistrationRepoImpl) DeleteRegistration(ctx context.Context, id string) error { if err := store.queries.DeleteRegistration(ctx, id); err != nil { return fmt.Errorf("an error occurred while deleting a registration: %w", err) } diff --git a/server/repository/supplierStore.go b/server/repository/supplierStore.go index c888765..c92f9ed 100644 --- a/server/repository/supplierStore.go +++ b/server/repository/supplierStore.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" ) -type SupplierStore interface { +type SupplierRepo interface { GetSuppliers(ctx context.Context) ([]db.Supplier, error) CreateSupplier(ctx context.Context, supplier *db.Supplier) error GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) @@ -18,16 +18,16 @@ type SupplierStore interface { DeleteSupplier(ctx context.Context, id string) error } -type SupplierStoreImpl struct { +type SupplierRepoImpl struct { queries *db.Queries } -func NewSupplierStore(sql *sql.DB) *SupplierStoreImpl { +func NewSupplierRepo(sql *sql.DB) *SupplierRepoImpl { queries := db.New(sql) - return &SupplierStoreImpl{queries: queries} + return &SupplierRepoImpl{queries: queries} } -func (store *SupplierStoreImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { +func (store *SupplierRepoImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { suppliers, err := store.queries.GetSuppliers(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting suppliers from the db: %w", err) @@ -53,7 +53,7 @@ func (store *SupplierStoreImpl) GetSuppliers(ctx context.Context) ([]db.Supplier return result, nil } -func (store *SupplierStoreImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { +func (store *SupplierRepoImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { supplierRow, err := store.queries.GetSupplierByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting suppliers from the db: %w", err) @@ -75,7 +75,7 @@ func (store *SupplierStoreImpl) GetSupplierById(ctx context.Context, id string) return &supplier, nil } -func (store *SupplierStoreImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) error { +func (store *SupplierRepoImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) error { supplier.ID = uuid.NewString() supplier.Created = sql.NullString{ String: time.Now().String(), @@ -102,7 +102,7 @@ func (store *SupplierStoreImpl) CreateSupplier(ctx context.Context, supplier *db return nil } -func (store *SupplierStoreImpl) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) error { +func (store *SupplierRepoImpl) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) error { if supplier.LogoImage.Valid && supplier.MarketingImage.Valid { params := db.UpdateSupplierParams{ Name: supplier.Name, @@ -139,7 +139,7 @@ func (store *SupplierStoreImpl) UpdateSupplier(ctx context.Context, id string, s return nil } -func (store *SupplierStoreImpl) DeleteSupplier(ctx context.Context, id string) error { +func (store *SupplierRepoImpl) DeleteSupplier(ctx context.Context, id string) error { if err := store.queries.DeleteSupplier(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting supplier: %w", err) } diff --git a/server/repository/termsStore.go b/server/repository/termsStore.go index af45f9b..f061c32 100644 --- a/server/repository/termsStore.go +++ b/server/repository/termsStore.go @@ -10,23 +10,23 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type TermsStore interface { +type TermsRepo interface { GetTerms(ctx context.Context) ([]db.Term, error) CreateTerm(ctx context.Context, term *db.Term) error UpdateTerm(ctx context.Context, id string, term *db.Term) error DeleteTerm(ctx context.Context, id string) error } -type TermsStoreImpl struct { +type TermsRepoImpl struct { queries *db.Queries } -func NewTermsStore(sql *sql.DB) *TermsStoreImpl { +func NewTermsRepo(sql *sql.DB) *TermsRepoImpl { queries := db.New(sql) - return &TermsStoreImpl{queries: queries} + return &TermsRepoImpl{queries: queries} } -func (store *TermsStoreImpl) GetTerms(ctx context.Context) ([]db.Term, error) { +func (store *TermsRepoImpl) GetTerms(ctx context.Context) ([]db.Term, error) { terms, err := store.queries.GetTerms(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for terms: %w", err) @@ -43,7 +43,7 @@ func (store *TermsStoreImpl) GetTerms(ctx context.Context) ([]db.Term, error) { return result, nil } -func (store *TermsStoreImpl) CreateTerm(ctx context.Context, term *db.Term) error { +func (store *TermsRepoImpl) CreateTerm(ctx context.Context, term *db.Term) error { term.ID = uuid.NewString() term.Created = sql.NullString{ String: time.Now().String(), @@ -61,7 +61,7 @@ func (store *TermsStoreImpl) CreateTerm(ctx context.Context, term *db.Term) erro return nil } -func (store *TermsStoreImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { +func (store *TermsRepoImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { params := db.UpdateTermParams{ Title: term.Title, Body: term.Body, @@ -74,7 +74,7 @@ func (store *TermsStoreImpl) UpdateTerm(ctx context.Context, id string, term *db return nil } -func (store *TermsStoreImpl) DeleteTerm(ctx context.Context, id string) error { +func (store *TermsRepoImpl) DeleteTerm(ctx context.Context, id string) error { if err := store.queries.DeleteTerm(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting term: %w", err) } diff --git a/server/repository/timelineStore.go b/server/repository/timelineStore.go index 1dff5a7..b133156 100644 --- a/server/repository/timelineStore.go +++ b/server/repository/timelineStore.go @@ -10,23 +10,23 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type TimelineStore interface { +type TimelineRepo interface { GetTimelines(ctx context.Context) ([]db.Timeline, error) CreateTimeline(ctx context.Context, timeline *db.Timeline) error UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error DeleteTimeline(ctx context.Context, id string) error } -type TimelineStoreImpl struct { +type TimelineRepoImpl struct { queries *db.Queries } -func NewTimelineStore(sql *sql.DB) *TimelineStoreImpl { +func NewTimelineRepo(sql *sql.DB) *TimelineRepoImpl { queries := db.New(sql) - return &TimelineStoreImpl{queries: queries} + return &TimelineRepoImpl{queries: queries} } -func (store *TimelineStoreImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { +func (store *TimelineRepoImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { timelines, err := store.queries.GetTimelines(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting timelines from the db: %w", err) @@ -45,7 +45,7 @@ func (store *TimelineStoreImpl) GetTimelines(ctx context.Context) ([]db.Timeline return result, nil } -func (store *TimelineStoreImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { +func (store *TimelineRepoImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { timeline.ID = uuid.NewString() timeline.Created = sql.NullString{ String: time.Now().String(), @@ -66,7 +66,7 @@ func (store *TimelineStoreImpl) CreateTimeline(ctx context.Context, timeline *db return nil } -func (store *TimelineStoreImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { +func (store *TimelineRepoImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { params := db.UpdateTimelineParams{ Title: timeline.Title, Date: timeline.Date, @@ -79,7 +79,7 @@ func (store *TimelineStoreImpl) UpdateTimeline(ctx context.Context, id string, t return nil } -func (store *TimelineStoreImpl) DeleteTimeline(ctx context.Context, id string) error { +func (store *TimelineRepoImpl) DeleteTimeline(ctx context.Context, id string) error { if err := store.queries.DeleteTimeline(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting the timeline: %w", err) } diff --git a/server/repository/videoStore.go b/server/repository/videoStore.go index 975fb0f..a6dfb8e 100644 --- a/server/repository/videoStore.go +++ b/server/repository/videoStore.go @@ -10,23 +10,23 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type VideoStore interface { +type VideoRepo interface { GetVideos(ctx context.Context, id string) ([]db.Video, error) CreateVideo(ctx context.Context, video *db.Video) error UpdateVideo(ctx context.Context, id string, video *db.Video) error DeleteVideo(ctx context.Context, id string) error } -type VideoStoreImpl struct { +type VideoRepoImpl struct { queries *db.Queries } -func NewVideoStore(sql *sql.DB) *VideoStoreImpl { +func NewVideoRepo(sql *sql.DB) *VideoRepoImpl { queries := db.New(sql) - return &VideoStoreImpl{queries: queries} + return &VideoRepoImpl{queries: queries} } -func (store *VideoStoreImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { +func (store *VideoRepoImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { videos, err := store.queries.SelectVideos(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting videos from the database: %w", err) @@ -47,7 +47,7 @@ func (store *VideoStoreImpl) GetVideos(ctx context.Context, id string) ([]db.Vid return result, nil } -func (store *VideoStoreImpl) CreateVideo(ctx context.Context, video *db.Video) error { +func (store *VideoRepoImpl) CreateVideo(ctx context.Context, video *db.Video) error { video.ID = uuid.NewString() video.Created = sql.NullString{ String: time.Now().String(), @@ -69,7 +69,7 @@ func (store *VideoStoreImpl) CreateVideo(ctx context.Context, video *db.Video) e return nil } -func (store *VideoStoreImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { +func (store *VideoRepoImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { params := db.UpdateVideoParams{ SupplierID: video.SupplierID, WebUrl: video.ThumbnailUrl, @@ -85,7 +85,7 @@ func (store *VideoStoreImpl) UpdateVideo(ctx context.Context, id string, video * return nil } -func (store *VideoStoreImpl) DeleteVideo(ctx context.Context, id string) error { +func (store *VideoRepoImpl) DeleteVideo(ctx context.Context, id string) error { if err := store.queries.DeleteMachine(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting video: %w", err) } diff --git a/server/repository/warrantyStore.go b/server/repository/warrantyStore.go index 445026a..04e2079 100644 --- a/server/repository/warrantyStore.go +++ b/server/repository/warrantyStore.go @@ -11,7 +11,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/db" ) -type WarrantyStore interface { +type WarrantyRepo interface { GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error @@ -19,17 +19,17 @@ type WarrantyStore interface { DeleteWarranty(ctx context.Context, id string) error } -type WarrantyStoreImpl struct { +type WarrantyRepoImpl struct { queries *db.Queries db *sql.DB } -func NewWarrantyStore(sqlDB *sql.DB) *WarrantyStoreImpl { +func NewWarrantyRepo(sqlDB *sql.DB) *WarrantyRepoImpl { queries := db.New(sqlDB) - return &WarrantyStoreImpl{queries: queries, db: sqlDB} + return &WarrantyRepoImpl{queries: queries, db: sqlDB} } -func (store *WarrantyStoreImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { +func (store *WarrantyRepoImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { warranties, err := store.queries.GetWarranties(ctx) if err != nil { return nil, fmt.Errorf("an error occurred while getting warranties: %w", err) @@ -46,7 +46,7 @@ func (store *WarrantyStoreImpl) GetWarranties(ctx context.Context) ([]types.Deal return result, nil } -func (store *WarrantyStoreImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { +func (store *WarrantyRepoImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { rows, err := store.queries.GetWarrantyByID(ctx, id) if err != nil { return nil, nil, fmt.Errorf("error occurred while getting warranty from the db: %w", err) @@ -92,7 +92,7 @@ func (store *WarrantyStoreImpl) GetWarrantyById(ctx context.Context, id string) return warranty, parts, nil } -func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { +func (store *WarrantyRepoImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { tx, err := store.db.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) @@ -153,7 +153,7 @@ func (store *WarrantyStoreImpl) CreateWarranty(ctx context.Context, warranty *db return nil } -func (store *WarrantyStoreImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { +func (store *WarrantyRepoImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { tx, err := store.db.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) @@ -210,7 +210,7 @@ func (store *WarrantyStoreImpl) UpdateWarranty(ctx context.Context, id string, w return nil } -func (store *WarrantyStoreImpl) DeleteWarranty(ctx context.Context, id string) error { +func (store *WarrantyRepoImpl) DeleteWarranty(ctx context.Context, id string) error { tx, err := store.db.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) diff --git a/server/routes/blogRoutes.go b/server/routes/blogRoutes.go index 3c642ef..5621780 100644 --- a/server/routes/blogRoutes.go +++ b/server/routes/blogRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitBlogs(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - blogStore := repository.NewBlogStore(database) - service := services.NewBlogService(blogStore, s3Client, "Blogs") + blogRepo := repository.NewBlogRepo(database) + service := services.NewBlogService(blogRepo, s3Client, "Blogs") handler := handlers.NewBlogHandler(service) BlogRoutes(router, handler, adminMiddleware) diff --git a/server/routes/carouselRoutes.go b/server/routes/carouselRoutes.go index 5190710..8649148 100644 --- a/server/routes/carouselRoutes.go +++ b/server/routes/carouselRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitCarousel(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleare *middleware.AdminMiddleware) { - carouselStore := repository.NewCarouselStore(database) - carouselService := services.NewCarouselService(carouselStore, s3Client, "Carousels") + carouselRepo := repository.NewCarouselRepo(database) + carouselService := services.NewCarouselService(carouselRepo, s3Client, "Carousels") carouselHandler := handlers.NewCarouselHandler(carouselService) CarouselRoutes(router, carouselHandler, adminMiddleare) diff --git a/server/routes/checkoutRoutes.go b/server/routes/checkoutRoutes.go index 6c5a2a9..90ce0e5 100644 --- a/server/routes/checkoutRoutes.go +++ b/server/routes/checkoutRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitCheckout(router *gin.Engine, database *sql.DB, secrets *lib.Secrets) { - itemStore := repository.NewLineItemStore(database) - service := services.NewCheckoutService(secrets, itemStore) + itemRepo := repository.NewLineItemRepo(database) + service := services.NewCheckoutService(secrets, itemRepo) handler := handlers.NewCheckoutHandler(service) CheckoutRoutes(router, handler) diff --git a/server/routes/employeeRoutes.go b/server/routes/employeeRoutes.go index 7a5b20f..b5f196c 100644 --- a/server/routes/employeeRoutes.go +++ b/server/routes/employeeRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitializeEmployee(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - employeeStore := repository.NewEmployeeStore(database) - service := services.NewEmployeeService(employeeStore, s3Client, "Employees") + employeeRepo := repository.NewEmployeeRepo(database) + service := services.NewEmployeeService(employeeRepo, s3Client, "Employees") handler := handlers.NewEmployeeHandler(service) EmployeeRoutes(router, handler, adminMiddleware) diff --git a/server/routes/exhibitionRoutes.go b/server/routes/exhibitionRoutes.go index ffe098e..71289ca 100644 --- a/server/routes/exhibitionRoutes.go +++ b/server/routes/exhibitionRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitExhibitions(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - exhibitionStore := repository.NewExhibitionStore(database) - service := services.NewExhibitionService(exhibitionStore) + exhibitionRepo := repository.NewExhibitionRepo(database) + service := services.NewExhibitionService(exhibitionRepo) handler := handlers.NewExhibitionHandler(service) ExhibitionRoutes(router, handler, adminMiddleware) diff --git a/server/routes/lineItemRoutes.go b/server/routes/lineItemRoutes.go index 9384ace..ec94e92 100644 --- a/server/routes/lineItemRoutes.go +++ b/server/routes/lineItemRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitLineItems(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - itemStore := repository.NewLineItemStore(database) - service := services.NewLineItemService(itemStore, s3Client, "Lineitems") + itemRepo := repository.NewLineItemRepo(database) + service := services.NewLineItemService(itemRepo, s3Client, "Lineitems") handler := handlers.NewLineItemHandler(service) LineItemRoutes(router, handler, adminMiddleware) diff --git a/server/routes/machineRoutes.go b/server/routes/machineRoutes.go index 6387e52..27d04e7 100644 --- a/server/routes/machineRoutes.go +++ b/server/routes/machineRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitMachines(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - machineStore := repository.NewMachineStore(database) - machineService := services.NewMachineService(machineStore, s3Client, "Machines") + machineRepo := repository.NewMachineRepo(database) + machineService := services.NewMachineService(machineRepo, s3Client, "Machines") machineHandler := handlers.NewMachineHandler(machineService) MachineRoutes(router, machineHandler, adminMiddleware) diff --git a/server/routes/partsRoutes.go b/server/routes/partsRoutes.go index c4d5e3c..b6ff2c4 100644 --- a/server/routes/partsRoutes.go +++ b/server/routes/partsRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitParts(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - partsStore := repository.NewPartsStore(database) - partsService := services.NewPartsService(partsStore, s3Client, "Spareparts") + partsRepo := repository.NewPartsRepo(database) + partsService := services.NewPartsService(partsRepo, s3Client, "Spareparts") partsHandler := handlers.NewPartsHandler(partsService) PartsRoutes(router, partsHandler, adminMiddleware) diff --git a/server/routes/privacyRoutes.go b/server/routes/privacyRoutes.go index ff20d1b..bb8c14c 100644 --- a/server/routes/privacyRoutes.go +++ b/server/routes/privacyRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitPrivacy(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - privacyStore := repository.NewPrivacyStore(database) - service := services.NewPrivacyService(privacyStore) + privacyRepo := repository.NewPrivacyRepo(database) + service := services.NewPrivacyService(privacyRepo) handler := handlers.NewPrivacyHandler(service) PrivacyRoutes(router, handler, adminMiddleware) diff --git a/server/routes/productRoutes.go b/server/routes/productRoutes.go index 7ca358e..3fe6d31 100644 --- a/server/routes/productRoutes.go +++ b/server/routes/productRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitProduct(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - productStore := repository.NewProductStore(database) - productService := services.NewProductService(productStore, s3Client, "Products") + productRepo := repository.NewProductRepo(database) + productService := services.NewProductService(productRepo, s3Client, "Products") productHandler := handlers.NewProductHandler(productService) ProductRoutes(router, productHandler, adminMiddleware) diff --git a/server/routes/registrationRoutes.go b/server/routes/registrationRoutes.go index ec75df5..5f8f331 100644 --- a/server/routes/registrationRoutes.go +++ b/server/routes/registrationRoutes.go @@ -12,7 +12,7 @@ import ( ) func InitRegistrations(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - store := repository.NewRegistrationStore(database) + store := repository.NewRegistrationRepo(database) service := services.NewRegistrationService(store, smtp) handler := handlers.NewRegistrationHandler(service) diff --git a/server/routes/supplierRoutes.go b/server/routes/supplierRoutes.go index d1a4f83..86bd747 100644 --- a/server/routes/supplierRoutes.go +++ b/server/routes/supplierRoutes.go @@ -13,8 +13,8 @@ import ( ) func InitSuppliers(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - supplierStore := repository.NewSupplierStore(database) - supplierService := services.NewSupplierService(supplierStore, s3Client, "Suppliers") + supplierRepo := repository.NewSupplierRepo(database) + supplierService := services.NewSupplierService(supplierRepo, s3Client, "Suppliers") supplierHandler := handlers.NewSupplierContoller(supplierService) SupplierRoutes(router, supplierHandler, adminMiddleware) diff --git a/server/routes/termsRoutes.go b/server/routes/termsRoutes.go index 6b17c66..7ded896 100644 --- a/server/routes/termsRoutes.go +++ b/server/routes/termsRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitTerms(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - termsStore := repository.NewTermsStore(database) - service := services.NewTermsService(termsStore) + termsRepo := repository.NewTermsRepo(database) + service := services.NewTermsService(termsRepo) handler := handlers.NewTermsHandler(service) TermsRoutes(router, handler, adminMiddleware) diff --git a/server/routes/timelineRoutes.go b/server/routes/timelineRoutes.go index 2004447..293f42a 100644 --- a/server/routes/timelineRoutes.go +++ b/server/routes/timelineRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitTimelines(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - timelineStore := repository.NewTimelineStore(database) - service := services.NewTimelineService(timelineStore) + timelineRepo := repository.NewTimelineRepo(database) + service := services.NewTimelineService(timelineRepo) handler := handlers.NewTimelineHandler(service) TimelineRoutes(router, handler, adminMiddleware) diff --git a/server/routes/videoRoutes.go b/server/routes/videoRoutes.go index dde733c..cc5e9f4 100644 --- a/server/routes/videoRoutes.go +++ b/server/routes/videoRoutes.go @@ -21,8 +21,8 @@ func InitVideos(router *gin.Engine, database *sql.DB, secrets *lib.Secrets, admi log.Fatal("error calling YouTube API: ", err) } - videoStore := repository.NewVideoStore(database) - videoService := services.NewVideoService(videoStore, youtubeService) + videoRepo := repository.NewVideoRepo(database) + videoService := services.NewVideoService(videoRepo, youtubeService) videoHandler := handlers.NewVideoHandler(videoService) VideoRoutes(router, videoHandler, adminMiddleware) diff --git a/server/routes/warrantyRoutes.go b/server/routes/warrantyRoutes.go index 77fff9f..1192669 100644 --- a/server/routes/warrantyRoutes.go +++ b/server/routes/warrantyRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitWarranty(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - warrantyStore := repository.NewWarrantyStore(database) - service := services.NewWarrantyService(warrantyStore, smtp) + warrantyRepo := repository.NewWarrantyRepo(database) + service := services.NewWarrantyService(warrantyRepo, smtp) handler := handlers.NewWarrantyHandler(service) WarrantyRoutes(router, handler, authMiddleware) diff --git a/server/services/blogService.go b/server/services/blogService.go index 39eb548..4dc8b95 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -21,12 +21,12 @@ type BlogService interface { } type BlogServiceImpl struct { - store repository.BlogStore + store repository.BlogRepo s3Client lib.S3Client folder string } -func NewBlogService(store repository.BlogStore, s3Client lib.S3Client, folder string) *BlogServiceImpl { +func NewBlogService(store repository.BlogRepo, s3Client lib.S3Client, folder string) *BlogServiceImpl { return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/carouselService.go b/server/services/carouselService.go index d7e407d..e7a1efa 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -20,12 +20,12 @@ type CarouselService interface { } type CarouselServiceImpl struct { - store repository.CarouselStore + store repository.CarouselRepo s3Client lib.S3Client folder string } -func NewCarouselService(store repository.CarouselStore, s3Client lib.S3Client, folder string) *CarouselServiceImpl { +func NewCarouselService(store repository.CarouselRepo, s3Client lib.S3Client, folder string) *CarouselServiceImpl { return &CarouselServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 5aa51ef..4095d9d 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -17,10 +17,10 @@ type CheckoutService interface { type CheckoutServiceImpl struct { secrets *lib.Secrets - store repository.LineItemStore + store repository.LineItemRepo } -func NewCheckoutService(secrets *lib.Secrets, store repository.LineItemStore) *CheckoutServiceImpl { +func NewCheckoutService(secrets *lib.Secrets, store repository.LineItemRepo) *CheckoutServiceImpl { return &CheckoutServiceImpl{secrets: secrets, store: store} } diff --git a/server/services/employeeService.go b/server/services/employeeService.go index b85fc12..7332451 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -20,12 +20,12 @@ type EmployeeService interface { } type EmployeeServiceImpl struct { - store repository.EmployeeStore + store repository.EmployeeRepo s3Client lib.S3Client folder string } -func NewEmployeeService(store repository.EmployeeStore, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { +func NewEmployeeService(store repository.EmployeeRepo, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index 2f57320..c387e39 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -16,10 +16,10 @@ type ExhibitionService interface { } type ExhibitionServiceImpl struct { - store repository.ExhibitionStore + store repository.ExhibitionRepo } -func NewExhibitionService(store repository.ExhibitionStore) *ExhibitionServiceImpl { +func NewExhibitionService(store repository.ExhibitionRepo) *ExhibitionServiceImpl { return &ExhibitionServiceImpl{store: store} } diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index 7f5b92e..6efd369 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -21,12 +21,12 @@ type LineItemService interface { } type LineItemServiceImpl struct { - store repository.LineItemStore + store repository.LineItemRepo s3Client lib.S3Client folder string } -func NewLineItemService(store repository.LineItemStore, s3Client lib.S3Client, folder string) *LineItemServiceImpl { +func NewLineItemService(store repository.LineItemRepo, s3Client lib.S3Client, folder string) *LineItemServiceImpl { return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} } diff --git a/server/services/machineService.go b/server/services/machineService.go index 218241d..5df0646 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -23,10 +23,10 @@ type MachineService interface { type MachineServiceImpl struct { folder string s3Client lib.S3Client - store repository.MachineStore + store repository.MachineRepo } -func NewMachineService(store repository.MachineStore, s3Client lib.S3Client, folder string) *MachineServiceImpl { +func NewMachineService(store repository.MachineRepo, s3Client lib.S3Client, folder string) *MachineServiceImpl { return &MachineServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/partsService.go b/server/services/partsService.go index 4b218d1..4692530 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -23,10 +23,10 @@ type PartsService interface { type PartsServiceImpl struct { folder string s3Client lib.S3Client - store repository.PartsStore + store repository.PartsRepo } -func NewPartsService(store repository.PartsStore, s3Client lib.S3Client, folder string) *PartsServiceImpl { +func NewPartsService(store repository.PartsRepo, s3Client lib.S3Client, folder string) *PartsServiceImpl { return &PartsServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/privacyService.go b/server/services/privacyService.go index 701b91f..c54b3fe 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -16,10 +16,10 @@ type PrivacyService interface { } type PrivacyServiceImpl struct { - store repository.PrivacyStore + store repository.PrivacyRepo } -func NewPrivacyService(store repository.PrivacyStore) *PrivacyServiceImpl { +func NewPrivacyService(store repository.PrivacyRepo) *PrivacyServiceImpl { return &PrivacyServiceImpl{store: store} } diff --git a/server/services/productService.go b/server/services/productService.go index 4c90e94..a43d1a4 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -22,10 +22,10 @@ type ProductService interface { type ProductServiceImpl struct { folder string s3Client lib.S3Client - store repository.ProductStore + store repository.ProductRepo } -func NewProductService(store repository.ProductStore, s3Client lib.S3Client, folder string) *ProductServiceImpl { +func NewProductService(store repository.ProductRepo, s3Client lib.S3Client, folder string) *ProductServiceImpl { return &ProductServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/registrationService.go b/server/services/registrationService.go index 84803e9..aba3fc9 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -19,10 +19,10 @@ type RegistrationService interface { type RegistrationServiceImpl struct { smtpClient lib.SMTPClient - store repository.RegistrationStore + store repository.RegistrationRepo } -func NewRegistrationService(store repository.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl { +func NewRegistrationService(store repository.RegistrationRepo, smtpClient lib.SMTPClient) *RegistrationServiceImpl { return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/services/supplierService.go b/server/services/supplierService.go index 7d30717..c060de9 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -23,10 +23,10 @@ type SupplierService interface { type SupplierServiceImpl struct { folder string s3Client lib.S3Client - store repository.SupplierStore + store repository.SupplierRepo } -func NewSupplierService(store repository.SupplierStore, s3Client lib.S3Client, folder string) *SupplierServiceImpl { +func NewSupplierService(store repository.SupplierRepo, s3Client lib.S3Client, folder string) *SupplierServiceImpl { return &SupplierServiceImpl{ store: store, s3Client: s3Client, diff --git a/server/services/termsService.go b/server/services/termsService.go index 7c1b04f..9824adf 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -16,10 +16,10 @@ type TermsService interface { } type TermsServiceImpl struct { - store repository.TermsStore + store repository.TermsRepo } -func NewTermsService(store repository.TermsStore) *TermsServiceImpl { +func NewTermsService(store repository.TermsRepo) *TermsServiceImpl { return &TermsServiceImpl{store: store} } diff --git a/server/services/timelineService.go b/server/services/timelineService.go index 46e71c6..54a0084 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -16,10 +16,10 @@ type TimelineService interface { } type TimelineServiceImpl struct { - store repository.TimelineStore + store repository.TimelineRepo } -func NewTimelineService(store repository.TimelineStore) *TimelineServiceImpl { +func NewTimelineService(store repository.TimelineRepo) *TimelineServiceImpl { return &TimelineServiceImpl{store: store} } diff --git a/server/services/videoService.go b/server/services/videoService.go index 34e8cb8..6cf6e19 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -22,11 +22,11 @@ type VideoService interface { } type VideoServiceImpl struct { - store repository.VideoStore + store repository.VideoRepo youtubeService *youtube.Service } -func NewVideoService(store repository.VideoStore, youtubeService *youtube.Service) *VideoServiceImpl { +func NewVideoService(store repository.VideoRepo, youtubeService *youtube.Service) *VideoServiceImpl { return &VideoServiceImpl{ store: store, youtubeService: youtubeService, diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index 5f7d956..8454f31 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -19,10 +19,10 @@ type WarrantyService interface { type WarrantyServiceImpl struct { smtpClient lib.SMTPClient - store repository.WarrantyStore + store repository.WarrantyRepo } -func NewWarrantyService(store repository.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl { +func NewWarrantyService(store repository.WarrantyRepo, smtpClient lib.SMTPClient) *WarrantyServiceImpl { return &WarrantyServiceImpl{store: store, smtpClient: smtpClient} } diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index 55870ad..ac9f546 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -56,7 +56,7 @@ func (suite *BlogTestSuite) SetupTest() { suite.db = database suite.mock = mock - store := repository.NewBlogStore(database) + store := repository.NewBlogRepo(database) s3Client := lib.NewNoOpS3Client() service := services.NewBlogService(store, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) From e58d26d1090429a0e73bb0b848a1749d4be92e6e Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:12:17 +0100 Subject: [PATCH 218/248] oops --- server/go.sum | 3 ++- server/repository/blogStore.go | 22 +++++++++++----------- server/repository/carouselStore.go | 22 +++++++++++----------- server/repository/employeeStore.go | 22 +++++++++++----------- server/repository/exhibitionStore.go | 16 ++++++++-------- server/repository/lineitemStore.go | 22 +++++++++++----------- server/repository/machineStore.go | 22 +++++++++++----------- server/repository/partsStore.go | 22 +++++++++++----------- server/repository/privacyStore.go | 16 ++++++++-------- server/repository/productStore.go | 22 +++++++++++----------- server/repository/registrationStore.go | 20 ++++++++++---------- server/repository/supplierStore.go | 22 +++++++++++----------- server/repository/termsStore.go | 16 ++++++++-------- server/repository/timelineStore.go | 16 ++++++++-------- server/repository/videoStore.go | 16 ++++++++-------- server/repository/warrantyStore.go | 26 +++++++++++++------------- server/routes/registrationRoutes.go | 4 ++-- server/services/blogService.go | 18 +++++++++--------- server/services/carouselService.go | 16 ++++++++-------- server/services/checkoutService.go | 8 ++++---- server/services/employeeService.go | 16 ++++++++-------- server/services/exhibitionService.go | 14 +++++++------- server/services/lineItemService.go | 18 +++++++++--------- server/services/machineService.go | 18 +++++++++--------- server/services/partsService.go | 16 ++++++++-------- server/services/privacyService.go | 14 +++++++------- server/services/productService.go | 16 ++++++++-------- server/services/registrationService.go | 16 ++++++++-------- server/services/supplierService.go | 18 +++++++++--------- server/services/termsService.go | 14 +++++++------- server/services/timelineService.go | 14 +++++++------- server/services/videoService.go | 14 +++++++------- server/services/warrantyService.go | 16 ++++++++-------- server/tests/blog_test.go | 4 ++-- 34 files changed, 280 insertions(+), 279 deletions(-) diff --git a/server/go.sum b/server/go.sum index e8c6b1d..561227a 100644 --- a/server/go.sum +++ b/server/go.sum @@ -5,7 +5,8 @@ cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1Yl cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= -cloud.google.com/go/firestore v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw= +cloud.google.com/go/firerepo v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw= +cloud.google.com/go/firerepo v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= cloud.google.com/go/firestore v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= cloud.google.com/go/iam v1.1.6 h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc= cloud.google.com/go/iam v1.1.6/go.mod h1:O0zxdPeGBoFdWW3HWmBxJsk0pfvNM/p/qa82rWOGTwI= diff --git a/server/repository/blogStore.go b/server/repository/blogStore.go index c37dc3b..b82b208 100644 --- a/server/repository/blogStore.go +++ b/server/repository/blogStore.go @@ -28,8 +28,8 @@ func NewBlogRepo(sql *sql.DB) *BlogRepoImpl { } } -func (store *BlogRepoImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { - blogs, err := store.queries.GetBlogs(ctx) +func (repo *BlogRepoImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { + blogs, err := repo.queries.GetBlogs(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) } @@ -50,8 +50,8 @@ func (store *BlogRepoImpl) GetBlogs(ctx context.Context) ([]db.Blog, error) { return result, nil } -func (store *BlogRepoImpl) GetBlogById(ctx context.Context, id string) (*db.Blog, error) { - blog, err := store.queries.GetBlogByID(ctx, id) +func (repo *BlogRepoImpl) GetBlogById(ctx context.Context, id string) (*db.Blog, error) { + blog, err := repo.queries.GetBlogByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying database: %w", err) } @@ -59,7 +59,7 @@ func (store *BlogRepoImpl) GetBlogById(ctx context.Context, id string) (*db.Blog return &blog, nil } -func (store *BlogRepoImpl) CreateBlog(ctx context.Context, blog *db.Blog) error { +func (repo *BlogRepoImpl) CreateBlog(ctx context.Context, blog *db.Blog) error { blog.ID = uuid.NewString() blog.Created = sql.NullString{String: time.Now().String(), Valid: true} @@ -73,7 +73,7 @@ func (store *BlogRepoImpl) CreateBlog(ctx context.Context, blog *db.Blog) error Created: blog.Created, } - err := store.queries.CreateBlog(ctx, params) + err := repo.queries.CreateBlog(ctx, params) if err != nil { return fmt.Errorf("error occurred while creating blog: %w", err) } @@ -81,7 +81,7 @@ func (store *BlogRepoImpl) CreateBlog(ctx context.Context, blog *db.Blog) error return nil } -func (store *BlogRepoImpl) UpdateBlog(ctx context.Context, id string, blog *db.Blog) error { +func (repo *BlogRepoImpl) UpdateBlog(ctx context.Context, id string, blog *db.Blog) error { if blog.MainImage.Valid { params := db.UpdateBlogParams{ Title: blog.Title, @@ -91,7 +91,7 @@ func (store *BlogRepoImpl) UpdateBlog(ctx context.Context, id string, blog *db.B Body: blog.Body, ID: id, } - err := store.queries.UpdateBlog(ctx, params) + err := repo.queries.UpdateBlog(ctx, params) if err != nil { return fmt.Errorf("error occurred while updating blog with image: %w", err) } @@ -103,7 +103,7 @@ func (store *BlogRepoImpl) UpdateBlog(ctx context.Context, id string, blog *db.B Body: blog.Body, ID: id, } - err := store.queries.UpdateBlogNoImage(ctx, params) + err := repo.queries.UpdateBlogNoImage(ctx, params) if err != nil { return fmt.Errorf("error occurred while updating blog without image: %w", err) } @@ -112,8 +112,8 @@ func (store *BlogRepoImpl) UpdateBlog(ctx context.Context, id string, blog *db.B return nil } -func (store *BlogRepoImpl) DeleteBlog(ctx context.Context, id string) error { - err := store.queries.DeleteBlog(ctx, id) +func (repo *BlogRepoImpl) DeleteBlog(ctx context.Context, id string) error { + err := repo.queries.DeleteBlog(ctx, id) if err != nil { return fmt.Errorf("error occurred while deleting blog: %w", err) } diff --git a/server/repository/carouselStore.go b/server/repository/carouselStore.go index 3deb8c0..eb9c08e 100644 --- a/server/repository/carouselStore.go +++ b/server/repository/carouselStore.go @@ -27,8 +27,8 @@ func NewCarouselRepo(sql *sql.DB) *CarouselRepoImpl { return &CarouselRepoImpl{queries: queries} } -func (store *CarouselRepoImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { - carousels, err := store.queries.GetCarousels(ctx) +func (repo *CarouselRepoImpl) GetCarousels(ctx context.Context) ([]db.Carousel, error) { + carousels, err := repo.queries.GetCarousels(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for carousels: %w", err) } @@ -45,8 +45,8 @@ func (store *CarouselRepoImpl) GetCarousels(ctx context.Context) ([]db.Carousel, return result, nil } -func (store *CarouselRepoImpl) GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) { - carousel, err := store.queries.GetCarouselByID(ctx, id) +func (repo *CarouselRepoImpl) GetCarouselById(ctx context.Context, id string) (*db.Carousel, error) { + carousel, err := repo.queries.GetCarouselByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for carousel: %w", err) } @@ -54,7 +54,7 @@ func (store *CarouselRepoImpl) GetCarouselById(ctx context.Context, id string) ( return &carousel, nil } -func (store *CarouselRepoImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) error { +func (repo *CarouselRepoImpl) CreateCarousel(ctx context.Context, carousel *db.Carousel) error { carousel.ID = uuid.NewString() carousel.Created = sql.NullString{ String: time.Now().String(), @@ -68,20 +68,20 @@ func (store *CarouselRepoImpl) CreateCarousel(ctx context.Context, carousel *db. Created: carousel.Created, } - if err := store.queries.CreateCarousel(ctx, params); err != nil { + if err := repo.queries.CreateCarousel(ctx, params); err != nil { return fmt.Errorf("error occurred while create a carousel: %w", err) } return nil } -func (store *CarouselRepoImpl) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) error { +func (repo *CarouselRepoImpl) UpdateCarousel(ctx context.Context, id string, carousel *db.Carousel) error { if carousel.Image.Valid { params := db.UpdateCarouselParams{ Name: carousel.Name, Image: carousel.Image, ID: id, } - if err := store.queries.UpdateCarousel(ctx, params); err != nil { + if err := repo.queries.UpdateCarousel(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a carousel: %w", err) } } else { @@ -89,15 +89,15 @@ func (store *CarouselRepoImpl) UpdateCarousel(ctx context.Context, id string, ca Name: carousel.Name, ID: id, } - if err := store.queries.UpdateCarouselNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateCarouselNoImage(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a carousel: %w", err) } } return nil } -func (store *CarouselRepoImpl) DeleteCarousel(ctx context.Context, id string) error { - if err := store.queries.DeleteCarousel(ctx, id); err != nil { +func (repo *CarouselRepoImpl) DeleteCarousel(ctx context.Context, id string) error { + if err := repo.queries.DeleteCarousel(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a carousel: %w", err) } return nil diff --git a/server/repository/employeeStore.go b/server/repository/employeeStore.go index 8f8d464..f0a172a 100644 --- a/server/repository/employeeStore.go +++ b/server/repository/employeeStore.go @@ -27,8 +27,8 @@ func NewEmployeeRepo(sql *sql.DB) *EmployeeRepoImpl { return &EmployeeRepoImpl{queries: queries} } -func (store *EmployeeRepoImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { - employees, err := store.queries.GetEmployees(ctx) +func (repo *EmployeeRepoImpl) GetEmployees(ctx context.Context) ([]db.Employee, error) { + employees, err := repo.queries.GetEmployees(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying employees: %w", err) } @@ -48,8 +48,8 @@ func (store *EmployeeRepoImpl) GetEmployees(ctx context.Context) ([]db.Employee, return result, nil } -func (store *EmployeeRepoImpl) GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) { - employee, err := store.queries.GetEmployee(ctx, id) +func (repo *EmployeeRepoImpl) GetEmployeeById(ctx context.Context, id string) (*db.Employee, error) { + employee, err := repo.queries.GetEmployee(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for employee: %w", err) } @@ -57,7 +57,7 @@ func (store *EmployeeRepoImpl) GetEmployeeById(ctx context.Context, id string) ( return &employee, nil } -func (store *EmployeeRepoImpl) CreateEmployee(ctx context.Context, employee *db.Employee) error { +func (repo *EmployeeRepoImpl) CreateEmployee(ctx context.Context, employee *db.Employee) error { employee.ID = uuid.NewString() employee.Created = sql.NullString{ String: time.Now().String(), @@ -72,14 +72,14 @@ func (store *EmployeeRepoImpl) CreateEmployee(ctx context.Context, employee *db. Created: employee.Created, } - if err := store.queries.CreateEmployee(ctx, params); err != nil { + if err := repo.queries.CreateEmployee(ctx, params); err != nil { return fmt.Errorf("error occurred while creating an employee: %w", err) } return nil } -func (store *EmployeeRepoImpl) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) error { +func (repo *EmployeeRepoImpl) UpdateEmployee(ctx context.Context, id string, employee *db.Employee) error { if employee.ProfileImage.Valid { params := db.UpdateEmployeeParams{ Name: employee.Name, @@ -88,7 +88,7 @@ func (store *EmployeeRepoImpl) UpdateEmployee(ctx context.Context, id string, em ProfileImage: employee.ProfileImage, ID: id, } - if err := store.queries.UpdateEmployee(ctx, params); err != nil { + if err := repo.queries.UpdateEmployee(ctx, params); err != nil { return fmt.Errorf("error occurred while updatig an employee: %w", err) } } else { @@ -98,15 +98,15 @@ func (store *EmployeeRepoImpl) UpdateEmployee(ctx context.Context, id string, em Role: employee.Role, ID: id, } - if err := store.queries.UpdateEmployeeNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateEmployeeNoImage(ctx, params); err != nil { return fmt.Errorf("an error occurred while updating the employee: %w", err) } } return nil } -func (store *EmployeeRepoImpl) DeleteEmployee(ctx context.Context, id string) error { - if err := store.queries.DeleteEmployee(ctx, id); err != nil { +func (repo *EmployeeRepoImpl) DeleteEmployee(ctx context.Context, id string) error { + if err := repo.queries.DeleteEmployee(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting employee: %w", err) } return nil diff --git a/server/repository/exhibitionStore.go b/server/repository/exhibitionStore.go index e60ef65..0694a67 100644 --- a/server/repository/exhibitionStore.go +++ b/server/repository/exhibitionStore.go @@ -26,8 +26,8 @@ func NewExhibitionRepo(sql *sql.DB) *ExhibitionRepoImpl { return &ExhibitionRepoImpl{queries: queries} } -func (store *ExhibitionRepoImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { - exhibitions, err := store.queries.GetExhibitions(ctx) +func (repo *ExhibitionRepoImpl) GetExhibitions(ctx context.Context) ([]db.Exhibition, error) { + exhibitions, err := repo.queries.GetExhibitions(ctx) if err != nil { return nil, fmt.Errorf("an error occurred while querying the database for exhibitions: %w", err) } @@ -47,7 +47,7 @@ func (store *ExhibitionRepoImpl) GetExhibitions(ctx context.Context) ([]db.Exhib return exhibitions, nil } -func (store *ExhibitionRepoImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { +func (repo *ExhibitionRepoImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { exhibition.ID = uuid.NewString() exhibition.Created = sql.NullString{ String: time.Now().String(), @@ -63,14 +63,14 @@ func (store *ExhibitionRepoImpl) CreateExhibition(ctx context.Context, exhibitio Created: exhibition.Created, } - if err := store.queries.CreateExhibition(ctx, params); err != nil { + if err := repo.queries.CreateExhibition(ctx, params); err != nil { return fmt.Errorf("error occurred while creating an exhibitions: %w", err) } return nil } -func (store *ExhibitionRepoImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { +func (repo *ExhibitionRepoImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { params := db.UpdateExhibitionParams{ Title: exhibition.Title, Date: exhibition.Date, @@ -79,14 +79,14 @@ func (store *ExhibitionRepoImpl) UpdateExhibition(ctx context.Context, id string ID: id, } - if err := store.queries.UpdateExhibition(ctx, params); err != nil { + if err := repo.queries.UpdateExhibition(ctx, params); err != nil { return fmt.Errorf("error occurred while updating an exhiibtion: %w", err) } return nil } -func (store *ExhibitionRepoImpl) DeleteExhibition(ctx context.Context, id string) error { - if err := store.queries.DeleteExhibition(ctx, id); err != nil { +func (repo *ExhibitionRepoImpl) DeleteExhibition(ctx context.Context, id string) error { + if err := repo.queries.DeleteExhibition(ctx, id); err != nil { return fmt.Errorf("error occurred while delting an exhibition: %w", err) } return nil diff --git a/server/repository/lineitemStore.go b/server/repository/lineitemStore.go index 8ea29c6..a753842 100644 --- a/server/repository/lineitemStore.go +++ b/server/repository/lineitemStore.go @@ -25,8 +25,8 @@ func NewLineItemRepo(sql *sql.DB) *LineItemRepoImpl { return &LineItemRepoImpl{queries: queries} } -func (store *LineItemRepoImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { - lineItems, err := store.queries.GetLineItems(ctx) +func (repo *LineItemRepoImpl) GetLineItems(ctx context.Context) ([]db.LineItem, error) { + lineItems, err := repo.queries.GetLineItems(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting line items: %w", err) } @@ -42,15 +42,15 @@ func (store *LineItemRepoImpl) GetLineItems(ctx context.Context) ([]db.LineItem, return result, nil } -func (store *LineItemRepoImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { - lineItem, err := store.queries.GetLineItemByID(ctx, id) +func (repo *LineItemRepoImpl) GetLineItemById(ctx context.Context, id string) (*db.LineItem, error) { + lineItem, err := repo.queries.GetLineItemByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting line items from db: %w", err) } return &lineItem, nil } -func (store *LineItemRepoImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error { +func (repo *LineItemRepoImpl) CreateLineItem(ctx context.Context, lineItem *db.LineItem) error { lineItem.ID = uuid.NewString() params := db.CreateLineItemParams{ @@ -59,13 +59,13 @@ func (store *LineItemRepoImpl) CreateLineItem(ctx context.Context, lineItem *db. Price: lineItem.Price, Image: lineItem.Image, } - if err := store.queries.CreateLineItem(ctx, params); err != nil { + if err := repo.queries.CreateLineItem(ctx, params); err != nil { return fmt.Errorf("error occurred while creating line items: %w", err) } return nil } -func (store *LineItemRepoImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error { +func (repo *LineItemRepoImpl) UpdateLineItem(ctx context.Context, id string, lineItem *db.LineItem) error { if lineItem.Image.Valid { params := db.UpdateLineItemParams{ Name: lineItem.Name, @@ -73,7 +73,7 @@ func (store *LineItemRepoImpl) UpdateLineItem(ctx context.Context, id string, li Image: lineItem.Image, ID: id, } - if err := store.queries.UpdateLineItem(ctx, params); err != nil { + if err := repo.queries.UpdateLineItem(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a line item: %w", err) } } else { @@ -82,15 +82,15 @@ func (store *LineItemRepoImpl) UpdateLineItem(ctx context.Context, id string, li Price: lineItem.Price, ID: id, } - if err := store.queries.UpdateLineItemNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateLineItemNoImage(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a line item: %w", err) } } return nil } -func (store *LineItemRepoImpl) DeleteLineItem(ctx context.Context, id string) error { - if err := store.queries.DeleteLineItem(ctx, id); err != nil { +func (repo *LineItemRepoImpl) DeleteLineItem(ctx context.Context, id string) error { + if err := repo.queries.DeleteLineItem(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a line item: %w", err) } return nil diff --git a/server/repository/machineStore.go b/server/repository/machineStore.go index 84637aa..2a2a20a 100644 --- a/server/repository/machineStore.go +++ b/server/repository/machineStore.go @@ -27,8 +27,8 @@ func NewMachineRepo(sql *sql.DB) *MachineRepoImpl { return &MachineRepoImpl{queries: queries} } -func (store *MachineRepoImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { - machines, err := store.queries.GetMachines(ctx, id) +func (repo *MachineRepoImpl) GetMachines(ctx context.Context, id string) ([]db.Machine, error) { + machines, err := repo.queries.GetMachines(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) } @@ -49,8 +49,8 @@ func (store *MachineRepoImpl) GetMachines(ctx context.Context, id string) ([]db. return result, nil } -func (store *MachineRepoImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { - machine, err := store.queries.GetMachineByID(ctx, id) +func (repo *MachineRepoImpl) GetMachineById(ctx context.Context, id string) (*db.Machine, error) { + machine, err := repo.queries.GetMachineByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for machines: %w", err) } @@ -58,7 +58,7 @@ func (store *MachineRepoImpl) GetMachineById(ctx context.Context, id string) (*d return &machine, nil } -func (store *MachineRepoImpl) CreateMachine(ctx context.Context, machine *db.Machine) error { +func (repo *MachineRepoImpl) CreateMachine(ctx context.Context, machine *db.Machine) error { machine.ID = uuid.NewString() machine.Created = sql.NullString{String: time.Now().String(), Valid: true} @@ -72,14 +72,14 @@ func (store *MachineRepoImpl) CreateMachine(ctx context.Context, machine *db.Mac Created: machine.Created, } - if err := store.queries.CreateMachine(ctx, params); err != nil { + if err := repo.queries.CreateMachine(ctx, params); err != nil { return fmt.Errorf("error occurred while creating a machine: %w", err) } return nil } -func (store *MachineRepoImpl) UpdateMachine(ctx context.Context, id string, machine *db.Machine) error { +func (repo *MachineRepoImpl) UpdateMachine(ctx context.Context, id string, machine *db.Machine) error { if machine.MachineImage.Valid { params := db.UpdateMachineParams{ SupplierID: machine.SupplierID, @@ -89,7 +89,7 @@ func (store *MachineRepoImpl) UpdateMachine(ctx context.Context, id string, mach MachineLink: machine.MachineLink, ID: id, } - if err := store.queries.UpdateMachine(ctx, params); err != nil { + if err := repo.queries.UpdateMachine(ctx, params); err != nil { return fmt.Errorf("error ocurred while updating a machine with image: %w", err) } } else { @@ -100,15 +100,15 @@ func (store *MachineRepoImpl) UpdateMachine(ctx context.Context, id string, mach MachineLink: machine.MachineLink, ID: id, } - if err := store.queries.UpdateMachineNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateMachineNoImage(ctx, params); err != nil { return fmt.Errorf("error occurred while updating the machine without image: %w", err) } } return nil } -func (store *MachineRepoImpl) DeleteMachine(ctx context.Context, id string) error { - if err := store.queries.DeleteMachine(ctx, id); err != nil { +func (repo *MachineRepoImpl) DeleteMachine(ctx context.Context, id string) error { + if err := repo.queries.DeleteMachine(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting machine: %w", err) } return nil diff --git a/server/repository/partsStore.go b/server/repository/partsStore.go index a56b22d..08f9794 100644 --- a/server/repository/partsStore.go +++ b/server/repository/partsStore.go @@ -25,8 +25,8 @@ func NewPartsRepo(sql *sql.DB) *PartsRepoImpl { return &PartsRepoImpl{queries: queries} } -func (store *PartsRepoImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { - parts, err := store.queries.GetParts(ctx, id) +func (repo *PartsRepoImpl) GetParts(ctx context.Context, id string) ([]db.SparePart, error) { + parts, err := repo.queries.GetParts(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting spare parts: %w", err) } @@ -43,15 +43,15 @@ func (store *PartsRepoImpl) GetParts(ctx context.Context, id string) ([]db.Spare return result, nil } -func (store *PartsRepoImpl) GetPartById(ctx context.Context, id string) (*db.SparePart, error) { - part, err := store.queries.GetPartByID(ctx, id) +func (repo *PartsRepoImpl) GetPartById(ctx context.Context, id string) (*db.SparePart, error) { + part, err := repo.queries.GetPartByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting part from the db: %w", err) } return &part, err } -func (store *PartsRepoImpl) CreatePart(ctx context.Context, part *db.SparePart) error { +func (repo *PartsRepoImpl) CreatePart(ctx context.Context, part *db.SparePart) error { part.ID = uuid.NewString() params := db.CreateSparePartParams{ @@ -61,13 +61,13 @@ func (store *PartsRepoImpl) CreatePart(ctx context.Context, part *db.SparePart) PartsImage: part.PartsImage, SparePartsLink: part.SparePartsLink, } - if err := store.queries.CreateSparePart(ctx, params); err != nil { + if err := repo.queries.CreateSparePart(ctx, params); err != nil { return fmt.Errorf("error occurred while creating spare parts: %w", err) } return nil } -func (store *PartsRepoImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) error { +func (repo *PartsRepoImpl) UpdatePart(ctx context.Context, id string, part *db.SparePart) error { if part.PartsImage.Valid { params := db.UpdateSparePartParams{ SupplierID: part.SupplierID, @@ -76,7 +76,7 @@ func (store *PartsRepoImpl) UpdatePart(ctx context.Context, id string, part *db. SparePartsLink: part.SparePartsLink, ID: id, } - if err := store.queries.UpdateSparePart(ctx, params); err != nil { + if err := repo.queries.UpdateSparePart(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a spare part: %w", err) } } else { @@ -86,15 +86,15 @@ func (store *PartsRepoImpl) UpdatePart(ctx context.Context, id string, part *db. SparePartsLink: part.SparePartsLink, ID: id, } - if err := store.queries.UpdateSparePartNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateSparePartNoImage(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a spare part: %w", err) } } return nil } -func (store *PartsRepoImpl) DeletePart(ctx context.Context, id string) error { - if err := store.queries.DeleteSparePart(ctx, id); err != nil { +func (repo *PartsRepoImpl) DeletePart(ctx context.Context, id string) error { + if err := repo.queries.DeleteSparePart(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a spare part: %w", err) } return nil diff --git a/server/repository/privacyStore.go b/server/repository/privacyStore.go index 69ca4c1..085e947 100644 --- a/server/repository/privacyStore.go +++ b/server/repository/privacyStore.go @@ -26,8 +26,8 @@ func NewPrivacyRepo(sql *sql.DB) *PrivacyRepoImpl { return &PrivacyRepoImpl{queries: queries} } -func (store *PrivacyRepoImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, error) { - privacies, err := store.queries.GetPrivacies(ctx) +func (repo *PrivacyRepoImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, error) { + privacies, err := repo.queries.GetPrivacies(ctx) if err != nil { return nil, fmt.Errorf("an error occurred while getting privacy policy: %w", err) } @@ -43,7 +43,7 @@ func (store *PrivacyRepoImpl) GetPrivacy(ctx context.Context) ([]db.Privacy, err return result, nil } -func (store *PrivacyRepoImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { +func (repo *PrivacyRepoImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { privacy.ID = uuid.NewString() privacy.Created = sql.NullString{ String: time.Now().String(), @@ -56,26 +56,26 @@ func (store *PrivacyRepoImpl) CreatePrivacy(ctx context.Context, privacy *db.Pri Body: privacy.Body, Created: privacy.Created, } - if err := store.queries.CreatePrivacy(ctx, params); err != nil { + if err := repo.queries.CreatePrivacy(ctx, params); err != nil { return fmt.Errorf("error occurred while creating policy: %w", err) } return nil } -func (store *PrivacyRepoImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { +func (repo *PrivacyRepoImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { params := db.UpdatePrivacyParams{ Title: privacy.Title, Body: privacy.Body, ID: id, } - if err := store.queries.UpdatePrivacy(ctx, params); err != nil { + if err := repo.queries.UpdatePrivacy(ctx, params); err != nil { return fmt.Errorf("an error occurred while") } return nil } -func (store *PrivacyRepoImpl) DeletePrivacy(ctx context.Context, id string) error { - if err := store.queries.DeletePrivacy(ctx, id); err != nil { +func (repo *PrivacyRepoImpl) DeletePrivacy(ctx context.Context, id string) error { + if err := repo.queries.DeletePrivacy(ctx, id); err != nil { return fmt.Errorf("an error occurred while deleting privacy: %w", err) } return nil diff --git a/server/repository/productStore.go b/server/repository/productStore.go index 3005e73..6220a1a 100644 --- a/server/repository/productStore.go +++ b/server/repository/productStore.go @@ -25,8 +25,8 @@ func NewProductRepo(sql *sql.DB) *ProductRepoImpl { return &ProductRepoImpl{queries: queries} } -func (store *ProductRepoImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { - products, err := store.queries.GetProducts(ctx, id) +func (repo *ProductRepoImpl) GetProducts(ctx context.Context, id string) ([]db.Product, error) { + products, err := repo.queries.GetProducts(ctx, id) if err != nil { return nil, fmt.Errorf("an error occurred while getting products: %w", err) } @@ -45,15 +45,15 @@ func (store *ProductRepoImpl) GetProducts(ctx context.Context, id string) ([]db. return result, nil } -func (store *ProductRepoImpl) GetProductById(ctx context.Context, id string) (*db.Product, error) { - product, err := store.queries.GetProductByID(ctx, id) +func (repo *ProductRepoImpl) GetProductById(ctx context.Context, id string) (*db.Product, error) { + product, err := repo.queries.GetProductByID(ctx, id) if err != nil { return nil, fmt.Errorf("an error occurred while getting product: %w", err) } return &product, nil } -func (store *ProductRepoImpl) CreateProduct(ctx context.Context, product *db.Product) error { +func (repo *ProductRepoImpl) CreateProduct(ctx context.Context, product *db.Product) error { product.ID = uuid.NewString() params := db.CreateProductParams{ ID: product.ID, @@ -63,13 +63,13 @@ func (store *ProductRepoImpl) CreateProduct(ctx context.Context, product *db.Pro Description: product.Description, ProductLink: product.ProductLink, } - if err := store.queries.CreateProduct(ctx, params); err != nil { + if err := repo.queries.CreateProduct(ctx, params); err != nil { return fmt.Errorf("an error occurred while creating a product: %w", err) } return nil } -func (store *ProductRepoImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) error { +func (repo *ProductRepoImpl) UpdateProduct(ctx context.Context, id string, product *db.Product) error { if product.ProductImage.Valid { params := db.UpdateProductParams{ MachineID: product.MachineID, @@ -79,7 +79,7 @@ func (store *ProductRepoImpl) UpdateProduct(ctx context.Context, id string, prod ProductLink: product.ProductLink, ID: id, } - if err := store.queries.UpdateProduct(ctx, params); err != nil { + if err := repo.queries.UpdateProduct(ctx, params); err != nil { return fmt.Errorf("an error occurred while updating product: %w", err) } } else { @@ -90,15 +90,15 @@ func (store *ProductRepoImpl) UpdateProduct(ctx context.Context, id string, prod ProductLink: product.ProductLink, ID: id, } - if err := store.queries.UpdateProductNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateProductNoImage(ctx, params); err != nil { return fmt.Errorf("an error occurred while updating product: %w", err) } } return nil } -func (store *ProductRepoImpl) DeleteProduct(ctx context.Context, id string) error { - if err := store.queries.DeleteProduct(ctx, id); err != nil { +func (repo *ProductRepoImpl) DeleteProduct(ctx context.Context, id string) error { + if err := repo.queries.DeleteProduct(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting a product: %w", err) } return nil diff --git a/server/repository/registrationStore.go b/server/repository/registrationStore.go index 05fdfc5..2567201 100644 --- a/server/repository/registrationStore.go +++ b/server/repository/registrationStore.go @@ -27,8 +27,8 @@ func NewRegistrationRepo(sql *sql.DB) *RegistrationRepoImpl { return &RegistrationRepoImpl{queries: queries} } -func (store *RegistrationRepoImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { - registrations, err := store.queries.GetRegistrations(ctx) +func (repo *RegistrationRepoImpl) GetRegistrations(ctx context.Context) ([]db.MachineRegistration, error) { + registrations, err := repo.queries.GetRegistrations(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting registration from the db: %w", err) } @@ -59,15 +59,15 @@ func (store *RegistrationRepoImpl) GetRegistrations(ctx context.Context) ([]db.M return result, nil } -func (store *RegistrationRepoImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { - registration, err := store.queries.GetRegistrationsByID(ctx, id) +func (repo *RegistrationRepoImpl) GetRegistrationById(ctx context.Context, id string) (*db.MachineRegistration, error) { + registration, err := repo.queries.GetRegistrationsByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting a registration: %w", err) } return ®istration, nil } -func (store *RegistrationRepoImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { +func (repo *RegistrationRepoImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { registration.ID = uuid.NewString() registration.Created = sql.NullString{ String: time.Now().String(), @@ -94,13 +94,13 @@ func (store *RegistrationRepoImpl) CreateRegistration(ctx context.Context, regis CompletedBy: registration.CompletedBy, Created: registration.Created, } - if err := store.queries.CreateRegistration(ctx, params); err != nil { + if err := repo.queries.CreateRegistration(ctx, params); err != nil { return fmt.Errorf("error occurred while creating a registration: %w", err) } return nil } -func (store *RegistrationRepoImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { +func (repo *RegistrationRepoImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { params := db.UpdateRegistrationParams{ DealerName: registration.DealerName, DealerAddress: registration.DealerAddress, @@ -120,15 +120,15 @@ func (store *RegistrationRepoImpl) UpdateRegistration(ctx context.Context, id st CompletedBy: registration.CompletedBy, ID: id, } - if err := store.queries.UpdateRegistration(ctx, params); err != nil { + if err := repo.queries.UpdateRegistration(ctx, params); err != nil { return fmt.Errorf("error occurred while updating registration: %w", err) } return nil } -func (store *RegistrationRepoImpl) DeleteRegistration(ctx context.Context, id string) error { - if err := store.queries.DeleteRegistration(ctx, id); err != nil { +func (repo *RegistrationRepoImpl) DeleteRegistration(ctx context.Context, id string) error { + if err := repo.queries.DeleteRegistration(ctx, id); err != nil { return fmt.Errorf("an error occurred while deleting a registration: %w", err) } return nil diff --git a/server/repository/supplierStore.go b/server/repository/supplierStore.go index c92f9ed..6b87062 100644 --- a/server/repository/supplierStore.go +++ b/server/repository/supplierStore.go @@ -27,8 +27,8 @@ func NewSupplierRepo(sql *sql.DB) *SupplierRepoImpl { return &SupplierRepoImpl{queries: queries} } -func (store *SupplierRepoImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { - suppliers, err := store.queries.GetSuppliers(ctx) +func (repo *SupplierRepoImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, error) { + suppliers, err := repo.queries.GetSuppliers(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting suppliers from the db: %w", err) } @@ -53,8 +53,8 @@ func (store *SupplierRepoImpl) GetSuppliers(ctx context.Context) ([]db.Supplier, return result, nil } -func (store *SupplierRepoImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { - supplierRow, err := store.queries.GetSupplierByID(ctx, id) +func (repo *SupplierRepoImpl) GetSupplierById(ctx context.Context, id string) (*db.Supplier, error) { + supplierRow, err := repo.queries.GetSupplierByID(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting suppliers from the db: %w", err) } @@ -75,7 +75,7 @@ func (store *SupplierRepoImpl) GetSupplierById(ctx context.Context, id string) ( return &supplier, nil } -func (store *SupplierRepoImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) error { +func (repo *SupplierRepoImpl) CreateSupplier(ctx context.Context, supplier *db.Supplier) error { supplier.ID = uuid.NewString() supplier.Created = sql.NullString{ String: time.Now().String(), @@ -96,13 +96,13 @@ func (store *SupplierRepoImpl) CreateSupplier(ctx context.Context, supplier *db. SocialWebsite: supplier.SocialWebsite, Created: supplier.Created, } - if err := store.queries.CreateSupplier(ctx, params); err != nil { + if err := repo.queries.CreateSupplier(ctx, params); err != nil { return fmt.Errorf("error occurred while creating supplier: %w", err) } return nil } -func (store *SupplierRepoImpl) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) error { +func (repo *SupplierRepoImpl) UpdateSupplier(ctx context.Context, id string, supplier *db.Supplier) error { if supplier.LogoImage.Valid && supplier.MarketingImage.Valid { params := db.UpdateSupplierParams{ Name: supplier.Name, @@ -117,7 +117,7 @@ func (store *SupplierRepoImpl) UpdateSupplier(ctx context.Context, id string, su SocialWebsite: supplier.SocialWebsite, ID: id, } - if err := store.queries.UpdateSupplier(ctx, params); err != nil { + if err := repo.queries.UpdateSupplier(ctx, params); err != nil { return fmt.Errorf("error while updating the supplier: %w", err) } } else { @@ -132,15 +132,15 @@ func (store *SupplierRepoImpl) UpdateSupplier(ctx context.Context, id string, su SocialWebsite: supplier.SocialWebsite, ID: id, } - if err := store.queries.UpdateSupplierNoImage(ctx, params); err != nil { + if err := repo.queries.UpdateSupplierNoImage(ctx, params); err != nil { return fmt.Errorf("error while updating the supplier: %w", err) } } return nil } -func (store *SupplierRepoImpl) DeleteSupplier(ctx context.Context, id string) error { - if err := store.queries.DeleteSupplier(ctx, id); err != nil { +func (repo *SupplierRepoImpl) DeleteSupplier(ctx context.Context, id string) error { + if err := repo.queries.DeleteSupplier(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting supplier: %w", err) } return nil diff --git a/server/repository/termsStore.go b/server/repository/termsStore.go index f061c32..e663c16 100644 --- a/server/repository/termsStore.go +++ b/server/repository/termsStore.go @@ -26,8 +26,8 @@ func NewTermsRepo(sql *sql.DB) *TermsRepoImpl { return &TermsRepoImpl{queries: queries} } -func (store *TermsRepoImpl) GetTerms(ctx context.Context) ([]db.Term, error) { - terms, err := store.queries.GetTerms(ctx) +func (repo *TermsRepoImpl) GetTerms(ctx context.Context) ([]db.Term, error) { + terms, err := repo.queries.GetTerms(ctx) if err != nil { return nil, fmt.Errorf("error occurred while querying the database for terms: %w", err) } @@ -43,7 +43,7 @@ func (store *TermsRepoImpl) GetTerms(ctx context.Context) ([]db.Term, error) { return result, nil } -func (store *TermsRepoImpl) CreateTerm(ctx context.Context, term *db.Term) error { +func (repo *TermsRepoImpl) CreateTerm(ctx context.Context, term *db.Term) error { term.ID = uuid.NewString() term.Created = sql.NullString{ String: time.Now().String(), @@ -55,27 +55,27 @@ func (store *TermsRepoImpl) CreateTerm(ctx context.Context, term *db.Term) error Body: term.Body, Created: term.Created, } - if err := store.queries.CreateTerm(ctx, params); err != nil { + if err := repo.queries.CreateTerm(ctx, params); err != nil { return fmt.Errorf("error occured while creating a term: %w", err) } return nil } -func (store *TermsRepoImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { +func (repo *TermsRepoImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { params := db.UpdateTermParams{ Title: term.Title, Body: term.Body, Created: term.Created, ID: id, } - if err := store.queries.UpdateTerm(ctx, params); err != nil { + if err := repo.queries.UpdateTerm(ctx, params); err != nil { return fmt.Errorf("error ocurred while updating a machine with image: %w", err) } return nil } -func (store *TermsRepoImpl) DeleteTerm(ctx context.Context, id string) error { - if err := store.queries.DeleteTerm(ctx, id); err != nil { +func (repo *TermsRepoImpl) DeleteTerm(ctx context.Context, id string) error { + if err := repo.queries.DeleteTerm(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting term: %w", err) } return nil diff --git a/server/repository/timelineStore.go b/server/repository/timelineStore.go index b133156..5fc3030 100644 --- a/server/repository/timelineStore.go +++ b/server/repository/timelineStore.go @@ -26,8 +26,8 @@ func NewTimelineRepo(sql *sql.DB) *TimelineRepoImpl { return &TimelineRepoImpl{queries: queries} } -func (store *TimelineRepoImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { - timelines, err := store.queries.GetTimelines(ctx) +func (repo *TimelineRepoImpl) GetTimelines(ctx context.Context) ([]db.Timeline, error) { + timelines, err := repo.queries.GetTimelines(ctx) if err != nil { return nil, fmt.Errorf("error occurred while getting timelines from the db: %w", err) } @@ -45,7 +45,7 @@ func (store *TimelineRepoImpl) GetTimelines(ctx context.Context) ([]db.Timeline, return result, nil } -func (store *TimelineRepoImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { +func (repo *TimelineRepoImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { timeline.ID = uuid.NewString() timeline.Created = sql.NullString{ String: time.Now().String(), @@ -60,27 +60,27 @@ func (store *TimelineRepoImpl) CreateTimeline(ctx context.Context, timeline *db. Created: timeline.Created, } - if err := store.queries.CreateTimeline(ctx, params); err != nil { + if err := repo.queries.CreateTimeline(ctx, params); err != nil { return fmt.Errorf("error occurred while creating a timeline: %w", err) } return nil } -func (store *TimelineRepoImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { +func (repo *TimelineRepoImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { params := db.UpdateTimelineParams{ Title: timeline.Title, Date: timeline.Date, Body: timeline.Body, ID: id, } - if err := store.queries.UpdateTimeline(ctx, params); err != nil { + if err := repo.queries.UpdateTimeline(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a timeline: %w", err) } return nil } -func (store *TimelineRepoImpl) DeleteTimeline(ctx context.Context, id string) error { - if err := store.queries.DeleteTimeline(ctx, id); err != nil { +func (repo *TimelineRepoImpl) DeleteTimeline(ctx context.Context, id string) error { + if err := repo.queries.DeleteTimeline(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting the timeline: %w", err) } return nil diff --git a/server/repository/videoStore.go b/server/repository/videoStore.go index a6dfb8e..3201130 100644 --- a/server/repository/videoStore.go +++ b/server/repository/videoStore.go @@ -26,8 +26,8 @@ func NewVideoRepo(sql *sql.DB) *VideoRepoImpl { return &VideoRepoImpl{queries: queries} } -func (store *VideoRepoImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { - videos, err := store.queries.SelectVideos(ctx, id) +func (repo *VideoRepoImpl) GetVideos(ctx context.Context, id string) ([]db.Video, error) { + videos, err := repo.queries.SelectVideos(ctx, id) if err != nil { return nil, fmt.Errorf("error occurred while getting videos from the database: %w", err) } @@ -47,7 +47,7 @@ func (store *VideoRepoImpl) GetVideos(ctx context.Context, id string) ([]db.Vide return result, nil } -func (store *VideoRepoImpl) CreateVideo(ctx context.Context, video *db.Video) error { +func (repo *VideoRepoImpl) CreateVideo(ctx context.Context, video *db.Video) error { video.ID = uuid.NewString() video.Created = sql.NullString{ String: time.Now().String(), @@ -63,13 +63,13 @@ func (store *VideoRepoImpl) CreateVideo(ctx context.Context, video *db.Video) er ThumbnailUrl: video.ThumbnailUrl, Created: video.Created, } - if err := store.queries.CreateVideo(ctx, params); err != nil { + if err := repo.queries.CreateVideo(ctx, params); err != nil { return fmt.Errorf("error occurred while creating a video in the db: %w", err) } return nil } -func (store *VideoRepoImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { +func (repo *VideoRepoImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { params := db.UpdateVideoParams{ SupplierID: video.SupplierID, WebUrl: video.ThumbnailUrl, @@ -79,14 +79,14 @@ func (store *VideoRepoImpl) UpdateVideo(ctx context.Context, id string, video *d ThumbnailUrl: video.ThumbnailUrl, ID: id, } - if err := store.queries.UpdateVideo(ctx, params); err != nil { + if err := repo.queries.UpdateVideo(ctx, params); err != nil { return fmt.Errorf("error occurred while updating a video: %w", err) } return nil } -func (store *VideoRepoImpl) DeleteVideo(ctx context.Context, id string) error { - if err := store.queries.DeleteMachine(ctx, id); err != nil { +func (repo *VideoRepoImpl) DeleteVideo(ctx context.Context, id string) error { + if err := repo.queries.DeleteMachine(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting video: %w", err) } return nil diff --git a/server/repository/warrantyStore.go b/server/repository/warrantyStore.go index 04e2079..6fdc253 100644 --- a/server/repository/warrantyStore.go +++ b/server/repository/warrantyStore.go @@ -29,8 +29,8 @@ func NewWarrantyRepo(sqlDB *sql.DB) *WarrantyRepoImpl { return &WarrantyRepoImpl{queries: queries, db: sqlDB} } -func (store *WarrantyRepoImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { - warranties, err := store.queries.GetWarranties(ctx) +func (repo *WarrantyRepoImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { + warranties, err := repo.queries.GetWarranties(ctx) if err != nil { return nil, fmt.Errorf("an error occurred while getting warranties: %w", err) } @@ -46,8 +46,8 @@ func (store *WarrantyRepoImpl) GetWarranties(ctx context.Context) ([]types.Deale return result, nil } -func (store *WarrantyRepoImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { - rows, err := store.queries.GetWarrantyByID(ctx, id) +func (repo *WarrantyRepoImpl) GetWarrantyById(ctx context.Context, id string) (*db.WarrantyClaim, []db.PartsRequired, error) { + rows, err := repo.queries.GetWarrantyByID(ctx, id) if err != nil { return nil, nil, fmt.Errorf("error occurred while getting warranty from the db: %w", err) } @@ -92,8 +92,8 @@ func (store *WarrantyRepoImpl) GetWarrantyById(ctx context.Context, id string) ( return warranty, parts, nil } -func (store *WarrantyRepoImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { - tx, err := store.db.BeginTx(ctx, nil) +func (repo *WarrantyRepoImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { + tx, err := repo.db.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) } @@ -104,7 +104,7 @@ func (store *WarrantyRepoImpl) CreateWarranty(ctx context.Context, warranty *db. } }(tx) - qtx := store.queries.WithTx(tx) + qtx := repo.queries.WithTx(tx) warranty.ID = uuid.NewString() warranty.Created = sql.NullString{ @@ -153,8 +153,8 @@ func (store *WarrantyRepoImpl) CreateWarranty(ctx context.Context, warranty *db. return nil } -func (store *WarrantyRepoImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { - tx, err := store.db.BeginTx(ctx, nil) +func (repo *WarrantyRepoImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { + tx, err := repo.db.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) } @@ -164,7 +164,7 @@ func (store *WarrantyRepoImpl) UpdateWarranty(ctx context.Context, id string, wa return } }(tx) - qtx := store.queries.WithTx(tx) + qtx := repo.queries.WithTx(tx) params := db.UpdateWarrantyParams{ Dealer: warranty.Dealer, @@ -210,8 +210,8 @@ func (store *WarrantyRepoImpl) UpdateWarranty(ctx context.Context, id string, wa return nil } -func (store *WarrantyRepoImpl) DeleteWarranty(ctx context.Context, id string) error { - tx, err := store.db.BeginTx(ctx, nil) +func (repo *WarrantyRepoImpl) DeleteWarranty(ctx context.Context, id string) error { + tx, err := repo.db.BeginTx(ctx, nil) if err != nil { return fmt.Errorf("failed to begin transaction: %w", err) } @@ -221,7 +221,7 @@ func (store *WarrantyRepoImpl) DeleteWarranty(ctx context.Context, id string) er return } }(tx) - qtx := store.queries.WithTx(tx) + qtx := repo.queries.WithTx(tx) if err = qtx.DeletePartsRequired(ctx, id); err != nil { return fmt.Errorf("error occurred while deleting parts required: %w", err) diff --git a/server/routes/registrationRoutes.go b/server/routes/registrationRoutes.go index 5f8f331..c10b5a3 100644 --- a/server/routes/registrationRoutes.go +++ b/server/routes/registrationRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitRegistrations(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - store := repository.NewRegistrationRepo(database) - service := services.NewRegistrationService(store, smtp) + repo := repository.NewRegistrationRepo(database) + service := services.NewRegistrationService(repo, smtp) handler := handlers.NewRegistrationHandler(service) RegistrationRoutes(router, handler, authMiddleware) diff --git a/server/services/blogService.go b/server/services/blogService.go index 4dc8b95..13a921f 100644 --- a/server/services/blogService.go +++ b/server/services/blogService.go @@ -21,17 +21,17 @@ type BlogService interface { } type BlogServiceImpl struct { - store repository.BlogRepo + repo repository.BlogRepo s3Client lib.S3Client folder string } -func NewBlogService(store repository.BlogRepo, s3Client lib.S3Client, folder string) *BlogServiceImpl { - return &BlogServiceImpl{store: store, s3Client: s3Client, folder: folder} +func NewBlogService(repo repository.BlogRepo, s3Client lib.S3Client, folder string) *BlogServiceImpl { + return &BlogServiceImpl{repo: repo, s3Client: s3Client, folder: folder} } func (service *BlogServiceImpl) GetBlogs(ctx context.Context) ([]types.Blog, error) { - blogs, err := service.store.GetBlogs(ctx) + blogs, err := service.repo.GetBlogs(ctx) if err != nil { return nil, err } @@ -44,7 +44,7 @@ func (service *BlogServiceImpl) GetBlogs(ctx context.Context) ([]types.Blog, err } func (service *BlogServiceImpl) GetBlogsByID(ctx context.Context, id string) (*types.Blog, error) { - blog, err := service.store.GetBlogById(ctx, id) + blog, err := service.repo.GetBlogById(ctx, id) if err != nil { return nil, err } @@ -68,7 +68,7 @@ func (service *BlogServiceImpl) CreateBlog(ctx context.Context, blog *db.Blog) ( blog.MainImage = sql.NullString{String: imageUrl, Valid: true} - if err := service.store.CreateBlog(ctx, blog); err != nil { + if err := service.repo.CreateBlog(ctx, blog); err != nil { return nil, err } @@ -95,7 +95,7 @@ func (service *BlogServiceImpl) UpdateBlog(ctx context.Context, id string, blog blog.MainImage = sql.NullString{String: imageUrl, Valid: true} } - if err := service.store.UpdateBlog(ctx, id, blog); err != nil { + if err := service.repo.UpdateBlog(ctx, id, blog); err != nil { return nil, err } @@ -108,7 +108,7 @@ func (service *BlogServiceImpl) UpdateBlog(ctx context.Context, id string, blog } func (service *BlogServiceImpl) DeleteBlog(ctx context.Context, id string) error { - blog, err := service.store.GetBlogById(ctx, id) + blog, err := service.repo.GetBlogById(ctx, id) if err != nil { return err } @@ -117,7 +117,7 @@ func (service *BlogServiceImpl) DeleteBlog(ctx context.Context, id string) error return err } - if err := service.store.DeleteBlog(ctx, id); err != nil { + if err := service.repo.DeleteBlog(ctx, id); err != nil { return err } diff --git a/server/services/carouselService.go b/server/services/carouselService.go index e7a1efa..0bbb6fd 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -20,21 +20,21 @@ type CarouselService interface { } type CarouselServiceImpl struct { - store repository.CarouselRepo + repo repository.CarouselRepo s3Client lib.S3Client folder string } -func NewCarouselService(store repository.CarouselRepo, s3Client lib.S3Client, folder string) *CarouselServiceImpl { +func NewCarouselService(repo repository.CarouselRepo, s3Client lib.S3Client, folder string) *CarouselServiceImpl { return &CarouselServiceImpl{ - store: store, + repo: repo, s3Client: s3Client, folder: folder, } } func (service *CarouselServiceImpl) GetCarousels(ctx context.Context) ([]types.Carousel, error) { - carousels, err := service.store.GetCarousels(ctx) + carousels, err := service.repo.GetCarousels(ctx) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (service *CarouselServiceImpl) CreateCarousel(ctx context.Context, carousel Valid: true, } - if err := service.store.CreateCarousel(ctx, carousel); err != nil { + if err := service.repo.CreateCarousel(ctx, carousel); err != nil { return nil, err } @@ -93,7 +93,7 @@ func (service *CarouselServiceImpl) UpdateCarousel(ctx context.Context, id strin } } - if err := service.store.UpdateCarousel(ctx, id, carousel); err != nil { + if err := service.repo.UpdateCarousel(ctx, id, carousel); err != nil { return nil, err } @@ -106,7 +106,7 @@ func (service *CarouselServiceImpl) UpdateCarousel(ctx context.Context, id strin } func (service *CarouselServiceImpl) DeleteCarousel(ctx context.Context, id string) error { - carousel, err := service.store.GetCarouselById(ctx, id) + carousel, err := service.repo.GetCarouselById(ctx, id) if err != nil { return err } @@ -115,7 +115,7 @@ func (service *CarouselServiceImpl) DeleteCarousel(ctx context.Context, id strin return err } - if err := service.store.DeleteCarousel(ctx, id); err != nil { + if err := service.repo.DeleteCarousel(ctx, id); err != nil { return err } diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 4095d9d..01b70f3 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -17,11 +17,11 @@ type CheckoutService interface { type CheckoutServiceImpl struct { secrets *lib.Secrets - store repository.LineItemRepo + repo repository.LineItemRepo } -func NewCheckoutService(secrets *lib.Secrets, store repository.LineItemRepo) *CheckoutServiceImpl { - return &CheckoutServiceImpl{secrets: secrets, store: store} +func NewCheckoutService(secrets *lib.Secrets, repo repository.LineItemRepo) *CheckoutServiceImpl { + return &CheckoutServiceImpl{secrets: secrets, repo: repo} } func (service *CheckoutServiceImpl) CreateCheckoutSession(ctx context.Context, id string) (*stripe.CheckoutSession, error) { @@ -29,7 +29,7 @@ func (service *CheckoutServiceImpl) CreateCheckoutSession(ctx context.Context, i log.Printf("Creating checkout session for product ID: %s", id) - product, err := service.store.GetLineItemById(ctx, id) + product, err := service.repo.GetLineItemById(ctx, id) if err != nil { log.Printf("Error retrieving product by ID: %v", err) return nil, err diff --git a/server/services/employeeService.go b/server/services/employeeService.go index 7332451..942fbe1 100644 --- a/server/services/employeeService.go +++ b/server/services/employeeService.go @@ -20,17 +20,17 @@ type EmployeeService interface { } type EmployeeServiceImpl struct { - store repository.EmployeeRepo + repo repository.EmployeeRepo s3Client lib.S3Client folder string } -func NewEmployeeService(store repository.EmployeeRepo, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { - return &EmployeeServiceImpl{store: store, s3Client: s3Client, folder: folder} +func NewEmployeeService(repo repository.EmployeeRepo, s3Client lib.S3Client, folder string) *EmployeeServiceImpl { + return &EmployeeServiceImpl{repo: repo, s3Client: s3Client, folder: folder} } func (service *EmployeeServiceImpl) GetEmployees(ctx context.Context) ([]types.Employee, error) { - employees, err := service.store.GetEmployees(ctx) + employees, err := service.repo.GetEmployees(ctx) if err != nil { return nil, err } @@ -59,7 +59,7 @@ func (service *EmployeeServiceImpl) CreateEmployee(ctx context.Context, employee Valid: true, } - if err := service.store.CreateEmployee(ctx, employee); err != nil { + if err := service.repo.CreateEmployee(ctx, employee); err != nil { return nil, err } @@ -89,7 +89,7 @@ func (service *EmployeeServiceImpl) UpdateEmployee(ctx context.Context, id strin } } - if err := service.store.UpdateEmployee(ctx, id, employee); err != nil { + if err := service.repo.UpdateEmployee(ctx, id, employee); err != nil { return nil, err } @@ -102,7 +102,7 @@ func (service *EmployeeServiceImpl) UpdateEmployee(ctx context.Context, id strin } func (service *EmployeeServiceImpl) DeleteEmployee(ctx context.Context, id string) error { - employee, err := service.store.GetEmployeeById(ctx, id) + employee, err := service.repo.GetEmployeeById(ctx, id) if err != nil { return err } @@ -111,7 +111,7 @@ func (service *EmployeeServiceImpl) DeleteEmployee(ctx context.Context, id strin return err } - if err := service.store.DeleteEmployee(ctx, id); err != nil { + if err := service.repo.DeleteEmployee(ctx, id); err != nil { return err } diff --git a/server/services/exhibitionService.go b/server/services/exhibitionService.go index c387e39..a7cf42f 100644 --- a/server/services/exhibitionService.go +++ b/server/services/exhibitionService.go @@ -16,15 +16,15 @@ type ExhibitionService interface { } type ExhibitionServiceImpl struct { - store repository.ExhibitionRepo + repo repository.ExhibitionRepo } -func NewExhibitionService(store repository.ExhibitionRepo) *ExhibitionServiceImpl { - return &ExhibitionServiceImpl{store: store} +func NewExhibitionService(repo repository.ExhibitionRepo) *ExhibitionServiceImpl { + return &ExhibitionServiceImpl{repo: repo} } func (service *ExhibitionServiceImpl) GetExhibitions(ctx context.Context) ([]types.Exhibition, error) { - exhibitions, err := service.store.GetExhibitions(ctx) + exhibitions, err := service.repo.GetExhibitions(ctx) if err != nil { return nil, err } @@ -36,7 +36,7 @@ func (service *ExhibitionServiceImpl) GetExhibitions(ctx context.Context) ([]typ } func (service *ExhibitionServiceImpl) CreateExhibition(ctx context.Context, exhibition *db.Exhibition) error { - if err := service.store.CreateExhibition(ctx, exhibition); err != nil { + if err := service.repo.CreateExhibition(ctx, exhibition); err != nil { return err } @@ -44,7 +44,7 @@ func (service *ExhibitionServiceImpl) CreateExhibition(ctx context.Context, exhi } func (service *ExhibitionServiceImpl) UpdateExhibition(ctx context.Context, id string, exhibition *db.Exhibition) error { - if err := service.store.UpdateExhibition(ctx, id, exhibition); err != nil { + if err := service.repo.UpdateExhibition(ctx, id, exhibition); err != nil { return err } @@ -52,7 +52,7 @@ func (service *ExhibitionServiceImpl) UpdateExhibition(ctx context.Context, id s } func (service *ExhibitionServiceImpl) DeleteExhibition(ctx context.Context, id string) error { - if err := service.store.DeleteExhibition(ctx, id); err != nil { + if err := service.repo.DeleteExhibition(ctx, id); err != nil { return err } diff --git a/server/services/lineItemService.go b/server/services/lineItemService.go index 6efd369..491365b 100644 --- a/server/services/lineItemService.go +++ b/server/services/lineItemService.go @@ -21,17 +21,17 @@ type LineItemService interface { } type LineItemServiceImpl struct { - store repository.LineItemRepo + repo repository.LineItemRepo s3Client lib.S3Client folder string } -func NewLineItemService(store repository.LineItemRepo, s3Client lib.S3Client, folder string) *LineItemServiceImpl { - return &LineItemServiceImpl{store: store, s3Client: s3Client, folder: folder} +func NewLineItemService(repo repository.LineItemRepo, s3Client lib.S3Client, folder string) *LineItemServiceImpl { + return &LineItemServiceImpl{repo: repo, s3Client: s3Client, folder: folder} } func (service *LineItemServiceImpl) GetLineItems(ctx context.Context) ([]types.LineItem, error) { - lineItems, err := service.store.GetLineItems(ctx) + lineItems, err := service.repo.GetLineItems(ctx) if err != nil { return nil, err } @@ -43,7 +43,7 @@ func (service *LineItemServiceImpl) GetLineItems(ctx context.Context) ([]types.L } func (service *LineItemServiceImpl) GetLineItemById(ctx context.Context, id string) (*types.LineItem, error) { - lineItem, err := service.store.GetLineItemById(ctx, id) + lineItem, err := service.repo.GetLineItemById(ctx, id) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func (service *LineItemServiceImpl) CreateLineItem(ctx context.Context, lineItem Valid: true, } - if err := service.store.CreateLineItem(ctx, lineItem); err != nil { + if err := service.repo.CreateLineItem(ctx, lineItem); err != nil { return nil, err } @@ -99,7 +99,7 @@ func (service *LineItemServiceImpl) UpdateLineItem(ctx context.Context, id strin } } - if err := service.store.UpdateLineItem(ctx, id, lineItem); err != nil { + if err := service.repo.UpdateLineItem(ctx, id, lineItem); err != nil { return nil, err } @@ -112,7 +112,7 @@ func (service *LineItemServiceImpl) UpdateLineItem(ctx context.Context, id strin } func (service *LineItemServiceImpl) DeleteLineItem(ctx context.Context, id string) error { - lineItem, err := service.store.GetLineItemById(ctx, id) + lineItem, err := service.repo.GetLineItemById(ctx, id) if err != nil { return err } @@ -121,7 +121,7 @@ func (service *LineItemServiceImpl) DeleteLineItem(ctx context.Context, id strin return err } - if err := service.store.DeleteLineItem(ctx, id); err != nil { + if err := service.repo.DeleteLineItem(ctx, id); err != nil { return err } diff --git a/server/services/machineService.go b/server/services/machineService.go index 5df0646..19fa401 100644 --- a/server/services/machineService.go +++ b/server/services/machineService.go @@ -23,19 +23,19 @@ type MachineService interface { type MachineServiceImpl struct { folder string s3Client lib.S3Client - store repository.MachineRepo + repo repository.MachineRepo } -func NewMachineService(store repository.MachineRepo, s3Client lib.S3Client, folder string) *MachineServiceImpl { +func NewMachineService(repo repository.MachineRepo, s3Client lib.S3Client, folder string) *MachineServiceImpl { return &MachineServiceImpl{ - store: store, + repo: repo, s3Client: s3Client, folder: folder, } } func (service *MachineServiceImpl) GetMachines(ctx context.Context, id string) ([]types.Machine, error) { - machines, err := service.store.GetMachines(ctx, id) + machines, err := service.repo.GetMachines(ctx, id) if err != nil { return nil, errors.New("machines with supplier_id not foud") } @@ -47,7 +47,7 @@ func (service *MachineServiceImpl) GetMachines(ctx context.Context, id string) ( } func (service *MachineServiceImpl) GetMachineById(ctx context.Context, id string) (*types.Machine, error) { - machine, err := service.store.GetMachineById(ctx, id) + machine, err := service.repo.GetMachineById(ctx, id) if err != nil { return nil, errors.New("machine with id not found") } @@ -73,7 +73,7 @@ func (service *MachineServiceImpl) CreateMachine(ctx context.Context, machine *d Valid: true, } - err = service.store.CreateMachine(ctx, machine) + err = service.repo.CreateMachine(ctx, machine) if err != nil { return nil, err } @@ -104,7 +104,7 @@ func (service *MachineServiceImpl) UpdateMachine(ctx context.Context, id string, } } - err = service.store.UpdateMachine(ctx, id, machine) + err = service.repo.UpdateMachine(ctx, id, machine) if err != nil { return nil, err } @@ -118,7 +118,7 @@ func (service *MachineServiceImpl) UpdateMachine(ctx context.Context, id string, } func (service *MachineServiceImpl) DeleteMachine(ctx context.Context, id string) error { - machine, err := service.store.GetMachineById(ctx, id) + machine, err := service.repo.GetMachineById(ctx, id) if err != nil { return err } @@ -127,7 +127,7 @@ func (service *MachineServiceImpl) DeleteMachine(ctx context.Context, id string) return err } - if err := service.store.DeleteMachine(ctx, id); err != nil { + if err := service.repo.DeleteMachine(ctx, id); err != nil { return err } diff --git a/server/services/partsService.go b/server/services/partsService.go index 4692530..b6165f8 100644 --- a/server/services/partsService.go +++ b/server/services/partsService.go @@ -23,19 +23,19 @@ type PartsService interface { type PartsServiceImpl struct { folder string s3Client lib.S3Client - store repository.PartsRepo + repo repository.PartsRepo } -func NewPartsService(store repository.PartsRepo, s3Client lib.S3Client, folder string) *PartsServiceImpl { +func NewPartsService(repo repository.PartsRepo, s3Client lib.S3Client, folder string) *PartsServiceImpl { return &PartsServiceImpl{ - store: store, + repo: repo, s3Client: s3Client, folder: folder, } } func (service *PartsServiceImpl) GetParts(ctx context.Context, id string) ([]types.Sparepart, error) { - parts, err := service.store.GetParts(ctx, id) + parts, err := service.repo.GetParts(ctx, id) if err != nil { return nil, err } @@ -84,7 +84,7 @@ func (service *PartsServiceImpl) CreatePart(ctx context.Context, part *db.SpareP Valid: true, } - err = service.store.CreatePart(ctx, part) + err = service.repo.CreatePart(ctx, part) if err != nil { log.Printf("Failed to create part: %v", err) return nil, err @@ -139,7 +139,7 @@ func (service *PartsServiceImpl) UpdatePart(ctx context.Context, id string, part Valid: true, } - err = service.store.UpdatePart(ctx, id, part) + err = service.repo.UpdatePart(ctx, id, part) if err != nil { log.Printf("Failed to update part: %v", err) return nil, err @@ -155,7 +155,7 @@ func (service *PartsServiceImpl) UpdatePart(ctx context.Context, id string, part } func (service *PartsServiceImpl) DeletePart(ctx context.Context, id string) error { - part, err := service.store.GetPartById(ctx, id) + part, err := service.repo.GetPartById(ctx, id) if err != nil { return err } @@ -164,7 +164,7 @@ func (service *PartsServiceImpl) DeletePart(ctx context.Context, id string) erro return err } - if err := service.store.DeletePart(ctx, id); err != nil { + if err := service.repo.DeletePart(ctx, id); err != nil { return err } diff --git a/server/services/privacyService.go b/server/services/privacyService.go index c54b3fe..2fc61ee 100644 --- a/server/services/privacyService.go +++ b/server/services/privacyService.go @@ -16,15 +16,15 @@ type PrivacyService interface { } type PrivacyServiceImpl struct { - store repository.PrivacyRepo + repo repository.PrivacyRepo } -func NewPrivacyService(store repository.PrivacyRepo) *PrivacyServiceImpl { - return &PrivacyServiceImpl{store: store} +func NewPrivacyService(repo repository.PrivacyRepo) *PrivacyServiceImpl { + return &PrivacyServiceImpl{repo: repo} } func (service *PrivacyServiceImpl) GetPrivacys(ctx context.Context) ([]types.Privacy, error) { - privacys, err := service.store.GetPrivacy(ctx) + privacys, err := service.repo.GetPrivacy(ctx) if err != nil { return nil, err } @@ -36,7 +36,7 @@ func (service *PrivacyServiceImpl) GetPrivacys(ctx context.Context) ([]types.Pri } func (service *PrivacyServiceImpl) CreatePrivacy(ctx context.Context, privacy *db.Privacy) error { - if err := service.store.CreatePrivacy(ctx, privacy); err != nil { + if err := service.repo.CreatePrivacy(ctx, privacy); err != nil { return err } @@ -44,7 +44,7 @@ func (service *PrivacyServiceImpl) CreatePrivacy(ctx context.Context, privacy *d } func (service *PrivacyServiceImpl) UpdatePrivacy(ctx context.Context, id string, privacy *db.Privacy) error { - if err := service.store.UpdatePrivacy(ctx, id, privacy); err != nil { + if err := service.repo.UpdatePrivacy(ctx, id, privacy); err != nil { return err } @@ -52,7 +52,7 @@ func (service *PrivacyServiceImpl) UpdatePrivacy(ctx context.Context, id string, } func (service *PrivacyServiceImpl) DeletePrivacy(ctx context.Context, id string) error { - if err := service.store.DeletePrivacy(ctx, id); err != nil { + if err := service.repo.DeletePrivacy(ctx, id); err != nil { return err } diff --git a/server/services/productService.go b/server/services/productService.go index a43d1a4..d12b9a5 100644 --- a/server/services/productService.go +++ b/server/services/productService.go @@ -22,19 +22,19 @@ type ProductService interface { type ProductServiceImpl struct { folder string s3Client lib.S3Client - store repository.ProductRepo + repo repository.ProductRepo } -func NewProductService(store repository.ProductRepo, s3Client lib.S3Client, folder string) *ProductServiceImpl { +func NewProductService(repo repository.ProductRepo, s3Client lib.S3Client, folder string) *ProductServiceImpl { return &ProductServiceImpl{ - store: store, + repo: repo, s3Client: s3Client, folder: folder, } } func (service *ProductServiceImpl) GetProducts(ctx context.Context, id string) ([]types.Product, error) { - products, err := service.store.GetProducts(ctx, id) + products, err := service.repo.GetProducts(ctx, id) if err != nil { return nil, err } @@ -62,7 +62,7 @@ func (service *ProductServiceImpl) CreateProduct(ctx context.Context, product *d Valid: true, } - err = service.store.CreateProduct(ctx, product) + err = service.repo.CreateProduct(ctx, product) if err != nil { return nil, err } @@ -93,7 +93,7 @@ func (service *ProductServiceImpl) UpdateProduct(ctx context.Context, id string, } } - err = service.store.UpdateProduct(ctx, id, product) + err = service.repo.UpdateProduct(ctx, id, product) if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (service *ProductServiceImpl) UpdateProduct(ctx context.Context, id string, } func (service *ProductServiceImpl) DeleteProduct(ctx context.Context, id string) error { - product, err := service.store.GetProductById(ctx, id) + product, err := service.repo.GetProductById(ctx, id) if err != nil { return nil } @@ -116,7 +116,7 @@ func (service *ProductServiceImpl) DeleteProduct(ctx context.Context, id string) return err } - if err := service.store.DeleteProduct(ctx, id); err != nil { + if err := service.repo.DeleteProduct(ctx, id); err != nil { return err } diff --git a/server/services/registrationService.go b/server/services/registrationService.go index aba3fc9..32a4351 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -19,15 +19,15 @@ type RegistrationService interface { type RegistrationServiceImpl struct { smtpClient lib.SMTPClient - store repository.RegistrationRepo + repo repository.RegistrationRepo } -func NewRegistrationService(store repository.RegistrationRepo, smtpClient lib.SMTPClient) *RegistrationServiceImpl { - return &RegistrationServiceImpl{store: store, smtpClient: smtpClient} +func NewRegistrationService(repo repository.RegistrationRepo, smtpClient lib.SMTPClient) *RegistrationServiceImpl { + return &RegistrationServiceImpl{repo: repo, smtpClient: smtpClient} } func (service *RegistrationServiceImpl) GetRegistrations(ctx context.Context) ([]types.MachineRegistration, error) { - registrations, err := service.store.GetRegistrations(ctx) + registrations, err := service.repo.GetRegistrations(ctx) if err != nil { return nil, err } @@ -39,7 +39,7 @@ func (service *RegistrationServiceImpl) GetRegistrations(ctx context.Context) ([ } func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, id string) (*types.MachineRegistration, error) { - registration, err := service.store.GetRegistrationById(ctx, id) + registration, err := service.repo.GetRegistrationById(ctx, id) if err != nil { return nil, err } @@ -48,7 +48,7 @@ func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, } func (service *RegistrationServiceImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { - if err := service.store.CreateRegistration(ctx, registration); err != nil { + if err := service.repo.CreateRegistration(ctx, registration); err != nil { return err } @@ -77,7 +77,7 @@ func (service *RegistrationServiceImpl) CreateRegistration(ctx context.Context, } func (service *RegistrationServiceImpl) UpdateRegistration(ctx context.Context, id string, registration *db.MachineRegistration) error { - if err := service.store.UpdateRegistration(ctx, id, registration); err != nil { + if err := service.repo.UpdateRegistration(ctx, id, registration); err != nil { return err } @@ -106,7 +106,7 @@ func (service *RegistrationServiceImpl) UpdateRegistration(ctx context.Context, } func (service *RegistrationServiceImpl) DeleteRegistration(ctx context.Context, id string) error { - if err := service.store.DeleteRegistration(ctx, id); err != nil { + if err := service.repo.DeleteRegistration(ctx, id); err != nil { return err } diff --git a/server/services/supplierService.go b/server/services/supplierService.go index c060de9..4e2795f 100644 --- a/server/services/supplierService.go +++ b/server/services/supplierService.go @@ -23,19 +23,19 @@ type SupplierService interface { type SupplierServiceImpl struct { folder string s3Client lib.S3Client - store repository.SupplierRepo + repo repository.SupplierRepo } -func NewSupplierService(store repository.SupplierRepo, s3Client lib.S3Client, folder string) *SupplierServiceImpl { +func NewSupplierService(repo repository.SupplierRepo, s3Client lib.S3Client, folder string) *SupplierServiceImpl { return &SupplierServiceImpl{ - store: store, + repo: repo, s3Client: s3Client, folder: folder, } } func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]types.Supplier, error) { - suppliers, err := service.store.GetSuppliers(ctx) + suppliers, err := service.repo.GetSuppliers(ctx) if err != nil { return nil, err } @@ -48,7 +48,7 @@ func (service *SupplierServiceImpl) GetSuppliers(ctx context.Context) ([]types.S } func (service *SupplierServiceImpl) GetSupplierById(ctx context.Context, id string) (*types.Supplier, error) { - supplier, err := service.store.GetSupplierById(ctx, id) + supplier, err := service.repo.GetSupplierById(ctx, id) if err != nil { return nil, err } @@ -85,7 +85,7 @@ func (service *SupplierServiceImpl) CreateSupplier(ctx context.Context, supplier Valid: true, } - err = service.store.CreateSupplier(ctx, &supplier) + err = service.repo.CreateSupplier(ctx, &supplier) if err != nil { return nil, err } @@ -129,7 +129,7 @@ func (service *SupplierServiceImpl) UpdateSupplier(ctx context.Context, id strin } } - err = service.store.UpdateSupplier(ctx, id, supplier) + err = service.repo.UpdateSupplier(ctx, id, supplier) if err != nil { return nil, err } @@ -145,7 +145,7 @@ func (service *SupplierServiceImpl) UpdateSupplier(ctx context.Context, id strin } func (service *SupplierServiceImpl) DeleteSupplier(ctx context.Context, id string) error { - supplier, err := service.store.GetSupplierById(ctx, id) + supplier, err := service.repo.GetSupplierById(ctx, id) if err != nil { return err } @@ -158,7 +158,7 @@ func (service *SupplierServiceImpl) DeleteSupplier(ctx context.Context, id strin return err } - if err := service.store.DeleteSupplier(ctx, id); err != nil { + if err := service.repo.DeleteSupplier(ctx, id); err != nil { return err } diff --git a/server/services/termsService.go b/server/services/termsService.go index 9824adf..c7ef3bb 100644 --- a/server/services/termsService.go +++ b/server/services/termsService.go @@ -16,15 +16,15 @@ type TermsService interface { } type TermsServiceImpl struct { - store repository.TermsRepo + repo repository.TermsRepo } -func NewTermsService(store repository.TermsRepo) *TermsServiceImpl { - return &TermsServiceImpl{store: store} +func NewTermsService(repo repository.TermsRepo) *TermsServiceImpl { + return &TermsServiceImpl{repo: repo} } func (service *TermsServiceImpl) GetTerms(ctx context.Context) ([]types.Terms, error) { - terms, err := service.store.GetTerms(ctx) + terms, err := service.repo.GetTerms(ctx) if err != nil { return nil, err } @@ -36,21 +36,21 @@ func (service *TermsServiceImpl) GetTerms(ctx context.Context) ([]types.Terms, e } func (service *TermsServiceImpl) CreateTerm(ctx context.Context, term *db.Term) error { - if err := service.store.CreateTerm(ctx, term); err != nil { + if err := service.repo.CreateTerm(ctx, term); err != nil { return err } return nil } func (service *TermsServiceImpl) UpdateTerm(ctx context.Context, id string, term *db.Term) error { - if err := service.store.UpdateTerm(ctx, id, term); err != nil { + if err := service.repo.UpdateTerm(ctx, id, term); err != nil { return err } return nil } func (service *TermsServiceImpl) DeleteTerm(ctx context.Context, id string) error { - if err := service.store.DeleteTerm(ctx, id); err != nil { + if err := service.repo.DeleteTerm(ctx, id); err != nil { return err } return nil diff --git a/server/services/timelineService.go b/server/services/timelineService.go index 54a0084..de3c9cf 100644 --- a/server/services/timelineService.go +++ b/server/services/timelineService.go @@ -16,15 +16,15 @@ type TimelineService interface { } type TimelineServiceImpl struct { - store repository.TimelineRepo + repo repository.TimelineRepo } -func NewTimelineService(store repository.TimelineRepo) *TimelineServiceImpl { - return &TimelineServiceImpl{store: store} +func NewTimelineService(repo repository.TimelineRepo) *TimelineServiceImpl { + return &TimelineServiceImpl{repo: repo} } func (service *TimelineServiceImpl) GetTimelines(ctx context.Context) ([]types.Timeline, error) { - timelines, err := service.store.GetTimelines(ctx) + timelines, err := service.repo.GetTimelines(ctx) if err != nil { return nil, err } @@ -36,21 +36,21 @@ func (service *TimelineServiceImpl) GetTimelines(ctx context.Context) ([]types.T } func (service *TimelineServiceImpl) CreateTimeline(ctx context.Context, timeline *db.Timeline) error { - if err := service.store.CreateTimeline(ctx, timeline); err != nil { + if err := service.repo.CreateTimeline(ctx, timeline); err != nil { return err } return nil } func (service *TimelineServiceImpl) UpdateTimeline(ctx context.Context, id string, timeline *db.Timeline) error { - if err := service.store.UpdateTimeline(ctx, id, timeline); err != nil { + if err := service.repo.UpdateTimeline(ctx, id, timeline); err != nil { return err } return nil } func (service *TimelineServiceImpl) DeleteTimeline(ctx context.Context, id string) error { - if err := service.store.DeleteTimeline(ctx, id); err != nil { + if err := service.repo.DeleteTimeline(ctx, id); err != nil { return err } return nil diff --git a/server/services/videoService.go b/server/services/videoService.go index 6cf6e19..5dfe34d 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -22,13 +22,13 @@ type VideoService interface { } type VideoServiceImpl struct { - store repository.VideoRepo + repo repository.VideoRepo youtubeService *youtube.Service } -func NewVideoService(store repository.VideoRepo, youtubeService *youtube.Service) *VideoServiceImpl { +func NewVideoService(repo repository.VideoRepo, youtubeService *youtube.Service) *VideoServiceImpl { return &VideoServiceImpl{ - store: store, + repo: repo, youtubeService: youtubeService, } } @@ -84,7 +84,7 @@ func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, erro } func (service *VideoServiceImpl) GetVideos(ctx context.Context, id string) ([]types.Video, error) { - videos, err := service.store.GetVideos(ctx, id) + videos, err := service.repo.GetVideos(ctx, id) if err != nil { return nil, err } @@ -101,7 +101,7 @@ func (service *VideoServiceImpl) CreateVideo(ctx context.Context, video *db.Vide return err } - err = service.store.CreateVideo(ctx, videoData) + err = service.repo.CreateVideo(ctx, videoData) if err != nil { return err } @@ -115,7 +115,7 @@ func (service *VideoServiceImpl) UpdateVideo(ctx context.Context, id string, vid return err } - err = service.store.UpdateVideo(ctx, id, videoData) + err = service.repo.UpdateVideo(ctx, id, videoData) if err != nil { return err } @@ -124,7 +124,7 @@ func (service *VideoServiceImpl) UpdateVideo(ctx context.Context, id string, vid } func (service *VideoServiceImpl) DeleteVideo(ctx context.Context, id string) error { - err := service.store.DeleteVideo(ctx, id) + err := service.repo.DeleteVideo(ctx, id) if err != nil { return err } diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index 8454f31..d260bd4 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -19,15 +19,15 @@ type WarrantyService interface { type WarrantyServiceImpl struct { smtpClient lib.SMTPClient - store repository.WarrantyRepo + repo repository.WarrantyRepo } -func NewWarrantyService(store repository.WarrantyRepo, smtpClient lib.SMTPClient) *WarrantyServiceImpl { - return &WarrantyServiceImpl{store: store, smtpClient: smtpClient} +func NewWarrantyService(repo repository.WarrantyRepo, smtpClient lib.SMTPClient) *WarrantyServiceImpl { + return &WarrantyServiceImpl{repo: repo, smtpClient: smtpClient} } func (service *WarrantyServiceImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { - warranties, err := service.store.GetWarranties(ctx) + warranties, err := service.repo.GetWarranties(ctx) if err != nil { return nil, err } @@ -36,7 +36,7 @@ func (service *WarrantyServiceImpl) GetWarranties(ctx context.Context) ([]types. } func (service *WarrantyServiceImpl) GetWarrantyById(ctx context.Context, id string) (*types.WarrantyClaim, []types.PartsRequired, error) { - warranty, partsRequired, err := service.store.GetWarrantyById(ctx, id) + warranty, partsRequired, err := service.repo.GetWarrantyById(ctx, id) if err != nil { return nil, nil, err } @@ -49,7 +49,7 @@ func (service *WarrantyServiceImpl) GetWarrantyById(ctx context.Context, id stri } func (service *WarrantyServiceImpl) CreateWarranty(ctx context.Context, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { - if err := service.store.CreateWarranty(ctx, warranty, parts); err != nil { + if err := service.repo.CreateWarranty(ctx, warranty, parts); err != nil { return err } @@ -78,7 +78,7 @@ func (service *WarrantyServiceImpl) CreateWarranty(ctx context.Context, warranty } func (service *WarrantyServiceImpl) UpdateWarranty(ctx context.Context, id string, warranty *db.WarrantyClaim, parts []db.PartsRequired) error { - if err := service.store.UpdateWarranty(ctx, id, warranty, parts); err != nil { + if err := service.repo.UpdateWarranty(ctx, id, warranty, parts); err != nil { return err } @@ -107,7 +107,7 @@ func (service *WarrantyServiceImpl) UpdateWarranty(ctx context.Context, id strin } func (service *WarrantyServiceImpl) DeleteWarranty(ctx context.Context, id string) error { - if err := service.store.DeleteWarranty(ctx, id); err != nil { + if err := service.repo.DeleteWarranty(ctx, id); err != nil { return err } diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index ac9f546..bf4e1e1 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -56,9 +56,9 @@ func (suite *BlogTestSuite) SetupTest() { suite.db = database suite.mock = mock - store := repository.NewBlogRepo(database) + repo := repository.NewBlogRepo(database) s3Client := lib.NewNoOpS3Client() - service := services.NewBlogService(store, s3Client, "test-folder") + service := services.NewBlogService(repo, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) suite.router = gin.Default() From a86c09b2170baedd71eb9232207f3fbf78c094d8 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:14:45 +0100 Subject: [PATCH 219/248] fixed for context --- server/go.mod | 22 +++++++------- server/go.sum | 47 +++++++++++++++--------------- server/services/carouselService.go | 2 +- server/services/checkoutService.go | 2 +- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/server/go.mod b/server/go.mod index 17698d6..84a2d41 100644 --- a/server/go.mod +++ b/server/go.mod @@ -5,11 +5,11 @@ go 1.22.0 require ( firebase.google.com/go v3.13.0+incompatible github.com/DATA-DOG/go-sqlmock v1.5.2 - github.com/aws/aws-sdk-go-v2 v1.25.1 + github.com/aws/aws-sdk-go-v2 v1.32.2 github.com/aws/aws-sdk-go-v2/config v1.27.3 github.com/aws/aws-sdk-go-v2/credentials v1.17.3 - github.com/aws/aws-sdk-go-v2/service/s3 v1.51.0 - github.com/aws/smithy-go v1.20.1 + github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 + github.com/aws/smithy-go v1.22.0 github.com/gin-contrib/cors v1.5.0 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.6.0 @@ -29,16 +29,16 @@ require ( cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/longrunning v0.5.5 // indirect cloud.google.com/go/storage v1.38.0 // indirect - github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.1 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect - github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.1 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.1 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.1 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.1 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.20.0 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.28.0 // indirect diff --git a/server/go.sum b/server/go.sum index 561227a..491097a 100644 --- a/server/go.sum +++ b/server/go.sum @@ -5,8 +5,7 @@ cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1Yl cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= -cloud.google.com/go/firerepo v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw= -cloud.google.com/go/firerepo v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= +cloud.google.com/go/firestore v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw= cloud.google.com/go/firestore v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= cloud.google.com/go/iam v1.1.6 h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc= cloud.google.com/go/iam v1.1.6/go.mod h1:O0zxdPeGBoFdWW3HWmBxJsk0pfvNM/p/qa82rWOGTwI= @@ -19,42 +18,42 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= -github.com/aws/aws-sdk-go-v2 v1.25.1 h1:P7hU6A5qEdmajGwvae/zDkOq+ULLC9tQBTwqqiwFGpI= -github.com/aws/aws-sdk-go-v2 v1.25.1/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1/go.mod h1:sxpLb+nZk7tIfCWChfd+h4QwHNUR57d8hA1cleTkjJo= +github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= +github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA= github.com/aws/aws-sdk-go-v2/config v1.27.3 h1:0PRdb/q5a77HVYj+2rvPiCObfMfl/pWhwa5cs3cnl3c= github.com/aws/aws-sdk-go-v2/config v1.27.3/go.mod h1:WeRAr9ENap9NAegbfNsLqGQd8ERz5ypdIUx4j0/ZgKI= github.com/aws/aws-sdk-go-v2/credentials v1.17.3 h1:dDM5wrgwOL5gTZ0Gv/bvewPldjBcJywoaO5ClERrOGE= github.com/aws/aws-sdk-go-v2/credentials v1.17.3/go.mod h1:G96Nuaw9qJS+s3OnK8RW8VEKEOjXi8H5Jk4lC/ZyZbw= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 h1:lk1ZZFbdb24qpOwVC1AwYNrswUjAxeyey6kFBVANudQ= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1/go.mod h1:/xJ6x1NehNGCX4tvGzzj2bq5TBOT/Yxq+qbL9Jpx2Vk= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1 h1:evvi7FbTAoFxdP/mixmP7LIYzQWAmzBcwNB/es9XPNc= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.1/go.mod h1:rH61DT6FDdikhPghymripNUCsf+uVF4Cnk4c4DBKH64= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.1 h1:RAnaIrbxPtlXNVI/OIlh1sidTQ3e1qM6LRjs7N0bE0I= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.1/go.mod h1:nbgAGkH5lk0RZRMh6A4K/oG6Xj11eC/1CyDow+DUAFI= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.1 h1:rtYJd3w6IWCTVS8vmMaiXjW198noh2PBm5CiXyJea9o= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.1/go.mod h1:zvXu+CTlib30LUy4LTNFc6HTZ/K6zCae5YIHTdX9wIo= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.1 h1:5Wxh862HkXL9CbQ83BIkWKLIgQapGeuh5zG2G9OZtQk= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.1/go.mod h1:V7GLA01pNUxMCYSQsibdVrqUrNIYIT/9lCOyR8ExNvQ= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.1 h1:cVP8mng1RjDyI3JN/AXFCn5FHNlsBaBH0/MBtG1bg0o= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.1/go.mod h1:C8sQjoyAsdfjC7hpy4+S6B92hnFzx0d0UAyHicaOTIE= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.1 h1:OYmmIcyw19f7x0qLBLQ3XsrCZSSyLhxd9GXng5evsN4= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.1/go.mod h1:s5rqdn74Vdg10k61Pwf4ZHEApOSD6CKRe6qpeHDq32I= -github.com/aws/aws-sdk-go-v2/service/s3 v1.51.0 h1:rNVsCe3bqTAhG+qjnHJKgYKdHEsqqo/GMK3gEYY8W6g= -github.com/aws/aws-sdk-go-v2/service/s3 v1.51.0/go.mod h1:lTW7O4iMAnO2o7H3XJTvqaWFZCH6zIPs+eP7RdG/yp0= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 h1:7edmS3VOBDhK00b/MwGtGglCm7hhwNYnjJs/PgFdMQE= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21/go.mod h1:Q9o5h4HoIWG8XfzxqiuK/CGUbepCJ8uTlaE3bAbxytQ= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 h1:4FMHqLfk0efmTqhXVRL5xYRqlEBNBiRI7N6w4jsEdd4= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2/go.mod h1:LWoqeWlK9OZeJxsROW2RqrSPvQHKTpp69r/iDjwsSaw= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 h1:s7NA1SOw8q/5c0wr8477yOPp0z+uBaXBnLE0XYb0POA= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2/go.mod h1:fnjjWyAW/Pj5HYOxl9LJqWtEwS7W2qgcRLWP+uWbss0= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 h1:t7iUP9+4wdc5lt3E41huP+GvQZJD38WLsgVp4iOtAjg= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2/go.mod h1:/niFCtmuQNxqx9v8WAPq5qh7EH25U4BF6tjoyq9bObM= +github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 h1:xA6XhTF7PE89BCNHJbQi8VvPzcgMtmGC5dr8S8N7lHk= +github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0/go.mod h1:cB6oAuus7YXRZhWCc1wIwPywwZ1XwweNp2TVAEGYeB8= github.com/aws/aws-sdk-go-v2/service/sso v1.20.0 h1:6YL8G91QZ52KlPrLkEgEez5kejIVwChVCgND3qgY5j0= github.com/aws/aws-sdk-go-v2/service/sso v1.20.0/go.mod h1:x6/tCd1o/AOKQR+iYnjrzhJxD+w0xRN34asGPaSV7ew= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0 h1:+DqIa5Ll7W311QLUvGFDdVit9uC4G0VioDdw08cXcow= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0/go.mod h1:lZB123q0SVQ3dfIbEOcGzhQHrwVBcHVReNS9tm20oU4= github.com/aws/aws-sdk-go-v2/service/sts v1.28.0 h1:F7tQr61zYnTaeY50Rn4jwfVQbtcqJuBRwN/nGGNwzb0= github.com/aws/aws-sdk-go-v2/service/sts v1.28.0/go.mod h1:ozhhG9/NB5c9jcmhGq6tX9dpp21LYdmRWRQVppASim4= -github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw= -github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= +github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.11.0 h1:FwNNv6Vu4z2Onf1++LNzxB/QhitD8wuTdpZzMTGITWo= diff --git a/server/services/carouselService.go b/server/services/carouselService.go index 0bbb6fd..c6b2e85 100644 --- a/server/services/carouselService.go +++ b/server/services/carouselService.go @@ -1,11 +1,11 @@ package services import ( + "context" "database/sql" "errors" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/types" - "golang.org/x/net/context" "log" "github.com/sean-david-welch/farmec-v2/server/db" diff --git a/server/services/checkoutService.go b/server/services/checkoutService.go index 01b70f3..857bad8 100644 --- a/server/services/checkoutService.go +++ b/server/services/checkoutService.go @@ -1,8 +1,8 @@ package services import ( + "context" "github.com/sean-david-welch/farmec-v2/server/lib" - "golang.org/x/net/context" "log" "github.com/sean-david-welch/farmec-v2/server/repository" From feecbd64979c495e77a0c4317321c62b8bd73292 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:17:28 +0100 Subject: [PATCH 220/248] go mods --- server/go.mod | 85 +++++++++++++++++++-------------------- server/go.sum | 107 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 124 insertions(+), 68 deletions(-) diff --git a/server/go.mod b/server/go.mod index 84a2d41..f7f06c3 100644 --- a/server/go.mod +++ b/server/go.mod @@ -10,25 +10,25 @@ require ( github.com/aws/aws-sdk-go-v2/credentials v1.17.3 github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 github.com/aws/smithy-go v1.22.0 - github.com/gin-contrib/cors v1.5.0 - github.com/gin-gonic/gin v1.9.1 + github.com/gin-contrib/cors v1.7.2 + github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 - github.com/mattn/go-sqlite3 v1.14.22 - github.com/signintech/gopdf v0.22.0 - github.com/stretchr/testify v1.8.4 - github.com/stripe/stripe-go/v76 v76.18.0 - google.golang.org/api v0.166.0 + github.com/mattn/go-sqlite3 v1.14.24 + github.com/signintech/gopdf v0.28.0 + github.com/stretchr/testify v1.9.0 + github.com/stripe/stripe-go/v76 v76.25.0 + google.golang.org/api v0.201.0 ) require ( - cloud.google.com/go v0.112.0 // indirect - cloud.google.com/go/compute v1.24.0 // indirect - cloud.google.com/go/compute/metadata v0.2.3 // indirect - cloud.google.com/go/firestore v1.14.0 // indirect - cloud.google.com/go/iam v1.1.6 // indirect - cloud.google.com/go/longrunning v0.5.5 // indirect - cloud.google.com/go/storage v1.38.0 // indirect + cloud.google.com/go v0.116.0 // indirect + cloud.google.com/go/compute v1.28.1 // indirect + cloud.google.com/go/compute/metadata v0.5.2 // indirect + cloud.google.com/go/firestore v1.17.0 // indirect + cloud.google.com/go/iam v1.2.1 // indirect + cloud.google.com/go/longrunning v0.6.1 // indirect + cloud.google.com/go/storage v1.43.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect @@ -42,24 +42,25 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.20.0 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.28.0 // indirect - github.com/bytedance/sonic v1.11.0 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect - github.com/chenzhuoyu/iasm v0.9.1 // indirect + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.18.0 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.3 // indirect - github.com/google/s2a-go v0.1.7 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect - github.com/googleapis/gax-go/v2 v2.12.1 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/s2a-go v0.1.8 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect + github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/kr/text v0.2.0 // indirect @@ -67,31 +68,31 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.1.1 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect - go.opentelemetry.io/otel v1.23.1 // indirect - go.opentelemetry.io/otel/metric v1.23.1 // indirect - go.opentelemetry.io/otel/trace v1.23.1 // indirect - golang.org/x/arch v0.7.0 // indirect - golang.org/x/crypto v0.19.0 // indirect - golang.org/x/net v0.21.0 // indirect - golang.org/x/oauth2 v0.17.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.5.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect + go.opentelemetry.io/otel v1.29.0 // indirect + go.opentelemetry.io/otel/metric v1.29.0 // indirect + go.opentelemetry.io/otel/trace v1.29.0 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect + golang.org/x/time v0.7.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect - google.golang.org/grpc v1.62.0 // indirect - google.golang.org/protobuf v1.32.0 // indirect + google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/grpc v1.67.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/go.sum b/server/go.sum index 491097a..7ec0eed 100644 --- a/server/go.sum +++ b/server/go.sum @@ -1,18 +1,26 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM= cloud.google.com/go v0.112.0/go.mod h1:3jEEVwZ/MHU4djK5t5RHuKOA/GbLddgTdVubX1qnPD4= +cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE= +cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U= cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1YlVg= cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40= +cloud.google.com/go/compute v1.28.1/go.mod h1:b72iXMY4FucVry3NR3Li4kVyyTvbMDE7x5WsqvxjsYk= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= cloud.google.com/go/firestore v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw= cloud.google.com/go/firestore v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= +cloud.google.com/go/firestore v1.17.0/go.mod h1:69uPx1papBsY8ZETooc71fOhoKkD70Q1DwMrtKuOT/Y= cloud.google.com/go/iam v1.1.6 h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc= cloud.google.com/go/iam v1.1.6/go.mod h1:O0zxdPeGBoFdWW3HWmBxJsk0pfvNM/p/qa82rWOGTwI= +cloud.google.com/go/iam v1.2.1/go.mod h1:3VUIJDPpwT6p/amXRC5GY8fCCh70lxPygguVtI0Z4/g= cloud.google.com/go/longrunning v0.5.5 h1:GOE6pZFdSrTb4KAiKnXsJBtlE6mEyaW44oKyMILWnOg= cloud.google.com/go/longrunning v0.5.5/go.mod h1:WV2LAxD8/rg5Z1cNW6FJ/ZpX4E4VnDnoTk0yawPBB7s= +cloud.google.com/go/longrunning v0.6.1/go.mod h1:nHISoOZpBcmlwbJmiVk5oDRz0qG/ZxPynEGs1iZ79s0= cloud.google.com/go/storage v1.38.0 h1:Az68ZRGlnNTpIBbLjSMIV2BDcwwXYlRlQzis0llkpJg= cloud.google.com/go/storage v1.38.0/go.mod h1:tlUADB0mAb9BgYls9lq+8MGkfzOXuLrnHXlpHmvFJoY= +cloud.google.com/go/storage v1.43.0/go.mod h1:ajvxEa7WmZS1PxvKRq4bq0tFT3vMd502JwstCcYv0Q0= firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -54,19 +62,16 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.28.0 h1:F7tQr61zYnTaeY50Rn4jwfVQbtcq github.com/aws/aws-sdk-go-v2/service/sts v1.28.0/go.mod h1:ozhhG9/NB5c9jcmhGq6tX9dpp21LYdmRWRQVppASim4= github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= -github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.11.0 h1:FwNNv6Vu4z2Onf1++LNzxB/QhitD8wuTdpZzMTGITWo= -github.com/bytedance/sonic v1.11.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= -github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= -github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= -github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ= github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= @@ -84,15 +89,18 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/gin-contrib/cors v1.5.0 h1:DgGKV7DDoOn36DFkNtbHrjoRiT5ExCe+PC9/xp7aKvk= -github.com/gin-contrib/cors v1.5.0/go.mod h1:TvU7MAZ3EwrPLI2ztzTt3tqgvBCq+wn8WpZmfADjupI= +github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw= +github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= @@ -101,8 +109,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U= -github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -123,6 +131,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -137,13 +146,16 @@ github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdf github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= +github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= github.com/googleapis/gax-go/v2 v2.12.1 h1:9F8GV9r9ztXyAi00gsMQHNoF51xPZm8uj1dpYt2ZETM= github.com/googleapis/gax-go/v2 v2.12.1/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= +github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -163,13 +175,17 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= +github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= -github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= +github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no= github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -182,18 +198,24 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/signintech/gopdf v0.22.0 h1:RyLMuDy6Ep0bGEfzePEKYuQ4jOcc5inn3WbU1egf8YA= github.com/signintech/gopdf v0.22.0/go.mod h1:wrLtZoWaRNrS4hphED0oflFoa6IWkOu6M3nJjm4VbO4= +github.com/signintech/gopdf v0.28.0 h1:zCUlRuedALiKaZmEdLSoA4EPqjpnzLBP6co8fjA6C7Q= +github.com/signintech/gopdf v0.28.0/go.mod h1:d23eO35GpEliSrF22eJ4bsM3wVeQJTjXTHq5x5qGKjA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stripe/stripe-go/v76 v76.18.0 h1:MYUgecXPoUDJ36hjKtc8h2fzpj0MpRBrN9KGCULFTbg= github.com/stripe/stripe-go/v76 v76.18.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4= +github.com/stripe/stripe-go/v76 v76.25.0 h1:kmDoOTvdQSTQssQzWZQQkgbAR2Q8eXdMWbN/ylNalWA= +github.com/stripe/stripe-go/v76 v76.25.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= @@ -203,24 +225,34 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 h1:P+/g8GpuJGYbOp2tAdKrIPUX9JO02q8Q0YNlHolpibA= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0/go.mod h1:tIKj3DbO8N9Y2xo52og3irLsPI4GW02DSMtrVgNMgxg= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 h1:doUP+ExOpH3spVTLS0FcWGLnQrPct/hD/bCPbDRUEAU= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0/go.mod h1:rdENBZMT2OE6Ne/KLwpiXudnAsbdrdBaqBvTN8M8BgA= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= go.opentelemetry.io/otel v1.23.1 h1:Za4UzOqJYS+MUczKI320AtqZHZb7EqxO00jAHE0jmQY= go.opentelemetry.io/otel v1.23.1/go.mod h1:Td0134eafDLcTS4y+zQ26GE8u3dEuRBiBCTUIRHaikA= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= go.opentelemetry.io/otel/metric v1.23.1 h1:PQJmqJ9u2QaJLBOELl1cxIdPcpbwzbkjfEyelTl2rlo= go.opentelemetry.io/otel/metric v1.23.1/go.mod h1:mpG2QPlAfnK8yNhNJAxDZruU9Y1/HubbC+KyH8FaCWI= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= go.opentelemetry.io/otel/trace v1.23.1 h1:4LrmmEd8AU2rFvU1zegmvqW7+kWarxtNOPyeL6HmYY8= go.opentelemetry.io/otel/trace v1.23.1/go.mod h1:4IpnpJFwr1mo/6HL8XIPJaE9y0+u1KcVmuW7dwFSVrI= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -236,17 +268,22 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ= golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -258,8 +295,11 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -269,8 +309,12 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -284,6 +328,8 @@ golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSm golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/api v0.166.0 h1:6m4NUwrZYhAaVIHZWxaKjw1L1vNAjtMwORmKRyEEo24= google.golang.org/api v0.166.0/go.mod h1:4FcBc686KFi7QI/U51/2GKKevfZMpM17sCdibqe/bSA= +google.golang.org/api v0.201.0 h1:+7AD9JNM3tREtawRMu8sOjSbb8VYcYXJG/2eEOmfDu0= +google.golang.org/api v0.201.0/go.mod h1:HVY0FCHVs89xIW9fzf/pBvOEm+OolHa86G/txFezyq4= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= @@ -293,10 +339,14 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c h1:Zmyn5CV/jxzKnF+3d+xzbomACPwLQqVpLTpyXN5uTaQ= google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= +google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 h1:nFS3IivktIU5Mk6KQa+v6RKkHUpdQpphqGNLxqNnbEk= +google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:tEzYTYZxbmVNOu0OAFH9HzdJtLn6h4Aj89zzlBCdHms= google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c h1:9g7erC9qu44ks7UK4gDNlnk4kOxZG707xKm4jVniy6o= google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= +google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f/go.mod h1:CLGoBuH1VHxAUXVPP8FfPwPEVJB6lz3URE5mY2SuayE= google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo= google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -304,6 +354,7 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk= google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -315,8 +366,12 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= +google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= From 20d4f1308f69e2b29e4d84aecb36a7448828fb91 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:23:40 +0100 Subject: [PATCH 221/248] more changes of names --- server/handlers/carouselHandler.go | 14 +++++++------- server/handlers/machineHandler.go | 16 ++++++++-------- server/handlers/partsHandler.go | 14 +++++++------- server/handlers/productHandler.go | 14 +++++++------- server/handlers/supplierHandler.go | 16 ++++++++-------- server/handlers/videoHandler.go | 14 +++++++------- server/middleware/authMiddleware.go | 4 ++-- server/routes/blogRoutes.go | 4 ++-- server/routes/carouselRoutes.go | 18 +++++++++--------- server/routes/checkoutRoutes.go | 4 ++-- server/routes/employeeRoutes.go | 4 ++-- server/routes/exhibitionRoutes.go | 4 ++-- server/routes/lineItemRoutes.go | 4 ++-- server/routes/machineRoutes.go | 20 ++++++++++---------- server/routes/partsRoutes.go | 18 +++++++++--------- server/routes/pdfRoutes.go | 12 ++++++------ server/routes/privacyRoutes.go | 4 ++-- server/routes/productRoutes.go | 18 +++++++++--------- server/routes/supplierRoutes.go | 20 ++++++++++---------- server/routes/termsRoutes.go | 4 ++-- server/routes/timelineRoutes.go | 4 ++-- server/routes/videoRoutes.go | 20 ++++++++++---------- server/routes/warrantyRoutes.go | 4 ++-- server/services/videoService.go | 12 ++++++------ 24 files changed, 133 insertions(+), 133 deletions(-) diff --git a/server/handlers/carouselHandler.go b/server/handlers/carouselHandler.go index 989da70..a08d00f 100644 --- a/server/handlers/carouselHandler.go +++ b/server/handlers/carouselHandler.go @@ -11,16 +11,16 @@ import ( ) type CarouselHandler struct { - carouselService services.CarouselService + service services.CarouselService } -func NewCarouselHandler(carouselService services.CarouselService) *CarouselHandler { - return &CarouselHandler{carouselService: carouselService} +func NewCarouselHandler(service services.CarouselService) *CarouselHandler { + return &CarouselHandler{service: service} } func (handler *CarouselHandler) GetCarousels(context *gin.Context) { ctx := context.Request.Context() - carousels, err := handler.carouselService.GetCarousels(ctx) + carousels, err := handler.service.GetCarousels(ctx) if err != nil { log.Printf("error getting carousels: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting carousel images"}) @@ -40,7 +40,7 @@ func (handler *CarouselHandler) CreateCarousel(context *gin.Context) { return } - result, err := handler.carouselService.CreateCarousel(ctx, &dbCarousel) + result, err := handler.service.CreateCarousel(ctx, &dbCarousel) if err != nil { log.Printf("Error creating carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating carousel", "details": err.Error()}) @@ -68,7 +68,7 @@ func (handler *CarouselHandler) UpdateCarousel(context *gin.Context) { return } - result, err := handler.carouselService.UpdateCarousel(ctx, id, &dbCarousel) + result, err := handler.service.UpdateCarousel(ctx, id, &dbCarousel) if err != nil { log.Printf("Error updating carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating carousel", "details": err.Error()}) @@ -88,7 +88,7 @@ func (handler *CarouselHandler) DeleteCarousel(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - if err := handler.carouselService.DeleteCarousel(ctx, id); err != nil { + if err := handler.service.DeleteCarousel(ctx, id); err != nil { log.Printf("Error deleting carousel: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting machine", "details": err.Error()}) return diff --git a/server/handlers/machineHandler.go b/server/handlers/machineHandler.go index 6a7d6d0..e4f6121 100644 --- a/server/handlers/machineHandler.go +++ b/server/handlers/machineHandler.go @@ -11,18 +11,18 @@ import ( ) type MachineHandler struct { - machineService services.MachineService + service services.MachineService } -func NewMachineHandler(machineService services.MachineService) *MachineHandler { - return &MachineHandler{machineService: machineService} +func NewMachineHandler(service services.MachineService) *MachineHandler { + return &MachineHandler{service: service} } func (handler *MachineHandler) GetMachines(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - machines, err := handler.machineService.GetMachines(ctx, id) + machines, err := handler.service.GetMachines(ctx, id) if err != nil { log.Printf("Error getting machines: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting machines"}) @@ -36,7 +36,7 @@ func (handler *MachineHandler) GetMachineById(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - machine, err := handler.machineService.GetMachineById(ctx, id) + machine, err := handler.service.GetMachineById(ctx, id) if err != nil { log.Printf("Error getting machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting machine"}) @@ -61,7 +61,7 @@ func (handler *MachineHandler) CreateMachine(context *gin.Context) { return } - result, err := handler.machineService.CreateMachine(ctx, &dbMachine) + result, err := handler.service.CreateMachine(ctx, &dbMachine) if err != nil { log.Printf("Error creating machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating machine", "details": err.Error()}) @@ -94,7 +94,7 @@ func (handler *MachineHandler) UpdateMachine(context *gin.Context) { return } - result, err := handler.machineService.UpdateMachine(ctx, id, &dbMachine) + result, err := handler.service.UpdateMachine(ctx, id, &dbMachine) if err != nil { log.Printf("Error updating machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) @@ -114,7 +114,7 @@ func (handler *MachineHandler) DeleteMachine(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - if err := handler.machineService.DeleteMachine(ctx, id); err != nil { + if err := handler.service.DeleteMachine(ctx, id); err != nil { log.Printf("Error deleting machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting machine", "details": err.Error()}) return diff --git a/server/handlers/partsHandler.go b/server/handlers/partsHandler.go index 0b29052..92abe7e 100644 --- a/server/handlers/partsHandler.go +++ b/server/handlers/partsHandler.go @@ -11,18 +11,18 @@ import ( ) type PartsHandler struct { - partsService services.PartsService + service services.PartsService } -func NewPartsHandler(partsService services.PartsService) *PartsHandler { - return &PartsHandler{partsService: partsService} +func NewPartsHandler(service services.PartsService) *PartsHandler { + return &PartsHandler{service: service} } func (handler *PartsHandler) GetParts(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - parts, err := handler.partsService.GetParts(ctx, id) + parts, err := handler.service.GetParts(ctx, id) if err != nil { log.Printf("Error getting parts: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting parts"}) @@ -47,7 +47,7 @@ func (handler *PartsHandler) CreateParts(context *gin.Context) { return } - result, err := handler.partsService.CreatePart(ctx, &dbPart) + result, err := handler.service.CreatePart(ctx, &dbPart) if err != nil { log.Printf("Error creating part: %v", err) context.JSON(http.StatusInternalServerError, @@ -82,7 +82,7 @@ func (handler *PartsHandler) UpdateParts(context *gin.Context) { return } - result, err := handler.partsService.UpdatePart(ctx, id, &dbPart) + result, err := handler.service.UpdatePart(ctx, id, &dbPart) if err != nil { log.Printf("Error updating part: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) @@ -103,7 +103,7 @@ func (handler *PartsHandler) DeletePart(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - if err := handler.partsService.DeletePart(ctx, id); err != nil { + if err := handler.service.DeletePart(ctx, id); err != nil { log.Printf("Erroir deleting part: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurrrd while deleting part", "details": err.Error()}) return diff --git a/server/handlers/productHandler.go b/server/handlers/productHandler.go index 4d06449..918f60b 100644 --- a/server/handlers/productHandler.go +++ b/server/handlers/productHandler.go @@ -11,18 +11,18 @@ import ( ) type ProductHandler struct { - productService services.ProductService + service services.ProductService } -func NewProductHandler(productService services.ProductService) *ProductHandler { - return &ProductHandler{productService: productService} +func NewProductHandler(service services.ProductService) *ProductHandler { + return &ProductHandler{service: service} } func (handler *ProductHandler) GetProducts(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - products, err := handler.productService.GetProducts(ctx, id) + products, err := handler.service.GetProducts(ctx, id) if err != nil { log.Printf("Error getting machines: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occured while getting products"}) @@ -47,7 +47,7 @@ func (handler *ProductHandler) CreateProduct(context *gin.Context) { return } - result, err := handler.productService.CreateProduct(ctx, &dbProduct) + result, err := handler.service.CreateProduct(ctx, &dbProduct) if err != nil { log.Printf("Error creating product: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating product", "details": err.Error()}) @@ -80,7 +80,7 @@ func (handler *ProductHandler) UpdateProduct(context *gin.Context) { return } - result, err := handler.productService.UpdateProduct(ctx, id, &dbProduct) + result, err := handler.service.UpdateProduct(ctx, id, &dbProduct) if err != nil { log.Printf("Error updating product: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating machine", "details": err.Error()}) @@ -100,7 +100,7 @@ func (handler *ProductHandler) DeleteProduct(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - if err := handler.productService.DeleteProduct(ctx, id); err != nil { + if err := handler.service.DeleteProduct(ctx, id); err != nil { log.Printf("Error deleting machine: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while deleting machine", "details": err.Error()}) return diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index b1756ef..e979e54 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -11,16 +11,16 @@ import ( ) type SupplierHandler struct { - supplierService services.SupplierService + service services.SupplierService } -func NewSupplierContoller(supplierService services.SupplierService) *SupplierHandler { - return &SupplierHandler{supplierService: supplierService} +func NewSupplierContoller(service services.SupplierService) *SupplierHandler { + return &SupplierHandler{service: service} } func (handler *SupplierHandler) GetSuppliers(context *gin.Context) { ctx := context.Request.Context() - suppliers, err := handler.supplierService.GetSuppliers(ctx) + suppliers, err := handler.service.GetSuppliers(ctx) if err != nil { log.Printf("Error getting suppliers: %v", err) @@ -33,7 +33,7 @@ func (handler *SupplierHandler) GetSuppliers(context *gin.Context) { func (handler *SupplierHandler) GetSupplierByID(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - supplier, err := handler.supplierService.GetSupplierById(ctx, id) + supplier, err := handler.service.GetSupplierById(ctx, id) if err != nil { log.Printf("Error getting suppliers: %v", err) @@ -53,7 +53,7 @@ func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { } dbSupplier := lib.DeserializeSupplier(supplier) - result, err := handler.supplierService.CreateSupplier(ctx, dbSupplier) + result, err := handler.service.CreateSupplier(ctx, dbSupplier) if err != nil { log.Printf("Error creating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating supplier", "details": err.Error()}) @@ -83,7 +83,7 @@ func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { return } - result, err := handler.supplierService.UpdateSupplier(ctx, id, &dbSupplier) + result, err := handler.service.UpdateSupplier(ctx, id, &dbSupplier) if err != nil { log.Printf("Error updating supplier: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating supplier", "details": err.Error()}) @@ -105,7 +105,7 @@ func (handler *SupplierHandler) DeleteSupplier(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - err := handler.supplierService.DeleteSupplier(ctx, id) + err := handler.service.DeleteSupplier(ctx, id) if err != nil { log.Printf("Error deleting supplier: %v", err) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index c8395ee..e9abdd5 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -11,18 +11,18 @@ import ( ) type VideoHandler struct { - videoService services.VideoService + service services.VideoService } -func NewVideoHandler(videoService services.VideoService) *VideoHandler { - return &VideoHandler{videoService: videoService} +func NewVideoHandler(service services.VideoService) *VideoHandler { + return &VideoHandler{service: service} } func (handler *VideoHandler) GetVideos(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - videos, err := handler.videoService.GetVideos(ctx, id) + videos, err := handler.service.GetVideos(ctx, id) if err != nil { log.Printf("Error getting suppliers: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while getting suppliers"}) @@ -42,7 +42,7 @@ func (handler *VideoHandler) CreateVideo(context *gin.Context) { return } - if err := handler.videoService.CreateVideo(ctx, &dbVideo); err != nil { + if err := handler.service.CreateVideo(ctx, &dbVideo); err != nil { log.Printf("Error creating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating video", "details": err.Error()}) return @@ -63,7 +63,7 @@ func (handler *VideoHandler) UpdateVideo(context *gin.Context) { return } - if err := handler.videoService.UpdateVideo(ctx, id, &dbVideo); err != nil { + if err := handler.service.UpdateVideo(ctx, id, &dbVideo); err != nil { log.Printf("Error updating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating video", "details": err.Error()}) return @@ -76,7 +76,7 @@ func (handler *VideoHandler) DeleteVideo(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - if err := handler.videoService.DeleteVideo(ctx, id); err != nil { + if err := handler.service.DeleteVideo(ctx, id); err != nil { log.Printf("Error deleting video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Erropr occurred while deleting supplier", "details": err.Error()}) return diff --git a/server/middleware/authMiddleware.go b/server/middleware/authMiddleware.go index 0967bef..8cb90ab 100644 --- a/server/middleware/authMiddleware.go +++ b/server/middleware/authMiddleware.go @@ -9,9 +9,9 @@ type AuthMiddleware struct { FirebaseService *lib.Firebase } -func NewAuthMiddleware(firebaseService *lib.Firebase) *AuthMiddleware { +func NewAuthMiddleware(service *lib.Firebase) *AuthMiddleware { return &AuthMiddleware{ - FirebaseService: firebaseService, + FirebaseService: service, } } diff --git a/server/routes/blogRoutes.go b/server/routes/blogRoutes.go index 5621780..811401e 100644 --- a/server/routes/blogRoutes.go +++ b/server/routes/blogRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitBlogs(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - blogRepo := repository.NewBlogRepo(database) - service := services.NewBlogService(blogRepo, s3Client, "Blogs") + repo := repository.NewBlogRepo(database) + service := services.NewBlogService(repo, s3Client, "Blogs") handler := handlers.NewBlogHandler(service) BlogRoutes(router, handler, adminMiddleware) diff --git a/server/routes/carouselRoutes.go b/server/routes/carouselRoutes.go index 8649148..1481382 100644 --- a/server/routes/carouselRoutes.go +++ b/server/routes/carouselRoutes.go @@ -12,22 +12,22 @@ import ( ) func InitCarousel(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleare *middleware.AdminMiddleware) { - carouselRepo := repository.NewCarouselRepo(database) - carouselService := services.NewCarouselService(carouselRepo, s3Client, "Carousels") - carouselHandler := handlers.NewCarouselHandler(carouselService) + repo := repository.NewCarouselRepo(database) + service := services.NewCarouselService(repo, s3Client, "Carousels") + handler := handlers.NewCarouselHandler(service) - CarouselRoutes(router, carouselHandler, adminMiddleare) + CarouselRoutes(router, handler, adminMiddleare) } -func CarouselRoutes(router *gin.Engine, carouselHandler *handlers.CarouselHandler, adminMiddleware *middleware.AdminMiddleware) { +func CarouselRoutes(router *gin.Engine, handler *handlers.CarouselHandler, adminMiddleware *middleware.AdminMiddleware) { carouselGroup := router.Group("/api/carousels") - carouselGroup.GET("", carouselHandler.GetCarousels) + carouselGroup.GET("", handler.GetCarousels) protected := carouselGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("", carouselHandler.CreateCarousel) - protected.PUT("/:id", carouselHandler.UpdateCarousel) - protected.DELETE("/:id", carouselHandler.DeleteCarousel) + protected.POST("", handler.CreateCarousel) + protected.PUT("/:id", handler.UpdateCarousel) + protected.DELETE("/:id", handler.DeleteCarousel) } } diff --git a/server/routes/checkoutRoutes.go b/server/routes/checkoutRoutes.go index 90ce0e5..b1bedb8 100644 --- a/server/routes/checkoutRoutes.go +++ b/server/routes/checkoutRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitCheckout(router *gin.Engine, database *sql.DB, secrets *lib.Secrets) { - itemRepo := repository.NewLineItemRepo(database) - service := services.NewCheckoutService(secrets, itemRepo) + repo := repository.NewLineItemRepo(database) + service := services.NewCheckoutService(secrets, repo) handler := handlers.NewCheckoutHandler(service) CheckoutRoutes(router, handler) diff --git a/server/routes/employeeRoutes.go b/server/routes/employeeRoutes.go index b5f196c..cb43447 100644 --- a/server/routes/employeeRoutes.go +++ b/server/routes/employeeRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitializeEmployee(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - employeeRepo := repository.NewEmployeeRepo(database) - service := services.NewEmployeeService(employeeRepo, s3Client, "Employees") + repo := repository.NewEmployeeRepo(database) + service := services.NewEmployeeService(repo, s3Client, "Employees") handler := handlers.NewEmployeeHandler(service) EmployeeRoutes(router, handler, adminMiddleware) diff --git a/server/routes/exhibitionRoutes.go b/server/routes/exhibitionRoutes.go index 71289ca..7f0d61d 100644 --- a/server/routes/exhibitionRoutes.go +++ b/server/routes/exhibitionRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitExhibitions(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - exhibitionRepo := repository.NewExhibitionRepo(database) - service := services.NewExhibitionService(exhibitionRepo) + repo := repository.NewExhibitionRepo(database) + service := services.NewExhibitionService(repo) handler := handlers.NewExhibitionHandler(service) ExhibitionRoutes(router, handler, adminMiddleware) diff --git a/server/routes/lineItemRoutes.go b/server/routes/lineItemRoutes.go index ec94e92..83cd7df 100644 --- a/server/routes/lineItemRoutes.go +++ b/server/routes/lineItemRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitLineItems(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - itemRepo := repository.NewLineItemRepo(database) - service := services.NewLineItemService(itemRepo, s3Client, "Lineitems") + repo := repository.NewLineItemRepo(database) + service := services.NewLineItemService(repo, s3Client, "Lineitems") handler := handlers.NewLineItemHandler(service) LineItemRoutes(router, handler, adminMiddleware) diff --git a/server/routes/machineRoutes.go b/server/routes/machineRoutes.go index 27d04e7..eac482f 100644 --- a/server/routes/machineRoutes.go +++ b/server/routes/machineRoutes.go @@ -12,23 +12,23 @@ import ( ) func InitMachines(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - machineRepo := repository.NewMachineRepo(database) - machineService := services.NewMachineService(machineRepo, s3Client, "Machines") - machineHandler := handlers.NewMachineHandler(machineService) + repo := repository.NewMachineRepo(database) + service := services.NewMachineService(repo, s3Client, "Machines") + handler := handlers.NewMachineHandler(service) - MachineRoutes(router, machineHandler, adminMiddleware) + MachineRoutes(router, handler, adminMiddleware) } -func MachineRoutes(router *gin.Engine, machineHandler *handlers.MachineHandler, adminMiddleware *middleware.AdminMiddleware) { +func MachineRoutes(router *gin.Engine, handler *handlers.MachineHandler, adminMiddleware *middleware.AdminMiddleware) { machineGroup := router.Group("/api/machines") - machineGroup.GET("/:id", machineHandler.GetMachineById) - machineGroup.GET("/suppliers/:id", machineHandler.GetMachines) + machineGroup.GET("/:id", handler.GetMachineById) + machineGroup.GET("/suppliers/:id", handler.GetMachines) protected := machineGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("", machineHandler.CreateMachine) - protected.PUT("/:id", machineHandler.UpdateMachine) - protected.DELETE("/:id", machineHandler.DeleteMachine) + protected.POST("", handler.CreateMachine) + protected.PUT("/:id", handler.UpdateMachine) + protected.DELETE("/:id", handler.DeleteMachine) } } diff --git a/server/routes/partsRoutes.go b/server/routes/partsRoutes.go index b6ff2c4..10a6bfc 100644 --- a/server/routes/partsRoutes.go +++ b/server/routes/partsRoutes.go @@ -12,22 +12,22 @@ import ( ) func InitParts(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - partsRepo := repository.NewPartsRepo(database) - partsService := services.NewPartsService(partsRepo, s3Client, "Spareparts") - partsHandler := handlers.NewPartsHandler(partsService) + repo := repository.NewPartsRepo(database) + service := services.NewPartsService(repo, s3Client, "Spareparts") + handler := handlers.NewPartsHandler(service) - PartsRoutes(router, partsHandler, adminMiddleware) + PartsRoutes(router, handler, adminMiddleware) } -func PartsRoutes(router *gin.Engine, partsHandler *handlers.PartsHandler, adminMiddleware *middleware.AdminMiddleware) { +func PartsRoutes(router *gin.Engine, handler *handlers.PartsHandler, adminMiddleware *middleware.AdminMiddleware) { partsGroup := router.Group("/api/spareparts") - partsGroup.GET("/:id", partsHandler.GetParts) + partsGroup.GET("/:id", handler.GetParts) protected := partsGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("", partsHandler.CreateParts) - protected.PUT("/:id", partsHandler.UpdateParts) - protected.DELETE("/:id", partsHandler.DeletePart) + protected.POST("", handler.CreateParts) + protected.PUT("/:id", handler.UpdateParts) + protected.DELETE("/:id", handler.DeletePart) } } diff --git a/server/routes/pdfRoutes.go b/server/routes/pdfRoutes.go index c9f2ceb..40a3a1b 100644 --- a/server/routes/pdfRoutes.go +++ b/server/routes/pdfRoutes.go @@ -8,17 +8,17 @@ import ( ) func InitPdfRenderer(router *gin.Engine, adminMiddleware *middleware.AdminMiddleware) { - pdfService := services.NewPdfService() - pdfHandler := handlers.NewPdfHandler(pdfService) + service := services.NewPdfService() + handler := handlers.NewPdfHandler(service) - PdfRenderRoutes(router, pdfHandler, adminMiddleware) + PdfRenderRoutes(router, handler, adminMiddleware) } -func PdfRenderRoutes(router *gin.Engine, pdfHandler *handlers.PdfHandler, adminMiddleware *middleware.AdminMiddleware) { +func PdfRenderRoutes(router *gin.Engine, handler *handlers.PdfHandler, adminMiddleware *middleware.AdminMiddleware) { pdfGroup := router.Group("/api/pdf") protected := pdfGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("/registration", pdfHandler.RenderRegistrationPdf) - protected.POST("/warranty", pdfHandler.RenderWarrantyClaimPdf) + protected.POST("/registration", handler.RenderRegistrationPdf) + protected.POST("/warranty", handler.RenderWarrantyClaimPdf) } } diff --git a/server/routes/privacyRoutes.go b/server/routes/privacyRoutes.go index bb8c14c..e6163cf 100644 --- a/server/routes/privacyRoutes.go +++ b/server/routes/privacyRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitPrivacy(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - privacyRepo := repository.NewPrivacyRepo(database) - service := services.NewPrivacyService(privacyRepo) + repo := repository.NewPrivacyRepo(database) + service := services.NewPrivacyService(repo) handler := handlers.NewPrivacyHandler(service) PrivacyRoutes(router, handler, adminMiddleware) diff --git a/server/routes/productRoutes.go b/server/routes/productRoutes.go index 3fe6d31..9cdaa1f 100644 --- a/server/routes/productRoutes.go +++ b/server/routes/productRoutes.go @@ -12,22 +12,22 @@ import ( ) func InitProduct(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - productRepo := repository.NewProductRepo(database) - productService := services.NewProductService(productRepo, s3Client, "Products") - productHandler := handlers.NewProductHandler(productService) + repo := repository.NewProductRepo(database) + service := services.NewProductService(repo, s3Client, "Products") + handler := handlers.NewProductHandler(service) - ProductRoutes(router, productHandler, adminMiddleware) + ProductRoutes(router, handler, adminMiddleware) } -func ProductRoutes(router *gin.Engine, productHandler *handlers.ProductHandler, adminMiddleware *middleware.AdminMiddleware) { +func ProductRoutes(router *gin.Engine, handler *handlers.ProductHandler, adminMiddleware *middleware.AdminMiddleware) { productGroup := router.Group("/api/products") - productGroup.GET("/:id", productHandler.GetProducts) + productGroup.GET("/:id", handler.GetProducts) protected := productGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("", productHandler.CreateProduct) - protected.PUT("/:id", productHandler.UpdateProduct) - protected.DELETE("/:id", productHandler.DeleteProduct) + protected.POST("", handler.CreateProduct) + protected.PUT("/:id", handler.UpdateProduct) + protected.DELETE("/:id", handler.DeleteProduct) } } diff --git a/server/routes/supplierRoutes.go b/server/routes/supplierRoutes.go index 86bd747..fe8de31 100644 --- a/server/routes/supplierRoutes.go +++ b/server/routes/supplierRoutes.go @@ -13,23 +13,23 @@ import ( ) func InitSuppliers(router *gin.Engine, database *sql.DB, s3Client lib.S3Client, adminMiddleware *middleware.AdminMiddleware) { - supplierRepo := repository.NewSupplierRepo(database) - supplierService := services.NewSupplierService(supplierRepo, s3Client, "Suppliers") - supplierHandler := handlers.NewSupplierContoller(supplierService) + repo := repository.NewSupplierRepo(database) + service := services.NewSupplierService(repo, s3Client, "Suppliers") + handler := handlers.NewSupplierContoller(service) - SupplierRoutes(router, supplierHandler, adminMiddleware) + SupplierRoutes(router, handler, adminMiddleware) } -func SupplierRoutes(router *gin.Engine, supplierHandler *handlers.SupplierHandler, adminMiddleware *middleware.AdminMiddleware) { +func SupplierRoutes(router *gin.Engine, handler *handlers.SupplierHandler, adminMiddleware *middleware.AdminMiddleware) { supplierGroup := router.Group("/api/suppliers") - supplierGroup.GET("", supplierHandler.GetSuppliers) - supplierGroup.GET("/:id", supplierHandler.GetSupplierByID) + supplierGroup.GET("", handler.GetSuppliers) + supplierGroup.GET("/:id", handler.GetSupplierByID) protected := supplierGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("", supplierHandler.CreateSupplier) - protected.PUT("/:id", supplierHandler.UpdateSupplier) - protected.DELETE("/:id", supplierHandler.DeleteSupplier) + protected.POST("", handler.CreateSupplier) + protected.PUT("/:id", handler.UpdateSupplier) + protected.DELETE("/:id", handler.DeleteSupplier) } } diff --git a/server/routes/termsRoutes.go b/server/routes/termsRoutes.go index 7ded896..511940e 100644 --- a/server/routes/termsRoutes.go +++ b/server/routes/termsRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitTerms(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - termsRepo := repository.NewTermsRepo(database) - service := services.NewTermsService(termsRepo) + repo := repository.NewTermsRepo(database) + service := services.NewTermsService(repo) handler := handlers.NewTermsHandler(service) TermsRoutes(router, handler, adminMiddleware) diff --git a/server/routes/timelineRoutes.go b/server/routes/timelineRoutes.go index 293f42a..e01271a 100644 --- a/server/routes/timelineRoutes.go +++ b/server/routes/timelineRoutes.go @@ -11,8 +11,8 @@ import ( ) func InitTimelines(router *gin.Engine, database *sql.DB, adminMiddleware *middleware.AdminMiddleware) { - timelineRepo := repository.NewTimelineRepo(database) - service := services.NewTimelineService(timelineRepo) + repo := repository.NewTimelineRepo(database) + service := services.NewTimelineService(repo) handler := handlers.NewTimelineHandler(service) TimelineRoutes(router, handler, adminMiddleware) diff --git a/server/routes/videoRoutes.go b/server/routes/videoRoutes.go index cc5e9f4..21701f3 100644 --- a/server/routes/videoRoutes.go +++ b/server/routes/videoRoutes.go @@ -16,27 +16,27 @@ import ( ) func InitVideos(router *gin.Engine, database *sql.DB, secrets *lib.Secrets, adminMiddleware *middleware.AdminMiddleware) { - youtubeService, err := youtube.NewService(context.Background(), option.WithAPIKey(secrets.YoutubeApiKey)) + service, err := youtube.NewService(context.Background(), option.WithAPIKey(secrets.YoutubeApiKey)) if err != nil { log.Fatal("error calling YouTube API: ", err) } - videoRepo := repository.NewVideoRepo(database) - videoService := services.NewVideoService(videoRepo, youtubeService) - videoHandler := handlers.NewVideoHandler(videoService) + repo := repository.NewVideoRepo(database) + service := services.NewVideoService(repo, service) + handler := handlers.NewVideoHandler(service) - VideoRoutes(router, videoHandler, adminMiddleware) + VideoRoutes(router, handler, adminMiddleware) } -func VideoRoutes(router *gin.Engine, videoHandler *handlers.VideoHandler, adminMiddleware *middleware.AdminMiddleware) { +func VideoRoutes(router *gin.Engine, handler *handlers.VideoHandler, adminMiddleware *middleware.AdminMiddleware) { videoGroup := router.Group("/api/videos") - videoGroup.GET("/:id", videoHandler.GetVideos) + videoGroup.GET("/:id", handler.GetVideos) protected := videoGroup.Group("").Use(adminMiddleware.Middleware()) { - protected.POST("", videoHandler.CreateVideo) - protected.PUT("/:id", videoHandler.UpdateVideo) - protected.DELETE("/:id", videoHandler.DeleteVideo) + protected.POST("", handler.CreateVideo) + protected.PUT("/:id", handler.UpdateVideo) + protected.DELETE("/:id", handler.DeleteVideo) } } diff --git a/server/routes/warrantyRoutes.go b/server/routes/warrantyRoutes.go index 1192669..6ff3a80 100644 --- a/server/routes/warrantyRoutes.go +++ b/server/routes/warrantyRoutes.go @@ -12,8 +12,8 @@ import ( ) func InitWarranty(router *gin.Engine, database *sql.DB, authMiddleware *middleware.AuthMiddleware, smtp lib.SMTPClient) { - warrantyRepo := repository.NewWarrantyRepo(database) - service := services.NewWarrantyService(warrantyRepo, smtp) + repo := repository.NewWarrantyRepo(database) + service := services.NewWarrantyService(repo, smtp) handler := handlers.NewWarrantyHandler(service) WarrantyRoutes(router, handler, authMiddleware) diff --git a/server/services/videoService.go b/server/services/videoService.go index 5dfe34d..e770965 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -22,14 +22,14 @@ type VideoService interface { } type VideoServiceImpl struct { - repo repository.VideoRepo - youtubeService *youtube.Service + repo repository.VideoRepo + service *youtube.Service } -func NewVideoService(repo repository.VideoRepo, youtubeService *youtube.Service) *VideoServiceImpl { +func NewVideoService(repo repository.VideoRepo, service *youtube.Service) *VideoServiceImpl { return &VideoServiceImpl{ - repo: repo, - youtubeService: youtubeService, + repo: repo, + service: service, } } @@ -46,7 +46,7 @@ func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, erro videoId := videoIdSplits[0] - call := service.youtubeService.Videos.List([]string{"id", "snippet"}).Id(videoId).MaxResults(1) + call := service.service.Videos.List([]string{"id", "snippet"}).Id(videoId).MaxResults(1) response, err := call.Do() if err != nil { return nil, fmt.Errorf("error calling YouTube API: %w", err) From 2ce99d42447256f3d612af015d2be274e4b0e7eb Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:25:31 +0100 Subject: [PATCH 222/248] fix yt errors --- server/routes/videoRoutes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/routes/videoRoutes.go b/server/routes/videoRoutes.go index 21701f3..22df7b7 100644 --- a/server/routes/videoRoutes.go +++ b/server/routes/videoRoutes.go @@ -16,13 +16,13 @@ import ( ) func InitVideos(router *gin.Engine, database *sql.DB, secrets *lib.Secrets, adminMiddleware *middleware.AdminMiddleware) { - service, err := youtube.NewService(context.Background(), option.WithAPIKey(secrets.YoutubeApiKey)) + yt, err := youtube.NewService(context.Background(), option.WithAPIKey(secrets.YoutubeApiKey)) if err != nil { log.Fatal("error calling YouTube API: ", err) } repo := repository.NewVideoRepo(database) - service := services.NewVideoService(repo, service) + service := services.NewVideoService(repo, yt) handler := handlers.NewVideoHandler(service) VideoRoutes(router, handler, adminMiddleware) From 9139ba48b85925b73c83ed09310d4f608c58cafd Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:28:07 +0100 Subject: [PATCH 223/248] rename --- server/lib/mocks.go | 15 +++++++++++++++ server/lib/noop.go | 15 --------------- server/tests/blog_test.go | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 server/lib/mocks.go delete mode 100644 server/lib/noop.go diff --git a/server/lib/mocks.go b/server/lib/mocks.go new file mode 100644 index 0000000..6046448 --- /dev/null +++ b/server/lib/mocks.go @@ -0,0 +1,15 @@ +package lib + +type MockS3Client struct{} + +func NewMockS3Client() *MockS3Client { + return &MockS3Client{} +} + +func (client *MockS3Client) GeneratePresignedUrl(folder, image string) (string, string, error) { + return "https://example.com/fake-presigned-url", "https://example.com/fake-image-url", nil +} + +func (client *MockS3Client) DeleteImageFromS3(imageUrl string) error { + return nil +} diff --git a/server/lib/noop.go b/server/lib/noop.go deleted file mode 100644 index 13d0cfe..0000000 --- a/server/lib/noop.go +++ /dev/null @@ -1,15 +0,0 @@ -package lib - -type NoOpS3Client struct{} - -func NewNoOpS3Client() *NoOpS3Client { - return &NoOpS3Client{} -} - -func (client *NoOpS3Client) GeneratePresignedUrl(folder, image string) (string, string, error) { - return "https://example.com/fake-presigned-url", "https://example.com/fake-image-url", nil -} - -func (client *NoOpS3Client) DeleteImageFromS3(imageUrl string) error { - return nil -} diff --git a/server/tests/blog_test.go b/server/tests/blog_test.go index bf4e1e1..202861a 100644 --- a/server/tests/blog_test.go +++ b/server/tests/blog_test.go @@ -57,7 +57,7 @@ func (suite *BlogTestSuite) SetupTest() { suite.mock = mock repo := repository.NewBlogRepo(database) - s3Client := lib.NewNoOpS3Client() + s3Client := lib.NewMockS3Client() service := services.NewBlogService(repo, s3Client, "test-folder") handler := handlers.NewBlogHandler(service) From 14b291ffa56294af8101539e2035d74bae2be0c9 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:28:37 +0100 Subject: [PATCH 224/248] warnings --- server/lib/mocks.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/lib/mocks.go b/server/lib/mocks.go index 6046448..c9b21dc 100644 --- a/server/lib/mocks.go +++ b/server/lib/mocks.go @@ -6,10 +6,10 @@ func NewMockS3Client() *MockS3Client { return &MockS3Client{} } -func (client *MockS3Client) GeneratePresignedUrl(folder, image string) (string, string, error) { +func (client *MockS3Client) GeneratePresignedUrl(string, string) (string, string, error) { return "https://example.com/fake-presigned-url", "https://example.com/fake-image-url", nil } -func (client *MockS3Client) DeleteImageFromS3(imageUrl string) error { +func (client *MockS3Client) DeleteImageFromS3(string) error { return nil } From 746f8c552f3af755693839a562d8acf6cf9384af Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:57:35 +0100 Subject: [PATCH 225/248] productHandler.go --- server/handlers/productHandler.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/handlers/productHandler.go b/server/handlers/productHandler.go index 918f60b..6ad65a8 100644 --- a/server/handlers/productHandler.go +++ b/server/handlers/productHandler.go @@ -35,18 +35,17 @@ func (handler *ProductHandler) GetProducts(context *gin.Context) { func (handler *ProductHandler) CreateProduct(context *gin.Context) { ctx := context.Request.Context() var product types.Product - dbProduct := lib.DeserializeProduct(product) if err := context.ShouldBindJSON(&product); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - if product.MachineID == "" || product.MachineID == "null" { context.JSON(http.StatusBadRequest, gin.H{"error": "SupplierID cannot be empty"}) return } + dbProduct := lib.DeserializeProduct(product) result, err := handler.service.CreateProduct(ctx, &dbProduct) if err != nil { log.Printf("Error creating product: %v", err) @@ -68,18 +67,16 @@ func (handler *ProductHandler) UpdateProduct(context *gin.Context) { id := context.Param("id") var product types.Product - dbProduct := lib.DeserializeProduct(product) - if err := context.ShouldBindJSON(&product); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "details": err.Error()}) return } - if product.MachineID == "" || product.MachineID == "null" { context.JSON(http.StatusBadRequest, gin.H{"error": "SupplierID cannot be empty"}) return } + dbProduct := lib.DeserializeProduct(product) result, err := handler.service.UpdateProduct(ctx, id, &dbProduct) if err != nil { log.Printf("Error updating product: %v", err) From a9cf3ef4ecb344558fa58cc4c0020215feee5186 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:58:27 +0100 Subject: [PATCH 226/248] registrationHandler.go --- server/handlers/registrationHandler.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/handlers/registrationHandler.go b/server/handlers/registrationHandler.go index db94bc7..d81b573 100644 --- a/server/handlers/registrationHandler.go +++ b/server/handlers/registrationHandler.go @@ -47,14 +47,13 @@ func (handler *RegistrationHandler) GetRegistrationById(context *gin.Context) { func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { ctx := context.Request.Context() var registration types.MachineRegistration - dbRegistration := lib.DeserializeMachineRegistration(registration) - if err := context.ShouldBindJSON(®istration); err != nil { log.Printf("error when creating registration: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred while creating registration - bad request"}) return } + dbRegistration := lib.DeserializeMachineRegistration(registration) if err := handler.service.CreateRegistration(ctx, &dbRegistration); err != nil { log.Printf("error when creating registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when creating registration"}) @@ -66,15 +65,15 @@ func (handler *RegistrationHandler) CreateRegistration(context *gin.Context) { func (handler *RegistrationHandler) UpdateRegistration(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var registration types.MachineRegistration - dbRegistration := lib.DeserializeMachineRegistration(registration) + var registration types.MachineRegistration if err := context.ShouldBindJSON(®istration); err != nil { log.Printf("error when updating registration: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred while updating registration - bad request"}) return } + dbRegistration := lib.DeserializeMachineRegistration(registration) if err := handler.service.UpdateRegistration(ctx, id, &dbRegistration); err != nil { log.Printf("error when updating registration: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error when updating registration"}) From da2c63fa4c15a2dffa9ec4c63959db1861129a30 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 13:59:46 +0100 Subject: [PATCH 227/248] partsHandler.go --- server/handlers/partsHandler.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/server/handlers/partsHandler.go b/server/handlers/partsHandler.go index 92abe7e..f3d4b1f 100644 --- a/server/handlers/partsHandler.go +++ b/server/handlers/partsHandler.go @@ -35,18 +35,17 @@ func (handler *PartsHandler) GetParts(context *gin.Context) { func (handler *PartsHandler) CreateParts(context *gin.Context) { ctx := context.Request.Context() var part types.Sparepart - dbPart := lib.DeserializeSparePart(part) if err := context.ShouldBindJSON(&part); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Ivalid request body", "details": err.Error()}) return } - if part.SupplierID == "" || part.SupplierID == "null" { context.JSON(http.StatusBadRequest, gin.H{"error": "SupplierID cannot be empty"}) return } + dbPart := lib.DeserializeSparePart(part) result, err := handler.service.CreatePart(ctx, &dbPart) if err != nil { log.Printf("Error creating part: %v", err) @@ -70,18 +69,16 @@ func (handler *PartsHandler) UpdateParts(context *gin.Context) { id := context.Param("id") var part types.Sparepart - dbPart := lib.DeserializeSparePart(part) - if err := context.ShouldBindJSON(&part); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "details": err.Error()}) return } - if part.SupplierID == "" || part.SupplierID == "null" { context.JSON(http.StatusBadRequest, gin.H{"error": "SupplierID cannot be empty"}) return } + dbPart := lib.DeserializeSparePart(part) result, err := handler.service.UpdatePart(ctx, id, &dbPart) if err != nil { log.Printf("Error updating part: %v", err) From 17391708f35e75920cb0df558dca443765f88aac Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:00:27 +0100 Subject: [PATCH 228/248] privacyHandler.go --- server/handlers/privacyHandler.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/handlers/privacyHandler.go b/server/handlers/privacyHandler.go index ba5bc88..d3e729b 100644 --- a/server/handlers/privacyHandler.go +++ b/server/handlers/privacyHandler.go @@ -33,13 +33,13 @@ func (handler *PrivacyHandler) GetPrivacys(context *gin.Context) { func (handler *PrivacyHandler) CreatePrivacy(context *gin.Context) { ctx := context.Request.Context() var privacy types.Privacy - dbPrivacy := lib.DeserializePrivacy(privacy) if err := context.ShouldBindJSON(&privacy); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbPrivacy := lib.DeserializePrivacy(privacy) if err := handler.service.CreatePrivacy(ctx, &dbPrivacy); err != nil { log.Printf("error while creating privacy: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating privacy", "details": err.Error()}) @@ -52,14 +52,14 @@ func (handler *PrivacyHandler) CreatePrivacy(context *gin.Context) { func (handler *PrivacyHandler) UpdatePrivacy(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var privacy types.Privacy - dbPrivacy := lib.DeserializePrivacy(privacy) + var privacy types.Privacy if err := context.ShouldBindJSON(&privacy); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbPrivacy := lib.DeserializePrivacy(privacy) if err := handler.service.UpdatePrivacy(ctx, id, &dbPrivacy); err != nil { log.Printf("error while updating privacy: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating privacy", "details": err.Error()}) From 52511149fb890cb209c6a3ac262ceabaee8ef85e Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:01:24 +0100 Subject: [PATCH 229/248] termsHandler.go --- server/handlers/termsHandler.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/handlers/termsHandler.go b/server/handlers/termsHandler.go index 9aaa14c..e47a4b8 100644 --- a/server/handlers/termsHandler.go +++ b/server/handlers/termsHandler.go @@ -33,13 +33,13 @@ func (handler *TermsHandler) GetTerms(context *gin.Context) { func (handler *TermsHandler) CreateTerm(context *gin.Context) { ctx := context.Request.Context() var term types.Terms - dbTerm := lib.DeserializeTerm(term) if err := context.ShouldBindJSON(&term); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbTerm := lib.DeserializeTerm(term) if err := handler.service.CreateTerm(ctx, &dbTerm); err != nil { log.Printf("error while creating term: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating term", "details": err.Error()}) @@ -52,14 +52,14 @@ func (handler *TermsHandler) CreateTerm(context *gin.Context) { func (handler *TermsHandler) UpdateTerm(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var term types.Terms - dbTerm := lib.DeserializeTerm(term) + var term types.Terms if err := context.ShouldBindJSON(&term); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbTerm := lib.DeserializeTerm(term) if err := handler.service.UpdateTerm(ctx, id, &dbTerm); err != nil { log.Printf("error while updating term: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating term", "details": err.Error()}) From 7af31a9a276dec355b0c1fa74e6e1af62c6b7734 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:03:00 +0100 Subject: [PATCH 230/248] supplier hanlder --- server/handlers/supplierHandler.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/handlers/supplierHandler.go b/server/handlers/supplierHandler.go index e979e54..dceaba7 100644 --- a/server/handlers/supplierHandler.go +++ b/server/handlers/supplierHandler.go @@ -51,8 +51,8 @@ func (handler *SupplierHandler) CreateSupplier(context *gin.Context) { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - dbSupplier := lib.DeserializeSupplier(supplier) + dbSupplier := lib.DeserializeSupplier(supplier) result, err := handler.service.CreateSupplier(ctx, dbSupplier) if err != nil { log.Printf("Error creating supplier: %v", err) @@ -76,13 +76,12 @@ func (handler *SupplierHandler) UpdateSupplier(context *gin.Context) { id := context.Param("id") var supplier types.Supplier - dbSupplier := lib.DeserializeSupplier(supplier) - if err := context.ShouldBindJSON(&supplier); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } + dbSupplier := lib.DeserializeSupplier(supplier) result, err := handler.service.UpdateSupplier(ctx, id, &dbSupplier) if err != nil { log.Printf("Error updating supplier: %v", err) From bdece8312b077355023165ec9f72c3a26b8edf97 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:03:27 +0100 Subject: [PATCH 231/248] videoHandler.go --- server/handlers/videoHandler.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index e9abdd5..7874555 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -35,13 +35,13 @@ func (handler *VideoHandler) GetVideos(context *gin.Context) { func (handler *VideoHandler) CreateVideo(context *gin.Context) { ctx := context.Request.Context() var video types.Video - dbVideo := lib.DeserializeVideo(video) if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } + dbVideo := lib.DeserializeVideo(video) if err := handler.service.CreateVideo(ctx, &dbVideo); err != nil { log.Printf("Error creating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating video", "details": err.Error()}) @@ -56,13 +56,12 @@ func (handler *VideoHandler) UpdateVideo(context *gin.Context) { id := context.Param("id") var video types.Video - dbVideo := lib.DeserializeVideo(video) - if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } + dbVideo := lib.DeserializeVideo(video) if err := handler.service.UpdateVideo(ctx, id, &dbVideo); err != nil { log.Printf("Error updating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while updating video", "details": err.Error()}) From 7d64ef9a267422bcda10c64eb8634997db3bcef0 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:03:51 +0100 Subject: [PATCH 232/248] timelineHandler.go --- server/handlers/timelineHandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/handlers/timelineHandler.go b/server/handlers/timelineHandler.go index 3b6b2f9..115e38a 100644 --- a/server/handlers/timelineHandler.go +++ b/server/handlers/timelineHandler.go @@ -33,13 +33,13 @@ func (handler *TimelineHandler) GetTimelines(context *gin.Context) { func (handler *TimelineHandler) CreateTimeline(context *gin.Context) { ctx := context.Request.Context() var timeline types.Timeline - dbTimeline := lib.DeserializeTimeline(timeline) if err := context.ShouldBindJSON(&timeline); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbTimeline := lib.DeserializeTimeline(timeline) if err := handler.service.CreateTimeline(ctx, &dbTimeline); err != nil { log.Printf("error while creating timeline: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating timeline", "details": err.Error()}) @@ -53,13 +53,13 @@ func (handler *TimelineHandler) UpdateTimeline(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") var timeline types.Timeline - dbTimeline := lib.DeserializeTimeline(timeline) if err := context.ShouldBindJSON(&timeline); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbTimeline := lib.DeserializeTimeline(timeline) if err := handler.service.UpdateTimeline(ctx, id, &dbTimeline); err != nil { log.Printf("error while updating timeline: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "Error occurred while updating timeline", "details": err.Error()}) From 0c687d041a23287079f91d3c76a93515acbb5f67 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:06:48 +0100 Subject: [PATCH 233/248] few more handlers --- server/handlers/blogHandler.go | 5 ++--- server/handlers/carouselHandler.go | 5 ++--- server/handlers/employeeHandler.go | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/server/handlers/blogHandler.go b/server/handlers/blogHandler.go index 940f3cb..00d7d83 100644 --- a/server/handlers/blogHandler.go +++ b/server/handlers/blogHandler.go @@ -46,7 +46,6 @@ func (handler *BlogHandler) GetBlogByID(context *gin.Context) { func (handler *BlogHandler) CreateBlog(context *gin.Context) { ctx := context.Request.Context() var blog types.Blog - dbBlog := lib.DeserializeBlog(blog) if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while creating blog: %v", err) @@ -54,6 +53,7 @@ func (handler *BlogHandler) CreateBlog(context *gin.Context) { return } + dbBlog := lib.DeserializeBlog(blog) result, err := handler.service.CreateBlog(ctx, &dbBlog) if err != nil { log.Printf("error while creating blog: %v", err) @@ -71,14 +71,13 @@ func (handler *BlogHandler) UpdateBlog(context *gin.Context) { id := context.Param("id") var blog types.Blog - dbBlog := lib.DeserializeBlog(blog) - if err := context.ShouldBindJSON(&blog); err != nil { log.Printf("error while updating blog: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred while updating blog"}) return } + dbBlog := lib.DeserializeBlog(blog) result, err := handler.service.UpdateBlog(ctx, id, &dbBlog) if err != nil { log.Printf("error while updating blog: %v", err) diff --git a/server/handlers/carouselHandler.go b/server/handlers/carouselHandler.go index a08d00f..a19f272 100644 --- a/server/handlers/carouselHandler.go +++ b/server/handlers/carouselHandler.go @@ -33,13 +33,13 @@ func (handler *CarouselHandler) GetCarousels(context *gin.Context) { func (handler *CarouselHandler) CreateCarousel(context *gin.Context) { ctx := context.Request.Context() var carousel types.Carousel - dbCarousel := lib.DeserializeCarousel(carousel) if err := context.ShouldBindJSON(&carousel); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbCarousel := lib.DeserializeCarousel(carousel) result, err := handler.service.CreateCarousel(ctx, &dbCarousel) if err != nil { log.Printf("Error creating carousel: %v", err) @@ -61,13 +61,12 @@ func (handler *CarouselHandler) UpdateCarousel(context *gin.Context) { id := context.Param("id") var carousel types.Carousel - dbCarousel := lib.DeserializeCarousel(carousel) - if err := context.ShouldBindJSON(&carousel); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbCarousel := lib.DeserializeCarousel(carousel) result, err := handler.service.UpdateCarousel(ctx, id, &dbCarousel) if err != nil { log.Printf("Error updating carousel: %v", err) diff --git a/server/handlers/employeeHandler.go b/server/handlers/employeeHandler.go index ff1e6af..8c3e22e 100644 --- a/server/handlers/employeeHandler.go +++ b/server/handlers/employeeHandler.go @@ -33,7 +33,6 @@ func (handler *EmployeeHandler) GetEmployees(context *gin.Context) { func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { ctx := context.Request.Context() var employee types.Employee - dbEmployee := lib.DeserializeEmployee(employee) if err := context.ShouldBindJSON(&employee); err != nil { log.Printf("Error creating employee: %v", err) @@ -41,6 +40,7 @@ func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { return } + dbEmployee := lib.DeserializeEmployee(employee) result, err := handler.service.CreateEmployee(ctx, &dbEmployee) if err != nil { log.Printf("Error creating employee: %v", err) @@ -60,15 +60,15 @@ func (handler *EmployeeHandler) CreateEmployee(context *gin.Context) { func (handler *EmployeeHandler) UpdateEmployee(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var employee types.Employee - dbEmployee := lib.DeserializeEmployee(employee) + var employee types.Employee if err := context.ShouldBindJSON(&employee); err != nil { log.Printf("Error creating employee: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbEmployee := lib.DeserializeEmployee(employee) result, err := handler.service.UpdateEmployee(ctx, id, &dbEmployee) if err != nil { log.Printf("Error creating employee: %v", err) From 4a9490c936986e37ee9617801970fb78e63b2ad1 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:08:32 +0100 Subject: [PATCH 234/248] more handlers --- server/handlers/exhibitionHandler.go | 5 ++--- server/handlers/lineItemHandler.go | 6 +++--- server/handlers/machineHandler.go | 7 ++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/server/handlers/exhibitionHandler.go b/server/handlers/exhibitionHandler.go index 326b1a4..bde3166 100644 --- a/server/handlers/exhibitionHandler.go +++ b/server/handlers/exhibitionHandler.go @@ -33,13 +33,13 @@ func (handler *ExhibitionHandler) GetExhibitions(context *gin.Context) { func (handler *ExhibitionHandler) CreateExhibition(context *gin.Context) { ctx := context.Request.Context() var exhibition types.Exhibition - dbExhibition := lib.DeserializeExhibition(exhibition) if err := context.ShouldBindJSON(&exhibition); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbExhibition := lib.DeserializeExhibition(exhibition) if err := handler.service.CreateExhibition(ctx, &dbExhibition); err != nil { log.Printf("error occurred while creating exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating exhibition", "details": err.Error()}) @@ -54,13 +54,12 @@ func (handler *ExhibitionHandler) UpdateExhibition(context *gin.Context) { id := context.Param("id") var exhibition types.Exhibition - dbExhibition := lib.DeserializeExhibition(exhibition) - if err := context.ShouldBindJSON(&exhibition); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body", "details": err.Error()}) return } + dbExhibition := lib.DeserializeExhibition(exhibition) if err := handler.service.UpdateExhibition(ctx, id, &dbExhibition); err != nil { log.Printf("error occurred while updating exhibition: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating exhibition", "details": err.Error()}) diff --git a/server/handlers/lineItemHandler.go b/server/handlers/lineItemHandler.go index 69175d2..dbdb240 100644 --- a/server/handlers/lineItemHandler.go +++ b/server/handlers/lineItemHandler.go @@ -47,7 +47,6 @@ func (handler *LineItemHandler) GetLineItemById(context *gin.Context) { func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { ctx := context.Request.Context() var lineItem types.LineItem - dbLineItem := lib.DeserializeLineItem(lineItem) if err := context.ShouldBindJSON(&lineItem); err != nil { log.Printf("error when creating lineItem: %v", err) @@ -55,6 +54,7 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { return } + dbLineItem := lib.DeserializeLineItem(lineItem) result, err := handler.service.CreateLineItem(ctx, &dbLineItem) if err != nil { log.Printf("error when creating lineItem: %v", err) @@ -73,15 +73,15 @@ func (handler *LineItemHandler) CreateLineItem(context *gin.Context) { func (handler *LineItemHandler) UpdateLineItem(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var lineItem types.LineItem - dbLineItem := lib.DeserializeLineItem(lineItem) + var lineItem types.LineItem if err := context.ShouldBindJSON(&lineItem); err != nil { log.Printf("error when updating lineItem: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred while updating lineItem - bad request"}) return } + dbLineItem := lib.DeserializeLineItem(lineItem) result, err := handler.service.UpdateLineItem(ctx, id, &dbLineItem) if err != nil { log.Printf("error when updating lineItem: %v", err) diff --git a/server/handlers/machineHandler.go b/server/handlers/machineHandler.go index e4f6121..dce2586 100644 --- a/server/handlers/machineHandler.go +++ b/server/handlers/machineHandler.go @@ -49,18 +49,17 @@ func (handler *MachineHandler) GetMachineById(context *gin.Context) { func (handler *MachineHandler) CreateMachine(context *gin.Context) { ctx := context.Request.Context() var machine types.Machine - dbMachine := lib.DeserializeMachine(machine) if err := context.ShouldBindJSON(&machine); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - if machine.SupplierID == "" || machine.SupplierID == "null" { context.JSON(http.StatusBadRequest, gin.H{"error": "SupplierID cannot be empty"}) return } + dbMachine := lib.DeserializeMachine(machine) result, err := handler.service.CreateMachine(ctx, &dbMachine) if err != nil { log.Printf("Error creating machine: %v", err) @@ -82,18 +81,16 @@ func (handler *MachineHandler) UpdateMachine(context *gin.Context) { id := context.Param("id") var machine types.Machine - dbMachine := lib.DeserializeMachine(machine) - if err := context.ShouldBindJSON(&machine); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body", "details": err.Error()}) return } - if machine.SupplierID == "" || machine.SupplierID == "null" { context.JSON(http.StatusBadRequest, gin.H{"error": "SupplierID cannot be empty"}) return } + dbMachine := lib.DeserializeMachine(machine) result, err := handler.service.UpdateMachine(ctx, id, &dbMachine) if err != nil { log.Printf("Error updating machine: %v", err) From b99a465abf81e9ed609db7c7d8d1bbcd1eac54b8 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 14:19:31 +0100 Subject: [PATCH 235/248] go mods --- server/go.mod | 71 ++++++++------ server/go.sum | 252 ++++++++++++++++++++++---------------------------- 2 files changed, 155 insertions(+), 168 deletions(-) diff --git a/server/go.mod b/server/go.mod index f7f06c3..c9bde60 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,13 +1,15 @@ module github.com/sean-david-welch/farmec-v2/server -go 1.22.0 +go 1.22.7 + +toolchain go1.23.2 require ( firebase.google.com/go v3.13.0+incompatible github.com/DATA-DOG/go-sqlmock v1.5.2 github.com/aws/aws-sdk-go-v2 v1.32.2 - github.com/aws/aws-sdk-go-v2/config v1.27.3 - github.com/aws/aws-sdk-go-v2/credentials v1.17.3 + github.com/aws/aws-sdk-go-v2/config v1.28.0 + github.com/aws/aws-sdk-go-v2/credentials v1.17.41 github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 github.com/aws/smithy-go v1.22.0 github.com/gin-contrib/cors v1.7.2 @@ -22,65 +24,79 @@ require ( ) require ( + cel.dev/expr v0.16.2 // indirect cloud.google.com/go v0.116.0 // indirect - cloud.google.com/go/compute v1.28.1 // indirect + cloud.google.com/go/auth v0.9.8 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect cloud.google.com/go/compute/metadata v0.5.2 // indirect cloud.google.com/go/firestore v1.17.0 // indirect cloud.google.com/go/iam v1.2.1 // indirect cloud.google.com/go/longrunning v0.6.1 // indirect - cloud.google.com/go/storage v1.43.0 // indirect + cloud.google.com/go/monitoring v1.21.1 // indirect + cloud.google.com/go/storage v1.45.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.3 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.3 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.3 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect - github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.20.0 // indirect - github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0 // indirect - github.com/aws/aws-sdk-go-v2/service/sts v1.28.0 // indirect - github.com/bytedance/sonic v1.11.6 // indirect - github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 // indirect + github.com/bytedance/sonic v1.12.3 // indirect + github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect + github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/envoyproxy/go-control-plane v0.13.1 // indirect + github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gabriel-vasile/mimetype v1.4.6 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.20.0 // indirect - github.com/goccy/go-json v0.10.2 // indirect + github.com/go-playground/validator/v10 v10.22.1 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect github.com/googleapis/gax-go/v2 v2.13.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/klauspost/cpuid/v2 v2.2.8 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect - go.opentelemetry.io/otel v1.29.0 // indirect - go.opentelemetry.io/otel/metric v1.29.0 // indirect - go.opentelemetry.io/otel/trace v1.29.0 // indirect - golang.org/x/arch v0.8.0 // indirect + go.opentelemetry.io/contrib/detectors/gcp v1.31.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/sdk v1.31.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.31.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect + golang.org/x/arch v0.11.0 // indirect golang.org/x/crypto v0.28.0 // indirect golang.org/x/net v0.30.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect @@ -89,10 +105,11 @@ require ( golang.org/x/text v0.19.0 // indirect golang.org/x/time v0.7.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect + google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect google.golang.org/grpc v1.67.1 // indirect + google.golang.org/grpc/stats/opentelemetry v0.0.0-20241018153737-98959d9a4904 // indirect google.golang.org/protobuf v1.35.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/go.sum b/server/go.sum index 7ec0eed..9c6f33c 100644 --- a/server/go.sum +++ b/server/go.sum @@ -1,47 +1,57 @@ +cel.dev/expr v0.16.2 h1:RwRhoH17VhAu9U5CMvMhH1PDVgf0tuz9FT+24AfMLfU= +cel.dev/expr v0.16.2/go.mod h1:gXngZQMkWJoSbE8mOzehJlXQyubn/Vg0vR9/F3W7iw8= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM= -cloud.google.com/go v0.112.0/go.mod h1:3jEEVwZ/MHU4djK5t5RHuKOA/GbLddgTdVubX1qnPD4= cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE= cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U= -cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1YlVg= -cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40= -cloud.google.com/go/compute v1.28.1/go.mod h1:b72iXMY4FucVry3NR3Li4kVyyTvbMDE7x5WsqvxjsYk= -cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= -cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/auth v0.9.8 h1:+CSJ0Gw9iVeSENVCKJoLHhdUykDgXSc4Qn+gu2BRtR8= +cloud.google.com/go/auth v0.9.8/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI= +cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy19DBn6B6bY= +cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc= +cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= -cloud.google.com/go/firestore v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw= -cloud.google.com/go/firestore v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ= +cloud.google.com/go/firestore v1.17.0 h1:iEd1LBbkDZTFsLw3sTH50eyg4qe8eoG6CjocmEXO9aQ= cloud.google.com/go/firestore v1.17.0/go.mod h1:69uPx1papBsY8ZETooc71fOhoKkD70Q1DwMrtKuOT/Y= -cloud.google.com/go/iam v1.1.6 h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc= -cloud.google.com/go/iam v1.1.6/go.mod h1:O0zxdPeGBoFdWW3HWmBxJsk0pfvNM/p/qa82rWOGTwI= +cloud.google.com/go/iam v1.2.1 h1:QFct02HRb7H12J/3utj0qf5tobFh9V4vR6h9eX5EBRU= cloud.google.com/go/iam v1.2.1/go.mod h1:3VUIJDPpwT6p/amXRC5GY8fCCh70lxPygguVtI0Z4/g= -cloud.google.com/go/longrunning v0.5.5 h1:GOE6pZFdSrTb4KAiKnXsJBtlE6mEyaW44oKyMILWnOg= -cloud.google.com/go/longrunning v0.5.5/go.mod h1:WV2LAxD8/rg5Z1cNW6FJ/ZpX4E4VnDnoTk0yawPBB7s= +cloud.google.com/go/logging v1.11.0 h1:v3ktVzXMV7CwHq1MBF65wcqLMA7i+z3YxbUsoK7mOKs= +cloud.google.com/go/logging v1.11.0/go.mod h1:5LDiJC/RxTt+fHc1LAt20R9TKiUTReDg6RuuFOZ67+A= +cloud.google.com/go/longrunning v0.6.1 h1:lOLTFxYpr8hcRtcwWir5ITh1PAKUD/sG2lKrTSYjyMc= cloud.google.com/go/longrunning v0.6.1/go.mod h1:nHISoOZpBcmlwbJmiVk5oDRz0qG/ZxPynEGs1iZ79s0= -cloud.google.com/go/storage v1.38.0 h1:Az68ZRGlnNTpIBbLjSMIV2BDcwwXYlRlQzis0llkpJg= -cloud.google.com/go/storage v1.38.0/go.mod h1:tlUADB0mAb9BgYls9lq+8MGkfzOXuLrnHXlpHmvFJoY= -cloud.google.com/go/storage v1.43.0/go.mod h1:ajvxEa7WmZS1PxvKRq4bq0tFT3vMd502JwstCcYv0Q0= +cloud.google.com/go/monitoring v1.21.1 h1:zWtbIoBMnU5LP9A/fz8LmWMGHpk4skdfeiaa66QdFGc= +cloud.google.com/go/monitoring v1.21.1/go.mod h1:Rj++LKrlht9uBi8+Eb530dIrzG/cU/lB8mt+lbeFK1c= +cloud.google.com/go/storage v1.45.0 h1:5av0QcIVj77t+44mV4gffFC/LscFRUhto6UBMB5SimM= +cloud.google.com/go/storage v1.45.0/go.mod h1:wpPblkIuMP5jCB/E48Pz9zIo2S/zD8g+ITmxKkPCITE= +cloud.google.com/go/trace v1.11.1 h1:UNqdP+HYYtnm6lb91aNA5JQ0X14GnxkABGlfz2PzPew= +cloud.google.com/go/trace v1.11.1/go.mod h1:IQKNQuBzH72EGaXEodKlNJrWykGZxet2zgjtS60OtjA= firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.3 h1:cb3br57K508pQEFgBxn9GDhPS9HefpyMPK1RzmtMNzk= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.3/go.mod h1:itPGVDKf9cC/ov4MdvJ2QZ0khw4bfoo9jzwTJlaxy2k= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.3 h1:xir5X8TS8UBVPWg2jHL+cSTf0jZgqYQSA54TscSt1/0= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.3/go.mod h1:SsdWig2J5PMnfMvfJuEb1uZa8Y+kvNyvrULFo69gTFk= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.48.3 h1:Nl7phYyHjnqofWDpD+6FYdiwtNIxebn0AHLry7Sxb0M= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.48.3/go.mod h1:pNP/L2wDlaQnQlFvkDKGSruDoYRpmAxB6drgsskfYwg= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.3 h1:2vcVkrNdSMJpoOVAWi9ApsQR5iqNeFGt5Qx8Xlt3IoI= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.3/go.mod h1:wRbFgBQUVm1YXrvWKofAEmq9HNJTDphbAaJSSX01KUI= github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA= -github.com/aws/aws-sdk-go-v2/config v1.27.3 h1:0PRdb/q5a77HVYj+2rvPiCObfMfl/pWhwa5cs3cnl3c= -github.com/aws/aws-sdk-go-v2/config v1.27.3/go.mod h1:WeRAr9ENap9NAegbfNsLqGQd8ERz5ypdIUx4j0/ZgKI= -github.com/aws/aws-sdk-go-v2/credentials v1.17.3 h1:dDM5wrgwOL5gTZ0Gv/bvewPldjBcJywoaO5ClERrOGE= -github.com/aws/aws-sdk-go-v2/credentials v1.17.3/go.mod h1:G96Nuaw9qJS+s3OnK8RW8VEKEOjXi8H5Jk4lC/ZyZbw= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1 h1:lk1ZZFbdb24qpOwVC1AwYNrswUjAxeyey6kFBVANudQ= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.1/go.mod h1:/xJ6x1NehNGCX4tvGzzj2bq5TBOT/Yxq+qbL9Jpx2Vk= +github.com/aws/aws-sdk-go-v2/config v1.28.0 h1:FosVYWcqEtWNxHn8gB/Vs6jOlNwSoyOCA/g/sxyySOQ= +github.com/aws/aws-sdk-go-v2/config v1.28.0/go.mod h1:pYhbtvg1siOOg8h5an77rXle9tVG8T+BWLWAo7cOukc= +github.com/aws/aws-sdk-go-v2/credentials v1.17.41 h1:7gXo+Axmp+R4Z+AK8YFQO0ZV3L0gizGINCOWxSLY9W8= +github.com/aws/aws-sdk-go-v2/credentials v1.17.41/go.mod h1:u4Eb8d3394YLubphT4jLEwN1rLNq2wFOlT6OuxFwPzU= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 h1:TMH3f/SCAWdNtXXVPPu5D6wrr4G5hI1rAxbcocKfC7Q= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17/go.mod h1:1ZRXLdTpzdJb9fwTMXiLipENRxkGMTn1sfKexGllQCw= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= -github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= -github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21 h1:7edmS3VOBDhK00b/MwGtGglCm7hhwNYnjJs/PgFdMQE= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.21/go.mod h1:Q9o5h4HoIWG8XfzxqiuK/CGUbepCJ8uTlaE3bAbxytQ= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g= @@ -54,52 +64,55 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2 h1:t7iUP9+4wdc5lt github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.2/go.mod h1:/niFCtmuQNxqx9v8WAPq5qh7EH25U4BF6tjoyq9bObM= github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0 h1:xA6XhTF7PE89BCNHJbQi8VvPzcgMtmGC5dr8S8N7lHk= github.com/aws/aws-sdk-go-v2/service/s3 v1.66.0/go.mod h1:cB6oAuus7YXRZhWCc1wIwPywwZ1XwweNp2TVAEGYeB8= -github.com/aws/aws-sdk-go-v2/service/sso v1.20.0 h1:6YL8G91QZ52KlPrLkEgEez5kejIVwChVCgND3qgY5j0= -github.com/aws/aws-sdk-go-v2/service/sso v1.20.0/go.mod h1:x6/tCd1o/AOKQR+iYnjrzhJxD+w0xRN34asGPaSV7ew= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0 h1:+DqIa5Ll7W311QLUvGFDdVit9uC4G0VioDdw08cXcow= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.0/go.mod h1:lZB123q0SVQ3dfIbEOcGzhQHrwVBcHVReNS9tm20oU4= -github.com/aws/aws-sdk-go-v2/service/sts v1.28.0 h1:F7tQr61zYnTaeY50Rn4jwfVQbtcqJuBRwN/nGGNwzb0= -github.com/aws/aws-sdk-go-v2/service/sts v1.28.0/go.mod h1:ozhhG9/NB5c9jcmhGq6tX9dpp21LYdmRWRQVppASim4= +github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 h1:bSYXVyUzoTHoKalBmwaZxs97HU9DWWI3ehHSAMa7xOk= +github.com/aws/aws-sdk-go-v2/service/sso v1.24.2/go.mod h1:skMqY7JElusiOUjMJMOv1jJsP7YUg7DrhgqZZWuzu1U= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 h1:AhmO1fHINP9vFYUE0LHzCWg/LfUWUF+zFPEcY9QXb7o= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2/go.mod h1:o8aQygT2+MVP0NaV6kbdE1YnnIM8RRVQzoeUH45GOdI= +github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 h1:CiS7i0+FUe+/YY1GvIBLLrR/XNGZ4CtM1Ll0XavNuVo= +github.com/aws/aws-sdk-go-v2/service/sts v1.32.2/go.mod h1:HtaiBI8CjYoNVde8arShXb94UbQQi9L4EMr6D+xGBwo= github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= -github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= -github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= -github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU= +github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= +github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= +github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ= -github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 h1:QVw89YDxXxEe+l8gU8ETbOasdwEV+avkR75ZzsVV9WI= +github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.13.1 h1:vPfJZCkob6yTMEgS+0TwfTUfbHjfy/6vOJ8hUWX/uXE= +github.com/envoyproxy/go-control-plane v0.13.1/go.mod h1:X45hY0mufo6Fd0KW3rqsGvQMw58jvjymeCzBU3mWyHw= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= -github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= +github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM= +github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc= +github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc= github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw= github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= @@ -109,10 +122,10 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= -github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= +github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -129,8 +142,7 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -142,19 +154,16 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw= -github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= -github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= -github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc= +github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= -github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= +github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= -github.com/googleapis/gax-go/v2 v2.12.1 h1:9F8GV9r9ztXyAi00gsMQHNoF51xPZm8uj1dpYt2ZETM= -github.com/googleapis/gax-go/v2 v2.12.1/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= +github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDPT0hH1s= github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= @@ -162,19 +171,17 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= +github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= -github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -182,38 +189,32 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= -github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no= github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo= +github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/signintech/gopdf v0.22.0 h1:RyLMuDy6Ep0bGEfzePEKYuQ4jOcc5inn3WbU1egf8YA= -github.com/signintech/gopdf v0.22.0/go.mod h1:wrLtZoWaRNrS4hphED0oflFoa6IWkOu6M3nJjm4VbO4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/signintech/gopdf v0.28.0 h1:zCUlRuedALiKaZmEdLSoA4EPqjpnzLBP6co8fjA6C7Q= github.com/signintech/gopdf v0.28.0/go.mod h1:d23eO35GpEliSrF22eJ4bsM3wVeQJTjXTHq5x5qGKjA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/stripe/stripe-go/v76 v76.18.0 h1:MYUgecXPoUDJ36hjKtc8h2fzpj0MpRBrN9KGCULFTbg= -github.com/stripe/stripe-go/v76 v76.18.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4= github.com/stripe/stripe-go/v76 v76.25.0 h1:kmDoOTvdQSTQssQzWZQQkgbAR2Q8eXdMWbN/ylNalWA= github.com/stripe/stripe-go/v76 v76.25.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= @@ -223,35 +224,28 @@ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 h1:P+/g8GpuJGYbOp2tAdKrIPUX9JO02q8Q0YNlHolpibA= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0/go.mod h1:tIKj3DbO8N9Y2xo52og3irLsPI4GW02DSMtrVgNMgxg= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 h1:doUP+ExOpH3spVTLS0FcWGLnQrPct/hD/bCPbDRUEAU= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0/go.mod h1:rdENBZMT2OE6Ne/KLwpiXudnAsbdrdBaqBvTN8M8BgA= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0/go.mod h1:L7UH0GbB0p47T4Rri3uHjbpCFYrVrwc1I25QhNPiGK8= -go.opentelemetry.io/otel v1.23.1 h1:Za4UzOqJYS+MUczKI320AtqZHZb7EqxO00jAHE0jmQY= -go.opentelemetry.io/otel v1.23.1/go.mod h1:Td0134eafDLcTS4y+zQ26GE8u3dEuRBiBCTUIRHaikA= -go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= -go.opentelemetry.io/otel/metric v1.23.1 h1:PQJmqJ9u2QaJLBOELl1cxIdPcpbwzbkjfEyelTl2rlo= -go.opentelemetry.io/otel/metric v1.23.1/go.mod h1:mpG2QPlAfnK8yNhNJAxDZruU9Y1/HubbC+KyH8FaCWI= -go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= -go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= -go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.23.1 h1:4LrmmEd8AU2rFvU1zegmvqW7+kWarxtNOPyeL6HmYY8= -go.opentelemetry.io/otel/trace v1.23.1/go.mod h1:4IpnpJFwr1mo/6HL8XIPJaE9y0+u1KcVmuW7dwFSVrI= -go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= -golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= -golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +go.opentelemetry.io/contrib/detectors/gcp v1.31.0 h1:G1JQOreVrfhRkner+l4mrGxmfqYCAuy76asTDAo0xsA= +go.opentelemetry.io/contrib/detectors/gcp v1.31.0/go.mod h1:tzQL6E1l+iV44YFTkcAeNQqzXUiekSYP9jjJjXwEd00= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 h1:yMkBS9yViCc7U7yeLzJPM2XizlfdVvBRSmsQDWu6qc0= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0/go.mod h1:n8MR6/liuGB5EmTETUBeU5ZgqMOlqKRxUaqPQBOANZ8= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= +go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= +go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0= +go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc= +go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= +golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4= +golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -268,21 +262,16 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ= -golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -295,10 +284,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -307,13 +293,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ= golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -324,10 +306,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= -google.golang.org/api v0.166.0 h1:6m4NUwrZYhAaVIHZWxaKjw1L1vNAjtMwORmKRyEEo24= -google.golang.org/api v0.166.0/go.mod h1:4FcBc686KFi7QI/U51/2GKKevfZMpM17sCdibqe/bSA= google.golang.org/api v0.201.0 h1:+7AD9JNM3tREtawRMu8sOjSbb8VYcYXJG/2eEOmfDu0= google.golang.org/api v0.201.0/go.mod h1:HVY0FCHVs89xIW9fzf/pBvOEm+OolHa86G/txFezyq4= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= @@ -337,24 +315,21 @@ google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c h1:Zmyn5CV/jxzKnF+3d+xzbomACPwLQqVpLTpyXN5uTaQ= -google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= -google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 h1:nFS3IivktIU5Mk6KQa+v6RKkHUpdQpphqGNLxqNnbEk= -google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:tEzYTYZxbmVNOu0OAFH9HzdJtLn6h4Aj89zzlBCdHms= -google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c h1:9g7erC9qu44ks7UK4gDNlnk4kOxZG707xKm4jVniy6o= -google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8= -google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f/go.mod h1:CLGoBuH1VHxAUXVPP8FfPwPEVJB6lz3URE5mY2SuayE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53 h1:Df6WuGvthPzc+JiQ/G+m+sNX24kc0aTBqoDN/0yyykE= +google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53/go.mod h1:fheguH3Am2dGp1LfXkrvwqC/KlFq8F0nLq3LryOMrrE= +google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 h1:fVoAXEKA4+yufmbdVYv+SE73+cPZbbbe8paLsHfkK+U= +google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53/go.mod h1:riSXTwQ4+nqmPGtobMFyW5FqVAmIs0St6VPp4Ug7CE4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk= -google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/grpc/stats/opentelemetry v0.0.0-20241018153737-98959d9a4904 h1:Lplo3VKrYtWeryBkDI4SZ4kJTFaWO4qUGs+xX7N2bFc= +google.golang.org/grpc/stats/opentelemetry v0.0.0-20241018153737-98959d9a4904/go.mod h1:jzYlkSMbKypzuu6xoAEijsNVo9ZeDF1u/zCfFgsx7jg= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -366,10 +341,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= -google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -381,4 +352,3 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= From 594ec66120d739efb7efc1d118d1cdd87672f87a Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 15:26:57 +0100 Subject: [PATCH 236/248] update video service --- server/services/videoService.go | 50 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/server/services/videoService.go b/server/services/videoService.go index e770965..c18bad5 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -6,11 +6,10 @@ import ( "fmt" "github.com/sean-david-welch/farmec-v2/server/db" "github.com/sean-david-welch/farmec-v2/server/lib" - "github.com/sean-david-welch/farmec-v2/server/types" - "strings" - "github.com/sean-david-welch/farmec-v2/server/repository" + "github.com/sean-david-welch/farmec-v2/server/types" "google.golang.org/api/youtube/v3" + "regexp" ) type VideoService interface { @@ -33,21 +32,27 @@ func NewVideoService(repo repository.VideoRepo, service *youtube.Service) *Video } } -func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, error) { - splits := strings.Split(video.WebUrl.String, "v=") - if len(splits) < 2 { - return nil, fmt.Errorf("invalid web_url format") +func extractVideoID(urlStr string) (string, error) { + re := regexp.MustCompile(`(?:v=|/)([0-9A-Za-z_-]{11}).*`) + matches := re.FindStringSubmatch(urlStr) + if len(matches) > 1 { + return matches[1], nil } + return "", fmt.Errorf("invalid YouTube URL") +} - videoIdSplits := strings.Split(splits[1], "&") - if len(videoIdSplits) < 1 { - return nil, fmt.Errorf("invalid web_url format") +func (service *VideoServiceImpl) TransformData(ctx context.Context, video *db.Video) (*db.Video, error) { + if !video.WebUrl.Valid { + return nil, fmt.Errorf("web_url is invalid") } - videoId := videoIdSplits[0] + videoId, err := extractVideoID(video.WebUrl.String) + if err != nil { + return nil, err + } - call := service.service.Videos.List([]string{"id", "snippet"}).Id(videoId).MaxResults(1) - response, err := call.Do() + call := service.service.Videos.List([]string{"id", "snippet"}).Id(videoId) + response, err := call.Context(ctx).Do() if err != nil { return nil, fmt.Errorf("error calling YouTube API: %w", err) } @@ -57,6 +62,13 @@ func (service *VideoServiceImpl) TransformData(video *db.Video) (*db.Video, erro } item := response.Items[0] + if item.Snippet == nil { + return nil, fmt.Errorf("video snippet is missing in YouTube API response") + } + if item.Snippet.Thumbnails == nil || item.Snippet.Thumbnails.Medium == nil { + return nil, fmt.Errorf("video thumbnail is missing in YouTube API response") + } + videoData := &db.Video{ ID: video.ID, SupplierID: video.SupplierID, @@ -96,21 +108,15 @@ func (service *VideoServiceImpl) GetVideos(ctx context.Context, id string) ([]ty } func (service *VideoServiceImpl) CreateVideo(ctx context.Context, video *db.Video) error { - videoData, err := service.TransformData(video) - if err != nil { - return err - } - - err = service.repo.CreateVideo(ctx, videoData) + videoData, err := service.TransformData(ctx, video) if err != nil { return err } - - return nil + return service.repo.CreateVideo(ctx, videoData) } func (service *VideoServiceImpl) UpdateVideo(ctx context.Context, id string, video *db.Video) error { - videoData, err := service.TransformData(video) + videoData, err := service.TransformData(ctx, video) if err != nil { return err } From 67fb97ee7776639329216fda15899f585532b58a Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 15:31:54 +0100 Subject: [PATCH 237/248] repo --- server/repository/{blogStore.go => blogRepo.go} | 0 server/repository/{carouselStore.go => carouselRepo.go} | 0 server/repository/{employeeStore.go => employeeRepo.go} | 0 server/repository/{exhibitionStore.go => exhibitionRepo.go} | 0 server/repository/{lineitemStore.go => lineitemRepo.go} | 0 server/repository/{machineStore.go => machineRepo.go} | 0 server/repository/{partsStore.go => partsRepo.go} | 0 server/repository/{privacyStore.go => privacyRepo.go} | 0 server/repository/{productStore.go => productRepo.go} | 0 server/repository/{registrationStore.go => registrationRepo.go} | 0 server/repository/{supplierStore.go => supplierRepo.go} | 0 server/repository/{termsStore.go => termsRepo.go} | 0 server/repository/{timelineStore.go => timelineRepo.go} | 0 server/repository/{videoStore.go => videoRepo.go} | 0 server/repository/{warrantyStore.go => warrantyRepo.go} | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename server/repository/{blogStore.go => blogRepo.go} (100%) rename server/repository/{carouselStore.go => carouselRepo.go} (100%) rename server/repository/{employeeStore.go => employeeRepo.go} (100%) rename server/repository/{exhibitionStore.go => exhibitionRepo.go} (100%) rename server/repository/{lineitemStore.go => lineitemRepo.go} (100%) rename server/repository/{machineStore.go => machineRepo.go} (100%) rename server/repository/{partsStore.go => partsRepo.go} (100%) rename server/repository/{privacyStore.go => privacyRepo.go} (100%) rename server/repository/{productStore.go => productRepo.go} (100%) rename server/repository/{registrationStore.go => registrationRepo.go} (100%) rename server/repository/{supplierStore.go => supplierRepo.go} (100%) rename server/repository/{termsStore.go => termsRepo.go} (100%) rename server/repository/{timelineStore.go => timelineRepo.go} (100%) rename server/repository/{videoStore.go => videoRepo.go} (100%) rename server/repository/{warrantyStore.go => warrantyRepo.go} (100%) diff --git a/server/repository/blogStore.go b/server/repository/blogRepo.go similarity index 100% rename from server/repository/blogStore.go rename to server/repository/blogRepo.go diff --git a/server/repository/carouselStore.go b/server/repository/carouselRepo.go similarity index 100% rename from server/repository/carouselStore.go rename to server/repository/carouselRepo.go diff --git a/server/repository/employeeStore.go b/server/repository/employeeRepo.go similarity index 100% rename from server/repository/employeeStore.go rename to server/repository/employeeRepo.go diff --git a/server/repository/exhibitionStore.go b/server/repository/exhibitionRepo.go similarity index 100% rename from server/repository/exhibitionStore.go rename to server/repository/exhibitionRepo.go diff --git a/server/repository/lineitemStore.go b/server/repository/lineitemRepo.go similarity index 100% rename from server/repository/lineitemStore.go rename to server/repository/lineitemRepo.go diff --git a/server/repository/machineStore.go b/server/repository/machineRepo.go similarity index 100% rename from server/repository/machineStore.go rename to server/repository/machineRepo.go diff --git a/server/repository/partsStore.go b/server/repository/partsRepo.go similarity index 100% rename from server/repository/partsStore.go rename to server/repository/partsRepo.go diff --git a/server/repository/privacyStore.go b/server/repository/privacyRepo.go similarity index 100% rename from server/repository/privacyStore.go rename to server/repository/privacyRepo.go diff --git a/server/repository/productStore.go b/server/repository/productRepo.go similarity index 100% rename from server/repository/productStore.go rename to server/repository/productRepo.go diff --git a/server/repository/registrationStore.go b/server/repository/registrationRepo.go similarity index 100% rename from server/repository/registrationStore.go rename to server/repository/registrationRepo.go diff --git a/server/repository/supplierStore.go b/server/repository/supplierRepo.go similarity index 100% rename from server/repository/supplierStore.go rename to server/repository/supplierRepo.go diff --git a/server/repository/termsStore.go b/server/repository/termsRepo.go similarity index 100% rename from server/repository/termsStore.go rename to server/repository/termsRepo.go diff --git a/server/repository/timelineStore.go b/server/repository/timelineRepo.go similarity index 100% rename from server/repository/timelineStore.go rename to server/repository/timelineRepo.go diff --git a/server/repository/videoStore.go b/server/repository/videoRepo.go similarity index 100% rename from server/repository/videoStore.go rename to server/repository/videoRepo.go diff --git a/server/repository/warrantyStore.go b/server/repository/warrantyRepo.go similarity index 100% rename from server/repository/warrantyStore.go rename to server/repository/warrantyRepo.go From a3c6dedb078396ae9e82641820a73854494984ba Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 15:39:56 +0100 Subject: [PATCH 238/248] fix --- server/handlers/videoHandler.go | 3 +++ server/services/videoService.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index 7874555..54fc2c5 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/types" "log" @@ -35,6 +36,7 @@ func (handler *VideoHandler) GetVideos(context *gin.Context) { func (handler *VideoHandler) CreateVideo(context *gin.Context) { ctx := context.Request.Context() var video types.Video + fmt.Printf("video: %v", video) if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) @@ -42,6 +44,7 @@ func (handler *VideoHandler) CreateVideo(context *gin.Context) { } dbVideo := lib.DeserializeVideo(video) + fmt.Printf("videodb: %v", dbVideo) if err := handler.service.CreateVideo(ctx, &dbVideo); err != nil { log.Printf("Error creating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating video", "details": err.Error()}) diff --git a/server/services/videoService.go b/server/services/videoService.go index c18bad5..d85a5d0 100644 --- a/server/services/videoService.go +++ b/server/services/videoService.go @@ -13,7 +13,7 @@ import ( ) type VideoService interface { - TransformData(video *db.Video) (*db.Video, error) + TransformData(ctx context.Context, video *db.Video) (*db.Video, error) GetVideos(ctx context.Context, id string) ([]types.Video, error) CreateVideo(ctx context.Context, video *db.Video) error UpdateVideo(ctx context.Context, id string, video *db.Video) error From 0fc3b4107433d8ce322da044611599d4b6e7c00c Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 16:25:47 +0100 Subject: [PATCH 239/248] video type --- server/types/supplierTypes.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/types/supplierTypes.go b/server/types/supplierTypes.go index ddf1de7..25b85d8 100644 --- a/server/types/supplierTypes.go +++ b/server/types/supplierTypes.go @@ -52,3 +52,8 @@ type Video struct { ThumbnailURL *string `json:"thumbnail_url"` Created string `json:"created"` } + +type VideoRequest struct { + SupplierID string `json:"supplier_id"` + WebURL string `json:"web_url"` +} From 63abf4217369af6a7276b25e5acbac5df67fc6ff Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 16:28:52 +0100 Subject: [PATCH 240/248] handler and serializer --- server/handlers/videoHandler.go | 6 +++--- server/lib/deserializers.go | 12 +++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index 54fc2c5..e21cd5e 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -35,13 +35,13 @@ func (handler *VideoHandler) GetVideos(context *gin.Context) { func (handler *VideoHandler) CreateVideo(context *gin.Context) { ctx := context.Request.Context() - var video types.Video - fmt.Printf("video: %v", video) + var video types.VideoRequest if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } + fmt.Printf("video: %v", video) dbVideo := lib.DeserializeVideo(video) fmt.Printf("videodb: %v", dbVideo) @@ -58,7 +58,7 @@ func (handler *VideoHandler) UpdateVideo(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") - var video types.Video + var video types.VideoRequest if err := context.ShouldBindJSON(&video); err != nil { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return diff --git a/server/lib/deserializers.go b/server/lib/deserializers.go index 81f42c3..ea8505b 100644 --- a/server/lib/deserializers.go +++ b/server/lib/deserializers.go @@ -177,16 +177,10 @@ func DeserializeTimeline(timeline types.Timeline) db.Timeline { } } -func DeserializeVideo(video types.Video) db.Video { +func DeserializeVideo(video types.VideoRequest) db.Video { return db.Video{ - ID: video.ID, - SupplierID: video.SupplierID, - WebUrl: sql.NullString{String: video.WebURL, Valid: video.WebURL != ""}, - Title: sql.NullString{String: *video.Title, Valid: video.Title != nil}, - Description: sql.NullString{String: *video.Description, Valid: video.Description != nil}, - VideoID: sql.NullString{String: *video.VideoID, Valid: video.VideoID != nil}, - ThumbnailUrl: sql.NullString{String: *video.ThumbnailURL, Valid: video.ThumbnailURL != nil}, - Created: sql.NullString{String: video.Created, Valid: video.Created != ""}, + SupplierID: video.SupplierID, + WebUrl: sql.NullString{String: video.WebURL, Valid: video.WebURL != ""}, } } From 35979c23269fb6c1add27795b82982e0fc8ad6b9 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 16:33:27 +0100 Subject: [PATCH 241/248] remove --- server/handlers/videoHandler.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/handlers/videoHandler.go b/server/handlers/videoHandler.go index e21cd5e..92788b5 100644 --- a/server/handlers/videoHandler.go +++ b/server/handlers/videoHandler.go @@ -1,7 +1,6 @@ package handlers import ( - "fmt" "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/types" "log" @@ -41,10 +40,7 @@ func (handler *VideoHandler) CreateVideo(context *gin.Context) { context.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Request Body", "Details": err.Error()}) return } - fmt.Printf("video: %v", video) - dbVideo := lib.DeserializeVideo(video) - fmt.Printf("videodb: %v", dbVideo) if err := handler.service.CreateVideo(ctx, &dbVideo); err != nil { log.Printf("Error creating video: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "Error occurred while creating video", "details": err.Error()}) From c34f19648a4cff2de4e7808d38331427f340e809 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 16:44:13 +0100 Subject: [PATCH 242/248] fix warrantyHandler.go --- server/handlers/warrantyHandler.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/handlers/warrantyHandler.go b/server/handlers/warrantyHandler.go index 7689f1d..313c9eb 100644 --- a/server/handlers/warrantyHandler.go +++ b/server/handlers/warrantyHandler.go @@ -52,19 +52,19 @@ func (handler *WarrantyHandler) GetWarrantyById(context *gin.Context) { func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { ctx := context.Request.Context() + var warrantyParts types.WarranrtyParts - warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) var parts []db.PartsRequired - for _, part := range warrantyParts.Parts { - parts = append(parts, lib.DeserializePartsRequired(part)) - } - if err := context.ShouldBindJSON(&warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred bad request"}) return } + warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) + for _, part := range warrantyParts.Parts { + parts = append(parts, lib.DeserializePartsRequired(part)) + } if err := handler.service.CreateWarranty(ctx, &warranty, parts); err != nil { log.Printf("error occurred while creating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating warranty claim"}) @@ -77,19 +77,19 @@ func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { ctx := context.Request.Context() id := context.Param("id") + var warrantyParts types.WarranrtyParts - warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) var parts []db.PartsRequired - for _, part := range warrantyParts.Parts { - parts = append(parts, lib.DeserializePartsRequired(part)) - } - if err := context.ShouldBindJSON(warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred bad request"}) return } + for _, part := range warrantyParts.Parts { + parts = append(parts, lib.DeserializePartsRequired(part)) + } + warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) if err := handler.service.UpdateWarranty(ctx, id, &warranty, parts); err != nil { log.Printf("error occurred while updating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while updating warranty claim"}) From e37a00e229a38d6dc49291ec04436b2818f6b2d2 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 16:47:58 +0100 Subject: [PATCH 243/248] again --- server/handlers/warrantyHandler.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/handlers/warrantyHandler.go b/server/handlers/warrantyHandler.go index 313c9eb..166aa7f 100644 --- a/server/handlers/warrantyHandler.go +++ b/server/handlers/warrantyHandler.go @@ -54,17 +54,18 @@ func (handler *WarrantyHandler) CreateWarranty(context *gin.Context) { ctx := context.Request.Context() var warrantyParts types.WarranrtyParts - var parts []db.PartsRequired if err := context.ShouldBindJSON(&warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred bad request"}) return } - warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) + var parts []db.PartsRequired for _, part := range warrantyParts.Parts { parts = append(parts, lib.DeserializePartsRequired(part)) } + + warranty := lib.DeserializeWarrantyClaim(*warrantyParts.Warranty) if err := handler.service.CreateWarranty(ctx, &warranty, parts); err != nil { log.Printf("error occurred while creating warranty: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while creating warranty claim"}) @@ -79,12 +80,13 @@ func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { id := context.Param("id") var warrantyParts types.WarranrtyParts - var parts []db.PartsRequired if err := context.ShouldBindJSON(warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred bad request"}) return } + + var parts []db.PartsRequired for _, part := range warrantyParts.Parts { parts = append(parts, lib.DeserializePartsRequired(part)) } From cc9abfd08965b65e7c04337a003d075a6a52d007 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 16:53:52 +0100 Subject: [PATCH 244/248] pointer --- server/handlers/warrantyHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handlers/warrantyHandler.go b/server/handlers/warrantyHandler.go index 166aa7f..b662eae 100644 --- a/server/handlers/warrantyHandler.go +++ b/server/handlers/warrantyHandler.go @@ -80,7 +80,7 @@ func (handler *WarrantyHandler) UpdateWarranty(context *gin.Context) { id := context.Param("id") var warrantyParts types.WarranrtyParts - if err := context.ShouldBindJSON(warrantyParts); err != nil { + if err := context.ShouldBindJSON(&warrantyParts); err != nil { log.Printf("error occurred - bad request: %v", err) context.JSON(http.StatusBadRequest, gin.H{"error": "error occurred bad request"}) return From e4f9685a61c0b362bb81168a6e8c2f6bec8f2f3b Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 17:10:55 +0100 Subject: [PATCH 245/248] warranty email async --- server/services/warrantyService.go | 67 ++++++++++++------------------ 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/server/services/warrantyService.go b/server/services/warrantyService.go index d260bd4..39ec16d 100644 --- a/server/services/warrantyService.go +++ b/server/services/warrantyService.go @@ -6,6 +6,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" + "log" "net/smtp" ) @@ -26,6 +27,30 @@ func NewWarrantyService(repo repository.WarrantyRepo, smtpClient lib.SMTPClient) return &WarrantyServiceImpl{repo: repo, smtpClient: smtpClient} } +func (service *WarrantyServiceImpl) sendWarrantyEmail(warranty *db.WarrantyClaim) { + client, err := service.smtpClient.SetupSMTPClient() + if err != nil { + log.Printf("Failed to setup SMTP client: %v", err) + return + } + defer func(client *smtp.Client) { + if err := client.Close(); err != nil { + log.Printf("Failed to close SMTP client: %v", err) + } + }(client) + + data := &types.EmailData{ + Name: warranty.OwnerName, + Email: warranty.Dealer, + Message: warranty.MachineModel, + } + + if err := service.smtpClient.SendFormNotification(client, data, "Warranty"); err != nil { + log.Printf("Failed to send warranty email: %v", err) + return + } +} + func (service *WarrantyServiceImpl) GetWarranties(ctx context.Context) ([]types.DealerOwnerInfo, error) { warranties, err := service.repo.GetWarranties(ctx) if err != nil { @@ -53,26 +78,7 @@ func (service *WarrantyServiceImpl) CreateWarranty(ctx context.Context, warranty return err } - client, err := service.smtpClient.SetupSMTPClient() - if err != nil { - return err - } - defer func(client *smtp.Client) { - err := client.Close() - if err != nil { - return - } - }(client) - - data := &types.EmailData{ - Name: warranty.OwnerName, - Email: warranty.Dealer, - Message: warranty.MachineModel, - } - - if err := service.smtpClient.SendFormNotification(client, data, "Warranty"); err != nil { - return err - } + go service.sendWarrantyEmail(warranty) return nil } @@ -82,26 +88,7 @@ func (service *WarrantyServiceImpl) UpdateWarranty(ctx context.Context, id strin return err } - client, err := service.smtpClient.SetupSMTPClient() - if err != nil { - return err - } - defer func(client *smtp.Client) { - err := client.Close() - if err != nil { - return - } - }(client) - - data := &types.EmailData{ - Name: warranty.OwnerName, - Email: warranty.Dealer, - Message: warranty.MachineModel, - } - - if err := service.smtpClient.SendFormNotification(client, data, "Warranty"); err != nil { - return err - } + go service.sendWarrantyEmail(warranty) return nil } From d51512fcefd84d768a6304a2974d2f75b15c1c2b Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 17:12:27 +0100 Subject: [PATCH 246/248] reg service email --- server/services/registrationService.go | 68 ++++++++++---------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/server/services/registrationService.go b/server/services/registrationService.go index 32a4351..7ef9aa1 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -6,6 +6,7 @@ import ( "github.com/sean-david-welch/farmec-v2/server/lib" "github.com/sean-david-welch/farmec-v2/server/repository" "github.com/sean-david-welch/farmec-v2/server/types" + "log" "net/smtp" ) @@ -22,6 +23,30 @@ type RegistrationServiceImpl struct { repo repository.RegistrationRepo } +func (service *RegistrationServiceImpl) sendRegistrationEmail(registration *db.MachineRegistration) { + client, err := service.smtpClient.SetupSMTPClient() + if err != nil { + log.Printf("Failed to setup SMTP client: %v", err) + return + } + defer func(client *smtp.Client) { + if err := client.Close(); err != nil { + log.Printf("Failed to close SMTP client: %v", err) + } + }(client) + + data := &types.EmailData{ + Name: registration.OwnerName, + Email: registration.DealerName, + Message: registration.MachineModel, + } + + if err := service.smtpClient.SendFormNotification(client, data, "Machine Registration"); err != nil { + log.Printf("Failed to send registration email: %v", err) + return + } +} + func NewRegistrationService(repo repository.RegistrationRepo, smtpClient lib.SMTPClient) *RegistrationServiceImpl { return &RegistrationServiceImpl{repo: repo, smtpClient: smtpClient} } @@ -46,32 +71,12 @@ func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, result := lib.SerializeMachineRegistration(*registration) return &result, nil } - func (service *RegistrationServiceImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { if err := service.repo.CreateRegistration(ctx, registration); err != nil { return err } - client, err := service.smtpClient.SetupSMTPClient() - if err != nil { - return err - } - defer func(client *smtp.Client) { - err := client.Close() - if err != nil { - return - } - }(client) - - data := &types.EmailData{ - Name: registration.OwnerName, - Email: registration.DealerName, - Message: registration.MachineModel, - } - - if err := service.smtpClient.SendFormNotification(client, data, "Machine Registration"); err != nil { - return err - } + go service.sendRegistrationEmail(registration) return nil } @@ -81,26 +86,7 @@ func (service *RegistrationServiceImpl) UpdateRegistration(ctx context.Context, return err } - client, err := service.smtpClient.SetupSMTPClient() - if err != nil { - return err - } - defer func(client *smtp.Client) { - err := client.Close() - if err != nil { - return - } - }(client) - - data := &types.EmailData{ - Name: registration.OwnerName, - Email: registration.DealerName, - Message: registration.MachineModel, - } - - if err := service.smtpClient.SendFormNotification(client, data, "Machine Registration"); err != nil { - return err - } + go service.sendRegistrationEmail(registration) return nil } From d1ba281b11d26bb7fad9f83e201f6c98bc309e10 Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sat, 19 Oct 2024 17:13:28 +0100 Subject: [PATCH 247/248] better --- server/services/registrationService.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/services/registrationService.go b/server/services/registrationService.go index 7ef9aa1..9c38058 100644 --- a/server/services/registrationService.go +++ b/server/services/registrationService.go @@ -71,6 +71,7 @@ func (service *RegistrationServiceImpl) GetRegistrationById(ctx context.Context, result := lib.SerializeMachineRegistration(*registration) return &result, nil } + func (service *RegistrationServiceImpl) CreateRegistration(ctx context.Context, registration *db.MachineRegistration) error { if err := service.repo.CreateRegistration(ctx, registration); err != nil { return err From c7c9c643c1fd13fb90c79b932d42ba95be74cdef Mon Sep 17 00:00:00 2001 From: Sean Welch Date: Sun, 20 Oct 2024 13:27:32 +0100 Subject: [PATCH 248/248] type --- server/handlers/warrantyHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/handlers/warrantyHandler.go b/server/handlers/warrantyHandler.go index b662eae..3dd288c 100644 --- a/server/handlers/warrantyHandler.go +++ b/server/handlers/warrantyHandler.go @@ -37,7 +37,7 @@ func (handler *WarrantyHandler) GetWarrantyById(context *gin.Context) { warranty, parts, err := handler.service.GetWarrantyById(ctx, id) if err != nil { - log.Printf("error occurred while getting warrantiy and adjoining parts: %v", err) + log.Printf("error occurred while getting warranty and adjoining parts: %v", err) context.JSON(http.StatusInternalServerError, gin.H{"error": "error occurred while getting warrantiy and adjoining parts"}) return }