Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions backend/src/main/java/com/lyrne/backend/TimeSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,43 @@ public class TimeSlot{ // A timeslot object that can be created by a tutor
private String start;
private String end;
public String id; // the ID will just be a concatenation of the start time & tutor ID for now
private float price;

// These long variables are assigned when the session actually starts and stops
private long sessionStart;
private long elapsedTime;
private long elapsedSeconds;
private long secondsDisplay;
private long elapsedMinutes;
private String minutesAndSeconds; // String Representation of Time

// Getter methods for all time tracking variables
public long getSessionStart() { return sessionStart; }
public long getElapsedTime() { return elapsedTime; }
public long getElapsedSeconds() { return elapsedSeconds; }
public long getSecondsDisplay() { return secondsDisplay; }
public long getElapsedMinutes() { return elapsedMinutes; }
public String getMinutesAndSeconds() { return minutesAndSeconds; }

// Call this when the session starts (when someone first joins the call or something)
public void startSession() {
sessionStart = System.currentTimeMillis();
elapsedTime = 0;
}

// Called when the session has stopped
public void updateTimes() {
elapsedSeconds = elapsedTime / 1000;
secondsDisplay = elapsedSeconds % 60;
elapsedMinutes = elapsedSeconds / 60;
minutesAndSeconds = elapsedMinutes + ":" + secondsDisplay;
}

// Call this when the session is over (everyone leaves the call or something)
public void stopSession() {
elapsedTime = System.currentTimeMillis();
updateTimes();
}

public TimeSlot(DateTime start, DateTime end, String tutorID){

Expand Down Expand Up @@ -62,6 +98,7 @@ public String getBookedBy() {
public String getID(){
return id;
}
public float getPrice() { return price; }

public boolean isBooked(){
return booked;
Expand Down
22 changes: 19 additions & 3 deletions backend/src/main/java/com/lyrne/backend/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import me.mrnavastar.sqlib.api.DataContainer;
import me.mrnavastar.sqlib.api.types.JavaTypes;

import org.apache.logging.log4j.core.util.ArrayUtils;
import org.joda.time.DateTime;
import org.joda.time.Interval;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Map;

Expand Down Expand Up @@ -59,14 +61,28 @@ public User(DataContainer container) {

// This function should be called everytime there are session changes
public void updateHoursAndEarnings() {
// Reset the values to zero to recalculate would be easy, but take up a lot of time
weeklyHours = 0;
weeklyEarnings = 0;
// We could also try remembering which session it was and remove it that way to save time
for (TimeSlot session: sessions) {
weeklyHours++; // There should be a value of time in each session
weeklyEarnings++; // There should be a value of earnings in each session
weeklyHours += Float.valueOf(session.getEndTime()) - Float.valueOf(session.getStartTime());
weeklyEarnings+= session.getPrice(); // There should be a value of earnings in each session
}
}

// Cancel a session by inserting the reference to the session
public void cancelSession(String ID) {
for (TimeSlot session: sessions) {
if (ID == session.getID()) {
sessions.remove(session);
}
}
updateHoursAndEarnings();
}

// HashMap for checking which user details are public (true) or private (false)
Map<String, Boolean> visibility = Map.ofEntries(
public Map<String, Boolean> visibility = Map.ofEntries(
Map.entry("id", true),
Map.entry("username", true),
Map.entry("email", false),
Expand Down
Loading