rf/improves *_id uint64 handling

This commit is contained in:
itsscb 2023-10-10 00:17:52 +02:00
parent 8733dec355
commit f25bbb347c
33 changed files with 181 additions and 214 deletions

View File

@ -510,7 +510,7 @@ func (mr *MockStoreMockRecorder) GetReturn(arg0, arg1 any) *gomock.Call {
}
// GetReturns mocks base method.
func (m *MockStore) GetReturns(arg0 context.Context, arg1 int64) ([]db.Return, error) {
func (m *MockStore) GetReturns(arg0 context.Context, arg1 uint64) ([]db.Return, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetReturns", arg0, arg1)
ret0, _ := ret[0].([]db.Return)
@ -615,7 +615,7 @@ func (mr *MockStoreMockRecorder) ListMails(arg0, arg1 any) *gomock.Call {
}
// ListPayments mocks base method.
func (m *MockStore) ListPayments(arg0 context.Context, arg1 int64) ([]db.Payment, error) {
func (m *MockStore) ListPayments(arg0 context.Context, arg1 uint64) ([]db.Payment, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ListPayments", arg0, arg1)
ret0, _ := ret[0].([]db.Payment)
@ -630,7 +630,7 @@ func (mr *MockStoreMockRecorder) ListPayments(arg0, arg1 any) *gomock.Call {
}
// ListPersons mocks base method.
func (m *MockStore) ListPersons(arg0 context.Context, arg1 int64) ([]db.Person, error) {
func (m *MockStore) ListPersons(arg0 context.Context, arg1 uint64) ([]db.Person, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ListPersons", arg0, arg1)
ret0, _ := ret[0].([]db.Person)

View File

@ -10,9 +10,10 @@ INSERT INTO documents (
"path",
"url",
"creator",
"changer"
"changer",
"mail_id"
) VALUES (
$1, $2, $3, $4, $5, $6, $7
$1, $2, $3, $4, $5, $6, $7, NULL
) RETURNING *;
-- name: CreateDocumentMail :one
@ -23,9 +24,10 @@ INSERT INTO documents (
"path",
"url",
"creator",
"changer"
"changer",
"person_id"
) VALUES (
$1, $2, $3, $4, $5, $6, $7
$1, $2, $3, $4, $5, $6, $7, NULL
) RETURNING *;
-- name: ListDocuments :many
@ -37,7 +39,6 @@ OFFSET $2;
-- name: UpdateDocument :one
UPDATE documents
SET
"person_id" = COALESCE(sqlc.narg(person_id), "person_id"),
"name" = COALESCE(sqlc.narg(name), "name"),
"type" = COALESCE(sqlc.narg(type), "type"),
"path" = COALESCE(sqlc.narg(path), "path"),

View File

@ -27,7 +27,6 @@ ORDER BY "payment_category";
-- name: UpdatePayment :one
UPDATE payments
SET
"account_id" = COALESCE(sqlc.narg(account_id), "account_id"),
"payment_category" = COALESCE(sqlc.narg(payment_category), "payment_category"),
"bankname" = COALESCE(sqlc.narg(bankname), "bankname"),
"IBAN" = COALESCE(sqlc.narg(IBAN), "IBAN"),
@ -36,9 +35,9 @@ SET
"paypal_id" = COALESCE(sqlc.narg(paypal_id), "paypal_id"),
"payment_system" = COALESCE(sqlc.narg(payment_system), "payment_system"),
"type" = COALESCE(sqlc.narg(type), "type"),
"changer" = $2,
"changer" = sqlc.arg(changer),
"changed" = now()
WHERE "id" = $1
WHERE "id" = sqlc.arg(id)
RETURNING *;
-- name: DeletePayment :exec

View File

@ -26,7 +26,6 @@ ORDER BY "lastname", "firstname";
-- name: UpdatePerson :one
UPDATE persons
SET
"account_id" = COALESCE(sqlc.narg(account_id), "account_id"),
"firstname" = COALESCE(sqlc.narg(firstname), "firstname"),
"lastname" = COALESCE(sqlc.narg(lastname), "lastname"),
"birthday" = COALESCE(sqlc.narg(birthday), "birthday"),

View File

@ -34,8 +34,6 @@ OFFSET $2;
-- name: UpdateReturn :one
UPDATE returns
SET
"person_id" = COALESCE(sqlc.narg(person_id), "person_id"),
"provider_id" = COALESCE(sqlc.narg(provider_id), "provider_id"),
"name" = COALESCE(sqlc.narg(name), "name"),
"description" = COALESCE(sqlc.narg(description), "description"),
"category" = COALESCE(sqlc.narg(category), "category"),

View File

@ -26,8 +26,6 @@ OFFSET $2;
-- name: UpdateReturnsLog :one
UPDATE "returnsLog"
SET
"return_id" = COALESCE(sqlc.narg(return_id), "return_id"),
"mail_id" = COALESCE(sqlc.narg(mail_id), "mail_id"),
"status" = COALESCE(sqlc.narg(status), "status"),
"changer" = $1,
"changed" = now()

View File

@ -18,9 +18,10 @@ INSERT INTO documents (
"path",
"url",
"creator",
"changer"
"changer",
"person_id"
) VALUES (
$1, $2, $3, $4, $5, $6, $7
$1, $2, $3, $4, $5, $6, $7, NULL
) RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
@ -72,9 +73,10 @@ INSERT INTO documents (
"path",
"url",
"creator",
"changer"
"changer",
"mail_id"
) VALUES (
$1, $2, $3, $4, $5, $6, $7
$1, $2, $3, $4, $5, $6, $7, NULL
) RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
@ -247,11 +249,10 @@ func (q *Queries) ListDocuments(ctx context.Context, arg ListDocumentsParams) ([
const updateDocument = `-- name: UpdateDocument :one
UPDATE documents
SET
"person_id" = COALESCE($3, "person_id"),
"name" = COALESCE($4, "name"),
"type" = COALESCE($5, "type"),
"path" = COALESCE($6, "path"),
"url" = COALESCE($7, "url"),
"name" = COALESCE($3, "name"),
"type" = COALESCE($4, "type"),
"path" = COALESCE($5, "path"),
"url" = COALESCE($6, "url"),
changer = $2,
changed = now()
WHERE "id" = $1
@ -259,20 +260,18 @@ RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by,
`
type UpdateDocumentParams struct {
ID uint64 `json:"id"`
Changer string `json:"changer"`
PersonID sql.NullInt64 `json:"person_id"`
Name sql.NullString `json:"name"`
Type sql.NullString `json:"type"`
Path sql.NullString `json:"path"`
Url sql.NullString `json:"url"`
ID uint64 `json:"id"`
Changer string `json:"changer"`
Name sql.NullString `json:"name"`
Type sql.NullString `json:"type"`
Path sql.NullString `json:"path"`
Url sql.NullString `json:"url"`
}
func (q *Queries) UpdateDocument(ctx context.Context, arg UpdateDocumentParams) (Document, error) {
row := q.db.QueryRowContext(ctx, updateDocument,
arg.ID,
arg.Changer,
arg.PersonID,
arg.Name,
arg.Type,
arg.Path,

View File

@ -65,7 +65,7 @@ type Mail struct {
type Payment struct {
ID uint64 `json:"id"`
AccountID int64 `json:"account_id"`
AccountID uint64 `json:"account_id"`
PaymentCategory string `json:"payment_category"`
Bankname sql.NullString `json:"bankname"`
IBAN sql.NullString `json:"IBAN"`
@ -82,7 +82,7 @@ type Payment struct {
type Person struct {
ID uint64 `json:"id"`
AccountID int64 `json:"account_id"`
AccountID uint64 `json:"account_id"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -110,8 +110,8 @@ type Provider struct {
type Return struct {
ID uint64 `json:"id"`
PersonID int64 `json:"person_id"`
ProviderID int64 `json:"provider_id"`
PersonID uint64 `json:"person_id"`
ProviderID uint64 `json:"provider_id"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
@ -125,8 +125,8 @@ type Return struct {
type ReturnsLog struct {
ID uint64 `json:"id"`
ReturnID int64 `json:"return_id"`
MailID int64 `json:"mail_id"`
ReturnID uint64 `json:"return_id"`
MailID uint64 `json:"mail_id"`
Status sql.NullString `json:"status"`
Creator string `json:"creator"`
Created time.Time `json:"created"`

View File

@ -29,7 +29,7 @@ INSERT INTO payments (
`
type CreatePaymentParams struct {
AccountID int64 `json:"account_id"`
AccountID uint64 `json:"account_id"`
PaymentCategory string `json:"payment_category"`
Bankname sql.NullString `json:"bankname"`
IBAN sql.NullString `json:"IBAN"`
@ -119,7 +119,7 @@ WHERE "account_id" = $1
ORDER BY "payment_category"
`
func (q *Queries) ListPayments(ctx context.Context, accountID int64) ([]Payment, error) {
func (q *Queries) ListPayments(ctx context.Context, accountID uint64) ([]Payment, error) {
rows, err := q.db.QueryContext(ctx, listPayments, accountID)
if err != nil {
return nil, err
@ -160,25 +160,21 @@ func (q *Queries) ListPayments(ctx context.Context, accountID int64) ([]Payment,
const updatePayment = `-- name: UpdatePayment :one
UPDATE payments
SET
"account_id" = COALESCE($3, "account_id"),
"payment_category" = COALESCE($4, "payment_category"),
"bankname" = COALESCE($5, "bankname"),
"IBAN" = COALESCE($6, "IBAN"),
"BIC" = COALESCE($7, "BIC"),
"paypal_account" = COALESCE($8, "paypal_account"),
"paypal_id" = COALESCE($9, "paypal_id"),
"payment_system" = COALESCE($10, "payment_system"),
"type" = COALESCE($11, "type"),
"changer" = $2,
"payment_category" = COALESCE($1, "payment_category"),
"bankname" = COALESCE($2, "bankname"),
"IBAN" = COALESCE($3, "IBAN"),
"BIC" = COALESCE($4, "BIC"),
"paypal_account" = COALESCE($5, "paypal_account"),
"paypal_id" = COALESCE($6, "paypal_id"),
"payment_system" = COALESCE($7, "payment_system"),
"type" = COALESCE($8, "type"),
"changer" = $9,
"changed" = now()
WHERE "id" = $1
WHERE "id" = $10
RETURNING id, account_id, payment_category, bankname, "IBAN", "BIC", paypal_account, paypal_id, payment_system, type, creator, created, changer, changed
`
type UpdatePaymentParams struct {
ID uint64 `json:"id"`
Changer string `json:"changer"`
AccountID sql.NullInt64 `json:"account_id"`
PaymentCategory sql.NullString `json:"payment_category"`
Bankname sql.NullString `json:"bankname"`
Iban sql.NullString `json:"iban"`
@ -187,13 +183,12 @@ type UpdatePaymentParams struct {
PaypalID sql.NullString `json:"paypal_id"`
PaymentSystem sql.NullString `json:"payment_system"`
Type sql.NullString `json:"type"`
Changer string `json:"changer"`
ID uint64 `json:"id"`
}
func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (Payment, error) {
row := q.db.QueryRowContext(ctx, updatePayment,
arg.ID,
arg.Changer,
arg.AccountID,
arg.PaymentCategory,
arg.Bankname,
arg.Iban,
@ -202,6 +197,8 @@ func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (P
arg.PaypalID,
arg.PaymentSystem,
arg.Type,
arg.Changer,
arg.ID,
)
var i Payment
err := row.Scan(

View File

@ -10,6 +10,27 @@ import (
"github.com/stretchr/testify/require"
)
func TestUpdatePayment(t *testing.T) {
payment1 := createRandomPayment(t)
require.NotEmpty(t, payment1)
arg := UpdatePaymentParams{
ID: payment1.ID,
Bankname: sql.NullString{
String: util.RandomName(),
Valid: true,
},
}
payment2, err := testQueries.UpdatePayment(context.Background(), arg)
require.NoError(t, err)
require.NotEmpty(t, payment2)
require.Equal(t, payment1.ID, payment2.ID)
require.Equal(t, payment1.PaymentCategory, payment2.PaymentCategory)
require.NotEqual(t, payment1.Bankname, payment2.Bankname)
}
func createRandomPayment(t *testing.T) Payment {
account := createRandomAccount(t)
require.NotEmpty(t, account)
@ -17,7 +38,7 @@ func createRandomPayment(t *testing.T) Payment {
creator := util.RandomName()
arg := CreatePaymentParams{
AccountID: int64(account.ID),
AccountID: account.ID,
PaymentCategory: util.RandomName(),
Bankname: sql.NullString{
Valid: true,
@ -48,25 +69,25 @@ func createRandomPayment(t *testing.T) Payment {
Changer: creator,
}
person, err := testQueries.CreatePayment(context.Background(), arg)
payment, err := testQueries.CreatePayment(context.Background(), arg)
require.NoError(t, err)
require.NotEmpty(t, person)
require.NotEmpty(t, payment)
require.Equal(t, arg.PaymentCategory, person.PaymentCategory)
require.Equal(t, arg.Bankname, person.Bankname)
require.Equal(t, arg.AccountID, person.AccountID)
require.Equal(t, arg.IBAN, person.IBAN)
require.Equal(t, arg.BIC, person.BIC)
require.Equal(t, arg.PaypalAccount, person.PaypalAccount)
require.Equal(t, arg.PaymentSystem, person.PaymentSystem)
require.Equal(t, arg.PaypalID, person.PaypalID)
require.Equal(t, arg.Creator, person.Creator)
require.Equal(t, arg.Type, person.Type)
require.Equal(t, arg.PaymentCategory, payment.PaymentCategory)
require.Equal(t, arg.Bankname, payment.Bankname)
require.Equal(t, arg.AccountID, payment.AccountID)
require.Equal(t, arg.IBAN, payment.IBAN)
require.Equal(t, arg.BIC, payment.BIC)
require.Equal(t, arg.PaypalAccount, payment.PaypalAccount)
require.Equal(t, arg.PaymentSystem, payment.PaymentSystem)
require.Equal(t, arg.PaypalID, payment.PaypalID)
require.Equal(t, arg.Creator, payment.Creator)
require.Equal(t, arg.Type, payment.Type)
require.NotZero(t, person.ID)
require.NotZero(t, person.Created)
require.NotZero(t, payment.ID)
require.NotZero(t, payment.Created)
return person
return payment
}
func TestCreatePayment(t *testing.T) {
@ -74,55 +95,34 @@ func TestCreatePayment(t *testing.T) {
}
func TestGetPayment(t *testing.T) {
newperson := createRandomPayment(t)
require.NotEmpty(t, newperson)
newpayment := createRandomPayment(t)
require.NotEmpty(t, newpayment)
person, err := testQueries.GetPayment(context.Background(), newperson.ID)
payment, err := testQueries.GetPayment(context.Background(), newpayment.ID)
require.NoError(t, err)
require.NotEmpty(t, person)
require.NotEmpty(t, payment)
require.Equal(t, newperson.PaymentCategory, person.PaymentCategory)
require.Equal(t, newperson.Bankname, person.Bankname)
require.Equal(t, newperson.AccountID, person.AccountID)
require.Equal(t, newperson.IBAN, person.IBAN)
require.Equal(t, newperson.BIC, person.BIC)
require.Equal(t, newperson.PaypalAccount, person.PaypalAccount)
require.Equal(t, newperson.PaymentSystem, person.PaymentSystem)
require.Equal(t, newperson.PaypalID, person.PaypalID)
require.Equal(t, newperson.Creator, person.Creator)
require.Equal(t, newperson.Type, person.Type)
require.Equal(t, newpayment.PaymentCategory, payment.PaymentCategory)
require.Equal(t, newpayment.Bankname, payment.Bankname)
require.Equal(t, newpayment.AccountID, payment.AccountID)
require.Equal(t, newpayment.IBAN, payment.IBAN)
require.Equal(t, newpayment.BIC, payment.BIC)
require.Equal(t, newpayment.PaypalAccount, payment.PaypalAccount)
require.Equal(t, newpayment.PaymentSystem, payment.PaymentSystem)
require.Equal(t, newpayment.PaypalID, payment.PaypalID)
require.Equal(t, newpayment.Creator, payment.Creator)
require.Equal(t, newpayment.Type, payment.Type)
require.WithinDuration(t, newperson.Created, person.Created, time.Second)
require.WithinDuration(t, newpayment.Created, payment.Created, time.Second)
}
func TestDeletePayment(t *testing.T) {
person1 := createRandomPayment(t)
err := testQueries.DeletePayment(context.Background(), person1.ID)
payment1 := createRandomPayment(t)
err := testQueries.DeletePayment(context.Background(), payment1.ID)
require.NoError(t, err)
person2, err := testQueries.GetPayment(context.Background(), person1.ID)
payment2, err := testQueries.GetPayment(context.Background(), payment1.ID)
require.Error(t, err)
require.EqualError(t, err, sql.ErrNoRows.Error())
require.Empty(t, person2)
}
func TestUpdatePayment(t *testing.T) {
person1 := createRandomPayment(t)
require.NotEmpty(t, person1)
arg := UpdatePaymentParams{
ID: person1.ID,
Bankname: sql.NullString{
String: util.RandomName(),
Valid: true,
},
}
person2, err := testQueries.UpdatePayment(context.Background(), arg)
require.NoError(t, err)
require.NotEmpty(t, person2)
require.Equal(t, person1.ID, person2.ID)
require.Equal(t, person1.PaymentCategory, person2.PaymentCategory)
require.NotEqual(t, person1.Bankname, person2.Bankname)
require.Empty(t, payment2)
}

View File

@ -29,7 +29,7 @@ INSERT INTO persons (
`
type CreatePersonParams struct {
AccountID int64 `json:"account_id"`
AccountID uint64 `json:"account_id"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -114,7 +114,7 @@ SELECT id, person_id, provider_id, name, description, category, email, status, c
WHERE "person_id" = $1
`
func (q *Queries) GetReturns(ctx context.Context, id int64) ([]Return, error) {
func (q *Queries) GetReturns(ctx context.Context, id uint64) ([]Return, error) {
rows, err := q.db.QueryContext(ctx, getReturns, id)
if err != nil {
return nil, err
@ -156,7 +156,7 @@ WHERE "account_id" = $1
ORDER BY "lastname", "firstname"
`
func (q *Queries) ListPersons(ctx context.Context, accountID int64) ([]Person, error) {
func (q *Queries) ListPersons(ctx context.Context, accountID uint64) ([]Person, error) {
rows, err := q.db.QueryContext(ctx, listPersons, accountID)
if err != nil {
return nil, err
@ -196,14 +196,13 @@ func (q *Queries) ListPersons(ctx context.Context, accountID int64) ([]Person, e
const updatePerson = `-- name: UpdatePerson :one
UPDATE persons
SET
"account_id" = COALESCE($3, "account_id"),
"firstname" = COALESCE($4, "firstname"),
"lastname" = COALESCE($5, "lastname"),
"birthday" = COALESCE($6, "birthday"),
"city" = COALESCE($7, "city"),
"zip" = COALESCE($8, "zip"),
"street" = COALESCE($9, "street"),
"country" = COALESCE($10, "country"),
"firstname" = COALESCE($3, "firstname"),
"lastname" = COALESCE($4, "lastname"),
"birthday" = COALESCE($5, "birthday"),
"city" = COALESCE($6, "city"),
"zip" = COALESCE($7, "zip"),
"street" = COALESCE($8, "street"),
"country" = COALESCE($9, "country"),
"changer" = $2,
"changed" = now()
WHERE "id" = $1
@ -213,7 +212,6 @@ RETURNING id, account_id, firstname, lastname, birthday, city, zip, street, coun
type UpdatePersonParams struct {
ID uint64 `json:"id"`
Changer string `json:"changer"`
AccountID sql.NullInt64 `json:"account_id"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
@ -227,7 +225,6 @@ func (q *Queries) UpdatePerson(ctx context.Context, arg UpdatePersonParams) (Per
row := q.db.QueryRowContext(ctx, updatePerson,
arg.ID,
arg.Changer,
arg.AccountID,
arg.Firstname,
arg.Lastname,
arg.Birthday,

View File

@ -17,7 +17,7 @@ func createRandomPerson(t *testing.T) Person {
creator := util.RandomName()
arg := CreatePersonParams{
AccountID: int64(account.ID),
AccountID: account.ID,
Firstname: util.RandomName(),
Lastname: util.RandomName(),
Birthday: time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC),

View File

@ -53,15 +53,15 @@ type Querier interface {
GetPerson(ctx context.Context, id uint64) (Person, error)
GetProvider(ctx context.Context, id uint64) (Provider, error)
GetReturn(ctx context.Context, id uint64) (Return, error)
GetReturns(ctx context.Context, id int64) ([]Return, error)
GetReturns(ctx context.Context, id uint64) ([]Return, error)
GetReturnsLog(ctx context.Context, id uint64) (ReturnsLog, error)
GetSession(ctx context.Context, id uuid.UUID) (Session, error)
InvalidateDocument(ctx context.Context, arg InvalidateDocumentParams) (Document, error)
ListAccounts(ctx context.Context, arg ListAccountsParams) ([]Account, error)
ListDocuments(ctx context.Context, arg ListDocumentsParams) ([]Document, error)
ListMails(ctx context.Context, arg ListMailsParams) ([]Mail, error)
ListPayments(ctx context.Context, accountID int64) ([]Payment, error)
ListPersons(ctx context.Context, accountID int64) ([]Person, error)
ListPayments(ctx context.Context, accountID uint64) ([]Payment, error)
ListPersons(ctx context.Context, accountID uint64) ([]Person, error)
ListProviders(ctx context.Context, arg ListProvidersParams) ([]Provider, error)
ListReturns(ctx context.Context, arg ListReturnsParams) ([]Return, error)
ListReturnsLogs(ctx context.Context, arg ListReturnsLogsParams) ([]ReturnsLog, error)

View File

@ -37,7 +37,7 @@ FROM providers
type CloneProvidersParams struct {
Creator string `json:"creator"`
PersonID int64 `json:"person_id"`
PersonID uint64 `json:"person_id"`
}
func (q *Queries) CloneProviders(ctx context.Context, arg CloneProvidersParams) error {
@ -70,8 +70,8 @@ INSERT INTO returns (
`
type CreateReturnParams struct {
PersonID int64 `json:"person_id"`
ProviderID int64 `json:"provider_id"`
PersonID uint64 `json:"person_id"`
ProviderID uint64 `json:"provider_id"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
@ -197,22 +197,18 @@ func (q *Queries) ListReturns(ctx context.Context, arg ListReturnsParams) ([]Ret
const updateReturn = `-- name: UpdateReturn :one
UPDATE returns
SET
"person_id" = COALESCE($1, "person_id"),
"provider_id" = COALESCE($2, "provider_id"),
"name" = COALESCE($3, "name"),
"description" = COALESCE($4, "description"),
"category" = COALESCE($5, "category"),
"email" = COALESCE($6, "email"),
"status" = COALESCE($7, "status"),
"changer" = $8,
"name" = COALESCE($1, "name"),
"description" = COALESCE($2, "description"),
"category" = COALESCE($3, "category"),
"email" = COALESCE($4, "email"),
"status" = COALESCE($5, "status"),
"changer" = $6,
"changed" = now()
WHERE "id" = $9
WHERE "id" = $7
RETURNING id, person_id, provider_id, name, description, category, email, status, creator, created, changer, changed
`
type UpdateReturnParams struct {
PersonID sql.NullInt64 `json:"person_id"`
ProviderID sql.NullInt64 `json:"provider_id"`
Name sql.NullString `json:"name"`
Description sql.NullString `json:"description"`
Category sql.NullString `json:"category"`
@ -224,8 +220,6 @@ type UpdateReturnParams struct {
func (q *Queries) UpdateReturn(ctx context.Context, arg UpdateReturnParams) (Return, error) {
row := q.db.QueryRowContext(ctx, updateReturn,
arg.PersonID,
arg.ProviderID,
arg.Name,
arg.Description,
arg.Category,

View File

@ -18,8 +18,8 @@ func createRandomReturn(t *testing.T) Return {
creator := util.RandomName()
arg := CreateReturnParams{
PersonID: int64(person.ID),
ProviderID: int64(provider.ID),
PersonID: person.ID,
ProviderID: provider.ID,
Status: util.RandomString(7),
Name: util.RandomName(),
Description: util.RandomString(30),

View File

@ -27,8 +27,8 @@ INSERT INTO "returnsLog" (
`
type CreateReturnsLogParams struct {
ReturnID int64 `json:"return_id"`
MailID int64 `json:"mail_id"`
ReturnID uint64 `json:"return_id"`
MailID uint64 `json:"mail_id"`
Status sql.NullString `json:"status"`
Creator string `json:"creator"`
}
@ -132,31 +132,21 @@ func (q *Queries) ListReturnsLogs(ctx context.Context, arg ListReturnsLogsParams
const updateReturnsLog = `-- name: UpdateReturnsLog :one
UPDATE "returnsLog"
SET
"return_id" = COALESCE($2, "return_id"),
"mail_id" = COALESCE($3, "mail_id"),
"status" = COALESCE($4, "status"),
"status" = COALESCE($2, "status"),
"changer" = $1,
"changed" = now()
WHERE "id" = $5
WHERE "id" = $3
RETURNING id, return_id, mail_id, status, creator, created, changer, changed
`
type UpdateReturnsLogParams struct {
Changer string `json:"changer"`
ReturnID sql.NullInt64 `json:"return_id"`
MailID sql.NullInt64 `json:"mail_id"`
Status sql.NullString `json:"status"`
ID uint64 `json:"id"`
Changer string `json:"changer"`
Status sql.NullString `json:"status"`
ID uint64 `json:"id"`
}
func (q *Queries) UpdateReturnsLog(ctx context.Context, arg UpdateReturnsLogParams) (ReturnsLog, error) {
row := q.db.QueryRowContext(ctx, updateReturnsLog,
arg.Changer,
arg.ReturnID,
arg.MailID,
arg.Status,
arg.ID,
)
row := q.db.QueryRowContext(ctx, updateReturnsLog, arg.Changer, arg.Status, arg.ID)
var i ReturnsLog
err := row.Scan(
&i.ID,

View File

@ -18,8 +18,8 @@ func createRandomReturnsLog(t *testing.T) ReturnsLog {
creator := util.RandomName()
arg := CreateReturnsLogParams{
ReturnID: int64(ret.ID),
MailID: int64(mail.ID),
ReturnID: ret.ID,
MailID: mail.ID,
Status: sql.NullString{
Valid: true,
String: util.RandomString(7),

View File

@ -6,7 +6,7 @@ import (
)
type CreatePersonTxParams struct {
AccountID int64 `json:"account_id"`
AccountID uint64 `json:"account_id"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -35,7 +35,7 @@ func (store *SQLStore) CreatePersonTx(ctx context.Context, arg CreatePersonTxPar
err = q.CloneProviders(ctx, CloneProvidersParams{
Creator: arg.Creator,
PersonID: int64(result.Person.ID),
PersonID: result.Person.ID,
})
return err
})

View File

@ -1015,7 +1015,7 @@
"properties": {
"id": {
"type": "string",
"format": "int64"
"format": "uint64"
},
"deleted": {
"type": "boolean"
@ -1032,7 +1032,7 @@
"properties": {
"id": {
"type": "string",
"format": "int64"
"format": "uint64"
},
"deleted": {
"type": "boolean"

View File

@ -38,9 +38,8 @@ func (server *Server) CreatePayment(ctx context.Context, req *pb.CreatePaymentRe
}
}
accountID := int64(req.GetAccountId())
arg := db.CreatePaymentParams{
AccountID: accountID,
AccountID: req.GetAccountId(),
PaymentCategory: req.GetPaymentCategory(),
Bankname: sql.NullString{
Valid: req.GetBankname() != "",

View File

@ -38,9 +38,8 @@ func (server *Server) CreatePerson(ctx context.Context, req *pb.CreatePersonRequ
}
}
accountID := int64(req.GetAccountId())
arg := db.CreatePersonTxParams{
AccountID: accountID,
AccountID: account.ID,
Firstname: req.GetFirstname(),
Lastname: req.GetLastname(),
Birthday: req.GetBirthday().AsTime(),

View File

@ -44,10 +44,7 @@ func (server *Server) DeletePayment(ctx context.Context, req *pb.DeletePaymentRe
return nil, status.Errorf(codes.Internal, "failed to get payment")
}
paymentID := int64(req.GetId())
accountID := int64(account.ID)
if payment.AccountID != accountID {
if payment.AccountID != account.ID {
if !server.isAdmin(ctx, authPayload) {
return nil, status.Error(codes.NotFound, "payment not found")
}
@ -60,7 +57,7 @@ func (server *Server) DeletePayment(ctx context.Context, req *pb.DeletePaymentRe
}
rsp := &pb.DeletePaymentResponse{
Id: paymentID,
Id: payment.ID,
Deleted: true,
}
return rsp, nil

View File

@ -44,10 +44,7 @@ func (server *Server) DeletePerson(ctx context.Context, req *pb.DeletePersonRequ
return nil, status.Errorf(codes.Internal, "failed to get person")
}
personID := int64(person.ID)
accountID := int64(account.ID)
if person.AccountID != accountID {
if person.AccountID != account.ID {
if !server.isAdmin(ctx, authPayload) {
return nil, status.Error(codes.NotFound, "person not found")
}
@ -60,7 +57,7 @@ func (server *Server) DeletePerson(ctx context.Context, req *pb.DeletePersonRequ
}
rsp := &pb.DeletePersonResponse{
Id: personID,
Id: person.ID,
Deleted: true,
}
return rsp, nil

View File

@ -44,9 +44,7 @@ func (server *Server) GetPayment(ctx context.Context, req *pb.GetPaymentRequest)
return nil, status.Error(codes.NotFound, "failed to get payments")
}
accountID := int64(account.ID)
if accountID != payment.AccountID {
if account.ID != payment.AccountID {
if !server.isAdmin(ctx, authPayload) {
return nil, status.Error(codes.NotFound, "account not found")
}

View File

@ -44,9 +44,7 @@ func (server *Server) GetPerson(ctx context.Context, req *pb.GetPersonRequest) (
return nil, status.Error(codes.NotFound, "failed to get persons")
}
accountID := int64(account.ID)
if accountID != person.AccountID {
if account.ID != person.AccountID {
if !server.isAdmin(ctx, authPayload) {
return nil, status.Error(codes.NotFound, "account not found")
}

View File

@ -42,9 +42,7 @@ func (server *Server) ListPayments(ctx context.Context, req *pb.ListPaymentsRequ
}
}
accountID := int64(account.ID)
dbPayments, err := server.store.ListPayments(ctx, accountID)
dbPayments, err := server.store.ListPayments(ctx, account.ID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, status.Error(codes.NotFound, "no payments found")

View File

@ -42,9 +42,7 @@ func (server *Server) ListPersons(ctx context.Context, req *pb.ListPersonsReques
}
}
accountID := int64(account.ID)
dbPersons, err := server.store.ListPersons(ctx, accountID)
dbPersons, err := server.store.ListPersons(ctx, account.ID)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, status.Error(codes.NotFound, "no persons found")

View File

@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"log/slog"
db "github.com/itsscb/df/bff/db/sqlc"
"github.com/itsscb/df/bff/pb"
@ -46,9 +47,7 @@ func (server *Server) UpdatePayment(ctx context.Context, req *pb.UpdatePaymentRe
return nil, status.Error(codes.Internal, "failed to get payment")
}
accountID := int64(account.ID)
if dbPayment.AccountID != accountID {
if dbPayment.AccountID != account.ID {
if !server.isAdmin(ctx, authPayload) {
return nil, status.Error(codes.NotFound, "payment not found")
}
@ -93,6 +92,7 @@ func (server *Server) UpdatePayment(ctx context.Context, req *pb.UpdatePaymentRe
payment, err := server.store.UpdatePayment(ctx, arg)
if err != nil {
slog.Error("Update Payment", slog.Int64("id", int64(req.GetId())), slog.String("error", err.Error()))
return nil, status.Error(codes.Internal, "failed to update payment")
}

View File

@ -73,8 +73,8 @@ type DeletePaymentResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Deleted bool `protobuf:"varint,2,opt,name=deleted,proto3" json:"deleted,omitempty"`
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Deleted bool `protobuf:"varint,2,opt,name=deleted,proto3" json:"deleted,omitempty"`
}
func (x *DeletePaymentResponse) Reset() {
@ -109,7 +109,7 @@ func (*DeletePaymentResponse) Descriptor() ([]byte, []int) {
return file_rpc_delete_payment_proto_rawDescGZIP(), []int{1}
}
func (x *DeletePaymentResponse) GetId() int64 {
func (x *DeletePaymentResponse) GetId() uint64 {
if x != nil {
return x.Id
}
@ -139,7 +139,7 @@ var file_rpc_delete_payment_proto_rawDesc = []byte{
0x01, 0x02, 0x69, 0x64, 0x32, 0x0b, 0x7b, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x20, 0x22, 0x31, 0x22,
0x7d, 0x22, 0x7f, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x61, 0x79, 0x6d, 0x65,
0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x64, 0x3a, 0x3c, 0x92, 0x41, 0x39, 0x0a, 0x19, 0x2a, 0x17, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x20, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x52, 0x65, 0x73, 0x70,

View File

@ -73,8 +73,8 @@ type DeletePersonResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Deleted bool `protobuf:"varint,2,opt,name=deleted,proto3" json:"deleted,omitempty"`
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Deleted bool `protobuf:"varint,2,opt,name=deleted,proto3" json:"deleted,omitempty"`
}
func (x *DeletePersonResponse) Reset() {
@ -109,7 +109,7 @@ func (*DeletePersonResponse) Descriptor() ([]byte, []int) {
return file_rpc_delete_person_proto_rawDescGZIP(), []int{1}
}
func (x *DeletePersonResponse) GetId() int64 {
func (x *DeletePersonResponse) GetId() uint64 {
if x != nil {
return x.Id
}
@ -139,7 +139,7 @@ var file_rpc_delete_person_proto_rawDesc = []byte{
0x32, 0x0b, 0x7b, 0x22, 0x69, 0x64, 0x22, 0x3a, 0x20, 0x22, 0x31, 0x22, 0x7d, 0x22, 0x7d, 0x0a,
0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64,
0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64,
0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x3a,
0x3b, 0x92, 0x41, 0x38, 0x0a, 0x18, 0x2a, 0x16, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x20, 0x50,
0x65, 0x72, 0x73, 0x6f, 0x6e, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x1c,

View File

@ -27,6 +27,6 @@ message DeletePaymentResponse {
};
example: "{\"id\": \"1\", \"deleted\": true}"
};
int64 id = 1;
uint64 id = 1;
bool deleted = 2;
}

View File

@ -27,6 +27,6 @@ message DeletePersonResponse {
};
example: "{\"id\": \"1\", \"deleted\": true}"
};
int64 id = 1;
uint64 id = 1;
bool deleted = 2;
}

View File

@ -15,8 +15,19 @@ sql:
overrides:
- db_type: "bigserial"
go_type: "uint64"
- db_type: "bigint"
null: false
- column: "payments.account_id"
go_type: "uint64"
- column: "persons.account_id"
go_type: "uint64"
- column: "documents.account_id"
go_type: "uint64"
- column: "returnsLog.return_id"
go_type: "uint64"
- column: "returnsLog.mail_id"
go_type: "uint64"
- column: "returns.provider_id"
go_type: "uint64"
- column: "returns.person_id"
go_type: "uint64"
- db_type: "timestamptz"
go_type: "time.Time"