PPaste!

Home - All the pastes - Authored by Thooms

Raw version

 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
class Account {
    private int id;
    private List<Favorite> favorites;
}

class Station {
    private int id;
    //...
}

class Favorite {
    private int id;
    private Account account;
    private Station station;
}

interface FavoriteRepository extends JpaRepository<Favorite, Integer> {
    public Favorite getOneByAccountAndStation(Account account, Station station);
}

class FavoriteService {
    private FavoriteRepository favoriteRepository;

    public newFav(Account a, Station s) {
        Favorite f = new Favorite(a, s);
        favoriteRepository.save(f);
        return f;
    }

    public deleteFav(Account a, Station s) {
        Favorite f = favoriteRepository.getOneByAccountAndStation(a, f);
        favoriteRepository.delete(f);
    }
}