forked from krojew/evernus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCachingMarketOrderProvider.cpp
More file actions
165 lines (132 loc) · 5.31 KB
/
Copy pathCachingMarketOrderProvider.cpp
File metadata and controls
165 lines (132 loc) · 5.31 KB
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
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CachingMarketOrderProvider.h"
namespace Evernus
{
CachingMarketOrderProvider::CachingMarketOrderProvider(const MarketOrderRepository &orderRepo)
: QObject{}
, MarketOrderProvider{}
, mOrderRepo{orderRepo}
{
}
MarketOrderProvider::OrderList CachingMarketOrderProvider::getSellOrders(Character::IdType characterId) const
{
auto it = mSellOrders.find(characterId);
if (it == std::end(mSellOrders))
it = mSellOrders.emplace(characterId, mOrderRepo.fetchForCharacter(characterId, MarketOrder::Type::Sell)).first;
return it->second;
}
MarketOrderProvider::OrderList CachingMarketOrderProvider::getBuyOrders(Character::IdType characterId) const
{
auto it = mBuyOrders.find(characterId);
if (it == std::end(mBuyOrders))
it = mBuyOrders.emplace(characterId, mOrderRepo.fetchForCharacter(characterId, MarketOrder::Type::Buy)).first;
return it->second;
}
MarketOrderProvider::OrderList CachingMarketOrderProvider
::getArchivedOrders(Character::IdType characterId, const QDateTime &from, const QDateTime &to) const
{
auto it = mArchivedOrders.find(characterId);
if (it == std::end(mArchivedOrders))
it = mArchivedOrders.emplace(characterId, mOrderRepo.fetchArchivedForCharacter(characterId)).first;
std::vector<std::shared_ptr<MarketOrder>> result;
for (const auto &order : it->second)
{
const auto lastSeen = order->getLastSeen();
if (lastSeen >= from && lastSeen <= to)
result.emplace_back(order);
}
return result;
}
MarketOrderProvider::OrderList CachingMarketOrderProvider::getSellOrdersForCorporation(quint64 corporationId) const
{
auto it = mCorpSellOrders.find(corporationId);
if (it == std::end(mCorpSellOrders))
it = mCorpSellOrders.emplace(corporationId, mOrderRepo.fetchForCorporation(corporationId, MarketOrder::Type::Sell)).first;
return it->second;
}
MarketOrderProvider::OrderList CachingMarketOrderProvider::getBuyOrdersForCorporation(quint64 corporationId) const
{
auto it = mCorpBuyOrders.find(corporationId);
if (it == std::end(mCorpBuyOrders))
it = mCorpBuyOrders.emplace(corporationId, mOrderRepo.fetchForCorporation(corporationId, MarketOrder::Type::Buy)).first;
return it->second;
}
MarketOrderProvider::OrderList CachingMarketOrderProvider
::getArchivedOrdersForCorporation(quint64 corporationId, const QDateTime &from, const QDateTime &to) const
{
auto it = mCorpArchivedOrders.find(corporationId);
if (it == std::end(mCorpArchivedOrders))
it = mCorpArchivedOrders.emplace(corporationId, mOrderRepo.fetchArchivedForCorporation(corporationId)).first;
std::vector<std::shared_ptr<MarketOrder>> result;
for (const auto &order : it->second)
{
const auto lastSeen = order->getLastSeen();
if (lastSeen >= from && lastSeen <= to)
result.emplace_back(order);
}
return result;
}
void CachingMarketOrderProvider::removeOrder(MarketOrder::IdType id)
{
clearAll();
mOrderRepo.remove(id);
emit orderChanged();
}
void CachingMarketOrderProvider::setOrderNotes(MarketOrder::IdType id, const QString ¬es)
{
clearAll();
mOrderRepo.setNotes(id, notes);
emit orderChanged();
}
void CachingMarketOrderProvider::setOrderStation(MarketOrder::IdType orderId, uint stationId)
{
clearAll();
mOrderRepo.setStation(orderId, stationId);
emit orderChanged();
}
void CachingMarketOrderProvider::setOrderColorTag(MarketOrder::IdType orderId, const QColor &color)
{
clearAll();
mOrderRepo.setColorTag(orderId, color);
emit orderChanged();
}
void CachingMarketOrderProvider::clearOrdersForCharacter(Character::IdType id) const
{
mSellOrders.erase(id);
mBuyOrders.erase(id);
mArchivedOrders.erase(id);
}
void CachingMarketOrderProvider::clearOrdersForCorporation(uint id) const
{
mCorpSellOrders.erase(id);
mCorpBuyOrders.erase(id);
mCorpArchivedOrders.erase(id);
}
void CachingMarketOrderProvider::clearArchived() const
{
mArchivedOrders.clear();
mCorpArchivedOrders.clear();
}
void CachingMarketOrderProvider::clearAll()
{
mSellOrders.clear();
mBuyOrders.clear();
mArchivedOrders.clear();
mCorpSellOrders.clear();
mCorpBuyOrders.clear();
mCorpArchivedOrders.clear();
}
}