-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotOfferService.java
More file actions
38 lines (30 loc) · 1.27 KB
/
Copy pathLotOfferService.java
File metadata and controls
38 lines (30 loc) · 1.27 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
package com.example.cw.services;
import com.example.cw.dao.DAO;
import com.example.cw.dao.DAOFactory;
import com.example.cw.model.Customer;
import com.example.cw.model.Lot;
import com.example.cw.model.LotOffer;
import com.example.cw.exceptions.DBException;
import java.util.List;
public class LotOfferService implements BusinessService {
private final DAO<LotOffer> lotOfferDAO;
private final DAO<Lot> lotDAO;
public LotOfferService(DAOFactory daoFactory) {
this.lotOfferDAO = daoFactory.getDAO(LotOffer.class);
this.lotDAO = daoFactory.getDAO(Lot.class);
}
public void createOffer(Double money, Long lotId, Long userID, String description) {
Lot lot= lotDAO.get(lotId).orElseThrow(()-> new DBException("Failed to find lot"));
if(lot.getStartPrice()>= money) {
throw new IllegalArgumentException("Bid must be bigger than the current price");
}
lotDAO.update(lot.setStartPrice(money));
lotOfferDAO.save(new LotOffer(money, new Customer().setId(userID), lot).setDescription(description));
}
public List<LotOffer> getOffersForLot(long lotId) {
return lotOfferDAO.getAll(new LotOffer().setLot(new Lot().setId(lotId)));
}
public Integer getSumOfRecords() {
return 2;
}
}