aboutsummaryrefslogtreecommitdiff
path: root/Week9 Webshop/src/com/camilstaps/shop/Order.java
blob: 2b0c5a73f1fa7adcca87dabc4f7d49db20790bf9 (plain) (blame)
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
/**
 * Copyright (c) 2015 Camil Staps <info@camilstaps.nl>
 * See the LICENSE file for copying permission.
 */

package com.camilstaps.shop;

import java.util.HashSet;
import java.util.Set;

/**
 * An order is a set of articles, purchased by a user
 * @author Camil Staps, s4498062
 */
public class Order extends DatabaseItem {
    
    private final Set<Article> articles;
    private final User user;
    private boolean paid = false;
    
    /**
     * This constructor takes the articles from the Cart of the User, and clears 
     * that Cart afterwards.
     * @param user 
     */
    public Order(User user) {
        this.user = user;
        articles = new HashSet<>();
        for (Article a : user.getCart().getArticles()) {
            articles.add(a);
        }
        user.getCart().getArticles().clear();
    }
    
    public User getUser() {
        return user;
    }
    
    public Set<Article> getArticles() {
        return articles;
    }
    
    public void setPaid(boolean set) {
        paid = set;
    }
    
    /**
     * See whether payment has been received for this article already
     * @return 
     */
    public boolean isPaid() {
        return paid;
    }
    
    /**
     * Get the total price of all articles
     * @return 
     */
    public float getTotalAmount() {
        float result = 0;
        for (Article a : articles) {
            result += a.getPrice();
        }
        return result;
    }
    
}