diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java index 3934647..3696b31 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java @@ -1185,7 +1185,7 @@ public class DBHelper extends SQLiteOpenHelper { + COLUMN_BOOKINGYEAR + " = ? AND " + COLUMN_BOOKINGMONTH + " = ? AND " + COLUMN_BOOKINGDATE + " = ? AND " - + COLUMN_BOOKINGSTART + " = ?)", + + COLUMN_BOOKINGSTART + " = ?", new String[] {booking.getServiceprovider().getUsername(), booking.getHomeowner().getUsername(), String.valueOf(booking.getYear()), @@ -1209,7 +1209,7 @@ public class DBHelper extends SQLiteOpenHelper { contentValues.put(COLUMN_AVERAGERATING, currentAverageRatings/(double)currentRaters); contentValues.put(COLUMN_RATERS, currentRaters); - writeDB.update(TABLE_BOOKINGS, contentValues, + writeDB.update(TABLE_SERVICEPROVIDERS, contentValues, COLUMN_SERVICEPROVIDERNAME + " = ? AND " + COLUMN_SERVICEPROVIDERSERVICE + " = ?", new String[] {booking.getServiceprovider().getUsername(), @@ -1274,9 +1274,9 @@ public class DBHelper extends SQLiteOpenHelper { public List getAllRatingsAndComments(String serviceProviderName, String serviceName){ return getAll("SELECT " + COLUMN_BOOKINGHOMEOWNER +", " + COLUMN_RATING + ", " + COLUMN_COMMENT + " FROM " + TABLE_BOOKINGS - + " WHERE " + COLUMN_BOOKINGSERVICEPROVIDER + " = " + serviceProviderName - + " AND " + COLUMN_BOOKINGSERVICE + " = " + serviceName - + " AND " + COLUMN_RATING + " > 0"); + + " WHERE " + COLUMN_BOOKINGSERVICEPROVIDER + " = '" + serviceProviderName + + "' AND " + COLUMN_BOOKINGSERVICE + " = '" + serviceName + + "' AND " + COLUMN_RATING + " > 0"); } public String[] getSpecificRatingAndComment(String serviceProviderName, String serviceName, @@ -1510,6 +1510,54 @@ public class DBHelper extends SQLiteOpenHelper { writeDB.execSQL("DELETE FROM " + TABLE_BOOKINGS); } + /** + * So I got really tired of trying to figure out how to rate and book at the same time. + * So Imma force it. + * + * @param serviceProvider + * @param homeOwner + * @param service + * @param year + * @param month + * @param day + * @param starth + * @param startmin + * @param endh + * @param endmin + */ + void forceAddBookingDONTTOUCH(String serviceProvider, String homeOwner, String service, + int year, int month, int day, + int starth, int startmin, int endh, int endmin){ + service = service.trim().toLowerCase(); + + Cursor cursor = writeDB.query(TABLE_SERVICEPROVIDERS, new String[]{COLUMN_SERVICEPROVIDERNAME}, + COLUMN_SERVICEPROVIDERNAME + " = ? AND " + + COLUMN_SERVICEPROVIDERSERVICE + " = ?", + new String[] {serviceProvider, service}, + null, null, null, "1"); + if (!cursor.moveToFirst()) { + cursor.close(); + return; + } + cursor.close(); + + + ContentValues contentValues = new ContentValues(); + contentValues.put(COLUMN_BOOKINGSTART, starth * 60 + startmin); + contentValues.put(COLUMN_BOOKINGEND, endh * 60 + endmin); + contentValues.put(COLUMN_BOOKINGDATE, day); + contentValues.put(COLUMN_BOOKINGMONTH, month); + contentValues.put(COLUMN_BOOKINGYEAR, year); + contentValues.put(COLUMN_BOOKINGSERVICEPROVIDER, serviceProvider); + contentValues.put(COLUMN_BOOKINGHOMEOWNER, homeOwner); + contentValues.put(COLUMN_BOOKINGSERVICE, service); + contentValues.put(COLUMN_BOOKINGSTATUS, Status.PENDING.toString()); + contentValues.put(COLUMN_RATING, 0); + + writeDB.insert(TABLE_BOOKINGS, null, contentValues); + + } + /** * Gets all items in a table * @param rawQuery SELECT * query @@ -1708,9 +1756,9 @@ public class DBHelper extends SQLiteOpenHelper { availabilityStart = cursor.getInt(0); availabilityEnd = cursor.getInt(1); - if ((availabilityStart < bookingStart && availabilityEnd > bookingStart)|| - (availabilityStart < bookingEnd && availabilityEnd > bookingEnd) || - (availabilityStart > bookingStart && availabilityEnd < bookingEnd)) return false; + if ((availabilityStart <= bookingStart && availabilityEnd >= bookingStart)|| + (availabilityStart <= bookingEnd && availabilityEnd >= bookingEnd) || + (availabilityStart >= bookingStart && availabilityEnd <= bookingEnd)) return false; cursor.moveToNext(); } diff --git a/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java b/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java index d3a2d0b..5370a70 100644 --- a/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java +++ b/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java @@ -447,6 +447,12 @@ public class DBIntegrationTest { boolean added = dbHelper.addBooking("jbO4aBF4dC", "7MuF1c59XP", "Hitman", 2020, 12, 1, 8, 12, 10, 0); assertTrue(added); + + //This booking has already been done so cannot be booked anymore + added = dbHelper.addBooking("jbO4aBF4dC", "7MuF1c59XP", "Hitman", + 2020, 12, 1, 8, 12, 10, 0); + assertTrue(!added); + //Provider is available from 5:20 to 21:11, but has a booking from 8:12 to 10:00 added = dbHelper.addBooking("jbO4aBF4dC", "7MuF1c59XP", "Hitman", 2020, 12, 1, 9, 12, 12, 0); @@ -522,10 +528,38 @@ public class DBIntegrationTest { dbHelper.deleteAll(); } -// @Test -// public void testRating(){ -// -// } + @Test + public void testRating(){ + setUp(TestAfter.BOOKING); + + ServiceProvider serviceProvider = (ServiceProvider)dbHelper.findUserByUsername("jbO4aBF4dC"); + HomeOwner homeOwner = (HomeOwner)dbHelper.findUserByUsername("7MuF1c59XP"); + Service service = dbHelper.findService("Hitman"); + + Booking booking = new Booking(8, 12, 10, 0, + 2, 10, 2018, + serviceProvider, homeOwner, service); + boolean added = dbHelper.addRating(booking, 5, "100%"); + assertTrue(added); + + double rating = dbHelper.getAverageRating("jbO4aBF4dC","Hitman"); + assertEquals(5, rating, 0.0001); + + booking = new Booking(10, 01, 11, 0, + 2, 10, 2018, + serviceProvider, homeOwner, service); + added = dbHelper.addRating(booking, 1, "Wrong target"); + assertTrue(added); + + rating = dbHelper.getAverageRating("jbO4aBF4dC","Hitman"); + assertEquals(3, rating, 0.0001); + + rating = dbHelper.getAverageRating("jbO4aBF4dC","exterminating flatworms"); + assertEquals(0, rating, 0.0001); + + dbHelper.deleteAll(); + + } // Ever gotten tired of adding things at the start of a test just to delete it all again? // I have. @@ -584,6 +618,14 @@ public class DBIntegrationTest { 12, 2020, serviceProvider1, homeOwner1, service1); dbHelper.addBooking(booking1); } + + if (testAfter.equals(TestAfter.BOOKING)){ + //October 2 2018 is a Tuesday + dbHelper.forceAddBookingDONTTOUCH("jbO4aBF4dC", "7MuF1c59XP", "Hitman", + 2018, 10, 2, 8, 12, 10, 0); + dbHelper.forceAddBookingDONTTOUCH("jbO4aBF4dC", "7MuF1c59XP", "Hitman", + 2018, 10, 2, 10, 01, 11, 0); + } } } }