summaryrefslogtreecommitdiffstats
path: root/src/database/db-interface.vala
blob: be9ffbac730dcc4ce25c2a7a34de1988aa1cc98c (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
/* Copyright 2013, Sebastian Reichel <sre@ring0.de>
 *
 * 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 StockEntry[] get_stock() throws IOError;
	public abstract PriceEntry[] get_prices(uint64 product) throws IOError;
	public abstract RestockEntry[] get_restocks(uint64 product) throws IOError;
	public abstract bool buy(int32 user, uint64 article) throws IOError, DatabaseError;
	public abstract string get_product_name(uint64 article) throws IOError, DatabaseError;
	public abstract int get_product_amount(uint64 article) throws IOError, DatabaseError;
	public abstract Price get_product_price(int user, uint64 article) throws IOError, DatabaseError;
	public abstract bool undo(int32 user) throws IOError, DatabaseError;
	public abstract bool restock(int user, uint64 product, uint amount, uint price, int supplier, int64 best_before_date) throws IOError, DatabaseError;
	public abstract bool new_product(uint64 id, string name, int memberprice, int guestprice) throws IOError, DatabaseError;
	public abstract bool new_price(uint64 product, int64 timestamp, int memberprice, int guestprice) throws IOError, DatabaseError;
	public abstract bool check_user_password(int32 user, string password) throws IOError;
	public abstract void set_user_password(int32 user, string password) throws IOError, DatabaseError;
	public abstract void set_sessionid(int user, string sessionid) throws IOError, DatabaseError;
	public abstract int get_user_by_sessionid(string sessionid) throws IOError, DatabaseError;
	public abstract UserInfo get_user_info(int user) throws IOError, DatabaseError;
	public abstract UserAuth get_user_auth(int user) throws IOError, DatabaseError;
	public abstract string get_username(int user) throws IOError, DatabaseError;
	public abstract InvoiceEntry[] get_invoice(int user, int64 from=0, int64 to=-1) throws IOError, DatabaseError;
	public abstract int64 get_first_purchase(int user) throws IOError;
	public abstract int64 get_last_purchase(int user) throws IOError;
	public abstract StatsInfo get_stats_info() throws IOError;
	public abstract int[] get_member_ids() throws IOError;
	public abstract void user_disable(int user, bool value) throws IOError, DatabaseError;
	public abstract void user_replace(UserInfo u) throws IOError, DatabaseError;
	public abstract bool user_is_disabled(int user) throws IOError, DatabaseError;
	public abstract bool user_exists(int user) throws IOError, DatabaseError;
	public abstract bool user_equals(UserInfo u) throws IOError, DatabaseError;
	public abstract int64 get_timestamp_of_last_purchase() throws IOError;
	public abstract Supplier[] get_supplier_list() throws IOError;
	public abstract Supplier get_supplier(int id) throws IOError;
	public abstract bool add_supplier(string name, string postal_code, string city, string street, string phone, string website) throws IOError, DatabaseError;
}

public struct StockEntry {
	public string id;
	public string name;
	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 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 int postcode;
	public string city;
	public string pgp;

	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;

		return true;
	}
}

public struct UserAuth {
	public int id;
	public bool disabled;
	public bool superuser;
}

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

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

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
}