aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java
blob: a6265610183fb9902fe3cdec53a74f50189016ab (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
package com.ufund.api.ufundapi.model;

import com.ufund.api.ufundapi.persistence.CupboardDAO;
import com.ufund.api.ufundapi.persistence.CupboardFileDao;

import java.io.IOException;

public class Cupboard {
    CupboardDAO dao = new CupboardFileDao();

    public void createNeed(Need need) throws IOException {
        int id = dao.getNeeds().length;
        dao.createNeed(need);
    }

//    public void updateID(int id) throws IOException {
//        for (int i = 0; i < getNeeds().length; i++) {
//            needs.get(i).setID(i);
//        }
//    }

    public Need[] findNeeds(String name) throws IOException {
        return dao.findNeeds(name);
    }

    public void updateNeed(Need need) throws IOException {
        dao.updateNeed(need);
    }

    public void removeNeed(int id) throws IOException {
        dao.deleteNeed(id);
    }

    public void removeNeed(String name) throws IOException {
        for (Need need : getNeeds()) {
            if (need.getName().equals(name)) {
                dao.deleteNeed(need.getId());
                return;
            }
        }
    }

    public Need[] getNeeds() throws IOException {
        return dao.getNeeds();
    }

    public Need getNeed(int id) throws IOException {
        return dao.getNeed(id);
    }

}