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 "persons";
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())
);
CREATE TABLE "customers" (
CREATE TABLE "accounts" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"username" varchar UNIQUE NOT NULL,
"passwordhash" varchar NOT NULL,
@ -38,7 +38,7 @@ CREATE TABLE "customers" (
CREATE TABLE "persons" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"customerID" bigint NOT NULL,
"accountID" bigint NOT NULL,
"firstname" varchar NOT NULL,
"lastname" varchar NOT NULL,
"birthday" timestamptz NOT NULL,
@ -71,7 +71,7 @@ CREATE TABLE "documents" (
CREATE TABLE "payments" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"customerID" bigint NOT NULL,
"accountID" bigint NOT NULL,
"paymentCategory" varchar NOT NULL,
"bankname" varchar,
"IBAN" varchar,
@ -124,13 +124,13 @@ CREATE TABLE "returnsLog" (
"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 ("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");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ INSERT INTO "returnsLog" (
$2,
$3,
$4,
$5
$4
) RETURNING "ID", "returnID", "mailID", status, creator, created, changer, changed
`
@ -31,7 +31,6 @@ type CreateReturnsLogParams struct {
Mailid int64 `json:"mailid"`
Status sql.NullString `json:"status"`
Creator string `json:"creator"`
Changer string `json:"changer"`
}
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.Status,
arg.Creator,
arg.Changer,
)
var i ReturnsLog
err := row.Scan(

View File

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