feat: 完成提交作业的后端

This commit is contained in:
2025-08-14 11:38:09 +08:00
parent 24622d30cf
commit e5dac3e731
13 changed files with 808 additions and 203 deletions

View File

@@ -2833,6 +2833,267 @@ export class ExamClient {
}
return Promise.resolve<ExamInfo>(null as any);
}
/**
* 提交作业
* @param examId 实验ID
* @param file (optional) 提交的文件
* @return 提交结果
*/
submitCommit(examId: string, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<Commit> {
let url_ = this.baseUrl + "/api/Exam/commit/{examId}";
if (examId === undefined || examId === null)
throw new Error("The parameter 'examId' must be defined.");
url_ = url_.replace("{examId}", encodeURIComponent("" + examId));
url_ = url_.replace(/[?&]$/, "");
const content_ = new FormData();
if (file === null || file === undefined)
throw new Error("The parameter 'file' cannot be null.");
else
content_.append("file", file.data, file.fileName ? file.fileName : "file");
let options_: AxiosRequestConfig = {
data: content_,
method: "POST",
url: url_,
headers: {
"Accept": "application/json"
},
cancelToken
};
return this.instance.request(options_).catch((_error: any) => {
if (isAxiosError(_error) && _error.response) {
return _error.response;
} else {
throw _error;
}
}).then((_response: AxiosResponse) => {
return this.processSubmitCommit(_response);
});
}
protected processSubmitCommit(response: AxiosResponse): Promise<Commit> {
const status = response.status;
let _headers: any = {};
if (response.headers && typeof response.headers === "object") {
for (const k in response.headers) {
if (response.headers.hasOwnProperty(k)) {
_headers[k] = response.headers[k];
}
}
}
if (status === 201) {
const _responseText = response.data;
let result201: any = null;
let resultData201 = _responseText;
result201 = Commit.fromJS(resultData201);
return Promise.resolve<Commit>(result201);
} else if (status === 400) {
const _responseText = response.data;
let result400: any = null;
let resultData400 = _responseText;
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
} else if (status === 401) {
const _responseText = response.data;
let result401: any = null;
let resultData401 = _responseText;
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
} else if (status === 404) {
const _responseText = response.data;
let result404: any = null;
let resultData404 = _responseText;
result404 = ProblemDetails.fromJS(resultData404);
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
} else if (status === 500) {
const _responseText = response.data;
return throwException("A server side error occurred.", status, _responseText, _headers);
} else if (status !== 200 && status !== 204) {
const _responseText = response.data;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Promise.resolve<Commit>(null as any);
}
/**
* 获取用户在指定实验中的提交记录
* @param examId 实验ID
* @return 提交记录列表
*/
getCommitsByExamId(examId: string, cancelToken?: CancelToken): Promise<Commit[]> {
let url_ = this.baseUrl + "/api/Exam/commits/{examId}";
if (examId === undefined || examId === null)
throw new Error("The parameter 'examId' must be defined.");
url_ = url_.replace("{examId}", encodeURIComponent("" + examId));
url_ = url_.replace(/[?&]$/, "");
let options_: AxiosRequestConfig = {
method: "GET",
url: url_,
headers: {
"Accept": "application/json"
},
cancelToken
};
return this.instance.request(options_).catch((_error: any) => {
if (isAxiosError(_error) && _error.response) {
return _error.response;
} else {
throw _error;
}
}).then((_response: AxiosResponse) => {
return this.processGetCommitsByExamId(_response);
});
}
protected processGetCommitsByExamId(response: AxiosResponse): Promise<Commit[]> {
const status = response.status;
let _headers: any = {};
if (response.headers && typeof response.headers === "object") {
for (const k in response.headers) {
if (response.headers.hasOwnProperty(k)) {
_headers[k] = response.headers[k];
}
}
}
if (status === 200) {
const _responseText = response.data;
let result200: any = null;
let resultData200 = _responseText;
if (Array.isArray(resultData200)) {
result200 = [] as any;
for (let item of resultData200)
result200!.push(Commit.fromJS(item));
}
else {
result200 = <any>null;
}
return Promise.resolve<Commit[]>(result200);
} else if (status === 400) {
const _responseText = response.data;
let result400: any = null;
let resultData400 = _responseText;
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
} else if (status === 401) {
const _responseText = response.data;
let result401: any = null;
let resultData401 = _responseText;
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
} else if (status === 404) {
const _responseText = response.data;
let result404: any = null;
let resultData404 = _responseText;
result404 = ProblemDetails.fromJS(resultData404);
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
} else if (status === 500) {
const _responseText = response.data;
return throwException("A server side error occurred.", status, _responseText, _headers);
} else if (status !== 200 && status !== 204) {
const _responseText = response.data;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Promise.resolve<Commit[]>(null as any);
}
/**
* 删除提交记录
* @param commitId 提交记录ID
* @return 删除结果
*/
deleteCommit(commitId: string, cancelToken?: CancelToken): Promise<void> {
let url_ = this.baseUrl + "/api/Exam/commit/{commitId}";
if (commitId === undefined || commitId === null)
throw new Error("The parameter 'commitId' must be defined.");
url_ = url_.replace("{commitId}", encodeURIComponent("" + commitId));
url_ = url_.replace(/[?&]$/, "");
let options_: AxiosRequestConfig = {
method: "DELETE",
url: url_,
headers: {
},
cancelToken
};
return this.instance.request(options_).catch((_error: any) => {
if (isAxiosError(_error) && _error.response) {
return _error.response;
} else {
throw _error;
}
}).then((_response: AxiosResponse) => {
return this.processDeleteCommit(_response);
});
}
protected processDeleteCommit(response: AxiosResponse): Promise<void> {
const status = response.status;
let _headers: any = {};
if (response.headers && typeof response.headers === "object") {
for (const k in response.headers) {
if (response.headers.hasOwnProperty(k)) {
_headers[k] = response.headers[k];
}
}
}
if (status === 200) {
const _responseText = response.data;
return Promise.resolve<void>(null as any);
} else if (status === 400) {
const _responseText = response.data;
let result400: any = null;
let resultData400 = _responseText;
result400 = ProblemDetails.fromJS(resultData400);
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
} else if (status === 401) {
const _responseText = response.data;
let result401: any = null;
let resultData401 = _responseText;
result401 = ProblemDetails.fromJS(resultData401);
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
} else if (status === 403) {
const _responseText = response.data;
let result403: any = null;
let resultData403 = _responseText;
result403 = ProblemDetails.fromJS(resultData403);
return throwException("A server side error occurred.", status, _responseText, _headers, result403);
} else if (status === 404) {
const _responseText = response.data;
let result404: any = null;
let resultData404 = _responseText;
result404 = ProblemDetails.fromJS(resultData404);
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
} else if (status === 500) {
const _responseText = response.data;
return throwException("A server side error occurred.", status, _responseText, _headers);
} else if (status !== 200 && status !== 204) {
const _responseText = response.data;
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Promise.resolve<void>(null as any);
}
}
export class HdmiVideoStreamClient {
@@ -3224,7 +3485,7 @@ export class JtagClient {
* @param bitstreamId (optional) 比特流ID
* @return 进度跟踪TaskID
*/
downloadBitstream(address: string | undefined, port: number | undefined, bitstreamId: number | undefined, cancelToken?: CancelToken): Promise<string> {
downloadBitstream(address: string | undefined, port: number | undefined, bitstreamId: string | undefined, cancelToken?: CancelToken): Promise<string> {
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
@@ -6475,7 +6736,7 @@ export class ResourceClient {
* @param resourceId 资源ID
* @return 资源文件
*/
getResourceById(resourceId: number, cancelToken?: CancelToken): Promise<FileResponse> {
getResourceById(resourceId: string, cancelToken?: CancelToken): Promise<FileResponse> {
let url_ = this.baseUrl + "/api/Resource/{resourceId}";
if (resourceId === undefined || resourceId === null)
throw new Error("The parameter 'resourceId' must be defined.");
@@ -6554,7 +6815,7 @@ export class ResourceClient {
* @param resourceId 资源ID
* @return 删除结果
*/
deleteResource(resourceId: number, cancelToken?: CancelToken): Promise<void> {
deleteResource(resourceId: string, cancelToken?: CancelToken): Promise<void> {
let url_ = this.baseUrl + "/api/Resource/{resourceId}";
if (resourceId === undefined || resourceId === null)
throw new Error("The parameter 'resourceId' must be defined.");
@@ -8069,6 +8330,74 @@ export interface IExamDto {
isVisibleToUsers: boolean;
}
export class Commit implements ICommit {
/** 资源的唯一标识符 */
id!: string;
/** 上传资源的用户ID */
userID!: string;
/** 所属实验ID */
examID?: string | undefined;
type!: CommitType;
resourceID!: string;
createdAt!: Date;
constructor(data?: ICommit) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(_data?: any) {
if (_data) {
this.id = _data["id"];
this.userID = _data["userID"];
this.examID = _data["examID"];
this.type = _data["type"];
this.resourceID = _data["resourceID"];
this.createdAt = _data["createdAt"] ? new Date(_data["createdAt"].toString()) : <any>undefined;
}
}
static fromJS(data: any): Commit {
data = typeof data === 'object' ? data : {};
let result = new Commit();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["id"] = this.id;
data["userID"] = this.userID;
data["examID"] = this.examID;
data["type"] = this.type;
data["resourceID"] = this.resourceID;
data["createdAt"] = this.createdAt ? this.createdAt.toISOString() : <any>undefined;
return data;
}
}
export interface ICommit {
/** 资源的唯一标识符 */
id: string;
/** 上传资源的用户ID */
userID: string;
/** 所属实验ID */
examID?: string | undefined;
type: CommitType;
resourceID: string;
createdAt: Date;
}
export enum CommitType {
Homework = 0,
Project = 1,
Markdown = 2,
}
export class HdmiVideoStreamEndpoint implements IHdmiVideoStreamEndpoint {
boardId!: string;
mjpegUrl!: string;
@@ -8587,7 +8916,7 @@ export interface IOscilloscopeDataResponse {
/** 资源信息类 */
export class ResourceInfo implements IResourceInfo {
/** 资源ID */
id!: number;
id!: string;
/** 资源名称 */
name!: string;
/** 资源类型 */
@@ -8645,7 +8974,7 @@ export class ResourceInfo implements IResourceInfo {
/** 资源信息类 */
export interface IResourceInfo {
/** 资源ID */
id: number;
id: string;
/** 资源名称 */
name: string;
/** 资源类型 */