rf/renames customer to account

seems to be more idiomatic
This commit is contained in:
itsscb 2023-09-21 21:41:30 +02:00
parent b88be701bb
commit fb6735c630
15 changed files with 154 additions and 150 deletions

7
api/account.go Normal file
View File

@ -0,0 +1,7 @@
package api
import "github.com/gin-gonic/gin"
func (server *Server) createAccount(ctx *gin.Context) {
}

View File

@ -5,7 +5,7 @@ DROP TABLE IF EXISTS "documents";
DROP TABLE IF EXISTS "mails"; DROP TABLE IF EXISTS "mails";
DROP TABLE IF EXISTS "persons"; DROP TABLE IF EXISTS "persons";
DROP TABLE IF EXISTS "providers"; DROP TABLE IF EXISTS "providers";
DROP TABLE IF EXISTS "customers"; DROP TABLE IF EXISTS "accounts";

View File

@ -12,7 +12,7 @@ CREATE TABLE "mails" (
"changed" timestamptz NOT NULL DEFAULT (now()) "changed" timestamptz NOT NULL DEFAULT (now())
); );
CREATE TABLE "customers" ( CREATE TABLE "accounts" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL, "ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"username" varchar UNIQUE NOT NULL, "username" varchar UNIQUE NOT NULL,
"passwordhash" varchar NOT NULL, "passwordhash" varchar NOT NULL,
@ -38,7 +38,7 @@ CREATE TABLE "customers" (
CREATE TABLE "persons" ( CREATE TABLE "persons" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL, "ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"customerID" bigint NOT NULL, "accountID" bigint NOT NULL,
"firstname" varchar NOT NULL, "firstname" varchar NOT NULL,
"lastname" varchar NOT NULL, "lastname" varchar NOT NULL,
"birthday" timestamptz NOT NULL, "birthday" timestamptz NOT NULL,
@ -71,7 +71,7 @@ CREATE TABLE "documents" (
CREATE TABLE "payments" ( CREATE TABLE "payments" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL, "ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"customerID" bigint NOT NULL, "accountID" bigint NOT NULL,
"paymentCategory" varchar NOT NULL, "paymentCategory" varchar NOT NULL,
"bankname" varchar, "bankname" varchar,
"IBAN" varchar, "IBAN" varchar,
@ -124,13 +124,13 @@ CREATE TABLE "returnsLog" (
"changed" timestamptz NOT NULL DEFAULT (now()) "changed" timestamptz NOT NULL DEFAULT (now())
); );
ALTER TABLE "persons" ADD FOREIGN KEY ("customerID") REFERENCES "customers" ("ID"); ALTER TABLE "persons" ADD FOREIGN KEY ("accountID") REFERENCES "accounts" ("ID");
ALTER TABLE "documents" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID"); ALTER TABLE "documents" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
ALTER TABLE "documents" ADD FOREIGN KEY ("mailID") REFERENCES "mails" ("ID"); ALTER TABLE "documents" ADD FOREIGN KEY ("mailID") REFERENCES "mails" ("ID");
ALTER TABLE "payments" ADD FOREIGN KEY ("customerID") REFERENCES "customers" ("ID"); ALTER TABLE "payments" ADD FOREIGN KEY ("accountID") REFERENCES "accounts" ("ID");
ALTER TABLE "returns" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID"); ALTER TABLE "returns" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");

View File

@ -1,9 +1,9 @@
-- name: GetCustomer :one -- name: GetAccount :one
SELECT * FROM customers SELECT * FROM accounts
WHERE "ID" = $1 LIMIT 1; WHERE "ID" = $1 LIMIT 1;
-- name: CreateCustomer :one -- name: CreateAccount :one
INSERT INTO customers ( INSERT INTO accounts (
username, username,
passwordhash, passwordhash,
firstname, firstname,
@ -21,14 +21,14 @@ INSERT INTO customers (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
) RETURNING *; ) RETURNING *;
-- name: ListCustomers :many -- name: ListAccounts :many
SELECT * FROM customers SELECT * FROM accounts
ORDER BY username ORDER BY username
LIMIT $1 LIMIT $1
OFFSET $2; OFFSET $2;
-- name: UpdateCustomer :one -- name: UpdateAccount :one
UPDATE customers UPDATE accounts
SET SET
username = COALESCE(sqlc.narg(username), username), username = COALESCE(sqlc.narg(username), username),
passwordhash = COALESCE(sqlc.narg(passwordhash), passwordhash), passwordhash = COALESCE(sqlc.narg(passwordhash), passwordhash),
@ -46,6 +46,6 @@ SET
WHERE "ID" = $1 WHERE "ID" = $1
RETURNING *; RETURNING *;
-- name: DeleteCustomer :exec -- name: DeleteAccount :exec
DELETE FROM customers DELETE FROM accounts
WHERE "ID" = $1; WHERE "ID" = $1;

View File

@ -4,7 +4,7 @@ WHERE "ID" = $1 LIMIT 1;
-- name: CreatePayment :one -- name: CreatePayment :one
INSERT INTO payments ( INSERT INTO payments (
"customerID", "accountID",
"paymentCategory", "paymentCategory",
bankname, bankname,
"IBAN", "IBAN",
@ -28,7 +28,7 @@ OFFSET $2;
-- name: UpdatePayment :one -- name: UpdatePayment :one
UPDATE payments UPDATE payments
SET SET
"customerID" = COALESCE(sqlc.narg(customerID), "customerID"), "accountID" = COALESCE(sqlc.narg(accountID), "accountID"),
"paymentCategory" = COALESCE(sqlc.narg(paymentCategory), "paymentCategory"), "paymentCategory" = COALESCE(sqlc.narg(paymentCategory), "paymentCategory"),
bankname = COALESCE(sqlc.narg(bankname), bankname), bankname = COALESCE(sqlc.narg(bankname), bankname),
"IBAN" = COALESCE(sqlc.narg(IBAN), "IBAN"), "IBAN" = COALESCE(sqlc.narg(IBAN), "IBAN"),

View File

@ -4,7 +4,7 @@ WHERE "ID" = $1 LIMIT 1;
-- name: CreatePerson :one -- name: CreatePerson :one
INSERT INTO persons ( INSERT INTO persons (
"customerID", "accountID",
firstname, firstname,
lastname, lastname,
birthday, birthday,
@ -27,7 +27,7 @@ OFFSET $2;
-- name: UpdatePerson :one -- name: UpdatePerson :one
UPDATE persons UPDATE persons
SET SET
"customerID" = COALESCE(sqlc.narg(customerID), "customerID"), "accountID" = COALESCE(sqlc.narg(accountID), "accountID"),
firstname = COALESCE(sqlc.narg(firstname), firstname), firstname = COALESCE(sqlc.narg(firstname), firstname),
lastname = COALESCE(sqlc.narg(lastname), lastname), lastname = COALESCE(sqlc.narg(lastname), lastname),
birthday = COALESCE(sqlc.narg(birthday), birthday), birthday = COALESCE(sqlc.narg(birthday), birthday),

View File

@ -1,7 +1,7 @@
// Code generated by sqlc. DO NOT EDIT. // Code generated by sqlc. DO NOT EDIT.
// versions: // versions:
// sqlc v1.21.0 // sqlc v1.21.0
// source: customer.sql // source: account.sql
package db package db
@ -11,8 +11,8 @@ import (
"time" "time"
) )
const createCustomer = `-- name: CreateCustomer :one const createAccount = `-- name: CreateAccount :one
INSERT INTO customers ( INSERT INTO accounts (
username, username,
passwordhash, passwordhash,
firstname, firstname,
@ -31,7 +31,7 @@ INSERT INTO customers (
) RETURNING "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed ) RETURNING "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
` `
type CreateCustomerParams struct { type CreateAccountParams struct {
Username string `json:"username"` Username string `json:"username"`
Passwordhash string `json:"passwordhash"` Passwordhash string `json:"passwordhash"`
Firstname string `json:"firstname"` Firstname string `json:"firstname"`
@ -47,8 +47,8 @@ type CreateCustomerParams struct {
Changer string `json:"changer"` Changer string `json:"changer"`
} }
func (q *Queries) CreateCustomer(ctx context.Context, arg CreateCustomerParams) (Customer, error) { func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
row := q.db.QueryRowContext(ctx, createCustomer, row := q.db.QueryRowContext(ctx, createAccount,
arg.Username, arg.Username,
arg.Passwordhash, arg.Passwordhash,
arg.Firstname, arg.Firstname,
@ -63,7 +63,7 @@ func (q *Queries) CreateCustomer(ctx context.Context, arg CreateCustomerParams)
arg.Creator, arg.Creator,
arg.Changer, arg.Changer,
) )
var i Customer var i Account
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.Username, &i.Username,
@ -90,24 +90,24 @@ func (q *Queries) CreateCustomer(ctx context.Context, arg CreateCustomerParams)
return i, err return i, err
} }
const deleteCustomer = `-- name: DeleteCustomer :exec const deleteAccount = `-- name: DeleteAccount :exec
DELETE FROM customers DELETE FROM accounts
WHERE "ID" = $1 WHERE "ID" = $1
` `
func (q *Queries) DeleteCustomer(ctx context.Context, id int64) error { func (q *Queries) DeleteAccount(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteCustomer, id) _, err := q.db.ExecContext(ctx, deleteAccount, id)
return err return err
} }
const getCustomer = `-- name: GetCustomer :one const getAccount = `-- name: GetAccount :one
SELECT "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM customers SELECT "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
WHERE "ID" = $1 LIMIT 1 WHERE "ID" = $1 LIMIT 1
` `
func (q *Queries) GetCustomer(ctx context.Context, id int64) (Customer, error) { func (q *Queries) GetAccount(ctx context.Context, id int64) (Account, error) {
row := q.db.QueryRowContext(ctx, getCustomer, id) row := q.db.QueryRowContext(ctx, getAccount, id)
var i Customer var i Account
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.Username, &i.Username,
@ -134,27 +134,27 @@ func (q *Queries) GetCustomer(ctx context.Context, id int64) (Customer, error) {
return i, err return i, err
} }
const listCustomers = `-- name: ListCustomers :many const listAccounts = `-- name: ListAccounts :many
SELECT "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM customers SELECT "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
ORDER BY username ORDER BY username
LIMIT $1 LIMIT $1
OFFSET $2 OFFSET $2
` `
type ListCustomersParams struct { type ListAccountsParams struct {
Limit int32 `json:"limit"` Limit int32 `json:"limit"`
Offset int32 `json:"offset"` Offset int32 `json:"offset"`
} }
func (q *Queries) ListCustomers(ctx context.Context, arg ListCustomersParams) ([]Customer, error) { func (q *Queries) ListAccounts(ctx context.Context, arg ListAccountsParams) ([]Account, error) {
rows, err := q.db.QueryContext(ctx, listCustomers, arg.Limit, arg.Offset) rows, err := q.db.QueryContext(ctx, listAccounts, arg.Limit, arg.Offset)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rows.Close() defer rows.Close()
items := []Customer{} items := []Account{}
for rows.Next() { for rows.Next() {
var i Customer var i Account
if err := rows.Scan( if err := rows.Scan(
&i.ID, &i.ID,
&i.Username, &i.Username,
@ -191,8 +191,8 @@ func (q *Queries) ListCustomers(ctx context.Context, arg ListCustomersParams) ([
return items, nil return items, nil
} }
const updateCustomer = `-- name: UpdateCustomer :one const updateAccount = `-- name: UpdateAccount :one
UPDATE customers UPDATE accounts
SET SET
username = COALESCE($3, username), username = COALESCE($3, username),
passwordhash = COALESCE($4, passwordhash), passwordhash = COALESCE($4, passwordhash),
@ -211,7 +211,7 @@ WHERE "ID" = $1
RETURNING "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed RETURNING "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
` `
type UpdateCustomerParams struct { type UpdateAccountParams struct {
ID int64 `json:"ID"` ID int64 `json:"ID"`
Changer string `json:"changer"` Changer string `json:"changer"`
Username sql.NullString `json:"username"` Username sql.NullString `json:"username"`
@ -227,8 +227,8 @@ type UpdateCustomerParams struct {
Country sql.NullString `json:"country"` Country sql.NullString `json:"country"`
} }
func (q *Queries) UpdateCustomer(ctx context.Context, arg UpdateCustomerParams) (Customer, error) { func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) {
row := q.db.QueryRowContext(ctx, updateCustomer, row := q.db.QueryRowContext(ctx, updateAccount,
arg.ID, arg.ID,
arg.Changer, arg.Changer,
arg.Username, arg.Username,
@ -243,7 +243,7 @@ func (q *Queries) UpdateCustomer(ctx context.Context, arg UpdateCustomerParams)
arg.Street, arg.Street,
arg.Country, arg.Country,
) )
var i Customer var i Account
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.Username, &i.Username,

View File

@ -10,11 +10,11 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func createRandomCustomer(t *testing.T) Customer { func createRandomAccount(t *testing.T) Account {
creator := util.RandomUser() creator := util.RandomUser()
arg := CreateCustomerParams{ arg := CreateAccountParams{
Username: util.RandomUser(), Username: util.RandomUser(),
Passwordhash: util.RandomString(30), Passwordhash: util.RandomString(30),
Firstname: util.RandomUser(), Firstname: util.RandomUser(),
@ -33,7 +33,7 @@ func createRandomCustomer(t *testing.T) Customer {
Changer: creator, Changer: creator,
} }
account, err := testQueries.CreateCustomer(context.Background(), arg) account, err := testQueries.CreateAccount(context.Background(), arg)
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, account) require.NotEmpty(t, account)
@ -57,15 +57,15 @@ func createRandomCustomer(t *testing.T) Customer {
return account return account
} }
func TestCreateCustomer(t *testing.T) { func TestCreateAccount(t *testing.T) {
createRandomCustomer(t) createRandomAccount(t)
} }
func TestGetCustomer(t *testing.T) { func TestGetAccount(t *testing.T) {
newAccount := createRandomCustomer(t) newAccount := createRandomAccount(t)
require.NotEmpty(t, newAccount) require.NotEmpty(t, newAccount)
account, err := testQueries.GetCustomer(context.Background(), newAccount.ID) account, err := testQueries.GetAccount(context.Background(), newAccount.ID)
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, account) require.NotEmpty(t, account)
@ -86,22 +86,22 @@ func TestGetCustomer(t *testing.T) {
require.WithinDuration(t, newAccount.Created, account.Created, time.Second) require.WithinDuration(t, newAccount.Created, account.Created, time.Second)
} }
func TestDeleteCustomer(t *testing.T) { func TestDeleteAccount(t *testing.T) {
account1 := createRandomCustomer(t) account1 := createRandomAccount(t)
err := testQueries.DeleteCustomer(context.Background(), account1.ID) err := testQueries.DeleteAccount(context.Background(), account1.ID)
require.NoError(t, err) require.NoError(t, err)
account2, err := testQueries.GetCustomer(context.Background(), account1.ID) account2, err := testQueries.GetAccount(context.Background(), account1.ID)
require.Error(t, err) require.Error(t, err)
require.EqualError(t, err, sql.ErrNoRows.Error()) require.EqualError(t, err, sql.ErrNoRows.Error())
require.Empty(t, account2) require.Empty(t, account2)
} }
func TestUpdateCustomer(t *testing.T) { func TestUpdateAccount(t *testing.T) {
account1 := createRandomCustomer(t) account1 := createRandomAccount(t)
require.NotEmpty(t, account1) require.NotEmpty(t, account1)
arg := UpdateCustomerParams{ arg := UpdateAccountParams{
ID: account1.ID, ID: account1.ID,
Phone: sql.NullString{ Phone: sql.NullString{
String: util.RandomPhone(), String: util.RandomPhone(),
@ -109,7 +109,7 @@ func TestUpdateCustomer(t *testing.T) {
}, },
} }
account2, err := testQueries.UpdateCustomer(context.Background(), arg) account2, err := testQueries.UpdateAccount(context.Background(), arg)
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, account2) require.NotEmpty(t, account2)
@ -119,17 +119,17 @@ func TestUpdateCustomer(t *testing.T) {
require.NotEqual(t, account1.Changer, account2.Changer) require.NotEqual(t, account1.Changer, account2.Changer)
} }
func TestListCustomers(t *testing.T) { func TestListAccounts(t *testing.T) {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
createRandomCustomer(t) createRandomAccount(t)
} }
arg := ListCustomersParams{ arg := ListAccountsParams{
Limit: 5, Limit: 5,
Offset: 5, Offset: 5,
} }
accounts, err := testQueries.ListCustomers(context.Background(), arg) accounts, err := testQueries.ListAccounts(context.Background(), arg)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, accounts, 5) require.Len(t, accounts, 5)

View File

@ -9,7 +9,7 @@ import (
"time" "time"
) )
type Customer struct { type Account struct {
ID int64 `json:"ID"` ID int64 `json:"ID"`
Username string `json:"username"` Username string `json:"username"`
Passwordhash string `json:"passwordhash"` Passwordhash string `json:"passwordhash"`
@ -66,7 +66,7 @@ type Mail struct {
type Payment struct { type Payment struct {
ID int64 `json:"ID"` ID int64 `json:"ID"`
CustomerID int64 `json:"customerID"` AccountID int64 `json:"accountID"`
PaymentCategory string `json:"paymentCategory"` PaymentCategory string `json:"paymentCategory"`
Bankname sql.NullString `json:"bankname"` Bankname sql.NullString `json:"bankname"`
IBAN sql.NullString `json:"IBAN"` IBAN sql.NullString `json:"IBAN"`
@ -82,19 +82,19 @@ type Payment struct {
} }
type Person struct { type Person struct {
ID int64 `json:"ID"` ID int64 `json:"ID"`
CustomerID int64 `json:"customerID"` AccountID int64 `json:"accountID"`
Firstname string `json:"firstname"` Firstname string `json:"firstname"`
Lastname string `json:"lastname"` Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"` Birthday time.Time `json:"birthday"`
City string `json:"city"` City string `json:"city"`
Zip string `json:"zip"` Zip string `json:"zip"`
Street string `json:"street"` Street string `json:"street"`
Country string `json:"country"` Country string `json:"country"`
Creator string `json:"creator"` Creator string `json:"creator"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Changer string `json:"changer"` Changer string `json:"changer"`
Changed time.Time `json:"changed"` Changed time.Time `json:"changed"`
} }
type Provider struct { type Provider struct {

View File

@ -12,7 +12,7 @@ import (
const createPayment = `-- name: CreatePayment :one const createPayment = `-- name: CreatePayment :one
INSERT INTO payments ( INSERT INTO payments (
"customerID", "accountID",
"paymentCategory", "paymentCategory",
bankname, bankname,
"IBAN", "IBAN",
@ -25,11 +25,11 @@ INSERT INTO payments (
changer changer
) VALUES ( ) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
) RETURNING "ID", "customerID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed ) RETURNING "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed
` `
type CreatePaymentParams struct { type CreatePaymentParams struct {
CustomerID int64 `json:"customerID"` AccountID int64 `json:"accountID"`
PaymentCategory string `json:"paymentCategory"` PaymentCategory string `json:"paymentCategory"`
Bankname sql.NullString `json:"bankname"` Bankname sql.NullString `json:"bankname"`
IBAN sql.NullString `json:"IBAN"` IBAN sql.NullString `json:"IBAN"`
@ -44,7 +44,7 @@ type CreatePaymentParams struct {
func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (Payment, error) { func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (Payment, error) {
row := q.db.QueryRowContext(ctx, createPayment, row := q.db.QueryRowContext(ctx, createPayment,
arg.CustomerID, arg.AccountID,
arg.PaymentCategory, arg.PaymentCategory,
arg.Bankname, arg.Bankname,
arg.IBAN, arg.IBAN,
@ -59,7 +59,7 @@ func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (P
var i Payment var i Payment
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.PaymentCategory, &i.PaymentCategory,
&i.Bankname, &i.Bankname,
&i.IBAN, &i.IBAN,
@ -87,7 +87,7 @@ func (q *Queries) DeletePayment(ctx context.Context, id int64) error {
} }
const getPayment = `-- name: GetPayment :one const getPayment = `-- name: GetPayment :one
SELECT "ID", "customerID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed FROM payments SELECT "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed FROM payments
WHERE "ID" = $1 LIMIT 1 WHERE "ID" = $1 LIMIT 1
` `
@ -96,7 +96,7 @@ func (q *Queries) GetPayment(ctx context.Context, id int64) (Payment, error) {
var i Payment var i Payment
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.PaymentCategory, &i.PaymentCategory,
&i.Bankname, &i.Bankname,
&i.IBAN, &i.IBAN,
@ -114,7 +114,7 @@ func (q *Queries) GetPayment(ctx context.Context, id int64) (Payment, error) {
} }
const listPayments = `-- name: ListPayments :many const listPayments = `-- name: ListPayments :many
SELECT "ID", "customerID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed FROM payments SELECT "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed FROM payments
ORDER BY "paymentCategory" ORDER BY "paymentCategory"
LIMIT $1 LIMIT $1
OFFSET $2 OFFSET $2
@ -136,7 +136,7 @@ func (q *Queries) ListPayments(ctx context.Context, arg ListPaymentsParams) ([]P
var i Payment var i Payment
if err := rows.Scan( if err := rows.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.PaymentCategory, &i.PaymentCategory,
&i.Bankname, &i.Bankname,
&i.IBAN, &i.IBAN,
@ -166,7 +166,7 @@ func (q *Queries) ListPayments(ctx context.Context, arg ListPaymentsParams) ([]P
const updatePayment = `-- name: UpdatePayment :one const updatePayment = `-- name: UpdatePayment :one
UPDATE payments UPDATE payments
SET SET
"customerID" = COALESCE($3, "customerID"), "accountID" = COALESCE($3, "accountID"),
"paymentCategory" = COALESCE($4, "paymentCategory"), "paymentCategory" = COALESCE($4, "paymentCategory"),
bankname = COALESCE($5, bankname), bankname = COALESCE($5, bankname),
"IBAN" = COALESCE($6, "IBAN"), "IBAN" = COALESCE($6, "IBAN"),
@ -178,13 +178,13 @@ SET
changer = $2, changer = $2,
changed = now() changed = now()
WHERE "ID" = $1 WHERE "ID" = $1
RETURNING "ID", "customerID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed RETURNING "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed
` `
type UpdatePaymentParams struct { type UpdatePaymentParams struct {
ID int64 `json:"ID"` ID int64 `json:"ID"`
Changer string `json:"changer"` Changer string `json:"changer"`
Customerid sql.NullInt64 `json:"customerid"` Accountid sql.NullInt64 `json:"accountid"`
Paymentcategory sql.NullString `json:"paymentcategory"` Paymentcategory sql.NullString `json:"paymentcategory"`
Bankname sql.NullString `json:"bankname"` Bankname sql.NullString `json:"bankname"`
Iban sql.NullString `json:"iban"` Iban sql.NullString `json:"iban"`
@ -199,7 +199,7 @@ func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (P
row := q.db.QueryRowContext(ctx, updatePayment, row := q.db.QueryRowContext(ctx, updatePayment,
arg.ID, arg.ID,
arg.Changer, arg.Changer,
arg.Customerid, arg.Accountid,
arg.Paymentcategory, arg.Paymentcategory,
arg.Bankname, arg.Bankname,
arg.Iban, arg.Iban,
@ -212,7 +212,7 @@ func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (P
var i Payment var i Payment
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.PaymentCategory, &i.PaymentCategory,
&i.Bankname, &i.Bankname,
&i.IBAN, &i.IBAN,

View File

@ -11,13 +11,13 @@ import (
) )
func createRandomPayment(t *testing.T) Payment { func createRandomPayment(t *testing.T) Payment {
account := createRandomCustomer(t) account := createRandomAccount(t)
require.NotEmpty(t, account) require.NotEmpty(t, account)
creator := util.RandomUser() creator := util.RandomUser()
arg := CreatePaymentParams{ arg := CreatePaymentParams{
CustomerID: account.ID, AccountID: account.ID,
PaymentCategory: util.RandomUser(), PaymentCategory: util.RandomUser(),
Bankname: sql.NullString{ Bankname: sql.NullString{
Valid: true, Valid: true,
@ -54,7 +54,7 @@ func createRandomPayment(t *testing.T) Payment {
require.Equal(t, arg.PaymentCategory, person.PaymentCategory) require.Equal(t, arg.PaymentCategory, person.PaymentCategory)
require.Equal(t, arg.Bankname, person.Bankname) require.Equal(t, arg.Bankname, person.Bankname)
require.Equal(t, arg.CustomerID, person.CustomerID) require.Equal(t, arg.AccountID, person.AccountID)
require.Equal(t, arg.IBAN, person.IBAN) require.Equal(t, arg.IBAN, person.IBAN)
require.Equal(t, arg.BIC, person.BIC) require.Equal(t, arg.BIC, person.BIC)
require.Equal(t, arg.PaypalAccount, person.PaypalAccount) require.Equal(t, arg.PaypalAccount, person.PaypalAccount)
@ -83,7 +83,7 @@ func TestGetPayment(t *testing.T) {
require.Equal(t, newperson.PaymentCategory, person.PaymentCategory) require.Equal(t, newperson.PaymentCategory, person.PaymentCategory)
require.Equal(t, newperson.Bankname, person.Bankname) require.Equal(t, newperson.Bankname, person.Bankname)
require.Equal(t, newperson.CustomerID, person.CustomerID) require.Equal(t, newperson.AccountID, person.AccountID)
require.Equal(t, newperson.IBAN, person.IBAN) require.Equal(t, newperson.IBAN, person.IBAN)
require.Equal(t, newperson.BIC, person.BIC) require.Equal(t, newperson.BIC, person.BIC)
require.Equal(t, newperson.PaypalAccount, person.PaypalAccount) require.Equal(t, newperson.PaypalAccount, person.PaypalAccount)

View File

@ -13,7 +13,7 @@ import (
const createPerson = `-- name: CreatePerson :one const createPerson = `-- name: CreatePerson :one
INSERT INTO persons ( INSERT INTO persons (
"customerID", "accountID",
firstname, firstname,
lastname, lastname,
birthday, birthday,
@ -25,25 +25,25 @@ INSERT INTO persons (
changer changer
) VALUES ( ) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10
) RETURNING "ID", "customerID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed ) RETURNING "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed
` `
type CreatePersonParams struct { type CreatePersonParams struct {
CustomerID int64 `json:"customerID"` AccountID int64 `json:"accountID"`
Firstname string `json:"firstname"` Firstname string `json:"firstname"`
Lastname string `json:"lastname"` Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"` Birthday time.Time `json:"birthday"`
City string `json:"city"` City string `json:"city"`
Zip string `json:"zip"` Zip string `json:"zip"`
Street string `json:"street"` Street string `json:"street"`
Country string `json:"country"` Country string `json:"country"`
Creator string `json:"creator"` Creator string `json:"creator"`
Changer string `json:"changer"` Changer string `json:"changer"`
} }
func (q *Queries) CreatePerson(ctx context.Context, arg CreatePersonParams) (Person, error) { func (q *Queries) CreatePerson(ctx context.Context, arg CreatePersonParams) (Person, error) {
row := q.db.QueryRowContext(ctx, createPerson, row := q.db.QueryRowContext(ctx, createPerson,
arg.CustomerID, arg.AccountID,
arg.Firstname, arg.Firstname,
arg.Lastname, arg.Lastname,
arg.Birthday, arg.Birthday,
@ -57,7 +57,7 @@ func (q *Queries) CreatePerson(ctx context.Context, arg CreatePersonParams) (Per
var i Person var i Person
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.Firstname, &i.Firstname,
&i.Lastname, &i.Lastname,
&i.Birthday, &i.Birthday,
@ -84,7 +84,7 @@ func (q *Queries) DeletePerson(ctx context.Context, id int64) error {
} }
const getPerson = `-- name: GetPerson :one const getPerson = `-- name: GetPerson :one
SELECT "ID", "customerID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons SELECT "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons
WHERE "ID" = $1 LIMIT 1 WHERE "ID" = $1 LIMIT 1
` `
@ -93,7 +93,7 @@ func (q *Queries) GetPerson(ctx context.Context, id int64) (Person, error) {
var i Person var i Person
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.Firstname, &i.Firstname,
&i.Lastname, &i.Lastname,
&i.Birthday, &i.Birthday,
@ -110,7 +110,7 @@ func (q *Queries) GetPerson(ctx context.Context, id int64) (Person, error) {
} }
const listPersons = `-- name: ListPersons :many const listPersons = `-- name: ListPersons :many
SELECT "ID", "customerID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons SELECT "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons
ORDER BY lastname, firstname ORDER BY lastname, firstname
LIMIT $1 LIMIT $1
OFFSET $2 OFFSET $2
@ -132,7 +132,7 @@ func (q *Queries) ListPersons(ctx context.Context, arg ListPersonsParams) ([]Per
var i Person var i Person
if err := rows.Scan( if err := rows.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.Firstname, &i.Firstname,
&i.Lastname, &i.Lastname,
&i.Birthday, &i.Birthday,
@ -161,7 +161,7 @@ func (q *Queries) ListPersons(ctx context.Context, arg ListPersonsParams) ([]Per
const updatePerson = `-- name: UpdatePerson :one const updatePerson = `-- name: UpdatePerson :one
UPDATE persons UPDATE persons
SET SET
"customerID" = COALESCE($3, "customerID"), "accountID" = COALESCE($3, "accountID"),
firstname = COALESCE($4, firstname), firstname = COALESCE($4, firstname),
lastname = COALESCE($5, lastname), lastname = COALESCE($5, lastname),
birthday = COALESCE($6, birthday), birthday = COALESCE($6, birthday),
@ -172,27 +172,27 @@ SET
changer = $2, changer = $2,
changed = now() changed = now()
WHERE "ID" = $1 WHERE "ID" = $1
RETURNING "ID", "customerID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed RETURNING "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed
` `
type UpdatePersonParams struct { type UpdatePersonParams struct {
ID int64 `json:"ID"` ID int64 `json:"ID"`
Changer string `json:"changer"` Changer string `json:"changer"`
Customerid sql.NullInt64 `json:"customerid"` Accountid sql.NullInt64 `json:"accountid"`
Firstname sql.NullString `json:"firstname"` Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"` Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"` Birthday sql.NullTime `json:"birthday"`
City sql.NullString `json:"city"` City sql.NullString `json:"city"`
Zip sql.NullString `json:"zip"` Zip sql.NullString `json:"zip"`
Street sql.NullString `json:"street"` Street sql.NullString `json:"street"`
Country sql.NullString `json:"country"` Country sql.NullString `json:"country"`
} }
func (q *Queries) UpdatePerson(ctx context.Context, arg UpdatePersonParams) (Person, error) { func (q *Queries) UpdatePerson(ctx context.Context, arg UpdatePersonParams) (Person, error) {
row := q.db.QueryRowContext(ctx, updatePerson, row := q.db.QueryRowContext(ctx, updatePerson,
arg.ID, arg.ID,
arg.Changer, arg.Changer,
arg.Customerid, arg.Accountid,
arg.Firstname, arg.Firstname,
arg.Lastname, arg.Lastname,
arg.Birthday, arg.Birthday,
@ -204,7 +204,7 @@ func (q *Queries) UpdatePerson(ctx context.Context, arg UpdatePersonParams) (Per
var i Person var i Person
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.CustomerID, &i.AccountID,
&i.Firstname, &i.Firstname,
&i.Lastname, &i.Lastname,
&i.Birthday, &i.Birthday,

View File

@ -11,29 +11,29 @@ import (
) )
func createRandomPerson(t *testing.T) Person { func createRandomPerson(t *testing.T) Person {
account := createRandomCustomer(t) account := createRandomAccount(t)
require.NotEmpty(t, account) require.NotEmpty(t, account)
creator := util.RandomUser() creator := util.RandomUser()
arg := CreatePersonParams{ arg := CreatePersonParams{
CustomerID: account.ID, AccountID: account.ID,
Firstname: util.RandomUser(), Firstname: util.RandomUser(),
Lastname: util.RandomUser(), Lastname: util.RandomUser(),
Birthday: time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC), Birthday: time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC),
City: util.RandomString(15), City: util.RandomString(15),
Zip: util.RandomString(5), Zip: util.RandomString(5),
Street: util.RandomString(20), Street: util.RandomString(20),
Country: util.RandomString(15), Country: util.RandomString(15),
Creator: creator, Creator: creator,
Changer: creator, Changer: creator,
} }
person, err := testQueries.CreatePerson(context.Background(), arg) person, err := testQueries.CreatePerson(context.Background(), arg)
require.NoError(t, err) require.NoError(t, err)
require.NotEmpty(t, person) require.NotEmpty(t, person)
require.Equal(t, arg.CustomerID, person.CustomerID) require.Equal(t, arg.AccountID, person.AccountID)
require.Equal(t, arg.Firstname, person.Firstname) require.Equal(t, arg.Firstname, person.Firstname)
require.Equal(t, arg.Lastname, person.Lastname) require.Equal(t, arg.Lastname, person.Lastname)
require.Equal(t, arg.Birthday, person.Birthday) require.Equal(t, arg.Birthday, person.Birthday)

View File

@ -22,7 +22,7 @@ INSERT INTO "returnsLog" (
$2, $2,
$3, $3,
$4, $4,
$5 $4
) RETURNING "ID", "returnID", "mailID", status, creator, created, changer, changed ) RETURNING "ID", "returnID", "mailID", status, creator, created, changer, changed
` `
@ -31,7 +31,6 @@ type CreateReturnsLogParams struct {
Mailid int64 `json:"mailid"` Mailid int64 `json:"mailid"`
Status sql.NullString `json:"status"` Status sql.NullString `json:"status"`
Creator string `json:"creator"` Creator string `json:"creator"`
Changer string `json:"changer"`
} }
func (q *Queries) CreateReturnsLog(ctx context.Context, arg CreateReturnsLogParams) (ReturnsLog, error) { func (q *Queries) CreateReturnsLog(ctx context.Context, arg CreateReturnsLogParams) (ReturnsLog, error) {
@ -40,7 +39,6 @@ func (q *Queries) CreateReturnsLog(ctx context.Context, arg CreateReturnsLogPara
arg.Mailid, arg.Mailid,
arg.Status, arg.Status,
arg.Creator, arg.Creator,
arg.Changer,
) )
var i ReturnsLog var i ReturnsLog
err := row.Scan( err := row.Scan(

View File

@ -25,7 +25,6 @@ func createRandomReturnsLog(t *testing.T) ReturnsLog {
String: util.RandomString(7), String: util.RandomString(7),
}, },
Creator: creator, Creator: creator,
Changer: creator,
} }
returnsLog, err := testQueries.CreateReturnsLog(context.Background(), arg) returnsLog, err := testQueries.CreateReturnsLog(context.Background(), arg)