Skip to content

Commit

Permalink
#125 Tutor queue panel with demo functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tktong committed Jan 13, 2016
1 parent d052b9c commit fc19a77
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.dcsc.admin.controllers.tutoring;

import org.dcsc.admin.dto.QueueSummary;
import org.dcsc.admin.dto.TutorQueueRefreshSummary;
import org.dcsc.core.course.AcademicCourse;
import org.dcsc.core.time.AcademicTermService;
import org.dcsc.core.tutor.Tutor;
import org.dcsc.core.tutor.TutorService;
import org.dcsc.core.user.DcscUser;
import org.dcsc.core.user.details.DcscUserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

@Controller
public class TutoringOfficeHourController {
@Autowired
private TutorService tutorService;
@Autowired
private AcademicTermService academicTermService;

@MessageMapping("/tutor/queue/refresh")
@SendToUser("/queue/office-hour")
public TutorQueueRefreshSummary courseQueueRefresh(Authentication authentication) throws Exception {
DcscUserDetails userDetails = (DcscUserDetails) authentication.getPrincipal();
DcscUser dcscUser = userDetails.getUser();

Tutor tutor = tutorService.getTutor(dcscUser);

// Demo code
List<QueueSummary> summaries = new ArrayList<>();
List<AcademicCourse> courses = tutor.getCourses(academicTermService.getCurrentTerm().getCode());
for (AcademicCourse course : courses) {
QueueSummary summary = new QueueSummary(course.getCode(), ThreadLocalRandom.current().nextInt(0, 19));
summaries.add(summary);
}

return new TutorQueueRefreshSummary(summaries);
}
}
31 changes: 31 additions & 0 deletions admin/src/main/java/org/dcsc/admin/dto/QueueSummary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.dcsc.admin.dto;

public class QueueSummary {
private String course;
private int size;

public QueueSummary() {

}

public QueueSummary(String course, int size) {
this.course = course;
this.size = size;
}

public String getCourse() {
return course;
}

public void setCourse(String course) {
this.course = course;
}

public int getSize() {
return size;
}

public void setSize(int size) {
this.size = size;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.dcsc.admin.dto;

import java.util.List;

public class TutorQueueRefreshSummary {
List<QueueSummary> summaries;

public TutorQueueRefreshSummary(List<QueueSummary> summaries) {
this.summaries = summaries;
}

public List<QueueSummary> getSummaries() {
return summaries;
}

public void setSummaries(List<QueueSummary> summaries) {
this.summaries = summaries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public boolean hasGroup(String group) {
}

public boolean hasGroup(String group, boolean adminOnly) {
return permissionEvaluator.hasGroup(authentication, group, true);
return permissionEvaluator.hasGroup(authentication, group, adminOnly);
}
}
2 changes: 1 addition & 1 deletion src/main/resources
Submodule resources updated from fbda0f to 79465e

0 comments on commit fc19a77

Please sign in to comment.