Commit eaa1d032 authored by Fjen Undso's avatar Fjen Undso
Browse files

models: add Date finder for Votes and Answers

parent 2d53bd6a
package controllers;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
......@@ -110,7 +111,10 @@ public class VoteController extends Controller {
sAll.value = v.value;
break;
case REQUEST:
// TODO: consider only last 5minutes?
// TODO: consider only last 5minutes
//Date date = new Date();
//long ms=date.getTime();
//Date updatedDate = new Date(ms - (5 * 60000)); //60000 is 1 minute equivalent in milliseconds
sRequests.value += v.value.compareTo(0);
break;
default:
......
......@@ -57,6 +57,10 @@ public class QuestionAnswer extends Model {
return QuestionAnswer.find.where().eq("owner", owner).findList();
}
public static List<QuestionAnswer> findAfterDate(Date date) {
return QuestionAnswer.find.where().between("date", date, new Date()).findList();
}
public QuestionAnswer(Session session, String owner, Answer answer) {
this.session = session;
this.owner = owner;
......
......@@ -27,7 +27,7 @@ public class Session extends Model {
public String id;
private final int IDMIN = 100000;
private final int IDMAX = 1000000;
private final int IDMAX = 999999;
@Constraints.Required
public String owner;
......@@ -66,7 +66,7 @@ public class Session extends Model {
Integer id;
do {
// try to find a unique id. not threadsafe...
id = rnd.nextInt(IDMAX - IDMIN) + IDMIN;
id = rnd.nextInt(IDMAX+1 - IDMIN) + IDMIN;
} while (Session.find.byId(id.toString()) != null);
this.id = id.toString();
......
package models;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
......@@ -53,6 +54,14 @@ public class Vote extends Model {
public static Finder<Long, Vote> find = new Finder<Long, Vote>(Long.class,
Vote.class);
public static List<Vote> findAfterDate(Date date) {
return Vote.find.where().between("date", date, new Date()).findList();
}
public static List<Vote> findBeforeDate(Date date) {
return Vote.find.where().between("date", new Date(0), date).findList();
}
public Vote(Session session, String owner, Type type, Integer value) {
this.session = session;
this.owner = owner;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment