summaryrefslogtreecommitdiffstats
path: root/src/database/db-interface.vala
blob: 63a0148eaf4e2eb83b81bc1cd7f237ad940a4493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* Copyright 2013, Sebastian Reichel <sre@ring0.de>
 * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

[DBus (name = "io.mainframe.shopsystem.Database")]
public interface Database : Object {
	public abstract DetailedProduct[] get_stock() throws DBusError, IOError;
	public abstract DetailedProduct get_product_for_ean(uint64 ean) throws DBusError, IOError, DatabaseError;
	public abstract PriceEntry[] get_prices(uint64 product) throws DBusError, IOError;
	public abstract RestockEntry[] get_restocks(uint64 product, bool descending) throws DBusError, IOError;
	public abstract bool buy(int32 user, uint64 article) throws DBusError, IOError, DatabaseError;
	public abstract string get_product_name(uint64 article) throws DBusError, IOError, DatabaseError;
	public abstract string get_product_category(uint64 article) throws DBusError, IOError, DatabaseError;
	public abstract int get_product_amount(uint64 article) throws DBusError, IOError, DatabaseError;
	public abstract bool get_product_deprecated(uint64 article) throws DBusError, IOError, DatabaseError;
	public abstract void product_deprecate(uint64 article, bool value) throws DBusError, IOError, DatabaseError;
	public abstract Price get_product_price(int user, uint64 article) throws DBusError, IOError, DatabaseError;
	public abstract string undo(int32 user) throws DBusError, IOError, DatabaseError;
	public abstract void restock(int user, uint64 product, uint amount, uint price, int supplier, int64 best_before_date) throws DBusError, IOError, DatabaseError;
	public abstract void new_product(uint64 id, string name, int category, int memberprice, int guestprice) throws DBusError, IOError, DatabaseError;
	public abstract void new_price(uint64 product, int64 timestamp, int memberprice, int guestprice) throws DBusError, IOError, DatabaseError;
	public abstract bool check_user_password(int32 user, string password) throws DBusError, IOError;
	public abstract void set_user_password(int32 user, string password) throws DBusError, IOError, DatabaseError;
	public abstract void set_sessionid(int user, string sessionid) throws DBusError, IOError, DatabaseError;
	public abstract void set_userTheme(int user, string userTheme) throws DBusError, IOError, DatabaseError;
	public abstract int get_user_by_sessionid(string sessionid) throws DBusError, IOError, DatabaseError;
	public abstract UserInfo get_user_info(int user) throws DBusError, IOError, DatabaseError;
	public abstract UserAuth get_user_auth(int user) throws DBusError, IOError, DatabaseError;
	public abstract void set_user_auth(UserAuth auth) throws DBusError, IOError, DatabaseError;
	public abstract string get_username(int user) throws DBusError, IOError, DatabaseError;
	public abstract string get_user_theme(int user, string fallback) throws DBusError, IOError, DatabaseError;
	public abstract InvoiceEntry[] get_invoice(int user, int64 from=0, int64 to=-1) throws DBusError, IOError, DatabaseError;
	public abstract int64 get_first_purchase(int user) throws DBusError, IOError;
	public abstract int64 get_last_purchase(int user) throws DBusError, IOError;
	public abstract StatsInfo get_stats_info() throws DBusError, IOError;
	public abstract int[] get_member_ids() throws DBusError, IOError;
	public abstract void user_disable(int user, bool value) throws DBusError, IOError, DatabaseError;
	public abstract void user_replace(UserInfo u) throws DBusError, IOError, DatabaseError;
	public abstract bool user_is_disabled(int user) throws DBusError, IOError, DatabaseError;
	public abstract bool user_exists(int user) throws DBusError, IOError, DatabaseError;
	public abstract bool user_equals(UserInfo u) throws DBusError, IOError, DatabaseError;
	public abstract int64 get_timestamp_of_last_purchase() throws DBusError, IOError;
	public abstract Category[] get_category_list() throws DBusError, IOError, DatabaseError;
	public abstract int add_category(string name) throws DBusError, IOError, DatabaseError;
	public abstract Supplier[] get_supplier_list() throws DBusError, IOError;
	public abstract Supplier get_supplier(int id) throws DBusError, IOError;
	public abstract void add_supplier(string name, string postal_code, string city, string street, string phone, string website) throws DBusError, IOError, DatabaseError;
	public abstract int[] get_users_with_sales(int64 timestamp_from, int64 timestamp_to) throws DBusError, IOError;
	public abstract Price get_user_invoice_sum(int user, int64 timestamp_from, int64 timestamp_to) throws DBusError, IOError;
	public abstract Price cashbox_status() throws DBusError, IOError;
	public abstract void cashbox_add(int user, Price amount, int64 timestamp) throws DBusError, IOError, DatabaseError;
	public abstract CashboxDiff[] cashbox_history() throws DBusError, IOError;
	public abstract CashboxDiff[] cashbox_changes(int64 start, int64 stop) throws DBusError, IOError;
	public abstract void ean_alias_add(uint64 ean, uint64 real_ean) throws DBusError, IOError, DatabaseError;
	public abstract uint64 ean_alias_get(uint64 ean) throws DBusError, IOError;
	public abstract EanAlias[] ean_alias_list() throws DBusError, IOError;
	public abstract BestBeforeEntry[] bestbeforelist() throws DBusError, IOError;
	public abstract int get_userid_for_rfid(string rfid) throws DBusError, IOError, DatabaseError;
	public abstract void addrfid(string rfid, int user) throws DBusError, IOError, DatabaseError;
	public abstract void delete_rfid_for_user(int user) throws DBusError, IOError, DatabaseError;
}

public struct Category {
	public int id;
	public string name;
}

public struct DetailedProduct {
	public uint64 ean;
	public string name;
	public string category;
	public int amount;
	public Price memberprice;
	public Price guestprice;
}

public struct PriceEntry {
	public int64 valid_from;
	public Price memberprice;
	public Price guestprice;
}

public struct RestockEntry {
	public int64 timestamp;
	public int amount;
	public string price;
	public int supplier;
	public int64 best_before_date;
}

public struct BestBeforeEntry {
	public uint64 ean;
	public string name;
	public int amount;
	public int64 best_before_date;
}

public struct Supplier {
	public int64 id;
	public string name;
	public string postal_code;
	public string city;
	public string street;
	public string phone;
	public string website;
}

public struct UserInfo {
	public int id;
	public string firstname;
	public string lastname;
	public string email;
	public string gender;
	public string street;
	public string postcode;
	public string city;
	public string pgp;
	public int64 joined_at;
	public bool disabled;
	public bool hidden;
	public string soundTheme;
	public string[] rfid;

	public bool equals(UserInfo x) {
		if(id != x.id) return false;
		if(firstname != x.firstname) return false;
		if(lastname != x.lastname) return false;
		if(email != x.email) return false;
		if(gender != x.gender) return false;
		if(street != x.street) return false;
		if(postcode != x.postcode) return false;
		if(city != x.city) return false;
		if(pgp != x.pgp) return false;
		if(joined_at != x.joined_at) return false;
		if(disabled != x.disabled) return false;
		if(hidden != x.hidden) return false;
		if(rfid != x.rfid) return false;

		return true;
	}
}

public struct UserAuth {
	public int id;
	public bool superuser;
	public bool auth_cashbox;
	public bool auth_products;
	public bool auth_users;
}

public struct Product {
	public uint64 ean;
	public string name;
}

public struct InvoiceEntry {
	public int64 timestamp;
	Product product;
	Price price;
}

public struct CashboxDiff {
	public int user;
	public Price amount;
	public int64 timestamp;
}

public struct EanAlias {
	public uint64 ean;
	public uint64 real_ean;
}

public struct StatsInfo {
	public int count_articles;
	public int count_users;
	public Price stock_value;
	public Price sales_total;
	public Price profit_total;
	public Price sales_today;
	public Price profit_today;
	public Price sales_this_month;
	public Price profit_this_month;
	public Price sales_per_day;
	public Price profit_per_day;
	public Price sales_per_month;
	public Price profit_per_month;
}

public errordomain DatabaseError {
	INTERNAL_ERROR,
	PRODUCT_NOT_FOUND,
	SESSION_NOT_FOUND,
	USER_NOT_FOUND,
	CONSTRAINT_FAILED,
	RFID_NOT_FOUND,
}