Commit 4303c873 authored by Adarsh's avatar Adarsh

comments servicees

parent 90b4f1ad
This source diff could not be displayed because it is too large. You can view the blob instead.
/*! \file
This service file is used to implement different functionalities of file workspace like upload, save, create and delete
files and directories.
*/
import {Injectable} from '@angular/core';
import {File} from './file';
import {Observable, of} from 'rxjs';
......@@ -10,6 +15,10 @@ import { User } from './user';
})
export class FileService {
/*
Url variables to store the backend urls for post and get requests.
*/
saveUrl = 'http://localhost/sfcode/backend/filesave.php';
uploadUrl = 'http://localhost/sfcode/backend/fileupload.php';
fileListUrl = 'http://localhost/sfcode/backend/dir_tree.php';
......@@ -20,6 +29,10 @@ export class FileService {
constructor(private http: HttpClient) {
}
/*
Temporary function to get files used for debugging.
*/
getFiles(): Observable<File[]> {
const ret: File[] = [];
......@@ -38,28 +51,50 @@ export class FileService {
return of(ret);
}
/*
Function to upload a file to the database using file interface and a boolean whether it is an attempt to a question
or created in ide.
*/
upload(file: File, isAttempt: boolean): Observable<any> {
return this.http.post(this.saveUrl, {file, isAttempt});
}
/*
Function to upload a file to the database using upload option, was used for debugging.
*/
upload2(file): Observable<any> {
const formData = new FormData();
formData.append('file', file, file.name);
return this.http.post(this.uploadUrl, formData);
}
/*
Function to delete a file from the database and server, by a post request, posting file, username and number of files .
*/
delete(file: any, isFile: boolean, username: string, nFiles: number): Observable<any> {
return this.http.post(this.deleteUrl, {file, isFile, username, nFiles});
}
/*
Function to get files from the database and server, by a post request, posting username.
*/
getFileList(username: string): Observable<any> {
return this.http.post(this.fileListUrl, {username});
}
/*
Function to get file's content from the database and server, by a post request, posting username and file's path.
*/
getFileContent(username: string, filepath: string): Observable<any> {
return this.http.post(this.fileContentUrl, {username, file_path: filepath});
}
/*
Function to create a directory for a particular user on the server while posting username, directory name and it's path.
*/
createDirectory(username: string, dirname: string, path: string): Observable<any> {
console.log(username, dirname, path);
return this.http.post(this.createDirUrl, {username, dirname, path});
......
/*! \file
This service file is used to get problems from a predefined const data structure and is used for debugging purposes only.
*/
import {Injectable} from '@angular/core';
import {Problem} from './problem';
import {Observable, of} from 'rxjs';
......
/*! \file
This service file is used to upload and get questions from the database.
*/
import {EventEmitter, Injectable, Output} from '@angular/core';
import {map} from 'rxjs/operators';
import {HttpClient} from '@angular/common/http';
......@@ -15,11 +19,16 @@ export class QuestionService {
constructor(private http: HttpClient) { }
/*
This function is used to upload question from each user to database.
*/
uploadQues(ques: Question): Observable<any> {
// console.log(ques);
return this.http.post(this.uploadUrl, ques);
}
/*
This function is used to get questions from all user from database.
*/
getQues(): Observable<Question[]> {
return this.http.get<Question[]>(this.getUrl);
}
......
/*! \file
This service file is used to compile and execute file, and also to compile, execute and verify the code
written by user for compettition questions for correctness.
*/
import {Injectable} from '@angular/core';
// import {Problem} from './problem';
import {Question} from './question';
......@@ -17,10 +22,18 @@ export class RunCodeService {
constructor(private httpClient: HttpClient) {
}
/*
This function is used to post the file data for compilation.
*/
compileFile(file: File): Observable<any> {
return this.httpClient.post(this.baseUrl + 'compile.php', file);
}
/*
This function is used to post the file data and custom input for execution.
*/
executeFile(file: File, input: string): Observable<any> {
return this.httpClient.post(this.baseUrl + 'execute.php', {
file,
......@@ -28,6 +41,10 @@ export class RunCodeService {
});
}
/*
This function is used to verify the testcases while posting the file data and other relaated parameters to the backend.
*/
verifyTestcase(file: File, out: string, ind: number, isSubmit: number): Observable<any> {
return this.httpClient.post(this.baseUrl + 'questions/check_output.php', {
title: file.filename,
......@@ -38,10 +55,18 @@ export class RunCodeService {
});
}
/*
This function is used to update the server about the result of user attempt to the question by a boolean.
*/
update(b: boolean): Observable<any> {
return this.httpClient.put(this.baseUrl + 'update_correct.php', {b});
}
/*
This function is for debugging purposes.
*/
compileQuestionFile(ques: Question, code: string[]): Observable<any> {
if (Math.floor(Math.random() * 2) === 1) {return of('done'); }
else {return throwError('error'); }
......
Markdown is supported
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