Add new components for AI and tutorials, update routing, and enhance file upload functionality
This commit is contained in:
+4
-4
@@ -1,13 +1,13 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TutorialService } from './tutorial.service';
|
||||
import { FileUploadApiService } from './file-upload-api.service';
|
||||
|
||||
describe('TutorialService', () => {
|
||||
let service: TutorialService;
|
||||
describe('FileUploadApiService', () => {
|
||||
let service: FileUploadApiService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(TutorialService);
|
||||
service = TestBed.inject(FileUploadApiService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
import {HttpClient, HttpEvent, HttpRequest} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {FileInfo} from '../models/file-info';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FileUploadService {
|
||||
private baseUrl = GlobalConstants.API_URL + '/file';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
upload(file: File): Observable<HttpEvent<any>> {
|
||||
const formData: FormData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const req = new HttpRequest('POST', `${this.baseUrl}/upload`, formData, {
|
||||
responseType: 'json',
|
||||
});
|
||||
|
||||
return this.http.request(req);
|
||||
}
|
||||
|
||||
getFiles(): Observable<FileInfo[]> {
|
||||
return this.http.get<FileInfo[]>(`${this.baseUrl}/files`);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Tutorial } from '../models/tutorial.model';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
const baseUrl = `${GlobalConstants.API_URL}/public/tutorials`;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TutorialService {
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getAllPublic(): Observable<Tutorial[]> {
|
||||
return this.http.get<Tutorial[]>(baseUrl);
|
||||
}
|
||||
|
||||
//
|
||||
// get(id: any): Observable<Tutorial> {
|
||||
// return this.http.get(`${baseUrl}/${id}`);
|
||||
// }
|
||||
//
|
||||
// create(data: any): Observable<any> {
|
||||
// return this.http.post(baseUrl, data);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// update(id: any, data: any): Observable<any> {
|
||||
// return this.http.put(`${baseUrl}/${id}`, data);
|
||||
// }
|
||||
//
|
||||
// delete(id: any): Observable<any> {
|
||||
// return this.http.delete(`${baseUrl}/${id}`);
|
||||
// }
|
||||
//
|
||||
// deleteAll(): Observable<any> {
|
||||
// return this.http.delete(baseUrl);
|
||||
// }
|
||||
|
||||
findByTitle(title: any): Observable<Tutorial[]> {
|
||||
return this.http.get<Tutorial[]>(`${baseUrl}?title=${title}`);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ZhipuaiImageService } from './zhipuai-image.service';
|
||||
|
||||
describe('ZhipuaiImageService', () => {
|
||||
let service: ZhipuaiImageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ZhipuaiImageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Tutorial} from '../models/tutorial.model';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Image} from '../models/image';
|
||||
import {SpinnerService} from './spinner.service';
|
||||
import {GlobalConstants} from '../global-constants';
|
||||
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
|
||||
export class ZhipuaiImageService {
|
||||
baseUrl : string = `${GlobalConstants.API_URL}/public/zhipuai`;
|
||||
|
||||
constructor(private http: HttpClient,public spinnerService: SpinnerService) {
|
||||
|
||||
}
|
||||
|
||||
generate(query: String): Observable<Image> {
|
||||
return this.http.get(`${(this.baseUrl)}/image/${query}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user