From dcd0024969603216df377b67d76fc500d6cd1bc8 Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sat, 16 Nov 2024 02:53:54 -0500 Subject: [PATCH 1/6] override uuid to string --- db/company.sql.go | 6 +-- db/company_documents.sql.go | 14 +++--- db/company_financials.sql.go | 12 +++--- db/company_questions_answers.sql.go | 34 +++++++-------- db/employee.sql.go | 10 ++--- db/funding_transactions.sql.go | 10 ++--- db/meetings.sql.go | 12 +++--- db/models.go | 66 ++++++++++++++--------------- db/projects.sql.go | 54 +++++++++++------------ db/resource_requests.sql.go | 10 ++--- db/tags.sql.go | 6 +-- db/users.sql.go | 2 +- go.mod | 3 +- go.sum | 2 - internal/server/auth.go | 13 +++--- internal/server/handler_helpers.go | 12 +++--- internal/server/startup.go | 6 +-- sqlc.yml | 3 ++ 18 files changed, 134 insertions(+), 141 deletions(-) diff --git a/db/company.sql.go b/db/company.sql.go index a8d0bc3..0a1ad79 100644 --- a/db/company.sql.go +++ b/db/company.sql.go @@ -33,7 +33,7 @@ RETURNING id, owner_user_id, name, description, is_verified, created_at, updated ` type CreateCompanyParams struct { - OwnerUserID pgtype.UUID + OwnerUserID string Name string Description pgtype.Text } @@ -60,7 +60,7 @@ WHERE id = $1 ` // TODO: Add + use auth to ensure only company owners can delete -func (q *Queries) DeleteCompany(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteCompany(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteCompany, id) return err } @@ -71,7 +71,7 @@ FROM companies WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetCompanyByID(ctx context.Context, id pgtype.UUID) (Company, error) { +func (q *Queries) GetCompanyByID(ctx context.Context, id string) (Company, error) { row := q.db.QueryRow(ctx, getCompanyByID, id) var i Company err := row.Scan( diff --git a/db/company_documents.sql.go b/db/company_documents.sql.go index 36b107f..c3eb816 100644 --- a/db/company_documents.sql.go +++ b/db/company_documents.sql.go @@ -7,8 +7,6 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" ) const createCompanyDocument = `-- name: CreateCompanyDocument :one @@ -23,7 +21,7 @@ RETURNING id, company_id, document_type, file_url, created_at, updated_at ` type CreateCompanyDocumentParams struct { - CompanyID pgtype.UUID + CompanyID string DocumentType string FileUrl string } @@ -47,7 +45,7 @@ DELETE FROM company_documents WHERE id = $1 ` -func (q *Queries) DeleteCompanyDocument(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteCompanyDocument(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteCompanyDocument, id) return err } @@ -57,7 +55,7 @@ SELECT id, company_id, document_type, file_url, created_at, updated_at FROM comp WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetCompanyDocumentByID(ctx context.Context, id pgtype.UUID) (CompanyDocument, error) { +func (q *Queries) GetCompanyDocumentByID(ctx context.Context, id string) (CompanyDocument, error) { row := q.db.QueryRow(ctx, getCompanyDocumentByID, id) var i CompanyDocument err := row.Scan( @@ -77,7 +75,7 @@ WHERE company_id = $1 ORDER BY created_at DESC ` -func (q *Queries) ListCompanyDocuments(ctx context.Context, companyID pgtype.UUID) ([]CompanyDocument, error) { +func (q *Queries) ListCompanyDocuments(ctx context.Context, companyID string) ([]CompanyDocument, error) { rows, err := q.db.Query(ctx, listCompanyDocuments, companyID) if err != nil { return nil, err @@ -111,7 +109,7 @@ ORDER BY created_at DESC ` type ListDocumentsByTypeParams struct { - CompanyID pgtype.UUID + CompanyID string DocumentType string } @@ -153,7 +151,7 @@ RETURNING id, company_id, document_type, file_url, created_at, updated_at ` type UpdateCompanyDocumentParams struct { - ID pgtype.UUID + ID string DocumentType string FileUrl string } diff --git a/db/company_financials.sql.go b/db/company_financials.sql.go index 0f48b22..c2d70d9 100644 --- a/db/company_financials.sql.go +++ b/db/company_financials.sql.go @@ -43,7 +43,7 @@ RETURNING id, company_id, financial_year, revenue, expenses, profit, sales, amou ` type CreateCompanyFinancialsParams struct { - CompanyID pgtype.UUID + CompanyID string FinancialYear int32 Revenue pgtype.Numeric Expenses pgtype.Numeric @@ -91,7 +91,7 @@ AND financial_year = $2 ` type DeleteCompanyFinancialsParams struct { - CompanyID pgtype.UUID + CompanyID string FinancialYear int32 } @@ -109,7 +109,7 @@ LIMIT 1 ` type GetCompanyFinancialsByYearParams struct { - CompanyID pgtype.UUID + CompanyID string FinancialYear int32 } @@ -141,7 +141,7 @@ ORDER BY financial_year DESC LIMIT 1 ` -func (q *Queries) GetLatestCompanyFinancials(ctx context.Context, companyID pgtype.UUID) (CompanyFinancial, error) { +func (q *Queries) GetLatestCompanyFinancials(ctx context.Context, companyID string) (CompanyFinancial, error) { row := q.db.QueryRow(ctx, getLatestCompanyFinancials, companyID) var i CompanyFinancial err := row.Scan( @@ -168,7 +168,7 @@ WHERE company_id = $1 ORDER BY financial_year DESC ` -func (q *Queries) ListCompanyFinancials(ctx context.Context, companyID pgtype.UUID) ([]CompanyFinancial, error) { +func (q *Queries) ListCompanyFinancials(ctx context.Context, companyID string) ([]CompanyFinancial, error) { rows, err := q.db.Query(ctx, listCompanyFinancials, companyID) if err != nil { return nil, err @@ -218,7 +218,7 @@ RETURNING id, company_id, financial_year, revenue, expenses, profit, sales, amou ` type UpdateCompanyFinancialsParams struct { - CompanyID pgtype.UUID + CompanyID string FinancialYear int32 Revenue pgtype.Numeric Expenses pgtype.Numeric diff --git a/db/company_questions_answers.sql.go b/db/company_questions_answers.sql.go index e219ab2..86ec273 100644 --- a/db/company_questions_answers.sql.go +++ b/db/company_questions_answers.sql.go @@ -23,8 +23,8 @@ RETURNING id, company_id, question_id, answer_text, created_at, updated_at, dele ` type CreateCompanyAnswerParams struct { - CompanyID pgtype.UUID - QuestionID pgtype.UUID + CompanyID string + QuestionID string AnswerText string } @@ -76,14 +76,14 @@ LIMIT 1 ` type GetCompanyAnswerParams struct { - CompanyID pgtype.UUID - QuestionID pgtype.UUID + CompanyID string + QuestionID string } type GetCompanyAnswerRow struct { - ID pgtype.UUID - CompanyID pgtype.UUID - QuestionID pgtype.UUID + ID string + CompanyID string + QuestionID string AnswerText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -113,7 +113,7 @@ WHERE id = $1 AND deleted_at IS NULL LIMIT 1 ` -func (q *Queries) GetQuestion(ctx context.Context, id pgtype.UUID) (Question, error) { +func (q *Queries) GetQuestion(ctx context.Context, id string) (Question, error) { row := q.db.QueryRow(ctx, getQuestion, id) var i Question err := row.Scan( @@ -137,9 +137,9 @@ ORDER BY cqa.created_at DESC ` type ListCompanyAnswersRow struct { - ID pgtype.UUID - CompanyID pgtype.UUID - QuestionID pgtype.UUID + ID string + CompanyID string + QuestionID string AnswerText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -147,7 +147,7 @@ type ListCompanyAnswersRow struct { QuestionText string } -func (q *Queries) ListCompanyAnswers(ctx context.Context, companyID pgtype.UUID) ([]ListCompanyAnswersRow, error) { +func (q *Queries) ListCompanyAnswers(ctx context.Context, companyID string) ([]ListCompanyAnswersRow, error) { rows, err := q.db.Query(ctx, listCompanyAnswers, companyID) if err != nil { return nil, err @@ -215,8 +215,8 @@ WHERE company_id = $1 AND question_id = $2 ` type SoftDeleteCompanyAnswerParams struct { - CompanyID pgtype.UUID - QuestionID pgtype.UUID + CompanyID string + QuestionID string } func (q *Queries) SoftDeleteCompanyAnswer(ctx context.Context, arg SoftDeleteCompanyAnswerParams) error { @@ -230,7 +230,7 @@ SET deleted_at = NOW() WHERE id = $1 ` -func (q *Queries) SoftDeleteQuestion(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) SoftDeleteQuestion(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, softDeleteQuestion, id) return err } @@ -245,8 +245,8 @@ RETURNING id, company_id, question_id, answer_text, created_at, updated_at, dele ` type UpdateCompanyAnswerParams struct { - CompanyID pgtype.UUID - QuestionID pgtype.UUID + CompanyID string + QuestionID string AnswerText string } diff --git a/db/employee.sql.go b/db/employee.sql.go index f9400f8..ac218ab 100644 --- a/db/employee.sql.go +++ b/db/employee.sql.go @@ -25,7 +25,7 @@ RETURNING id, company_id, name, email, role, bio, created_at, updated_at ` type CreateEmployeeParams struct { - CompanyID pgtype.UUID + CompanyID string Name string Email string Role string @@ -59,7 +59,7 @@ DELETE FROM employees WHERE id = $1 ` -func (q *Queries) DeleteEmployee(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteEmployee(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteEmployee, id) return err } @@ -90,7 +90,7 @@ SELECT id, company_id, name, email, role, bio, created_at, updated_at FROM emplo WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetEmployeeByID(ctx context.Context, id pgtype.UUID) (Employee, error) { +func (q *Queries) GetEmployeeByID(ctx context.Context, id string) (Employee, error) { row := q.db.QueryRow(ctx, getEmployeeByID, id) var i Employee err := row.Scan( @@ -146,7 +146,7 @@ WHERE company_id = $1 ORDER BY created_at DESC ` -func (q *Queries) ListEmployeesByCompany(ctx context.Context, companyID pgtype.UUID) ([]Employee, error) { +func (q *Queries) ListEmployeesByCompany(ctx context.Context, companyID string) ([]Employee, error) { rows, err := q.db.Query(ctx, listEmployeesByCompany, companyID) if err != nil { return nil, err @@ -187,7 +187,7 @@ RETURNING id, company_id, name, email, role, bio, created_at, updated_at ` type UpdateEmployeeParams struct { - ID pgtype.UUID + ID string Name string Role string Bio pgtype.Text diff --git a/db/funding_transactions.sql.go b/db/funding_transactions.sql.go index e78b3cf..b1723d5 100644 --- a/db/funding_transactions.sql.go +++ b/db/funding_transactions.sql.go @@ -27,7 +27,7 @@ RETURNING id, project_id, amount, currency, transaction_hash, from_wallet_addres ` type CreateFundingTransactionParams struct { - ProjectID pgtype.UUID + ProjectID string Amount pgtype.Numeric Currency string TransactionHash string @@ -67,7 +67,7 @@ DELETE FROM funding_transactions WHERE id = $1 ` -func (q *Queries) DeleteFundingTransaction(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteFundingTransaction(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteFundingTransaction, id) return err } @@ -77,7 +77,7 @@ SELECT id, project_id, amount, currency, transaction_hash, from_wallet_address, WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetFundingTransaction(ctx context.Context, id pgtype.UUID) (FundingTransaction, error) { +func (q *Queries) GetFundingTransaction(ctx context.Context, id string) (FundingTransaction, error) { row := q.db.QueryRow(ctx, getFundingTransaction, id) var i FundingTransaction err := row.Scan( @@ -137,7 +137,7 @@ WHERE project_id = $1 ORDER BY created_at DESC ` -func (q *Queries) ListProjectFundingTransactions(ctx context.Context, projectID pgtype.UUID) ([]FundingTransaction, error) { +func (q *Queries) ListProjectFundingTransactions(ctx context.Context, projectID string) ([]FundingTransaction, error) { rows, err := q.db.Query(ctx, listProjectFundingTransactions, projectID) if err != nil { return nil, err @@ -178,7 +178,7 @@ RETURNING id, project_id, amount, currency, transaction_hash, from_wallet_addres ` type UpdateFundingTransactionStatusParams struct { - ID pgtype.UUID + ID string Status string } diff --git a/db/meetings.sql.go b/db/meetings.sql.go index d45eea1..689b535 100644 --- a/db/meetings.sql.go +++ b/db/meetings.sql.go @@ -27,8 +27,8 @@ RETURNING id, project_id, scheduled_by_user_id, start_time, end_time, meeting_ur ` type CreateMeetingParams struct { - ProjectID pgtype.UUID - ScheduledByUserID pgtype.UUID + ProjectID string + ScheduledByUserID string StartTime pgtype.Timestamp EndTime pgtype.Timestamp MeetingUrl pgtype.Text @@ -67,7 +67,7 @@ DELETE FROM meetings WHERE id = $1 ` -func (q *Queries) DeleteMeeting(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteMeeting(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteMeeting, id) return err } @@ -77,7 +77,7 @@ SELECT id, project_id, scheduled_by_user_id, start_time, end_time, meeting_url, WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetMeeting(ctx context.Context, id pgtype.UUID) (Meeting, error) { +func (q *Queries) GetMeeting(ctx context.Context, id string) (Meeting, error) { row := q.db.QueryRow(ctx, getMeeting, id) var i Meeting err := row.Scan( @@ -137,7 +137,7 @@ WHERE project_id = $1 ORDER BY start_time DESC ` -func (q *Queries) ListProjectMeetings(ctx context.Context, projectID pgtype.UUID) ([]Meeting, error) { +func (q *Queries) ListProjectMeetings(ctx context.Context, projectID string) ([]Meeting, error) { rows, err := q.db.Query(ctx, listProjectMeetings, projectID) if err != nil { return nil, err @@ -182,7 +182,7 @@ RETURNING id, project_id, scheduled_by_user_id, start_time, end_time, meeting_ur ` type UpdateMeetingParams struct { - ID pgtype.UUID + ID string StartTime pgtype.Timestamp EndTime pgtype.Timestamp MeetingUrl pgtype.Text diff --git a/db/models.go b/db/models.go index e22402e..5301794 100644 --- a/db/models.go +++ b/db/models.go @@ -9,8 +9,8 @@ import ( ) type Company struct { - ID pgtype.UUID - OwnerUserID pgtype.UUID + ID string + OwnerUserID string Name string Description pgtype.Text IsVerified bool @@ -20,8 +20,8 @@ type Company struct { } type CompanyDocument struct { - ID pgtype.UUID - CompanyID pgtype.UUID + ID string + CompanyID string DocumentType string FileUrl string CreatedAt pgtype.Timestamp @@ -29,8 +29,8 @@ type CompanyDocument struct { } type CompanyFinancial struct { - ID pgtype.UUID - CompanyID pgtype.UUID + ID string + CompanyID string FinancialYear int32 Revenue pgtype.Numeric Expenses pgtype.Numeric @@ -44,9 +44,9 @@ type CompanyFinancial struct { } type CompanyQuestionAnswer struct { - ID pgtype.UUID - CompanyID pgtype.UUID - QuestionID pgtype.UUID + ID string + CompanyID string + QuestionID string AnswerText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -54,8 +54,8 @@ type CompanyQuestionAnswer struct { } type Employee struct { - ID pgtype.UUID - CompanyID pgtype.UUID + ID string + CompanyID string Name string Email string Role string @@ -65,8 +65,8 @@ type Employee struct { } type FundingTransaction struct { - ID pgtype.UUID - ProjectID pgtype.UUID + ID string + ProjectID string Amount pgtype.Numeric Currency string TransactionHash string @@ -78,9 +78,9 @@ type FundingTransaction struct { } type Meeting struct { - ID pgtype.UUID - ProjectID pgtype.UUID - ScheduledByUserID pgtype.UUID + ID string + ProjectID string + ScheduledByUserID string StartTime pgtype.Timestamp EndTime pgtype.Timestamp MeetingUrl pgtype.Text @@ -91,8 +91,8 @@ type Meeting struct { } type Project struct { - ID pgtype.UUID - CompanyID pgtype.UUID + ID string + CompanyID string Title string Description pgtype.Text Status string @@ -101,17 +101,17 @@ type Project struct { } type ProjectComment struct { - ID pgtype.UUID - ProjectID pgtype.UUID - UserID pgtype.UUID + ID string + ProjectID string + UserID string Comment string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } type ProjectFile struct { - ID pgtype.UUID - ProjectID pgtype.UUID + ID string + ProjectID string FileType string FileUrl string CreatedAt pgtype.Timestamp @@ -119,8 +119,8 @@ type ProjectFile struct { } type ProjectLink struct { - ID pgtype.UUID - ProjectID pgtype.UUID + ID string + ProjectID string LinkType string Url string CreatedAt pgtype.Timestamp @@ -128,14 +128,14 @@ type ProjectLink struct { } type ProjectTag struct { - ID pgtype.UUID - ProjectID pgtype.UUID - TagID pgtype.UUID + ID string + ProjectID string + TagID string CreatedAt pgtype.Timestamp } type Question struct { - ID pgtype.UUID + ID string QuestionText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -143,8 +143,8 @@ type Question struct { } type ResourceRequest struct { - ID pgtype.UUID - CompanyID pgtype.UUID + ID string + CompanyID string ResourceType string Description pgtype.Text Status string @@ -153,14 +153,14 @@ type ResourceRequest struct { } type Tag struct { - ID pgtype.UUID + ID string Name string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } type User struct { - ID pgtype.UUID + ID string Email string PasswordHash string FirstName pgtype.Text diff --git a/db/projects.sql.go b/db/projects.sql.go index 081f31d..c618c3e 100644 --- a/db/projects.sql.go +++ b/db/projects.sql.go @@ -22,8 +22,8 @@ RETURNING id, project_id, tag_id, created_at ` type AddProjectTagParams struct { - ProjectID pgtype.UUID - TagID pgtype.UUID + ProjectID string + TagID string } func (q *Queries) AddProjectTag(ctx context.Context, arg AddProjectTagParams) (ProjectTag, error) { @@ -51,7 +51,7 @@ RETURNING id, company_id, title, description, status, created_at, updated_at ` type CreateProjectParams struct { - CompanyID pgtype.UUID + CompanyID string Title string Description pgtype.Text Status string @@ -89,8 +89,8 @@ RETURNING id, project_id, user_id, comment, created_at, updated_at ` type CreateProjectCommentParams struct { - ProjectID pgtype.UUID - UserID pgtype.UUID + ProjectID string + UserID string Comment string } @@ -120,7 +120,7 @@ RETURNING id, project_id, file_type, file_url, created_at, updated_at ` type CreateProjectFileParams struct { - ProjectID pgtype.UUID + ProjectID string FileType string FileUrl string } @@ -151,7 +151,7 @@ RETURNING id, project_id, link_type, url, created_at, updated_at ` type CreateProjectLinkParams struct { - ProjectID pgtype.UUID + ProjectID string LinkType string Url string } @@ -175,7 +175,7 @@ DELETE FROM project_tags WHERE project_id = $1 ` -func (q *Queries) DeleteAllProjectTags(ctx context.Context, projectID pgtype.UUID) error { +func (q *Queries) DeleteAllProjectTags(ctx context.Context, projectID string) error { _, err := q.db.Exec(ctx, deleteAllProjectTags, projectID) return err } @@ -185,7 +185,7 @@ DELETE FROM projects WHERE id = $1 ` -func (q *Queries) DeleteProject(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteProject(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteProject, id) return err } @@ -195,7 +195,7 @@ DELETE FROM project_comments WHERE id = $1 ` -func (q *Queries) DeleteProjectComment(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteProjectComment(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteProjectComment, id) return err } @@ -205,7 +205,7 @@ DELETE FROM project_files WHERE id = $1 ` -func (q *Queries) DeleteProjectFile(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteProjectFile(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteProjectFile, id) return err } @@ -215,7 +215,7 @@ DELETE FROM project_links WHERE id = $1 ` -func (q *Queries) DeleteProjectLink(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteProjectLink(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteProjectLink, id) return err } @@ -226,8 +226,8 @@ WHERE project_id = $1 AND tag_id = $2 ` type DeleteProjectTagParams struct { - ProjectID pgtype.UUID - TagID pgtype.UUID + ProjectID string + TagID string } func (q *Queries) DeleteProjectTag(ctx context.Context, arg DeleteProjectTagParams) error { @@ -240,7 +240,7 @@ SELECT id, company_id, title, description, status, created_at, updated_at FROM p WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetProject(ctx context.Context, id pgtype.UUID) (Project, error) { +func (q *Queries) GetProject(ctx context.Context, id string) (Project, error) { row := q.db.QueryRow(ctx, getProject, id) var i Project err := row.Scan( @@ -268,9 +268,9 @@ ORDER BY pc.created_at DESC ` type GetProjectCommentsRow struct { - ID pgtype.UUID - ProjectID pgtype.UUID - UserID pgtype.UUID + ID string + ProjectID string + UserID string Comment string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -279,7 +279,7 @@ type GetProjectCommentsRow struct { Email string } -func (q *Queries) GetProjectComments(ctx context.Context, projectID pgtype.UUID) ([]GetProjectCommentsRow, error) { +func (q *Queries) GetProjectComments(ctx context.Context, projectID string) ([]GetProjectCommentsRow, error) { rows, err := q.db.Query(ctx, getProjectComments, projectID) if err != nil { return nil, err @@ -315,7 +315,7 @@ WHERE project_id = $1 ORDER BY created_at DESC ` -func (q *Queries) ListProjectFiles(ctx context.Context, projectID pgtype.UUID) ([]ProjectFile, error) { +func (q *Queries) ListProjectFiles(ctx context.Context, projectID string) ([]ProjectFile, error) { rows, err := q.db.Query(ctx, listProjectFiles, projectID) if err != nil { return nil, err @@ -348,7 +348,7 @@ WHERE project_id = $1 ORDER BY created_at DESC ` -func (q *Queries) ListProjectLinks(ctx context.Context, projectID pgtype.UUID) ([]ProjectLink, error) { +func (q *Queries) ListProjectLinks(ctx context.Context, projectID string) ([]ProjectLink, error) { rows, err := q.db.Query(ctx, listProjectLinks, projectID) if err != nil { return nil, err @@ -386,14 +386,14 @@ ORDER BY t.name ` type ListProjectTagsRow struct { - ID pgtype.UUID - ProjectID pgtype.UUID - TagID pgtype.UUID + ID string + ProjectID string + TagID string CreatedAt pgtype.Timestamp TagName string } -func (q *Queries) ListProjectTags(ctx context.Context, projectID pgtype.UUID) ([]ListProjectTagsRow, error) { +func (q *Queries) ListProjectTags(ctx context.Context, projectID string) ([]ListProjectTagsRow, error) { rows, err := q.db.Query(ctx, listProjectTags, projectID) if err != nil { return nil, err @@ -458,7 +458,7 @@ WHERE company_id = $1 ORDER BY created_at DESC ` -func (q *Queries) ListProjectsByCompany(ctx context.Context, companyID pgtype.UUID) ([]Project, error) { +func (q *Queries) ListProjectsByCompany(ctx context.Context, companyID string) ([]Project, error) { rows, err := q.db.Query(ctx, listProjectsByCompany, companyID) if err != nil { return nil, err @@ -498,7 +498,7 @@ RETURNING id, company_id, title, description, status, created_at, updated_at ` type UpdateProjectParams struct { - ID pgtype.UUID + ID string Title string Description pgtype.Text Status string diff --git a/db/resource_requests.sql.go b/db/resource_requests.sql.go index e468bfb..f55d2f1 100644 --- a/db/resource_requests.sql.go +++ b/db/resource_requests.sql.go @@ -33,7 +33,7 @@ RETURNING id, company_id, resource_type, description, status, created_at, update ` type CreateResourceRequestParams struct { - CompanyID pgtype.UUID + CompanyID string ResourceType string Description pgtype.Text Status string @@ -64,7 +64,7 @@ DELETE FROM resource_requests WHERE id = $1 ` -func (q *Queries) DeleteResourceRequest(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteResourceRequest(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteResourceRequest, id) return err } @@ -74,7 +74,7 @@ SELECT id, company_id, resource_type, description, status, created_at, updated_a WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetResourceRequestByID(ctx context.Context, id pgtype.UUID) (ResourceRequest, error) { +func (q *Queries) GetResourceRequestByID(ctx context.Context, id string) (ResourceRequest, error) { row := q.db.QueryRow(ctx, getResourceRequestByID, id) var i ResourceRequest err := row.Scan( @@ -128,7 +128,7 @@ WHERE company_id = $1 ORDER BY updated_at DESC ` -func (q *Queries) ListResourceRequestsByCompany(ctx context.Context, companyID pgtype.UUID) ([]ResourceRequest, error) { +func (q *Queries) ListResourceRequestsByCompany(ctx context.Context, companyID string) ([]ResourceRequest, error) { rows, err := q.db.Query(ctx, listResourceRequestsByCompany, companyID) if err != nil { return nil, err @@ -166,7 +166,7 @@ RETURNING id, company_id, resource_type, description, status, created_at, update ` type UpdateResourceRequestStatusParams struct { - ID pgtype.UUID + ID string Status string } diff --git a/db/tags.sql.go b/db/tags.sql.go index 145ba6d..c8e94b1 100644 --- a/db/tags.sql.go +++ b/db/tags.sql.go @@ -7,8 +7,6 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" ) const createTag = `-- name: CreateTag :one @@ -37,7 +35,7 @@ DELETE FROM tags WHERE id = $1 ` -func (q *Queries) DeleteTag(ctx context.Context, id pgtype.UUID) error { +func (q *Queries) DeleteTag(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteTag, id) return err } @@ -47,7 +45,7 @@ SELECT id, name, created_at, updated_at FROM tags WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetTag(ctx context.Context, id pgtype.UUID) (Tag, error) { +func (q *Queries) GetTag(ctx context.Context, id string) (Tag, error) { row := q.db.QueryRow(ctx, getTag, id) var i Tag err := row.Scan( diff --git a/db/users.sql.go b/db/users.sql.go index 6ca964f..8a609ec 100644 --- a/db/users.sql.go +++ b/db/users.sql.go @@ -81,7 +81,7 @@ SELECT id, email, password_hash, first_name, last_name, role, wallet_address, cr WHERE id = $1 LIMIT 1 ` -func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (User, error) { +func (q *Queries) GetUserByID(ctx context.Context, id string) (User, error) { row := q.db.QueryRow(ctx, getUserByID, id) var i User err := row.Scan( diff --git a/go.mod b/go.mod index 966a5d5..618cb69 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/KonferCA/NoKap go 1.23.2 require ( - github.com/emicklei/pgtalk v1.5.0 github.com/go-playground/validator/v10 v10.22.1 github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/google/uuid v1.6.0 github.com/jackc/pgx/v5 v5.7.1 github.com/joho/godotenv v1.5.1 github.com/labstack/echo/v4 v4.12.0 @@ -20,7 +20,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect - github.com/google/uuid v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect diff --git a/go.sum b/go.sum index 4e8c50b..dc39b8e 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 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/emicklei/pgtalk v1.5.0 h1:qD2YUvB3VFZYxRmLKymlUrsVBgfXPec1SWkPFD58SQI= -github.com/emicklei/pgtalk v1.5.0/go.mod h1:Gl6hNbBV10II4aLKBxf4lQub6b2hxKD6NJ98P/PNML0= 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/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= diff --git a/internal/server/auth.go b/internal/server/auth.go index f06edd5..9abe6d1 100644 --- a/internal/server/auth.go +++ b/internal/server/auth.go @@ -6,7 +6,6 @@ import ( "github.com/KonferCA/NoKap/db" "github.com/KonferCA/NoKap/internal/jwt" - "github.com/emicklei/pgtalk/convert" "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" "golang.org/x/crypto/bcrypt" @@ -31,7 +30,7 @@ func (s *Server) handleSignup(c echo.Context) error { ctx := context.Background() existingUser, err := s.queries.GetUserByEmail(ctx, req.Email) - if err == nil && existingUser.ID.Valid { + if err == nil && existingUser.ID != "" { return echo.NewHTTPError(http.StatusConflict, "email already registered") } @@ -51,8 +50,7 @@ func (s *Server) handleSignup(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, "failed to create user") } - userID := convert.UUIDToString(user.ID) - accessToken, refreshToken, err := jwt.Generate(userID, user.Role) + accessToken, refreshToken, err := jwt.Generate(user.ID, user.Role) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "failed to generate token") } @@ -61,7 +59,7 @@ func (s *Server) handleSignup(c echo.Context) error { AccessToken: accessToken, RefreshToken: refreshToken, User: User{ - ID: userID, + ID: user.ID, Email: user.Email, FirstName: user.FirstName.String, LastName: user.LastName.String, @@ -91,8 +89,7 @@ func (s *Server) handleSignin(c echo.Context) error { return echo.NewHTTPError(http.StatusUnauthorized, "invalid credentials") } - userID := convert.UUIDToString(user.ID) - accessToken, refreshToken, err := jwt.Generate(userID, user.Role) + accessToken, refreshToken, err := jwt.Generate(user.ID, user.Role) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "failed to generate token") } @@ -101,7 +98,7 @@ func (s *Server) handleSignin(c echo.Context) error { AccessToken: accessToken, RefreshToken: refreshToken, User: User{ - ID: userID, + ID: user.ID, Email: user.Email, FirstName: user.FirstName.String, LastName: user.LastName.String, diff --git a/internal/server/handler_helpers.go b/internal/server/handler_helpers.go index 51a674b..6acc11c 100644 --- a/internal/server/handler_helpers.go +++ b/internal/server/handler_helpers.go @@ -5,6 +5,7 @@ import ( "net/http" "time" + "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -23,16 +24,15 @@ func validateBody(c echo.Context, requestBodyType interface{}) error { return nil } -func validateUUID(id string, fieldName string) (pgtype.UUID, error) { - var uuid pgtype.UUID +func validateUUID(id string, fieldName string) (string, error) { if id == "" { - return uuid, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Missing %s ID :(", fieldName)) + return "", echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Missing %s ID :(", fieldName)) } - if err := uuid.Scan(id); err != nil { - return uuid, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid %s ID format :(", fieldName)) + if err := uuid.Validate(id); err != nil { + return "", echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid %s ID format :(", fieldName)) } - return uuid, nil + return id, nil } func handleDBError(err error, operation string, resourceType string) error { diff --git a/internal/server/startup.go b/internal/server/startup.go index 1d88579..6edc7b2 100644 --- a/internal/server/startup.go +++ b/internal/server/startup.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/KonferCA/NoKap/db" + "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -19,14 +20,13 @@ func (s *Server) handleCreateStartup(c echo.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err.Error()) } - var ownerUUID pgtype.UUID - if err := ownerUUID.Scan(req.OwnerUserID); err != nil { + if err := uuid.Validate(req.OwnerUserID); err != nil { return echo.NewHTTPError(http.StatusBadRequest, "invalid owner ID format") } queries := db.New(s.DBPool) params := db.CreateCompanyParams{ - OwnerUserID: ownerUUID, + OwnerUserID: req.OwnerUserID, Name: req.Name, Description: pgtype.Text{String: req.Description, Valid: true}, } diff --git a/sqlc.yml b/sqlc.yml index 2a6bcdb..527a32c 100644 --- a/sqlc.yml +++ b/sqlc.yml @@ -8,3 +8,6 @@ sql: package: "db" out: "db" sql_package: "pgx/v5" + overrides: + - db_type: "uuid" + go_type: "string" From 10d9c59874abff14cdedd9f4d4b5b5f0218088bb Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sat, 16 Nov 2024 03:08:21 -0500 Subject: [PATCH 2/6] override text to string and emit nil pointers for nullable --- db/company_documents.sql.go | 4 ++-- db/company_questions_answers.sql.go | 14 +++++++------- db/models.go | 12 ++++++------ db/projects.sql.go | 8 ++++---- internal/server/company_documents.go | 4 ++-- internal/server/company_questions_answers.go | 6 +++--- internal/server/projects.go | 6 +++--- sqlc.yml | 5 +++++ 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/db/company_documents.sql.go b/db/company_documents.sql.go index c3eb816..38132de 100644 --- a/db/company_documents.sql.go +++ b/db/company_documents.sql.go @@ -23,7 +23,7 @@ RETURNING id, company_id, document_type, file_url, created_at, updated_at type CreateCompanyDocumentParams struct { CompanyID string DocumentType string - FileUrl string + FileUrl *string } func (q *Queries) CreateCompanyDocument(ctx context.Context, arg CreateCompanyDocumentParams) (CompanyDocument, error) { @@ -153,7 +153,7 @@ RETURNING id, company_id, document_type, file_url, created_at, updated_at type UpdateCompanyDocumentParams struct { ID string DocumentType string - FileUrl string + FileUrl *string } func (q *Queries) UpdateCompanyDocument(ctx context.Context, arg UpdateCompanyDocumentParams) (CompanyDocument, error) { diff --git a/db/company_questions_answers.sql.go b/db/company_questions_answers.sql.go index 86ec273..c00b5fa 100644 --- a/db/company_questions_answers.sql.go +++ b/db/company_questions_answers.sql.go @@ -25,7 +25,7 @@ RETURNING id, company_id, question_id, answer_text, created_at, updated_at, dele type CreateCompanyAnswerParams struct { CompanyID string QuestionID string - AnswerText string + AnswerText *string } func (q *Queries) CreateCompanyAnswer(ctx context.Context, arg CreateCompanyAnswerParams) (CompanyQuestionAnswer, error) { @@ -52,7 +52,7 @@ INSERT INTO questions ( RETURNING id, question_text, created_at, updated_at, deleted_at ` -func (q *Queries) CreateQuestion(ctx context.Context, questionText string) (Question, error) { +func (q *Queries) CreateQuestion(ctx context.Context, questionText *string) (Question, error) { row := q.db.QueryRow(ctx, createQuestion, questionText) var i Question err := row.Scan( @@ -84,11 +84,11 @@ type GetCompanyAnswerRow struct { ID string CompanyID string QuestionID string - AnswerText string + AnswerText *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp - QuestionText string + QuestionText *string } func (q *Queries) GetCompanyAnswer(ctx context.Context, arg GetCompanyAnswerParams) (GetCompanyAnswerRow, error) { @@ -140,11 +140,11 @@ type ListCompanyAnswersRow struct { ID string CompanyID string QuestionID string - AnswerText string + AnswerText *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp - QuestionText string + QuestionText *string } func (q *Queries) ListCompanyAnswers(ctx context.Context, companyID string) ([]ListCompanyAnswersRow, error) { @@ -247,7 +247,7 @@ RETURNING id, company_id, question_id, answer_text, created_at, updated_at, dele type UpdateCompanyAnswerParams struct { CompanyID string QuestionID string - AnswerText string + AnswerText *string } func (q *Queries) UpdateCompanyAnswer(ctx context.Context, arg UpdateCompanyAnswerParams) (CompanyQuestionAnswer, error) { diff --git a/db/models.go b/db/models.go index 5301794..ce03efa 100644 --- a/db/models.go +++ b/db/models.go @@ -23,7 +23,7 @@ type CompanyDocument struct { ID string CompanyID string DocumentType string - FileUrl string + FileUrl *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -47,7 +47,7 @@ type CompanyQuestionAnswer struct { ID string CompanyID string QuestionID string - AnswerText string + AnswerText *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp @@ -104,7 +104,7 @@ type ProjectComment struct { ID string ProjectID string UserID string - Comment string + Comment *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -113,7 +113,7 @@ type ProjectFile struct { ID string ProjectID string FileType string - FileUrl string + FileUrl *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -122,7 +122,7 @@ type ProjectLink struct { ID string ProjectID string LinkType string - Url string + Url *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -136,7 +136,7 @@ type ProjectTag struct { type Question struct { ID string - QuestionText string + QuestionText *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp diff --git a/db/projects.sql.go b/db/projects.sql.go index c618c3e..ae8fd9b 100644 --- a/db/projects.sql.go +++ b/db/projects.sql.go @@ -91,7 +91,7 @@ RETURNING id, project_id, user_id, comment, created_at, updated_at type CreateProjectCommentParams struct { ProjectID string UserID string - Comment string + Comment *string } func (q *Queries) CreateProjectComment(ctx context.Context, arg CreateProjectCommentParams) (ProjectComment, error) { @@ -122,7 +122,7 @@ RETURNING id, project_id, file_type, file_url, created_at, updated_at type CreateProjectFileParams struct { ProjectID string FileType string - FileUrl string + FileUrl *string } func (q *Queries) CreateProjectFile(ctx context.Context, arg CreateProjectFileParams) (ProjectFile, error) { @@ -153,7 +153,7 @@ RETURNING id, project_id, link_type, url, created_at, updated_at type CreateProjectLinkParams struct { ProjectID string LinkType string - Url string + Url *string } func (q *Queries) CreateProjectLink(ctx context.Context, arg CreateProjectLinkParams) (ProjectLink, error) { @@ -271,7 +271,7 @@ type GetProjectCommentsRow struct { ID string ProjectID string UserID string - Comment string + Comment *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp FirstName pgtype.Text diff --git a/internal/server/company_documents.go b/internal/server/company_documents.go index bd4dd1b..a7a1a14 100644 --- a/internal/server/company_documents.go +++ b/internal/server/company_documents.go @@ -29,7 +29,7 @@ func (s *Server) handleCreateCompanyDocument(c echo.Context) error { params := db.CreateCompanyDocumentParams{ CompanyID: companyID, DocumentType: req.DocumentType, - FileUrl: req.FileURL, + FileUrl: &req.FileURL, } document, err := queries.CreateCompanyDocument(context.Background(), params) @@ -106,7 +106,7 @@ func (s *Server) handleUpdateCompanyDocument(c echo.Context) error { params := db.UpdateCompanyDocumentParams{ ID: documentID, DocumentType: req.DocumentType, - FileUrl: req.FileURL, + FileUrl: &req.FileURL, } document, err := queries.UpdateCompanyDocument(context.Background(), params) diff --git a/internal/server/company_questions_answers.go b/internal/server/company_questions_answers.go index 11f6c64..6be4f10 100644 --- a/internal/server/company_questions_answers.go +++ b/internal/server/company_questions_answers.go @@ -15,7 +15,7 @@ func (s *Server) handleCreateQuestion(c echo.Context) error { } queries := db.New(s.DBPool) - question, err := queries.CreateQuestion(context.Background(), req.QuestionText) + question, err := queries.CreateQuestion(context.Background(), &req.QuestionText) if err != nil { return handleDBError(err, "create", "question") } @@ -79,7 +79,7 @@ func (s *Server) handleCreateCompanyAnswer(c echo.Context) error { params := db.CreateCompanyAnswerParams{ CompanyID: companyID, QuestionID: questionID, - AnswerText: req.AnswerText, + AnswerText: &req.AnswerText, } answer, err := queries.CreateCompanyAnswer(context.Background(), params) @@ -161,7 +161,7 @@ func (s *Server) handleUpdateCompanyAnswer(c echo.Context) error { params := db.UpdateCompanyAnswerParams{ CompanyID: companyID, QuestionID: questionID, - AnswerText: req.AnswerText, + AnswerText: &req.AnswerText, } answer, err := queries.UpdateCompanyAnswer(context.Background(), params) diff --git a/internal/server/projects.go b/internal/server/projects.go index d4d1dca..09c6107 100644 --- a/internal/server/projects.go +++ b/internal/server/projects.go @@ -130,7 +130,7 @@ func (s *Server) handleCreateProjectFile(c echo.Context) error { params := db.CreateProjectFileParams{ ProjectID: projectID, FileType: req.FileType, - FileUrl: req.FileURL, + FileUrl: &req.FileURL, } file, err := queries.CreateProjectFile(context.Background(), params) @@ -196,7 +196,7 @@ func (s *Server) handleCreateProjectComment(c echo.Context) error { params := db.CreateProjectCommentParams{ ProjectID: projectID, UserID: userID, - Comment: req.Comment, + Comment: &req.Comment, } comment, err := queries.CreateProjectComment(context.Background(), params) @@ -257,7 +257,7 @@ func (s *Server) handleCreateProjectLink(c echo.Context) error { params := db.CreateProjectLinkParams{ ProjectID: projectID, LinkType: req.LinkType, - Url: req.URL, + Url: &req.URL, } link, err := queries.CreateProjectLink(context.Background(), params) diff --git a/sqlc.yml b/sqlc.yml index 527a32c..d4b96c7 100644 --- a/sqlc.yml +++ b/sqlc.yml @@ -11,3 +11,8 @@ sql: overrides: - db_type: "uuid" go_type: "string" + - db_type: "text" + go_type: + type: "string" + # allow to emit *string for nullable text columns + pointer: true From 23b6e6c0550d092cd4d6f499590a07f125e1accf Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sat, 16 Nov 2024 03:28:08 -0500 Subject: [PATCH 3/6] refactor text-like override types --- db/company.sql.go | 4 +- db/company_documents.sql.go | 4 +- db/company_questions_answers.sql.go | 14 ++--- db/employee.sql.go | 6 +- db/meetings.sql.go | 12 ++-- db/models.go | 32 +++++----- db/projects.sql.go | 16 ++--- db/resource_requests.sql.go | 4 +- db/users.sql.go | 6 +- internal/server/auth.go | 16 ++--- internal/server/company.go | 3 +- internal/server/company_documents.go | 4 +- internal/server/company_questions_answers.go | 6 +- internal/server/employee.go | 11 +--- internal/server/meetings.go | 37 +++--------- internal/server/projects.go | 18 +++--- internal/server/resource_request.go | 3 +- internal/server/startup.go | 3 +- internal/server/types.go | 62 ++++++++++---------- sqlc.yml | 9 ++- 20 files changed, 117 insertions(+), 153 deletions(-) diff --git a/db/company.sql.go b/db/company.sql.go index 0a1ad79..a2936ff 100644 --- a/db/company.sql.go +++ b/db/company.sql.go @@ -7,8 +7,6 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" ) const createCompany = `-- name: CreateCompany :one @@ -35,7 +33,7 @@ RETURNING id, owner_user_id, name, description, is_verified, created_at, updated type CreateCompanyParams struct { OwnerUserID string Name string - Description pgtype.Text + Description *string } func (q *Queries) CreateCompany(ctx context.Context, arg CreateCompanyParams) (Company, error) { diff --git a/db/company_documents.sql.go b/db/company_documents.sql.go index 38132de..c3eb816 100644 --- a/db/company_documents.sql.go +++ b/db/company_documents.sql.go @@ -23,7 +23,7 @@ RETURNING id, company_id, document_type, file_url, created_at, updated_at type CreateCompanyDocumentParams struct { CompanyID string DocumentType string - FileUrl *string + FileUrl string } func (q *Queries) CreateCompanyDocument(ctx context.Context, arg CreateCompanyDocumentParams) (CompanyDocument, error) { @@ -153,7 +153,7 @@ RETURNING id, company_id, document_type, file_url, created_at, updated_at type UpdateCompanyDocumentParams struct { ID string DocumentType string - FileUrl *string + FileUrl string } func (q *Queries) UpdateCompanyDocument(ctx context.Context, arg UpdateCompanyDocumentParams) (CompanyDocument, error) { diff --git a/db/company_questions_answers.sql.go b/db/company_questions_answers.sql.go index c00b5fa..86ec273 100644 --- a/db/company_questions_answers.sql.go +++ b/db/company_questions_answers.sql.go @@ -25,7 +25,7 @@ RETURNING id, company_id, question_id, answer_text, created_at, updated_at, dele type CreateCompanyAnswerParams struct { CompanyID string QuestionID string - AnswerText *string + AnswerText string } func (q *Queries) CreateCompanyAnswer(ctx context.Context, arg CreateCompanyAnswerParams) (CompanyQuestionAnswer, error) { @@ -52,7 +52,7 @@ INSERT INTO questions ( RETURNING id, question_text, created_at, updated_at, deleted_at ` -func (q *Queries) CreateQuestion(ctx context.Context, questionText *string) (Question, error) { +func (q *Queries) CreateQuestion(ctx context.Context, questionText string) (Question, error) { row := q.db.QueryRow(ctx, createQuestion, questionText) var i Question err := row.Scan( @@ -84,11 +84,11 @@ type GetCompanyAnswerRow struct { ID string CompanyID string QuestionID string - AnswerText *string + AnswerText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp - QuestionText *string + QuestionText string } func (q *Queries) GetCompanyAnswer(ctx context.Context, arg GetCompanyAnswerParams) (GetCompanyAnswerRow, error) { @@ -140,11 +140,11 @@ type ListCompanyAnswersRow struct { ID string CompanyID string QuestionID string - AnswerText *string + AnswerText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp - QuestionText *string + QuestionText string } func (q *Queries) ListCompanyAnswers(ctx context.Context, companyID string) ([]ListCompanyAnswersRow, error) { @@ -247,7 +247,7 @@ RETURNING id, company_id, question_id, answer_text, created_at, updated_at, dele type UpdateCompanyAnswerParams struct { CompanyID string QuestionID string - AnswerText *string + AnswerText string } func (q *Queries) UpdateCompanyAnswer(ctx context.Context, arg UpdateCompanyAnswerParams) (CompanyQuestionAnswer, error) { diff --git a/db/employee.sql.go b/db/employee.sql.go index ac218ab..911298e 100644 --- a/db/employee.sql.go +++ b/db/employee.sql.go @@ -7,8 +7,6 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" ) const createEmployee = `-- name: CreateEmployee :one @@ -29,7 +27,7 @@ type CreateEmployeeParams struct { Name string Email string Role string - Bio pgtype.Text + Bio *string } func (q *Queries) CreateEmployee(ctx context.Context, arg CreateEmployeeParams) (Employee, error) { @@ -190,7 +188,7 @@ type UpdateEmployeeParams struct { ID string Name string Role string - Bio pgtype.Text + Bio *string } func (q *Queries) UpdateEmployee(ctx context.Context, arg UpdateEmployeeParams) (Employee, error) { diff --git a/db/meetings.sql.go b/db/meetings.sql.go index 689b535..494044e 100644 --- a/db/meetings.sql.go +++ b/db/meetings.sql.go @@ -31,9 +31,9 @@ type CreateMeetingParams struct { ScheduledByUserID string StartTime pgtype.Timestamp EndTime pgtype.Timestamp - MeetingUrl pgtype.Text - Location pgtype.Text - Notes pgtype.Text + MeetingUrl *string + Location *string + Notes *string } func (q *Queries) CreateMeeting(ctx context.Context, arg CreateMeetingParams) (Meeting, error) { @@ -185,9 +185,9 @@ type UpdateMeetingParams struct { ID string StartTime pgtype.Timestamp EndTime pgtype.Timestamp - MeetingUrl pgtype.Text - Location pgtype.Text - Notes pgtype.Text + MeetingUrl *string + Location *string + Notes *string } func (q *Queries) UpdateMeeting(ctx context.Context, arg UpdateMeetingParams) (Meeting, error) { diff --git a/db/models.go b/db/models.go index ce03efa..6d3b582 100644 --- a/db/models.go +++ b/db/models.go @@ -12,7 +12,7 @@ type Company struct { ID string OwnerUserID string Name string - Description pgtype.Text + Description *string IsVerified bool CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -23,7 +23,7 @@ type CompanyDocument struct { ID string CompanyID string DocumentType string - FileUrl *string + FileUrl string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -47,7 +47,7 @@ type CompanyQuestionAnswer struct { ID string CompanyID string QuestionID string - AnswerText *string + AnswerText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp @@ -59,7 +59,7 @@ type Employee struct { Name string Email string Role string - Bio pgtype.Text + Bio *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -83,9 +83,9 @@ type Meeting struct { ScheduledByUserID string StartTime pgtype.Timestamp EndTime pgtype.Timestamp - MeetingUrl pgtype.Text - Location pgtype.Text - Notes pgtype.Text + MeetingUrl *string + Location *string + Notes *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -94,7 +94,7 @@ type Project struct { ID string CompanyID string Title string - Description pgtype.Text + Description *string Status string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -104,7 +104,7 @@ type ProjectComment struct { ID string ProjectID string UserID string - Comment *string + Comment string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -113,7 +113,7 @@ type ProjectFile struct { ID string ProjectID string FileType string - FileUrl *string + FileUrl string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -122,7 +122,7 @@ type ProjectLink struct { ID string ProjectID string LinkType string - Url *string + Url string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } @@ -136,7 +136,7 @@ type ProjectTag struct { type Question struct { ID string - QuestionText *string + QuestionText string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp DeletedAt pgtype.Timestamp @@ -146,7 +146,7 @@ type ResourceRequest struct { ID string CompanyID string ResourceType string - Description pgtype.Text + Description *string Status string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp @@ -163,10 +163,10 @@ type User struct { ID string Email string PasswordHash string - FirstName pgtype.Text - LastName pgtype.Text + FirstName *string + LastName *string Role string - WalletAddress pgtype.Text + WalletAddress *string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp } diff --git a/db/projects.sql.go b/db/projects.sql.go index ae8fd9b..cc01aa3 100644 --- a/db/projects.sql.go +++ b/db/projects.sql.go @@ -53,7 +53,7 @@ RETURNING id, company_id, title, description, status, created_at, updated_at type CreateProjectParams struct { CompanyID string Title string - Description pgtype.Text + Description *string Status string } @@ -91,7 +91,7 @@ RETURNING id, project_id, user_id, comment, created_at, updated_at type CreateProjectCommentParams struct { ProjectID string UserID string - Comment *string + Comment string } func (q *Queries) CreateProjectComment(ctx context.Context, arg CreateProjectCommentParams) (ProjectComment, error) { @@ -122,7 +122,7 @@ RETURNING id, project_id, file_type, file_url, created_at, updated_at type CreateProjectFileParams struct { ProjectID string FileType string - FileUrl *string + FileUrl string } func (q *Queries) CreateProjectFile(ctx context.Context, arg CreateProjectFileParams) (ProjectFile, error) { @@ -153,7 +153,7 @@ RETURNING id, project_id, link_type, url, created_at, updated_at type CreateProjectLinkParams struct { ProjectID string LinkType string - Url *string + Url string } func (q *Queries) CreateProjectLink(ctx context.Context, arg CreateProjectLinkParams) (ProjectLink, error) { @@ -271,11 +271,11 @@ type GetProjectCommentsRow struct { ID string ProjectID string UserID string - Comment *string + Comment string CreatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp - FirstName pgtype.Text - LastName pgtype.Text + FirstName *string + LastName *string Email string } @@ -500,7 +500,7 @@ RETURNING id, company_id, title, description, status, created_at, updated_at type UpdateProjectParams struct { ID string Title string - Description pgtype.Text + Description *string Status string } diff --git a/db/resource_requests.sql.go b/db/resource_requests.sql.go index f55d2f1..722f5f0 100644 --- a/db/resource_requests.sql.go +++ b/db/resource_requests.sql.go @@ -7,8 +7,6 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" ) const createResourceRequest = `-- name: CreateResourceRequest :one @@ -35,7 +33,7 @@ RETURNING id, company_id, resource_type, description, status, created_at, update type CreateResourceRequestParams struct { CompanyID string ResourceType string - Description pgtype.Text + Description *string Status string } diff --git a/db/users.sql.go b/db/users.sql.go index 8a609ec..7265ade 100644 --- a/db/users.sql.go +++ b/db/users.sql.go @@ -7,8 +7,6 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" ) const createUser = `-- name: CreateUser :one @@ -26,8 +24,8 @@ INSERT INTO users ( type CreateUserParams struct { Email string PasswordHash string - FirstName pgtype.Text - LastName pgtype.Text + FirstName *string + LastName *string Role string } diff --git a/internal/server/auth.go b/internal/server/auth.go index 9abe6d1..d59c2fa 100644 --- a/internal/server/auth.go +++ b/internal/server/auth.go @@ -42,8 +42,8 @@ func (s *Server) handleSignup(c echo.Context) error { user, err := s.queries.CreateUser(ctx, db.CreateUserParams{ Email: req.Email, PasswordHash: string(hashedPassword), - FirstName: pgtype.Text{String: req.FirstName, Valid: true}, - LastName: pgtype.Text{String: req.LastName, Valid: true}, + FirstName: &req.FirstName, + LastName: &req.LastName, Role: req.Role, }) if err != nil { @@ -61,10 +61,10 @@ func (s *Server) handleSignup(c echo.Context) error { User: User{ ID: user.ID, Email: user.Email, - FirstName: user.FirstName.String, - LastName: user.LastName.String, + FirstName: *user.FirstName, + LastName: *user.LastName, Role: user.Role, - WalletAddress: getStringPtr(user.WalletAddress), + WalletAddress: user.WalletAddress, }, }) } @@ -100,10 +100,10 @@ func (s *Server) handleSignin(c echo.Context) error { User: User{ ID: user.ID, Email: user.Email, - FirstName: user.FirstName.String, - LastName: user.LastName.String, + FirstName: *user.FirstName, + LastName: *user.LastName, Role: user.Role, - WalletAddress: getStringPtr(user.WalletAddress), + WalletAddress: user.WalletAddress, }, }) } diff --git a/internal/server/company.go b/internal/server/company.go index fdc6440..2cf9d0c 100644 --- a/internal/server/company.go +++ b/internal/server/company.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/KonferCA/NoKap/db" - "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -24,7 +23,7 @@ func (s *Server) handleCreateCompany(c echo.Context) error { params := db.CreateCompanyParams{ OwnerUserID: ownerUUID, Name: req.Name, - Description: pgtype.Text{String: req.Description, Valid: req.Description != ""}, + Description: req.Description, } company, err := queries.CreateCompany(context.Background(), params) diff --git a/internal/server/company_documents.go b/internal/server/company_documents.go index a7a1a14..bd4dd1b 100644 --- a/internal/server/company_documents.go +++ b/internal/server/company_documents.go @@ -29,7 +29,7 @@ func (s *Server) handleCreateCompanyDocument(c echo.Context) error { params := db.CreateCompanyDocumentParams{ CompanyID: companyID, DocumentType: req.DocumentType, - FileUrl: &req.FileURL, + FileUrl: req.FileURL, } document, err := queries.CreateCompanyDocument(context.Background(), params) @@ -106,7 +106,7 @@ func (s *Server) handleUpdateCompanyDocument(c echo.Context) error { params := db.UpdateCompanyDocumentParams{ ID: documentID, DocumentType: req.DocumentType, - FileUrl: &req.FileURL, + FileUrl: req.FileURL, } document, err := queries.UpdateCompanyDocument(context.Background(), params) diff --git a/internal/server/company_questions_answers.go b/internal/server/company_questions_answers.go index 6be4f10..11f6c64 100644 --- a/internal/server/company_questions_answers.go +++ b/internal/server/company_questions_answers.go @@ -15,7 +15,7 @@ func (s *Server) handleCreateQuestion(c echo.Context) error { } queries := db.New(s.DBPool) - question, err := queries.CreateQuestion(context.Background(), &req.QuestionText) + question, err := queries.CreateQuestion(context.Background(), req.QuestionText) if err != nil { return handleDBError(err, "create", "question") } @@ -79,7 +79,7 @@ func (s *Server) handleCreateCompanyAnswer(c echo.Context) error { params := db.CreateCompanyAnswerParams{ CompanyID: companyID, QuestionID: questionID, - AnswerText: &req.AnswerText, + AnswerText: req.AnswerText, } answer, err := queries.CreateCompanyAnswer(context.Background(), params) @@ -161,7 +161,7 @@ func (s *Server) handleUpdateCompanyAnswer(c echo.Context) error { params := db.UpdateCompanyAnswerParams{ CompanyID: companyID, QuestionID: questionID, - AnswerText: &req.AnswerText, + AnswerText: req.AnswerText, } answer, err := queries.UpdateCompanyAnswer(context.Background(), params) diff --git a/internal/server/employee.go b/internal/server/employee.go index 9af84c1..c61b38c 100644 --- a/internal/server/employee.go +++ b/internal/server/employee.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/KonferCA/NoKap/db" - "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -37,10 +36,7 @@ func (s *Server) handleCreateEmployee(c echo.Context) error { Name: req.Name, Email: req.Email, Role: req.Role, - Bio: pgtype.Text{ - String: req.Bio, - Valid: req.Bio != "", - }, + Bio: req.Bio, } employee, err := queries.CreateEmployee(context.Background(), params) @@ -113,10 +109,7 @@ func (s *Server) handleUpdateEmployee(c echo.Context) error { ID: employeeID, Name: req.Name, Role: req.Role, - Bio: pgtype.Text{ - String: req.Bio, - Valid: req.Bio != "", - }, + Bio: req.Bio, } employee, err := queries.UpdateEmployee(context.Background(), params) diff --git a/internal/server/meetings.go b/internal/server/meetings.go index a98ee20..674f358 100644 --- a/internal/server/meetings.go +++ b/internal/server/meetings.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/KonferCA/NoKap/db" - "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -51,18 +50,9 @@ func (s *Server) handleCreateMeeting(c echo.Context) error { ScheduledByUserID: userID, StartTime: startTime, EndTime: endTime, - MeetingUrl: pgtype.Text{ - String: req.MeetingURL, - Valid: req.MeetingURL != "", - }, - Location: pgtype.Text{ - String: req.Location, - Valid: req.Location != "", - }, - Notes: pgtype.Text{ - String: req.Notes, - Valid: req.Notes != "", - }, + MeetingUrl: req.MeetingURL, + Location: req.Location, + Notes: req.Notes, } meeting, err := queries.CreateMeeting(context.Background(), params) @@ -152,21 +142,12 @@ func (s *Server) handleUpdateMeeting(c echo.Context) error { } params := db.UpdateMeetingParams{ - ID: meetingID, - StartTime: startTime, - EndTime: endTime, - MeetingUrl: pgtype.Text{ - String: req.MeetingURL, - Valid: req.MeetingURL != "", - }, - Location: pgtype.Text{ - String: req.Location, - Valid: req.Location != "", - }, - Notes: pgtype.Text{ - String: req.Notes, - Valid: req.Notes != "", - }, + ID: meetingID, + StartTime: startTime, + EndTime: endTime, + MeetingUrl: req.MeetingURL, + Location: req.Location, + Notes: req.Notes, } meeting, err := queries.UpdateMeeting(context.Background(), params) diff --git a/internal/server/projects.go b/internal/server/projects.go index 09c6107..9f0d1dd 100644 --- a/internal/server/projects.go +++ b/internal/server/projects.go @@ -6,7 +6,6 @@ import ( "net/http" "github.com/KonferCA/NoKap/db" - "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -32,13 +31,10 @@ func (s *Server) handleCreateProject(c echo.Context) error { companyID, req.Title, req.Status) params := db.CreateProjectParams{ - CompanyID: companyID, - Title: req.Title, - Description: pgtype.Text{ - String: req.Description, - Valid: req.Description != "", - }, - Status: req.Status, + CompanyID: companyID, + Title: req.Title, + Description: req.Description, + Status: req.Status, } project, err := queries.CreateProject(context.Background(), params) @@ -130,7 +126,7 @@ func (s *Server) handleCreateProjectFile(c echo.Context) error { params := db.CreateProjectFileParams{ ProjectID: projectID, FileType: req.FileType, - FileUrl: &req.FileURL, + FileUrl: req.FileURL, } file, err := queries.CreateProjectFile(context.Background(), params) @@ -196,7 +192,7 @@ func (s *Server) handleCreateProjectComment(c echo.Context) error { params := db.CreateProjectCommentParams{ ProjectID: projectID, UserID: userID, - Comment: &req.Comment, + Comment: req.Comment, } comment, err := queries.CreateProjectComment(context.Background(), params) @@ -257,7 +253,7 @@ func (s *Server) handleCreateProjectLink(c echo.Context) error { params := db.CreateProjectLinkParams{ ProjectID: projectID, LinkType: req.LinkType, - Url: &req.URL, + Url: req.URL, } link, err := queries.CreateProjectLink(context.Background(), params) diff --git a/internal/server/resource_request.go b/internal/server/resource_request.go index 859b7d6..336ffc3 100644 --- a/internal/server/resource_request.go +++ b/internal/server/resource_request.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/KonferCA/NoKap/db" - "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -29,7 +28,7 @@ func (s *Server) handleCreateResourceRequest(c echo.Context) error { params := db.CreateResourceRequestParams{ CompanyID: companyID, ResourceType: req.ResourceType, - Description: pgtype.Text{String: req.Description, Valid: req.Description != ""}, + Description: req.Description, Status: req.Status, } diff --git a/internal/server/startup.go b/internal/server/startup.go index 6edc7b2..3b3f4ff 100644 --- a/internal/server/startup.go +++ b/internal/server/startup.go @@ -6,7 +6,6 @@ import ( "github.com/KonferCA/NoKap/db" "github.com/google/uuid" - "github.com/jackc/pgx/v5/pgtype" "github.com/labstack/echo/v4" ) @@ -28,7 +27,7 @@ func (s *Server) handleCreateStartup(c echo.Context) error { params := db.CreateCompanyParams{ OwnerUserID: req.OwnerUserID, Name: req.Name, - Description: pgtype.Text{String: req.Description, Valid: true}, + Description: req.Description, } company, err := queries.CreateCompany(context.Background(), params) diff --git a/internal/server/types.go b/internal/server/types.go index 9995d85..d97fad1 100644 --- a/internal/server/types.go +++ b/internal/server/types.go @@ -28,16 +28,16 @@ type HealthReport struct { } type CreateCompanyRequest struct { - OwnerUserID string `json:"owner_user_id" validate:"required,uuid"` - Name string `json:"name" validate:"required"` - Description string `json:"description"` + OwnerUserID string `json:"owner_user_id" validate:"required,uuid"` + Name string `json:"name" validate:"required"` + Description *string `json:"description"` } type CreateResourceRequestRequest struct { - CompanyID string `json:"company_id" validate:"required,uuid"` - ResourceType string `json:"resource_type" validate:"required"` - Description string `json:"description"` - Status string `json:"status" validate:"required"` + CompanyID string `json:"company_id" validate:"required,uuid"` + ResourceType string `json:"resource_type" validate:"required"` + Description *string `json:"description"` + Status string `json:"status" validate:"required"` } type SignupRequest struct { @@ -80,17 +80,17 @@ type CreateCompanyFinancialsRequest struct { } type CreateEmployeeRequest struct { - CompanyID string `json:"company_id" validate:"required,uuid"` - Name string `json:"name" validate:"required"` - Email string `json:"email" validate:"required,email"` - Role string `json:"role" validate:"required"` - Bio string `json:"bio"` + CompanyID string `json:"company_id" validate:"required,uuid"` + Name string `json:"name" validate:"required"` + Email string `json:"email" validate:"required,email"` + Role string `json:"role" validate:"required"` + Bio *string `json:"bio"` } type UpdateEmployeeRequest struct { - Name string `json:"name" validate:"required"` - Role string `json:"role" validate:"required"` - Bio string `json:"bio"` + Name string `json:"name" validate:"required"` + Role string `json:"role" validate:"required"` + Bio *string `json:"bio"` } type CreateCompanyDocumentRequest struct { @@ -118,10 +118,10 @@ type UpdateCompanyAnswerRequest struct { } type CreateProjectRequest struct { - CompanyID string `json:"company_id" validate:"required"` - Title string `json:"title" validate:"required"` - Description string `json:"description"` - Status string `json:"status" validate:"required"` + CompanyID string `json:"company_id" validate:"required"` + Title string `json:"title" validate:"required"` + Description *string `json:"description"` + Status string `json:"status" validate:"required"` } type UpdateProjectRequest struct { @@ -168,19 +168,19 @@ type UpdateFundingTransactionStatusRequest struct { } type CreateMeetingRequest struct { - ProjectID string `json:"project_id" validate:"required,uuid"` - ScheduledByUserID string `json:"scheduled_by_user_id" validate:"required,uuid"` - StartTime string `json:"start_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` - EndTime string `json:"end_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` - MeetingURL string `json:"meeting_url" validate:"omitempty,url"` - Location string `json:"location"` - Notes string `json:"notes"` + ProjectID string `json:"project_id" validate:"required,uuid"` + ScheduledByUserID string `json:"scheduled_by_user_id" validate:"required,uuid"` + StartTime string `json:"start_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` + EndTime string `json:"end_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` + MeetingURL *string `json:"meeting_url" validate:"omitempty,url"` + Location *string `json:"location"` + Notes *string `json:"notes"` } type UpdateMeetingRequest struct { - StartTime string `json:"start_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` - EndTime string `json:"end_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` - MeetingURL string `json:"meeting_url" validate:"omitempty,url"` - Location string `json:"location"` - Notes string `json:"notes"` + StartTime string `json:"start_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` + EndTime string `json:"end_time" validate:"required,datetime=2006-01-02T15:04:05.000Z"` + MeetingURL *string `json:"meeting_url" validate:"omitempty,url"` + Location *string `json:"location"` + Notes *string `json:"notes"` } diff --git a/sqlc.yml b/sqlc.yml index d4b96c7..69fcc9e 100644 --- a/sqlc.yml +++ b/sqlc.yml @@ -8,11 +8,16 @@ sql: package: "db" out: "db" sql_package: "pgx/v5" + emit_pointers_for_null_types: true overrides: - db_type: "uuid" go_type: "string" - db_type: "text" go_type: type: "string" - # allow to emit *string for nullable text columns - pointer: true + - db_type: "pg_catalog.varchar" + go_type: + type: "string" + - db_type: "pg_catalog.bpchar" + go_type: + type: "string" From f06a733769dade678bca31f4169c0e760d833397 Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sat, 16 Nov 2024 03:29:24 -0500 Subject: [PATCH 4/6] remove old placeholder code --- internal/server/index.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/internal/server/index.go b/internal/server/index.go index 33ae1a5..72d7520 100644 --- a/internal/server/index.go +++ b/internal/server/index.go @@ -73,7 +73,6 @@ func New(testing bool) (*Server, error) { e.Use(apiLimiter.RateLimit()) // global rate limit customValidator := middleware.NewRequestBodyValidator() - fmt.Printf("Initializing validator: %+v\n", customValidator) e.Validator = customValidator server := &Server{ @@ -108,12 +107,6 @@ func New(testing bool) (*Server, error) { func (s *Server) setupV1Routes() { s.apiV1 = s.echoInstance.Group("/api/v1") - s.echoInstance.GET("/", func(c echo.Context) error { - return c.JSON(200, map[string]string{ - "message": "Server do be running...", - }) - }) - for _, route := range s.echoInstance.Routes() { s.echoInstance.Logger.Printf("Route: %s %s", route.Method, route.Path) } From ad71eb5ac958402b5639275c017db6416d66936c Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sat, 16 Nov 2024 03:38:10 -0500 Subject: [PATCH 5/6] override timestamps to time.Time --- db/meetings.sql.go | 11 +++++------ db/models.go | 14 ++++++++------ internal/server/handler_helpers.go | 19 ++++++------------- internal/server/meetings.go | 9 +++++---- sqlc.yml | 2 ++ 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/db/meetings.sql.go b/db/meetings.sql.go index 494044e..0e72a96 100644 --- a/db/meetings.sql.go +++ b/db/meetings.sql.go @@ -7,8 +7,7 @@ package db import ( "context" - - "github.com/jackc/pgx/v5/pgtype" + "time" ) const createMeeting = `-- name: CreateMeeting :one @@ -29,8 +28,8 @@ RETURNING id, project_id, scheduled_by_user_id, start_time, end_time, meeting_ur type CreateMeetingParams struct { ProjectID string ScheduledByUserID string - StartTime pgtype.Timestamp - EndTime pgtype.Timestamp + StartTime time.Time + EndTime time.Time MeetingUrl *string Location *string Notes *string @@ -183,8 +182,8 @@ RETURNING id, project_id, scheduled_by_user_id, start_time, end_time, meeting_ur type UpdateMeetingParams struct { ID string - StartTime pgtype.Timestamp - EndTime pgtype.Timestamp + StartTime time.Time + EndTime time.Time MeetingUrl *string Location *string Notes *string diff --git a/db/models.go b/db/models.go index 6d3b582..2d1cd0f 100644 --- a/db/models.go +++ b/db/models.go @@ -5,6 +5,8 @@ package db import ( + "time" + "github.com/jackc/pgx/v5/pgtype" ) @@ -14,8 +16,8 @@ type Company struct { Name string Description *string IsVerified bool - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + CreatedAt time.Time + UpdatedAt time.Time DeletedAt pgtype.Timestamp } @@ -81,8 +83,8 @@ type Meeting struct { ID string ProjectID string ScheduledByUserID string - StartTime pgtype.Timestamp - EndTime pgtype.Timestamp + StartTime time.Time + EndTime time.Time MeetingUrl *string Location *string Notes *string @@ -148,8 +150,8 @@ type ResourceRequest struct { ResourceType string Description *string Status string - CreatedAt pgtype.Timestamp - UpdatedAt pgtype.Timestamp + CreatedAt time.Time + UpdatedAt time.Time } type Tag struct { diff --git a/internal/server/handler_helpers.go b/internal/server/handler_helpers.go index 6acc11c..5723c32 100644 --- a/internal/server/handler_helpers.go +++ b/internal/server/handler_helpers.go @@ -75,28 +75,21 @@ func validateNumeric(value string) (pgtype.Numeric, error) { return num, nil } -func validateTimestamp(timeStr string, fieldName string) (pgtype.Timestamp, error) { - var ts pgtype.Timestamp +func validateTimestamp(timeStr string, fieldName string) (*time.Time, error) { if timeStr == "" { - return ts, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Missing %s :(", fieldName)) + return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Missing %s :(", fieldName)) } parsedTime, err := time.Parse(time.RFC3339, timeStr) if err != nil { - return ts, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid %s format :(", fieldName)) + return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid %s format :(", fieldName)) } - ts.Time = parsedTime - ts.Valid = true - return ts, nil + return &parsedTime, nil } -func validateTimeRange(startTime, endTime pgtype.Timestamp) error { - if !startTime.Valid || !endTime.Valid { - return echo.NewHTTPError(http.StatusBadRequest, "Invalid time values :(") - } - - if endTime.Time.Before(startTime.Time) { +func validateTimeRange(startTime, endTime time.Time) error { + if endTime.Before(startTime) { return echo.NewHTTPError(http.StatusBadRequest, "End time cannot be before start time :(") } diff --git a/internal/server/meetings.go b/internal/server/meetings.go index 674f358..2705f02 100644 --- a/internal/server/meetings.go +++ b/internal/server/meetings.go @@ -3,6 +3,7 @@ package server import ( "context" "net/http" + "time" "github.com/KonferCA/NoKap/db" "github.com/labstack/echo/v4" @@ -24,12 +25,12 @@ func (s *Server) handleCreateMeeting(c echo.Context) error { return err } - startTime, err := validateTimestamp(req.StartTime, "start time") + startTime, err := time.Parse(time.RFC3339, req.StartTime) if err != nil { return err } - endTime, err := validateTimestamp(req.EndTime, "end time") + endTime, err := time.Parse(time.RFC3339, req.EndTime) if err != nil { return err } @@ -120,12 +121,12 @@ func (s *Server) handleUpdateMeeting(c echo.Context) error { return err } - startTime, err := validateTimestamp(req.StartTime, "start time") + startTime, err := time.Parse(time.RFC3339, req.StartTime) if err != nil { return err } - endTime, err := validateTimestamp(req.EndTime, "end time") + endTime, err := time.Parse(time.RFC3339, req.EndTime) if err != nil { return err } diff --git a/sqlc.yml b/sqlc.yml index 69fcc9e..fd4d4a7 100644 --- a/sqlc.yml +++ b/sqlc.yml @@ -21,3 +21,5 @@ sql: - db_type: "pg_catalog.bpchar" go_type: type: "string" + - db_type: "pg_catalog.timestamp" + go_type: "time.Time" From ea96d71959dcb44dec505f67e6cedf62a0a34201 Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Sat, 16 Nov 2024 03:42:44 -0500 Subject: [PATCH 6/6] refactor sqlc config --- sqlc.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sqlc.yml b/sqlc.yml index fd4d4a7..cd97b74 100644 --- a/sqlc.yml +++ b/sqlc.yml @@ -13,13 +13,10 @@ sql: - db_type: "uuid" go_type: "string" - db_type: "text" - go_type: - type: "string" + go_type: "string" - db_type: "pg_catalog.varchar" - go_type: - type: "string" + go_type: "string" - db_type: "pg_catalog.bpchar" - go_type: - type: "string" + go_type: "string" - db_type: "pg_catalog.timestamp" go_type: "time.Time"