Skip to content
Snippets Groups Projects
lecturer-info.service.ts 2.87 KiB
Newer Older
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {HttpErrorService} from 'src/app/ErrorComponents/http-error.service';
import {Observable} from 'rxjs';
import {catchError} from 'rxjs/operators';
import {MinutePaperWrapperDao} from 'src/app/dao/minute-paper-wrapper.dao';
ywb16155's avatar
ywb16155 committed
import {environment} from '../../environments/environment';

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
  })
};

@Injectable()
export class LecturerInfoService {

  constructor(private http$: HttpClient, private errorService: HttpErrorService) {
  }

  public getLecturerClasses(username: String): Observable<String | Object> {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/getLecturerClasses', {username: username}, httpOptions).pipe(
      catchError(this.errorService.handleError)
    );
  }

  public getClassPapers(username: String, classCode: String): Observable<String | Object> {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/getClassPapers', {username: username, classCode: classCode}, httpOptions).pipe(
      catchError(this.errorService.handleError)
    );
  }

  public getPaperQuestions(paperId: String): Observable<String | Object> {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/getPaperQuestions', {paperId: paperId}, httpOptions).pipe(
      catchError(this.errorService.handleError)
    );
  }

  public getPaperAnswers(paperId: String): Observable<String | Object> {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/getPaperAnswers', {paperId: paperId}, httpOptions).pipe(
  public getTemplates(username: String): Observable<String | Object> {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/getTemplates', {username: username}, httpOptions).pipe(
  public createPaper(request: MinutePaperWrapperDao) {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/createPaper', request, httpOptions).pipe(
      catchError(this.errorService.handleError)
    );
  }

  public deletePaper(paperId: String) {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/deletePaper', {paperId: paperId}, httpOptions).pipe(
  public createTemplate(request: MinutePaperWrapperDao) {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/createTemplate', request, httpOptions).pipe(
      catchError(this.errorService.handleError)
    );
  }

  public deleteTemplate(paperId: String) {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/deleteTemplate', {paperId: paperId}, httpOptions).pipe(
  public getClassResponseData(username: String) {
ywb16155's avatar
ywb16155 committed
    return this.http$.post(environment.apiUrl + '/getResponseData', {username: username}, httpOptions).pipe(
      catchError(this.errorService.handleError)
    );
  }