add privacy fields of db.account to db calls and endpoints (#38)

This commit is contained in:
itsscb 2023-09-27 00:30:29 +02:00 committed by GitHub
parent a07c91e9b9
commit 34889a5fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 608 additions and 446 deletions

View File

@ -11,6 +11,7 @@ import (
type createAccountRequest struct {
Passwordhash string `binding:"required" json:"passwordhash"`
PrivacyAccepted bool `json:"privacy_accepted"`
Firstname string `binding:"required" json:"firstname"`
Lastname string `binding:"required" json:"lastname"`
Birthday time.Time `binding:"required" json:"birthday"`
@ -31,6 +32,10 @@ func (server *Server) createAccount(ctx *gin.Context) {
arg := db.CreateAccountTxParams{
Passwordhash: req.Passwordhash,
PrivacyAccepted: sql.NullBool{
Valid: true,
Bool: req.PrivacyAccepted,
},
Firstname: req.Firstname,
Lastname: req.Lastname,
Birthday: req.Birthday,
@ -46,6 +51,13 @@ func (server *Server) createAccount(ctx *gin.Context) {
},
}
// if req.PrivacyAccepted {
// arg.PrivacyAcceptedDate = sql.NullTime{
// Valid: true,
// Time: time.Now(),
// }
// }
account, err := server.store.CreateAccountTx(ctx, arg)
if err != nil {
ctx.JSON(http.StatusInternalServerError, errorResponse(err))
@ -111,6 +123,7 @@ func (server *Server) listAccounts(ctx *gin.Context) {
type updateAccountRequest struct {
ID int64 `binding:"required" json:"ID"`
Changer string `binding:"required" json:"changer"`
PrivacyAccepted bool `json:"privacy_accepted"`
Passwordhash string `json:"passwordhash"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
@ -130,6 +143,12 @@ func (server *Server) updateAccount(ctx *gin.Context) {
return
}
account, err := server.store.GetAccount(ctx, req.ID)
if err != nil {
ctx.JSON(http.StatusNotFound, errorResponse(err))
return
}
arg := db.UpdateAccountTxParams{
ID: req.ID,
Changer: req.Changer,
@ -173,9 +192,13 @@ func (server *Server) updateAccount(ctx *gin.Context) {
String: req.Phone,
Valid: req.Phone != "",
},
PrivacyAccepted: sql.NullBool{
Valid: account.PrivacyAccepted.Bool != req.PrivacyAccepted,
Bool: req.PrivacyAccepted,
},
}
account, err := server.store.UpdateAccountTx(ctx, arg)
account, err = server.store.UpdateAccountTx(ctx, arg)
if err != nil {
ctx.JSON(http.StatusInternalServerError, errorResponse(err))
return

View File

@ -19,6 +19,8 @@ import (
"go.uber.org/mock/gomock"
)
var timestamp = time.Now()
func TestCreateAccountAPI(t *testing.T) {
account := randomAccount()
@ -32,6 +34,7 @@ func TestCreateAccountAPI(t *testing.T) {
name: "OK",
body: gin.H{
"passwordhash": account.Passwordhash,
"privacy_accepted": account.PrivacyAccepted.Bool,
"firstname": account.Firstname,
"lastname": account.Lastname,
"birthday": account.Birthday,
@ -46,6 +49,7 @@ func TestCreateAccountAPI(t *testing.T) {
buildStubs: func(store *mockdb.MockStore) {
arg := db.CreateAccountTxParams{
Passwordhash: account.Passwordhash,
PrivacyAccepted: account.PrivacyAccepted,
Firstname: account.Firstname,
Lastname: account.Lastname,
Birthday: account.Birthday,
@ -100,6 +104,8 @@ func TestCreateAccountAPI(t *testing.T) {
name: "InternalServerError",
body: gin.H{
"passwordhash": account.Passwordhash,
"privacy_accepted": account.PrivacyAccepted.Bool,
"privacy_accepted_date": account.PrivacyAcceptedDate.Time,
"firstname": account.Firstname,
"lastname": account.Lastname,
"birthday": account.Birthday,
@ -269,6 +275,7 @@ func TestUpdateAccountTxAPI(t *testing.T) {
changer := util.RandomName()
newPassword := util.RandomString(30)
newEmail := util.RandomEmail()
testCases := []struct {
name string
body gin.H
@ -296,6 +303,10 @@ func TestUpdateAccountTxAPI(t *testing.T) {
Changer: changer,
}
store.EXPECT().
GetAccount(gomock.Any(), gomock.Eq(account.ID)).
Times(1)
store.EXPECT().
UpdateAccountTx(gomock.Any(), gomock.Eq(arg)).
Times(1).
@ -328,6 +339,10 @@ func TestUpdateAccountTxAPI(t *testing.T) {
Changer: changer,
}
store.EXPECT().
GetAccount(gomock.Any(), gomock.Eq(account.ID)).
Times(1)
store.EXPECT().
UpdateAccountTx(gomock.Any(), gomock.Eq(arg)).
Times(1).
@ -339,6 +354,39 @@ func TestUpdateAccountTxAPI(t *testing.T) {
},
},
// {
// name: "OK_PrivacyAccepted",
// body: gin.H{
// "id": account.ID,
// "privacy_accepted": true,
// "changer": changer,
// },
// buildStubs: func(store *mockdb.MockStore) {
// accountAccepted := account
// accountAccepted.PrivacyAccepted = sql.NullBool{
// Valid: true,
// Bool: true,
// }
// accountAccepted.PrivacyAcceptedDate = sql.NullTime{
// Valid: true,
// Time: timestamp,
// }
// arg := db.UpdateAccountTxParams{
// ID: account.ID,
// PrivacyAccepted: sql.NullBool{
// Valid: true,
// Bool: true,
// },
// Changer: changer,
// }
// store.EXPECT().
// UpdateAccountTx(gomock.Any(), gomock.Eq(arg)).
// Times(1).
// Return(accountAccepted, nil)
// },
// },
// {
// name: "NoAuthorization",
// body: gin.H{
// "currency": account.Currency,
@ -367,20 +415,6 @@ func TestUpdateAccountTxAPI(t *testing.T) {
require.Equal(t, http.StatusBadRequest, recorder.Code)
},
},
/* {
name: "InvalidCurrency",
body: gin.H{
"currency": "invalid",
},
buildStubs: func(store *mockdb.MockStore) {
store.EXPECT().
CreateAccount(gomock.Any(), gomock.Any()).
Times(0)
},
checkResponse: func(recorder *httptest.ResponseRecorder) {
require.Equal(t, http.StatusBadRequest, recorder.Code)
},
}, */
}
for i := range testCases {
@ -540,12 +574,20 @@ func TestListAccountsAPI(t *testing.T) {
}
func randomAccount() db.Account {
return db.Account{
acc := db.Account{
ID: util.RandomInt(1, 1000),
Passwordhash: util.RandomString(250),
Firstname: util.RandomName(),
Lastname: util.RandomName(),
Email: util.RandomEmail(),
PrivacyAccepted: sql.NullBool{
Valid: true,
Bool: true,
},
PrivacyAcceptedDate: sql.NullTime{
Valid: true,
Time: timestamp,
},
Phone: sql.NullString{
String: util.RandomPhone(),
Valid: true,
@ -560,6 +602,8 @@ func randomAccount() db.Account {
Changed: time.Date(1990, 1, 1, 0, 0, 0, 0, time.UTC),
Birthday: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC),
}
return acc
}
func requireBodyMatchAccount(t *testing.T, body *bytes.Buffer, account db.Account) {
@ -569,7 +613,18 @@ func requireBodyMatchAccount(t *testing.T, body *bytes.Buffer, account db.Accoun
var getAccount db.Account
err = json.Unmarshal(data, &getAccount)
require.NoError(t, err)
require.Equal(t, account, getAccount)
require.Equal(t, account.Firstname, getAccount.Firstname)
require.Equal(t, account.Lastname, getAccount.Lastname)
require.Equal(t, account.Passwordhash, getAccount.Passwordhash)
require.Equal(t, account.Email, getAccount.Email)
require.Equal(t, account.Phone, getAccount.Phone)
require.Equal(t, account.City, getAccount.City)
require.Equal(t, account.Street, getAccount.Street)
require.Equal(t, account.Country, getAccount.Country)
require.Equal(t, account.Zip, getAccount.Zip)
require.Equal(t, account.Creator, getAccount.Creator)
require.Equal(t, account.PrivacyAccepted, getAccount.PrivacyAccepted)
// require.WithinDuration(t, account.PrivacyAcceptedDate.Time, getAccount.PrivacyAcceptedDate.Time, time.Minute)
}
func requireBodyMatchAccounts(t *testing.T, body *bytes.Buffer, accounts []db.Account) {
@ -579,5 +634,23 @@ func requireBodyMatchAccounts(t *testing.T, body *bytes.Buffer, accounts []db.Ac
var gotAccounts []db.Account
err = json.Unmarshal(data, &gotAccounts)
require.NoError(t, err)
require.Equal(t, accounts, gotAccounts)
for i := range accounts {
a := accounts[i]
b := gotAccounts[i]
require.Equal(t, a.Firstname, b.Firstname)
require.Equal(t, a.Lastname, b.Lastname)
require.Equal(t, a.Passwordhash, b.Passwordhash)
require.Equal(t, a.Email, b.Email)
require.Equal(t, a.Phone, b.Phone)
require.Equal(t, a.City, b.City)
require.Equal(t, a.Street, b.Street)
require.Equal(t, a.Country, b.Country)
require.Equal(t, a.Zip, b.Zip)
require.Equal(t, a.Creator, b.Creator)
require.Equal(t, a.PrivacyAccepted, b.PrivacyAccepted)
}
// require.Equal(t, accounts, gotAccounts)
}

View File

@ -1,5 +1,5 @@
CREATE TABLE "mails" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"from" varchar NOT NULL,
"to" varchar[] NOT NULL,
"cc" varchar[],
@ -13,13 +13,13 @@ CREATE TABLE "mails" (
);
CREATE TABLE "accounts" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"passwordhash" varchar NOT NULL,
"firstname" varchar NOT NULL,
"lastname" varchar NOT NULL,
"birthday" timestamptz NOT NULL,
"privacyAccepted" boolean NOT NULL DEFAULT false,
"privacyAcceptedDate" timestamptz,
"privacy_accepted" boolean DEFAULT false,
"privacy_accepted_date" timestamptz,
"email" varchar UNIQUE NOT NULL,
"phone" varchar,
"city" varchar NOT NULL,
@ -27,8 +27,8 @@ CREATE TABLE "accounts" (
"street" varchar NOT NULL,
"country" varchar NOT NULL,
"token" varchar,
"tokenValid" boolean DEFAULT false,
"tokenExpiration" timestamptz NOT NULL DEFAULT (now()),
"token_valid" boolean DEFAULT false,
"token_expiration" timestamptz NOT NULL DEFAULT (now()),
"creator" varchar NOT NULL,
"created" timestamptz NOT NULL DEFAULT (now()),
"changer" varchar NOT NULL,
@ -36,8 +36,8 @@ CREATE TABLE "accounts" (
);
CREATE TABLE "persons" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"accountID" bigint NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"account_id" bigint NOT NULL,
"firstname" varchar NOT NULL,
"lastname" varchar NOT NULL,
"birthday" timestamptz NOT NULL,
@ -52,16 +52,16 @@ CREATE TABLE "persons" (
);
CREATE TABLE "documents" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"personID" bigint,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"person_id" bigint,
"name" varchar NOT NULL,
"type" varchar NOT NULL,
"path" varchar NOT NULL,
"url" varchar NOT NULL,
"valid" boolean NOT NULL DEFAULT false,
"validDate" timestamptz,
"validatedBy" varchar,
"mailID" bigint,
"valid_date" timestamptz,
"validated_by" varchar,
"mail_id" bigint,
"creator" varchar NOT NULL,
"created" timestamptz NOT NULL DEFAULT (now()),
"changer" varchar NOT NULL,
@ -69,15 +69,15 @@ CREATE TABLE "documents" (
);
CREATE TABLE "payments" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"accountID" bigint NOT NULL,
"paymentCategory" varchar NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"account_id" bigint NOT NULL,
"payment_category" varchar NOT NULL,
"bankname" varchar,
"IBAN" varchar,
"BIC" varchar,
"paypalAccount" varchar,
"paypalID" varchar,
"paymentSystem" varchar,
"iban" varchar,
"bic" varchar,
"paypal_account" varchar,
"paypal_id" varchar,
"payment_system" varchar,
"type" varchar NOT NULL,
"creator" varchar NOT NULL,
"created" timestamptz NOT NULL DEFAULT (now()),
@ -86,7 +86,7 @@ CREATE TABLE "payments" (
);
CREATE TABLE "providers" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"name" varchar NOT NULL,
"description" text NOT NULL,
"category" varchar NOT NULL,
@ -98,9 +98,9 @@ CREATE TABLE "providers" (
);
CREATE TABLE "returns" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"personID" bigint NOT NULL,
"providerID" bigint NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"person_id" bigint NOT NULL,
"provider_id" bigint NOT NULL,
"name" varchar NOT NULL,
"description" text NOT NULL,
"category" varchar NOT NULL,
@ -113,9 +113,9 @@ CREATE TABLE "returns" (
);
CREATE TABLE "returnsLog" (
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
"returnID" bigint NOT NULL,
"mailID" bigint NOT NULL,
"id" bigserial UNIQUE PRIMARY KEY NOT NULL,
"return_id" bigint NOT NULL,
"mail_id" bigint NOT NULL,
"status" varchar,
"creator" varchar NOT NULL,
"created" timestamptz NOT NULL DEFAULT (now()),
@ -123,18 +123,18 @@ CREATE TABLE "returnsLog" (
"changed" timestamptz NOT NULL DEFAULT (now())
);
ALTER TABLE "persons" ADD FOREIGN KEY ("accountID") REFERENCES "accounts" ("ID");
ALTER TABLE "persons" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");
ALTER TABLE "documents" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
ALTER TABLE "documents" ADD FOREIGN KEY ("person_id") REFERENCES "persons" ("id");
ALTER TABLE "documents" ADD FOREIGN KEY ("mailID") REFERENCES "mails" ("ID");
ALTER TABLE "documents" ADD FOREIGN KEY ("mail_id") REFERENCES "mails" ("id");
ALTER TABLE "payments" ADD FOREIGN KEY ("accountID") REFERENCES "accounts" ("ID");
ALTER TABLE "payments" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");
ALTER TABLE "returns" ADD FOREIGN KEY ("personID") REFERENCES "persons" ("ID");
ALTER TABLE "returns" ADD FOREIGN KEY ("person_id") REFERENCES "persons" ("id");
ALTER TABLE "returns" ADD FOREIGN KEY ("providerID") REFERENCES "providers" ("ID");
ALTER TABLE "returns" ADD FOREIGN KEY ("provider_id") REFERENCES "providers" ("id");
ALTER TABLE "returnsLog" ADD FOREIGN KEY ("returnID") REFERENCES "returns" ("ID");
ALTER TABLE "returnsLog" ADD FOREIGN KEY ("return_id") REFERENCES "returns" ("id");
ALTER TABLE "returnsLog" ADD FOREIGN KEY ("mailID") REFERENCES "mails" ("ID");
ALTER TABLE "returnsLog" ADD FOREIGN KEY ("mail_id") REFERENCES "mails" ("id");

View File

@ -1,15 +1,17 @@
-- name: GetAccount :one
SELECT * FROM accounts
WHERE "ID" = $1 LIMIT 1;
WHERE "id" = $1 LIMIT 1;
-- name: GetAccountForUpdate :one
SELECT * FROM accounts
WHERE "ID" = $1 LIMIT 1
WHERE "id" = $1 LIMIT 1
FOR NO KEY UPDATE;
-- name: CreateAccount :one
INSERT INTO accounts (
"passwordhash",
"privacy_accepted",
"privacy_accepted_date",
"firstname",
"lastname",
"birthday",
@ -22,7 +24,20 @@ INSERT INTO accounts (
"creator",
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11
sqlc.arg(passwordhash),
sqlc.arg(privacy_accepted),
sqlc.arg(privacy_accepted_date),
sqlc.arg(firstname),
sqlc.arg(lastname),
sqlc.arg(birthday),
sqlc.arg(email),
sqlc.arg(phone),
sqlc.arg(city),
sqlc.arg(zip),
sqlc.arg(street),
sqlc.arg(country),
sqlc.arg(creator),
sqlc.arg(creator)
) RETURNING *;
-- name: ListAccounts :many
@ -35,6 +50,8 @@ OFFSET $2;
UPDATE accounts
SET
"passwordhash" = COALESCE(sqlc.narg(passwordhash), "passwordhash"),
"privacy_accepted" = COALESCE(sqlc.narg(privacy_accepted), "privacy_accepted"),
"privacy_accepted_date" = COALESCE(sqlc.narg(privacy_accepted_date), "privacy_accepted_date"),
"firstname" = COALESCE(sqlc.narg(firstname), "firstname"),
"lastname" = COALESCE(sqlc.narg(lastname), "lastname"),
"birthday" = COALESCE(sqlc.narg(birthday), "birthday"),
@ -46,9 +63,9 @@ SET
"country" = COALESCE(sqlc.narg(country), "country"),
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: DeleteAccount :exec
DELETE FROM accounts
WHERE "ID" = $1;
WHERE "id" = $1;

View File

@ -1,10 +1,10 @@
-- name: GetDocument :one
SELECT * FROM documents
WHERE "ID" = $1 LIMIT 1;
WHERE "id" = $1 LIMIT 1;
-- name: CreateDocumentUpload :one
INSERT INTO documents (
"personID",
"person_id",
"name",
"type",
"path",
@ -17,7 +17,7 @@ INSERT INTO documents (
-- name: CreateDocumentMail :one
INSERT INTO documents (
"mailID",
"mail_id",
"name",
"type",
"path",
@ -37,38 +37,38 @@ OFFSET $2;
-- name: UpdateDocument :one
UPDATE documents
SET
"personID" = COALESCE(sqlc.narg(personID), "personID"),
"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"),
"url" = COALESCE(sqlc.narg(url), "url"),
changer = $2,
changed = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: ValidateDocument :one
UPDATE documents
SET
"valid" = true,
"validDate" = now(),
"validatedBy" = $2,
"valid_date" = now(),
"validated_by" = $2,
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: InvalidateDocument :one
UPDATE documents
SET
"valid" = false,
"validDate" = NULL,
"validatedBy" = NULL,
"valid_date" = NULL,
"validated_by" = NULL,
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: DeleteDocument :exec
DELETE FROM documents
WHERE "ID" = $1;
WHERE "id" = $1;

View File

@ -1,6 +1,6 @@
-- name: GetMail :one
SELECT * FROM mails
WHERE "ID" = $1 LIMIT 1;
WHERE "id" = $1 LIMIT 1;
-- name: CreateMail :one
INSERT INTO mails (
@ -35,9 +35,9 @@ OFFSET $2;
-- "timestamp" = COALESCE(sqlc.narg(timestamp), "timestamp"),
-- changer = $2,
-- changed = now()
-- WHERE "ID" = $1
-- WHERE "id" = $1
-- RETURNING *;
-- name: DeleteMail :exec
DELETE FROM mails
WHERE "ID" = $1;
WHERE "id" = $1;

View File

@ -1,17 +1,17 @@
-- name: GetPayment :one
SELECT * FROM payments
WHERE "ID" = $1 LIMIT 1;
WHERE "id" = $1 LIMIT 1;
-- name: CreatePayment :one
INSERT INTO payments (
"accountID",
"paymentCategory",
"account_id",
"payment_category",
"bankname",
"IBAN",
"BIC",
"paypalAccount",
"paypalID",
"paymentSystem",
"iban",
"bic",
"paypal_account",
"paypal_id",
"payment_system",
"type",
"creator",
"changer"
@ -21,27 +21,27 @@ INSERT INTO payments (
-- name: ListPayments :many
SELECT * FROM payments
ORDER BY "paymentCategory"
ORDER BY "payment_category"
LIMIT $1
OFFSET $2;
-- name: UpdatePayment :one
UPDATE payments
SET
"accountID" = COALESCE(sqlc.narg(accountID), "accountID"),
"paymentCategory" = COALESCE(sqlc.narg(paymentCategory), "paymentCategory"),
"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"),
"BIC" = COALESCE(sqlc.narg(BIC), "BIC"),
"paypalAccount" = COALESCE(sqlc.narg(paypalAccount), "paypalAccount"),
"paypalID" = COALESCE(sqlc.narg(paypalID), "paypalID"),
"paymentSystem" = COALESCE(sqlc.narg(paymentSystem), "paymentSystem"),
"iban" = COALESCE(sqlc.narg(iban), "iban"),
"bic" = COALESCE(sqlc.narg(bic), "bic"),
"paypal_account" = COALESCE(sqlc.narg(paypal_account), "paypal_account"),
"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,
"changed" = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: DeletePayment :exec
DELETE FROM payments
WHERE "ID" = $1;
WHERE "id" = $1;

View File

@ -1,10 +1,10 @@
-- name: GetPerson :one
SELECT * FROM persons
WHERE "ID" = $1 LIMIT 1;
WHERE "id" = $1 LIMIT 1;
-- name: CreatePerson :one
INSERT INTO persons (
"accountID",
"account_id",
"firstname",
"lastname",
"birthday",
@ -27,7 +27,7 @@ OFFSET $2;
-- name: UpdatePerson :one
UPDATE persons
SET
"accountID" = COALESCE(sqlc.narg(accountID), "accountID"),
"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"),
@ -37,9 +37,9 @@ SET
"country" = COALESCE(sqlc.narg(country), "country"),
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: DeletePerson :exec
DELETE FROM persons
WHERE "ID" = $1;
WHERE "id" = $1;

View File

@ -1,6 +1,6 @@
-- name: GetProvider :one
SELECT * FROM providers
WHERE "ID" = $1 LIMIT 1;
WHERE "id" = $1 LIMIT 1;
-- name: CreateProvider :one
INSERT INTO providers (
@ -29,9 +29,9 @@ SET
"email" = COALESCE(sqlc.narg(email), "email"),
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
WHERE "id" = $1
RETURNING *;
-- name: DeleteProvider :exec
DELETE FROM providers
WHERE "ID" = $1;
WHERE "id" = $1;

View File

@ -1,11 +1,11 @@
-- name: GetReturn :one
SELECT * FROM returns
WHERE "ID" = sqlc.arg(ID) LIMIT 1;
WHERE "id" = sqlc.arg(id) LIMIT 1;
-- name: CreateReturn :one
INSERT INTO returns (
"personID",
"providerID",
"person_id",
"provider_id",
"name",
"description",
"category",
@ -14,8 +14,8 @@ INSERT INTO returns (
"creator",
"changer"
) VALUES (
sqlc.arg(personID),
sqlc.arg(providerID),
sqlc.arg(person_id),
sqlc.arg(provider_id),
sqlc.arg(name),
sqlc.arg(description),
sqlc.arg(category),
@ -34,8 +34,8 @@ OFFSET $2;
-- name: UpdateReturn :one
UPDATE returns
SET
"personID" = COALESCE(sqlc.narg(personID), "personID"),
"providerID" = COALESCE(sqlc.narg(providerID), "providerID"),
"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"),
@ -43,9 +43,9 @@ SET
"status" = COALESCE(sqlc.narg(status), "status"),
"changer" = sqlc.arg(changer),
"changed" = now()
WHERE "ID" = sqlc.arg(ID)
WHERE "id" = sqlc.arg(id)
RETURNING *;
-- name: DeleteReturn :exec
DELETE FROM returns
WHERE "ID" = sqlc.arg(ID);
WHERE "id" = sqlc.arg(id);

View File

@ -1,17 +1,17 @@
-- name: GetReturnsLog :one
SELECT * FROM "returnsLog"
WHERE "ID" = sqlc.arg(ID) LIMIT 1;
WHERE "id" = sqlc.arg(id) LIMIT 1;
-- name: CreateReturnsLog :one
INSERT INTO "returnsLog" (
"returnID",
"mailID",
"return_id",
"mail_id",
"status",
"creator",
"changer"
) VALUES (
sqlc.arg(returnID),
sqlc.arg(mailID),
sqlc.arg(return_id),
sqlc.arg(mail_id),
sqlc.arg(status),
sqlc.arg(creator),
sqlc.arg(creator)
@ -26,14 +26,14 @@ OFFSET $2;
-- name: UpdateReturnsLog :one
UPDATE "returnsLog"
SET
"returnID" = COALESCE(sqlc.narg(returnID), "returnID"),
"mailID" = COALESCE(sqlc.narg(mailID), "mailID"),
"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()
WHERE "ID" = sqlc.arg(ID)
WHERE "id" = sqlc.arg(id)
RETURNING *;
-- name: DeleteReturnsLog :exec
DELETE FROM "returnsLog"
WHERE "ID" = sqlc.arg(ID);
WHERE "id" = sqlc.arg(id);

View File

@ -14,6 +14,8 @@ import (
const createAccount = `-- name: CreateAccount :one
INSERT INTO accounts (
"passwordhash",
"privacy_accepted",
"privacy_accepted_date",
"firstname",
"lastname",
"birthday",
@ -26,12 +28,27 @@ INSERT INTO accounts (
"creator",
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11
) RETURNING "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12,
$13,
$13
) RETURNING id, passwordhash, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, email, phone, city, zip, street, country, token, token_valid, token_expiration, creator, created, changer, changed
`
type CreateAccountParams struct {
Passwordhash string `json:"passwordhash"`
PrivacyAccepted sql.NullBool `json:"privacy_accepted"`
PrivacyAcceptedDate sql.NullTime `json:"privacy_accepted_date"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -47,6 +64,8 @@ type CreateAccountParams struct {
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
row := q.db.QueryRowContext(ctx, createAccount,
arg.Passwordhash,
arg.PrivacyAccepted,
arg.PrivacyAcceptedDate,
arg.Firstname,
arg.Lastname,
arg.Birthday,
@ -86,7 +105,7 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
const deleteAccount = `-- name: DeleteAccount :exec
DELETE FROM accounts
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeleteAccount(ctx context.Context, id int64) error {
@ -95,8 +114,8 @@ func (q *Queries) DeleteAccount(ctx context.Context, id int64) error {
}
const getAccount = `-- name: GetAccount :one
SELECT "ID", 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
SELECT id, passwordhash, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, email, phone, city, zip, street, country, token, token_valid, token_expiration, creator, created, changer, changed FROM accounts
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetAccount(ctx context.Context, id int64) (Account, error) {
@ -128,8 +147,8 @@ func (q *Queries) GetAccount(ctx context.Context, id int64) (Account, error) {
}
const getAccountForUpdate = `-- name: GetAccountForUpdate :one
SELECT "ID", 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
SELECT id, passwordhash, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, email, phone, city, zip, street, country, token, token_valid, token_expiration, creator, created, changer, changed FROM accounts
WHERE "id" = $1 LIMIT 1
FOR NO KEY UPDATE
`
@ -162,7 +181,7 @@ func (q *Queries) GetAccountForUpdate(ctx context.Context, id int64) (Account, e
}
const listAccounts = `-- name: ListAccounts :many
SELECT "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
SELECT id, passwordhash, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, email, phone, city, zip, street, country, token, token_valid, token_expiration, creator, created, changer, changed FROM accounts
ORDER BY "lastname", "firstname"
LIMIT $1
OFFSET $2
@ -221,25 +240,29 @@ const updateAccount = `-- name: UpdateAccount :one
UPDATE accounts
SET
"passwordhash" = COALESCE($3, "passwordhash"),
"firstname" = COALESCE($4, "firstname"),
"lastname" = COALESCE($5, "lastname"),
"birthday" = COALESCE($6, "birthday"),
"email" = COALESCE($7, "email"),
"phone" = COALESCE($8, "phone"),
"city" = COALESCE($9, "city"),
"zip" = COALESCE($10, "zip"),
"street" = COALESCE($11, "street"),
"country" = COALESCE($12, "country"),
"privacy_accepted" = COALESCE($4, "privacy_accepted"),
"privacy_accepted_date" = COALESCE($5, "privacy_accepted_date"),
"firstname" = COALESCE($6, "firstname"),
"lastname" = COALESCE($7, "lastname"),
"birthday" = COALESCE($8, "birthday"),
"email" = COALESCE($9, "email"),
"phone" = COALESCE($10, "phone"),
"city" = COALESCE($11, "city"),
"zip" = COALESCE($12, "zip"),
"street" = COALESCE($13, "street"),
"country" = COALESCE($14, "country"),
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
RETURNING "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
WHERE "id" = $1
RETURNING id, passwordhash, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, email, phone, city, zip, street, country, token, token_valid, token_expiration, creator, created, changer, changed
`
type UpdateAccountParams struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Changer string `json:"changer"`
Passwordhash sql.NullString `json:"passwordhash"`
PrivacyAccepted sql.NullBool `json:"privacy_accepted"`
PrivacyAcceptedDate sql.NullTime `json:"privacy_accepted_date"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
@ -256,6 +279,8 @@ func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (A
arg.ID,
arg.Changer,
arg.Passwordhash,
arg.PrivacyAccepted,
arg.PrivacyAcceptedDate,
arg.Firstname,
arg.Lastname,
arg.Birthday,

View File

@ -24,6 +24,10 @@ func createRandomAccount(t *testing.T) Account {
Valid: true,
String: util.RandomPhone(),
},
PrivacyAccepted: sql.NullBool{
Valid: true,
Bool: true,
},
City: util.RandomString(15),
Zip: util.RandomString(5),
Street: util.RandomString(20),

View File

@ -12,7 +12,7 @@ import (
const createDocumentMail = `-- name: CreateDocumentMail :one
INSERT INTO documents (
"mailID",
"mail_id",
"name",
"type",
"path",
@ -21,11 +21,11 @@ INSERT INTO documents (
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6, $7
) RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
) RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
type CreateDocumentMailParams struct {
MailID sql.NullInt64 `json:"mailID"`
MailID sql.NullInt64 `json:"mail_id"`
Name string `json:"name"`
Type string `json:"type"`
Path string `json:"path"`
@ -66,7 +66,7 @@ func (q *Queries) CreateDocumentMail(ctx context.Context, arg CreateDocumentMail
const createDocumentUpload = `-- name: CreateDocumentUpload :one
INSERT INTO documents (
"personID",
"person_id",
"name",
"type",
"path",
@ -75,11 +75,11 @@ INSERT INTO documents (
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6, $7
) RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
) RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
type CreateDocumentUploadParams struct {
PersonID sql.NullInt64 `json:"personID"`
PersonID sql.NullInt64 `json:"person_id"`
Name string `json:"name"`
Type string `json:"type"`
Path string `json:"path"`
@ -120,7 +120,7 @@ func (q *Queries) CreateDocumentUpload(ctx context.Context, arg CreateDocumentUp
const deleteDocument = `-- name: DeleteDocument :exec
DELETE FROM documents
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeleteDocument(ctx context.Context, id int64) error {
@ -129,8 +129,8 @@ func (q *Queries) DeleteDocument(ctx context.Context, id int64) error {
}
const getDocument = `-- name: GetDocument :one
SELECT "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed FROM documents
WHERE "ID" = $1 LIMIT 1
SELECT id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed FROM documents
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetDocument(ctx context.Context, id int64) (Document, error) {
@ -159,16 +159,16 @@ const invalidateDocument = `-- name: InvalidateDocument :one
UPDATE documents
SET
"valid" = false,
"validDate" = NULL,
"validatedBy" = NULL,
"valid_date" = NULL,
"validated_by" = NULL,
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
WHERE "id" = $1
RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
type InvalidateDocumentParams struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Changer string `json:"changer"`
}
@ -195,7 +195,7 @@ func (q *Queries) InvalidateDocument(ctx context.Context, arg InvalidateDocument
}
const listDocuments = `-- name: ListDocuments :many
SELECT "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed FROM documents
SELECT id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed FROM documents
ORDER BY "valid", "type", "name"
LIMIT $1
OFFSET $2
@ -247,21 +247,21 @@ func (q *Queries) ListDocuments(ctx context.Context, arg ListDocumentsParams) ([
const updateDocument = `-- name: UpdateDocument :one
UPDATE documents
SET
"personID" = COALESCE($3, "personID"),
"person_id" = COALESCE($3, "person_id"),
"name" = COALESCE($4, "name"),
"type" = COALESCE($5, "type"),
"path" = COALESCE($6, "path"),
"url" = COALESCE($7, "url"),
changer = $2,
changed = now()
WHERE "ID" = $1
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
WHERE "id" = $1
RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
type UpdateDocumentParams struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Changer string `json:"changer"`
Personid sql.NullInt64 `json:"personid"`
PersonID sql.NullInt64 `json:"person_id"`
Name sql.NullString `json:"name"`
Type sql.NullString `json:"type"`
Path sql.NullString `json:"path"`
@ -272,7 +272,7 @@ func (q *Queries) UpdateDocument(ctx context.Context, arg UpdateDocumentParams)
row := q.db.QueryRowContext(ctx, updateDocument,
arg.ID,
arg.Changer,
arg.Personid,
arg.PersonID,
arg.Name,
arg.Type,
arg.Path,
@ -302,17 +302,17 @@ const validateDocument = `-- name: ValidateDocument :one
UPDATE documents
SET
"valid" = true,
"validDate" = now(),
"validatedBy" = $2,
"valid_date" = now(),
"validated_by" = $2,
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
RETURNING "ID", "personID", name, type, path, url, valid, "validDate", "validatedBy", "mailID", creator, created, changer, changed
WHERE "id" = $1
RETURNING id, person_id, name, type, path, url, valid, valid_date, validated_by, mail_id, creator, created, changer, changed
`
type ValidateDocumentParams struct {
ID int64 `json:"ID"`
ValidatedBy sql.NullString `json:"validatedBy"`
ID int64 `json:"id"`
ValidatedBy sql.NullString `json:"validated_by"`
}
func (q *Queries) ValidateDocument(ctx context.Context, arg ValidateDocumentParams) (Document, error) {

View File

@ -26,7 +26,7 @@ INSERT INTO mails (
VALUES (
$1, $2, $3, $4, $5, $6, $7, $8
)
RETURNING "ID", "from", "to", cc, timestamp, subject, body, creator, created, changer, changed
RETURNING id, "from", "to", cc, timestamp, subject, body, creator, created, changer, changed
`
type CreateMailParams struct {
@ -71,7 +71,7 @@ func (q *Queries) CreateMail(ctx context.Context, arg CreateMailParams) (Mail, e
const deleteMail = `-- name: DeleteMail :exec
DELETE FROM mails
WHERE "ID" = $1
WHERE "id" = $1
`
// -- name: UpdateMail :one
@ -87,7 +87,7 @@ WHERE "ID" = $1
// changer = $2,
// changed = now()
//
// WHERE "ID" = $1
// WHERE "id" = $1
// RETURNING *;
func (q *Queries) DeleteMail(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteMail, id)
@ -95,8 +95,8 @@ func (q *Queries) DeleteMail(ctx context.Context, id int64) error {
}
const getMail = `-- name: GetMail :one
SELECT "ID", "from", "to", cc, timestamp, subject, body, creator, created, changer, changed FROM mails
WHERE "ID" = $1 LIMIT 1
SELECT id, "from", "to", cc, timestamp, subject, body, creator, created, changer, changed FROM mails
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetMail(ctx context.Context, id int64) (Mail, error) {
@ -119,7 +119,7 @@ func (q *Queries) GetMail(ctx context.Context, id int64) (Mail, error) {
}
const listMails = `-- name: ListMails :many
SELECT "ID", "from", "to", cc, timestamp, subject, body, creator, created, changer, changed FROM mails
SELECT id, "from", "to", cc, timestamp, subject, body, creator, created, changer, changed FROM mails
ORDER BY "timestamp", "from"
LIMIT $1
OFFSET $2

View File

@ -10,13 +10,13 @@ import (
)
type Account struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Passwordhash string `json:"passwordhash"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
PrivacyAccepted bool `json:"privacyAccepted"`
PrivacyAcceptedDate sql.NullTime `json:"privacyAcceptedDate"`
PrivacyAccepted sql.NullBool `json:"privacy_accepted"`
PrivacyAcceptedDate sql.NullTime `json:"privacy_accepted_date"`
Email string `json:"email"`
Phone sql.NullString `json:"phone"`
City string `json:"city"`
@ -24,8 +24,8 @@ type Account struct {
Street string `json:"street"`
Country string `json:"country"`
Token sql.NullString `json:"token"`
TokenValid sql.NullBool `json:"tokenValid"`
TokenExpiration time.Time `json:"tokenExpiration"`
TokenValid sql.NullBool `json:"token_valid"`
TokenExpiration time.Time `json:"token_expiration"`
Creator string `json:"creator"`
Created time.Time `json:"created"`
Changer string `json:"changer"`
@ -33,16 +33,16 @@ type Account struct {
}
type Document struct {
ID int64 `json:"ID"`
PersonID sql.NullInt64 `json:"personID"`
ID int64 `json:"id"`
PersonID sql.NullInt64 `json:"person_id"`
Name string `json:"name"`
Type string `json:"type"`
Path string `json:"path"`
Url string `json:"url"`
Valid bool `json:"valid"`
ValidDate sql.NullTime `json:"validDate"`
ValidatedBy sql.NullString `json:"validatedBy"`
MailID sql.NullInt64 `json:"mailID"`
ValidDate sql.NullTime `json:"valid_date"`
ValidatedBy sql.NullString `json:"validated_by"`
MailID sql.NullInt64 `json:"mail_id"`
Creator string `json:"creator"`
Created time.Time `json:"created"`
Changer string `json:"changer"`
@ -50,7 +50,7 @@ type Document struct {
}
type Mail struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
From string `json:"from"`
To []string `json:"to"`
Cc []string `json:"cc"`
@ -64,15 +64,15 @@ type Mail struct {
}
type Payment struct {
ID int64 `json:"ID"`
AccountID int64 `json:"accountID"`
PaymentCategory string `json:"paymentCategory"`
ID int64 `json:"id"`
AccountID int64 `json:"account_id"`
PaymentCategory string `json:"payment_category"`
Bankname sql.NullString `json:"bankname"`
IBAN sql.NullString `json:"IBAN"`
BIC sql.NullString `json:"BIC"`
PaypalAccount sql.NullString `json:"paypalAccount"`
PaypalID sql.NullString `json:"paypalID"`
PaymentSystem sql.NullString `json:"paymentSystem"`
Iban sql.NullString `json:"iban"`
Bic sql.NullString `json:"bic"`
PaypalAccount sql.NullString `json:"paypal_account"`
PaypalID sql.NullString `json:"paypal_id"`
PaymentSystem sql.NullString `json:"payment_system"`
Type string `json:"type"`
Creator string `json:"creator"`
Created time.Time `json:"created"`
@ -81,8 +81,8 @@ type Payment struct {
}
type Person struct {
ID int64 `json:"ID"`
AccountID int64 `json:"accountID"`
ID int64 `json:"id"`
AccountID int64 `json:"account_id"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -97,7 +97,7 @@ type Person struct {
}
type Provider struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
@ -109,9 +109,9 @@ type Provider struct {
}
type Return struct {
ID int64 `json:"ID"`
PersonID int64 `json:"personID"`
ProviderID int64 `json:"providerID"`
ID int64 `json:"id"`
PersonID int64 `json:"person_id"`
ProviderID int64 `json:"provider_id"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
@ -124,9 +124,9 @@ type Return struct {
}
type ReturnsLog struct {
ID int64 `json:"ID"`
ReturnID int64 `json:"returnID"`
MailID int64 `json:"mailID"`
ID int64 `json:"id"`
ReturnID int64 `json:"return_id"`
MailID int64 `json:"mail_id"`
Status sql.NullString `json:"status"`
Creator string `json:"creator"`
Created time.Time `json:"created"`

View File

@ -12,31 +12,31 @@ import (
const createPayment = `-- name: CreatePayment :one
INSERT INTO payments (
"accountID",
"paymentCategory",
"account_id",
"payment_category",
"bankname",
"IBAN",
"BIC",
"paypalAccount",
"paypalID",
"paymentSystem",
"iban",
"bic",
"paypal_account",
"paypal_id",
"payment_system",
"type",
"creator",
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
) RETURNING "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed
) RETURNING id, account_id, payment_category, bankname, iban, bic, paypal_account, paypal_id, payment_system, type, creator, created, changer, changed
`
type CreatePaymentParams struct {
AccountID int64 `json:"accountID"`
PaymentCategory string `json:"paymentCategory"`
AccountID int64 `json:"account_id"`
PaymentCategory string `json:"payment_category"`
Bankname sql.NullString `json:"bankname"`
IBAN sql.NullString `json:"IBAN"`
BIC sql.NullString `json:"BIC"`
PaypalAccount sql.NullString `json:"paypalAccount"`
PaypalID sql.NullString `json:"paypalID"`
PaymentSystem sql.NullString `json:"paymentSystem"`
Iban sql.NullString `json:"iban"`
Bic sql.NullString `json:"bic"`
PaypalAccount sql.NullString `json:"paypal_account"`
PaypalID sql.NullString `json:"paypal_id"`
PaymentSystem sql.NullString `json:"payment_system"`
Type string `json:"type"`
Creator string `json:"creator"`
Changer string `json:"changer"`
@ -47,8 +47,8 @@ func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (P
arg.AccountID,
arg.PaymentCategory,
arg.Bankname,
arg.IBAN,
arg.BIC,
arg.Iban,
arg.Bic,
arg.PaypalAccount,
arg.PaypalID,
arg.PaymentSystem,
@ -62,8 +62,8 @@ func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (P
&i.AccountID,
&i.PaymentCategory,
&i.Bankname,
&i.IBAN,
&i.BIC,
&i.Iban,
&i.Bic,
&i.PaypalAccount,
&i.PaypalID,
&i.PaymentSystem,
@ -78,7 +78,7 @@ func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (P
const deletePayment = `-- name: DeletePayment :exec
DELETE FROM payments
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeletePayment(ctx context.Context, id int64) error {
@ -87,8 +87,8 @@ func (q *Queries) DeletePayment(ctx context.Context, id int64) error {
}
const getPayment = `-- name: GetPayment :one
SELECT "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed FROM payments
WHERE "ID" = $1 LIMIT 1
SELECT id, account_id, payment_category, bankname, iban, bic, paypal_account, paypal_id, payment_system, type, creator, created, changer, changed FROM payments
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetPayment(ctx context.Context, id int64) (Payment, error) {
@ -99,8 +99,8 @@ func (q *Queries) GetPayment(ctx context.Context, id int64) (Payment, error) {
&i.AccountID,
&i.PaymentCategory,
&i.Bankname,
&i.IBAN,
&i.BIC,
&i.Iban,
&i.Bic,
&i.PaypalAccount,
&i.PaypalID,
&i.PaymentSystem,
@ -114,8 +114,8 @@ func (q *Queries) GetPayment(ctx context.Context, id int64) (Payment, error) {
}
const listPayments = `-- name: ListPayments :many
SELECT "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed FROM payments
ORDER BY "paymentCategory"
SELECT id, account_id, payment_category, bankname, iban, bic, paypal_account, paypal_id, payment_system, type, creator, created, changer, changed FROM payments
ORDER BY "payment_category"
LIMIT $1
OFFSET $2
`
@ -139,8 +139,8 @@ func (q *Queries) ListPayments(ctx context.Context, arg ListPaymentsParams) ([]P
&i.AccountID,
&i.PaymentCategory,
&i.Bankname,
&i.IBAN,
&i.BIC,
&i.Iban,
&i.Bic,
&i.PaypalAccount,
&i.PaypalID,
&i.PaymentSystem,
@ -166,32 +166,32 @@ func (q *Queries) ListPayments(ctx context.Context, arg ListPaymentsParams) ([]P
const updatePayment = `-- name: UpdatePayment :one
UPDATE payments
SET
"accountID" = COALESCE($3, "accountID"),
"paymentCategory" = COALESCE($4, "paymentCategory"),
"account_id" = COALESCE($3, "account_id"),
"payment_category" = COALESCE($4, "payment_category"),
"bankname" = COALESCE($5, "bankname"),
"IBAN" = COALESCE($6, "IBAN"),
"BIC" = COALESCE($7, "BIC"),
"paypalAccount" = COALESCE($8, "paypalAccount"),
"paypalID" = COALESCE($9, "paypalID"),
"paymentSystem" = COALESCE($10, "paymentSystem"),
"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,
"changed" = now()
WHERE "ID" = $1
RETURNING "ID", "accountID", "paymentCategory", bankname, "IBAN", "BIC", "paypalAccount", "paypalID", "paymentSystem", type, creator, created, changer, changed
WHERE "id" = $1
RETURNING id, account_id, payment_category, bankname, iban, bic, paypal_account, paypal_id, payment_system, type, creator, created, changer, changed
`
type UpdatePaymentParams struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Changer string `json:"changer"`
Accountid sql.NullInt64 `json:"accountid"`
Paymentcategory sql.NullString `json:"paymentcategory"`
AccountID sql.NullInt64 `json:"account_id"`
PaymentCategory sql.NullString `json:"payment_category"`
Bankname sql.NullString `json:"bankname"`
Iban sql.NullString `json:"iban"`
Bic sql.NullString `json:"bic"`
Paypalaccount sql.NullString `json:"paypalaccount"`
Paypalid sql.NullString `json:"paypalid"`
Paymentsystem sql.NullString `json:"paymentsystem"`
PaypalAccount sql.NullString `json:"paypal_account"`
PaypalID sql.NullString `json:"paypal_id"`
PaymentSystem sql.NullString `json:"payment_system"`
Type sql.NullString `json:"type"`
}
@ -199,14 +199,14 @@ func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (P
row := q.db.QueryRowContext(ctx, updatePayment,
arg.ID,
arg.Changer,
arg.Accountid,
arg.Paymentcategory,
arg.AccountID,
arg.PaymentCategory,
arg.Bankname,
arg.Iban,
arg.Bic,
arg.Paypalaccount,
arg.Paypalid,
arg.Paymentsystem,
arg.PaypalAccount,
arg.PaypalID,
arg.PaymentSystem,
arg.Type,
)
var i Payment
@ -215,8 +215,8 @@ func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (P
&i.AccountID,
&i.PaymentCategory,
&i.Bankname,
&i.IBAN,
&i.BIC,
&i.Iban,
&i.Bic,
&i.PaypalAccount,
&i.PaypalID,
&i.PaymentSystem,

View File

@ -23,11 +23,11 @@ func createRandomPayment(t *testing.T) Payment {
Valid: true,
String: util.RandomName(),
},
IBAN: sql.NullString{
Iban: sql.NullString{
Valid: true,
String: util.RandomName(),
},
BIC: sql.NullString{
Bic: sql.NullString{
Valid: true,
String: util.RandomName(),
},
@ -55,8 +55,8 @@ func createRandomPayment(t *testing.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.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)
@ -84,8 +84,8 @@ func TestGetPayment(t *testing.T) {
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.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)

View File

@ -13,7 +13,7 @@ import (
const createPerson = `-- name: CreatePerson :one
INSERT INTO persons (
"accountID",
"account_id",
"firstname",
"lastname",
"birthday",
@ -25,11 +25,11 @@ INSERT INTO persons (
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
) RETURNING "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed
) RETURNING id, account_id, firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed
`
type CreatePersonParams struct {
AccountID int64 `json:"accountID"`
AccountID int64 `json:"account_id"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -75,7 +75,7 @@ func (q *Queries) CreatePerson(ctx context.Context, arg CreatePersonParams) (Per
const deletePerson = `-- name: DeletePerson :exec
DELETE FROM persons
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeletePerson(ctx context.Context, id int64) error {
@ -84,8 +84,8 @@ func (q *Queries) DeletePerson(ctx context.Context, id int64) error {
}
const getPerson = `-- name: GetPerson :one
SELECT "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons
WHERE "ID" = $1 LIMIT 1
SELECT id, account_id, firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetPerson(ctx context.Context, id int64) (Person, error) {
@ -110,7 +110,7 @@ func (q *Queries) GetPerson(ctx context.Context, id int64) (Person, error) {
}
const listPersons = `-- name: ListPersons :many
SELECT "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons
SELECT id, account_id, firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed FROM persons
ORDER BY "lastname", "firstname"
LIMIT $1
OFFSET $2
@ -161,7 +161,7 @@ func (q *Queries) ListPersons(ctx context.Context, arg ListPersonsParams) ([]Per
const updatePerson = `-- name: UpdatePerson :one
UPDATE persons
SET
"accountID" = COALESCE($3, "accountID"),
"account_id" = COALESCE($3, "account_id"),
"firstname" = COALESCE($4, "firstname"),
"lastname" = COALESCE($5, "lastname"),
"birthday" = COALESCE($6, "birthday"),
@ -171,14 +171,14 @@ SET
"country" = COALESCE($10, "country"),
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
RETURNING "ID", "accountID", firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed
WHERE "id" = $1
RETURNING id, account_id, firstname, lastname, birthday, city, zip, street, country, creator, created, changer, changed
`
type UpdatePersonParams struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Changer string `json:"changer"`
Accountid sql.NullInt64 `json:"accountid"`
AccountID sql.NullInt64 `json:"account_id"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
@ -192,7 +192,7 @@ func (q *Queries) UpdatePerson(ctx context.Context, arg UpdatePersonParams) (Per
row := q.db.QueryRowContext(ctx, updatePerson,
arg.ID,
arg.Changer,
arg.Accountid,
arg.AccountID,
arg.Firstname,
arg.Lastname,
arg.Birthday,

View File

@ -20,7 +20,7 @@ INSERT INTO providers (
"changer"
) VALUES (
$1, $2, $3, $4, $5, $6
) RETURNING "ID", name, description, category, email, creator, created, changer, changed
) RETURNING id, name, description, category, email, creator, created, changer, changed
`
type CreateProviderParams struct {
@ -58,7 +58,7 @@ func (q *Queries) CreateProvider(ctx context.Context, arg CreateProviderParams)
const deleteProvider = `-- name: DeleteProvider :exec
DELETE FROM providers
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeleteProvider(ctx context.Context, id int64) error {
@ -67,8 +67,8 @@ func (q *Queries) DeleteProvider(ctx context.Context, id int64) error {
}
const getProvider = `-- name: GetProvider :one
SELECT "ID", name, description, category, email, creator, created, changer, changed FROM providers
WHERE "ID" = $1 LIMIT 1
SELECT id, name, description, category, email, creator, created, changer, changed FROM providers
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetProvider(ctx context.Context, id int64) (Provider, error) {
@ -89,7 +89,7 @@ func (q *Queries) GetProvider(ctx context.Context, id int64) (Provider, error) {
}
const listProviders = `-- name: ListProviders :many
SELECT "ID", name, description, category, email, creator, created, changer, changed FROM providers
SELECT id, name, description, category, email, creator, created, changer, changed FROM providers
ORDER BY "name"
LIMIT $1
OFFSET $2
@ -142,12 +142,12 @@ SET
"email" = COALESCE($6, "email"),
"changer" = $2,
"changed" = now()
WHERE "ID" = $1
RETURNING "ID", name, description, category, email, creator, created, changer, changed
WHERE "id" = $1
RETURNING id, name, description, category, email, creator, created, changer, changed
`
type UpdateProviderParams struct {
ID int64 `json:"ID"`
ID int64 `json:"id"`
Changer string `json:"changer"`
Name sql.NullString `json:"name"`
Description sql.NullString `json:"description"`

View File

@ -31,7 +31,7 @@ type Querier interface {
// "timestamp" = COALESCE(sqlc.narg(timestamp), "timestamp"),
// changer = $2,
// changed = now()
// WHERE "ID" = $1
// WHERE "id" = $1
// RETURNING *;
DeleteMail(ctx context.Context, id int64) error
DeletePayment(ctx context.Context, id int64) error

View File

@ -12,8 +12,8 @@ import (
const createReturn = `-- name: CreateReturn :one
INSERT INTO returns (
"personID",
"providerID",
"person_id",
"provider_id",
"name",
"description",
"category",
@ -31,12 +31,12 @@ INSERT INTO returns (
$7,
$8,
$9
) RETURNING "ID", "personID", "providerID", name, description, category, email, status, creator, created, changer, changed
) RETURNING id, person_id, provider_id, name, description, category, email, status, creator, created, changer, changed
`
type CreateReturnParams struct {
Personid int64 `json:"personid"`
Providerid int64 `json:"providerid"`
PersonID int64 `json:"person_id"`
ProviderID int64 `json:"provider_id"`
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
@ -48,8 +48,8 @@ type CreateReturnParams struct {
func (q *Queries) CreateReturn(ctx context.Context, arg CreateReturnParams) (Return, error) {
row := q.db.QueryRowContext(ctx, createReturn,
arg.Personid,
arg.Providerid,
arg.PersonID,
arg.ProviderID,
arg.Name,
arg.Description,
arg.Category,
@ -78,7 +78,7 @@ func (q *Queries) CreateReturn(ctx context.Context, arg CreateReturnParams) (Ret
const deleteReturn = `-- name: DeleteReturn :exec
DELETE FROM returns
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeleteReturn(ctx context.Context, id int64) error {
@ -87,8 +87,8 @@ func (q *Queries) DeleteReturn(ctx context.Context, id int64) error {
}
const getReturn = `-- name: GetReturn :one
SELECT "ID", "personID", "providerID", name, description, category, email, status, creator, created, changer, changed FROM returns
WHERE "ID" = $1 LIMIT 1
SELECT id, person_id, provider_id, name, description, category, email, status, creator, created, changer, changed FROM returns
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetReturn(ctx context.Context, id int64) (Return, error) {
@ -112,7 +112,7 @@ func (q *Queries) GetReturn(ctx context.Context, id int64) (Return, error) {
}
const listReturns = `-- name: ListReturns :many
SELECT "ID", "personID", "providerID", name, description, category, email, status, creator, created, changer, changed FROM returns
SELECT id, person_id, provider_id, name, description, category, email, status, creator, created, changer, changed FROM returns
ORDER BY "name"
LIMIT $1
OFFSET $2
@ -162,8 +162,8 @@ func (q *Queries) ListReturns(ctx context.Context, arg ListReturnsParams) ([]Ret
const updateReturn = `-- name: UpdateReturn :one
UPDATE returns
SET
"personID" = COALESCE($1, "personID"),
"providerID" = COALESCE($2, "providerID"),
"person_id" = COALESCE($1, "person_id"),
"provider_id" = COALESCE($2, "provider_id"),
"name" = COALESCE($3, "name"),
"description" = COALESCE($4, "description"),
"category" = COALESCE($5, "category"),
@ -171,13 +171,13 @@ SET
"status" = COALESCE($7, "status"),
"changer" = $8,
"changed" = now()
WHERE "ID" = $9
RETURNING "ID", "personID", "providerID", name, description, category, email, status, creator, created, changer, changed
WHERE "id" = $9
RETURNING id, person_id, provider_id, name, description, category, email, status, creator, created, changer, changed
`
type UpdateReturnParams struct {
Personid sql.NullInt64 `json:"personid"`
Providerid sql.NullInt64 `json:"providerid"`
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"`
@ -189,8 +189,8 @@ 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.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: person.ID,
Providerid: provider.ID,
PersonID: person.ID,
ProviderID: provider.ID,
Status: util.RandomString(7),
Name: util.RandomName(),
Description: util.RandomString(30),
@ -34,8 +34,8 @@ func createRandomReturn(t *testing.T) Return {
require.NotEmpty(t, ret)
require.Equal(t, arg.Name, ret.Name)
require.Equal(t, arg.Personid, ret.PersonID)
require.Equal(t, arg.Providerid, ret.ProviderID)
require.Equal(t, arg.PersonID, ret.PersonID)
require.Equal(t, arg.ProviderID, ret.ProviderID)
require.Equal(t, arg.Description, ret.Description)
require.Equal(t, arg.Category, ret.Category)
require.Equal(t, arg.Status, ret.Status)

View File

@ -12,8 +12,8 @@ import (
const createReturnsLog = `-- name: CreateReturnsLog :one
INSERT INTO "returnsLog" (
"returnID",
"mailID",
"return_id",
"mail_id",
"status",
"creator",
"changer"
@ -23,20 +23,20 @@ INSERT INTO "returnsLog" (
$3,
$4,
$4
) RETURNING "ID", "returnID", "mailID", status, creator, created, changer, changed
) RETURNING id, return_id, mail_id, status, creator, created, changer, changed
`
type CreateReturnsLogParams struct {
Returnid int64 `json:"returnid"`
Mailid int64 `json:"mailid"`
ReturnID int64 `json:"return_id"`
MailID int64 `json:"mail_id"`
Status sql.NullString `json:"status"`
Creator string `json:"creator"`
}
func (q *Queries) CreateReturnsLog(ctx context.Context, arg CreateReturnsLogParams) (ReturnsLog, error) {
row := q.db.QueryRowContext(ctx, createReturnsLog,
arg.Returnid,
arg.Mailid,
arg.ReturnID,
arg.MailID,
arg.Status,
arg.Creator,
)
@ -56,7 +56,7 @@ func (q *Queries) CreateReturnsLog(ctx context.Context, arg CreateReturnsLogPara
const deleteReturnsLog = `-- name: DeleteReturnsLog :exec
DELETE FROM "returnsLog"
WHERE "ID" = $1
WHERE "id" = $1
`
func (q *Queries) DeleteReturnsLog(ctx context.Context, id int64) error {
@ -65,8 +65,8 @@ func (q *Queries) DeleteReturnsLog(ctx context.Context, id int64) error {
}
const getReturnsLog = `-- name: GetReturnsLog :one
SELECT "ID", "returnID", "mailID", status, creator, created, changer, changed FROM "returnsLog"
WHERE "ID" = $1 LIMIT 1
SELECT id, return_id, mail_id, status, creator, created, changer, changed FROM "returnsLog"
WHERE "id" = $1 LIMIT 1
`
func (q *Queries) GetReturnsLog(ctx context.Context, id int64) (ReturnsLog, error) {
@ -86,7 +86,7 @@ func (q *Queries) GetReturnsLog(ctx context.Context, id int64) (ReturnsLog, erro
}
const listReturnsLogs = `-- name: ListReturnsLogs :many
SELECT "ID", "returnID", "mailID", status, creator, created, changer, changed FROM "returnsLog"
SELECT id, return_id, mail_id, status, creator, created, changer, changed FROM "returnsLog"
ORDER BY "status"
LIMIT $1
OFFSET $2
@ -132,19 +132,19 @@ func (q *Queries) ListReturnsLogs(ctx context.Context, arg ListReturnsLogsParams
const updateReturnsLog = `-- name: UpdateReturnsLog :one
UPDATE "returnsLog"
SET
"returnID" = COALESCE($2, "returnID"),
"mailID" = COALESCE($3, "mailID"),
"return_id" = COALESCE($2, "return_id"),
"mail_id" = COALESCE($3, "mail_id"),
"status" = COALESCE($4, "status"),
"changer" = $1,
"changed" = now()
WHERE "ID" = $5
RETURNING "ID", "returnID", "mailID", status, creator, created, changer, changed
WHERE "id" = $5
RETURNING id, return_id, mail_id, status, creator, created, changer, changed
`
type UpdateReturnsLogParams struct {
Changer string `json:"changer"`
Returnid sql.NullInt64 `json:"returnid"`
Mailid sql.NullInt64 `json:"mailid"`
ReturnID sql.NullInt64 `json:"return_id"`
MailID sql.NullInt64 `json:"mail_id"`
Status sql.NullString `json:"status"`
ID int64 `json:"id"`
}
@ -152,8 +152,8 @@ type UpdateReturnsLogParams struct {
func (q *Queries) UpdateReturnsLog(ctx context.Context, arg UpdateReturnsLogParams) (ReturnsLog, error) {
row := q.db.QueryRowContext(ctx, updateReturnsLog,
arg.Changer,
arg.Returnid,
arg.Mailid,
arg.ReturnID,
arg.MailID,
arg.Status,
arg.ID,
)

View File

@ -18,8 +18,8 @@ func createRandomReturnsLog(t *testing.T) ReturnsLog {
creator := util.RandomName()
arg := CreateReturnsLogParams{
Returnid: ret.ID,
Mailid: mail.ID,
ReturnID: ret.ID,
MailID: mail.ID,
Status: sql.NullString{
Valid: true,
String: util.RandomString(7),
@ -31,8 +31,8 @@ func createRandomReturnsLog(t *testing.T) ReturnsLog {
require.NoError(t, err)
require.NotEmpty(t, returnsLog)
require.Equal(t, arg.Returnid, returnsLog.ReturnID)
require.Equal(t, arg.Mailid, returnsLog.MailID)
require.Equal(t, arg.ReturnID, returnsLog.ReturnID)
require.Equal(t, arg.MailID, returnsLog.MailID)
require.Equal(t, arg.Status, returnsLog.Status)
require.Equal(t, arg.Creator, returnsLog.Creator)

View File

@ -8,6 +8,8 @@ import (
type CreateAccountTxParams struct {
Passwordhash string `json:"passwordhash"`
PrivacyAccepted sql.NullBool `json:"privacy_accepted"`
PrivacyAcceptedDate sql.NullTime `json:"privacy_accepted_date"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Birthday time.Time `json:"birthday"`
@ -27,22 +29,17 @@ type CreateAccountTxResult struct {
func (store *SQLStore) CreateAccountTx(ctx context.Context, arg CreateAccountTxParams) (Account, error) {
var result CreateAccountTxResult
if arg.PrivacyAccepted.Bool && arg.PrivacyAccepted.Valid && !arg.PrivacyAcceptedDate.Valid {
arg.PrivacyAcceptedDate = sql.NullTime{
Valid: true,
Time: time.Now(),
}
}
err := store.execTx(ctx, func(q *Queries) error {
var err error
result.Account, err = q.CreateAccount(ctx, CreateAccountParams(arg)) //{
// Passwordhash: arg.Passwordhash,
// Firstname: arg.Firstname,
// Lastname: arg.Lastname,
// Birthday: arg.Birthday,
// City: arg.City,
// Zip: arg.Zip,
// Street: arg.Street,
// Country: arg.Country,
// Creator: arg.Creator,
// Phone: arg.Phone,
// Email: arg.Email,
// })
result.Account, err = q.CreateAccount(ctx, CreateAccountParams(arg))
return err
})

View File

@ -3,12 +3,15 @@ package db
import (
"context"
"database/sql"
"time"
)
type UpdateAccountTxParams struct {
ID int64 `json:"ID"`
Changer string `json:"changer"`
Passwordhash sql.NullString `json:"passwordhash"`
PrivacyAccepted sql.NullBool `json:"privacy_accepted"`
PrivacyAcceptedDate sql.NullTime `json:"privacy_accepted_date"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
@ -27,10 +30,30 @@ type UpdateAccountTxResult struct {
func (store *SQLStore) UpdateAccountTx(ctx context.Context, arg UpdateAccountTxParams) (Account, error) {
var result UpdateAccountTxResult
err := store.execTx(ctx, func(q *Queries) error {
account, err := store.GetAccount(ctx, arg.ID)
if err != nil {
return Account{}, err
}
if arg.PrivacyAccepted.Bool && arg.PrivacyAccepted.Bool != account.PrivacyAccepted.Bool {
arg.PrivacyAcceptedDate = sql.NullTime{
Valid: true,
Time: time.Now(),
}
}
if !account.PrivacyAccepted.Bool && !arg.PrivacyAccepted.Bool {
arg.PrivacyAcceptedDate = sql.NullTime{
Valid: true,
Time: time.Time{},
}
}
err = store.execTx(ctx, func(q *Queries) error {
var err error
result.Account, err = q.UpdateAccount(ctx, UpdateAccountParams(arg))
return err
})
return result.Account, err
}