[ADD] update and insert coupon

This commit is contained in:
Sem van der Hoeven
2020-12-16 10:56:03 +01:00
parent 512ad3980f
commit 49f78efdd3
2 changed files with 11 additions and 0 deletions

View File

@@ -22,6 +22,9 @@ public interface CouponDao {
@Query("SELECT * FROM coupon")
LiveData<List<Coupon>> selectAll();
@Update
public void update(Coupon coupon);
/*
to add an observer to the livedata, you can use the example from https://medium.com/mindorks/using-room-database-with-livedata-android-jetpack-cbf89b677b47
*/

View File

@@ -20,6 +20,14 @@ public class CouponRepository {
mAllCoupons = mCouponDao.selectAll();
}
public void insert(Coupon... coupons) {
mCouponDao.insertAll(coupons);
}
public void update(Coupon coupon) {
mCouponDao.update(coupon);
}
public LiveData<List<Coupon>> getAllCoupons() {
return mAllCoupons;
}