Skip to content

Commit

Permalink
Merge pull request #3 from chocoearly44/development
Browse files Browse the repository at this point in the history
Verzija 2.1
  • Loading branch information
chocoearly44 authored Feb 20, 2022
2 parents 1e79920 + dccd0d2 commit 5c57c9f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>tk.thesuperlab</groupId>
<artifactId>jea</artifactId>
<version>2.0</version>
<version>2.1</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
78 changes: 74 additions & 4 deletions src/main/java/tk/thesuperlab/jea/JEA.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
import org.jsoup.select.Elements;
import org.opentimetable.javaottf.entities.Timetable;
import tk.thesuperlab.jea.entities.Evaluation;
import tk.thesuperlab.jea.entities.Subject;
import tk.thesuperlab.jea.entities.filters.WeekFilter;
import tk.thesuperlab.jea.exceptions.IncorrectCredentialsException;
import tk.thesuperlab.jea.parseentities.AjaxPrijava;
import tk.thesuperlab.jea.utils.RestUtils;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

Expand All @@ -24,13 +30,14 @@
* @since 2.0
*/
public class JEA {
private String uporabniskoIme;
private String geslo;
private final String uporabniskoIme;
private final String geslo;

private String bearerToken;
private String childId;

private static final ObjectMapper om;
private static final Format formatter = new SimpleDateFormat("yyyy-MM-dd");

static {
om = new ObjectMapper();
Expand Down Expand Up @@ -78,7 +85,7 @@ public List<Evaluation> getPastEvaluations() {
}

/**
* Metoda vam vrne OTTF objekt urnika za teden
* Metoda vam vrne OTTF objekt tedenskega urnika
*
* @param ponedeljek Datum ponedeljka v tednu
* @param nedelja Datum nedelje v tednu
Expand All @@ -87,10 +94,73 @@ public List<Evaluation> getPastEvaluations() {
* @since 2.0
*/
public Timetable getTimetable(Date ponedeljek, Date nedelja) {
Format formatter = new SimpleDateFormat("yyyy-MM-dd");
return RestUtils.getTimetable(bearerToken, childId, formatter.format(ponedeljek), formatter.format(nedelja));
}

/**
* Metoda vam vrne OTTF objekt tedenskega urnika glede na tedenski filter
*
* @param tedenskiFilter Tedenski filter
* @return OTTF objekt urnika
* @author chocoearly44
* @since 2.1
*/
public Timetable getTimetable(WeekFilter tedenskiFilter) {
Date monday;
Date sunday;

LocalDate currentMonday = LocalDate.now().with(DayOfWeek.MONDAY);
LocalDate currentSunday = LocalDate.now().with(DayOfWeek.SUNDAY);

Calendar cal = Calendar.getInstance();

switch(tedenskiFilter) {
case LAST_WEEK:
cal.setTime(getDate(currentMonday));
cal.add(Calendar.DATE, -7);
monday = cal.getTime();

cal.setTime(getDate(currentSunday));
cal.add(Calendar.DATE, -7);
sunday = cal.getTime();
break;

case NEXT_WEEK:
cal.setTime(getDate(currentMonday));
cal.add(Calendar.DATE, 7);
monday = cal.getTime();

cal.setTime(getDate(currentSunday));
cal.add(Calendar.DATE, 7);
sunday = cal.getTime();
break;

default:
monday = getDate(currentMonday);
sunday = getDate(currentSunday);
break;
}

return RestUtils.getTimetable(bearerToken, childId, formatter.format(monday), formatter.format(sunday));
}

/**
* Metoda vam vrne seznam vseh predmetov
*
* @return seznam vseh predmetov
* @author chocoearly44
* @since 2.1
*/
public List<Subject> getAllGrades() {
return RestUtils.getAllGrades(bearerToken, childId);
}

private Date getDate(LocalDate localDate) {
return Date.from(
localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()
);
}

private void getAccessToken() throws IncorrectCredentialsException {
OkHttpClient client = new OkHttpClient();

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/tk/thesuperlab/jea/entities/filters/WeekFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tk.thesuperlab.jea.entities.filters;

/**
* Tedenski filter za urnik
*
* @author chocoearly44
* @since 2.1
*/
public enum WeekFilter {
/**
* Pridobi urnik za prejšnji teden
*/
LAST_WEEK,

/**
* Pridobi urnik za trenutni (tekoči) teden
*/
CURRENT_WEEK,

/**
* Pridobi urnik za naslednji teden
*/
NEXT_WEEK
}

0 comments on commit 5c57c9f

Please sign in to comment.