Add the work management
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
90f83ec698
commit
0e97f37bff
@ -0,0 +1,21 @@
|
||||
<h2>Works</h2>
|
||||
|
||||
<ul>
|
||||
<li *ngFor="let work of works">
|
||||
{{ work.id_work }} - {{ work.link }} - {{ work.content }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<form #addBookForm="ngForm" (ngSubmit)="onSubmit(addBookForm)">
|
||||
<div class="form-group">
|
||||
<label for="link">Link</label>
|
||||
<input type="text" class="form-control" id="link" name="link" ngModel required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="content">Content</label>
|
||||
<input type="text" class="form-control" id="content" name="content" ngModel required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WorksListComponent } from './works-list.component';
|
||||
|
||||
describe('WorksListComponent', () => {
|
||||
let component: WorksListComponent;
|
||||
let fixture: ComponentFixture<WorksListComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [WorksListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(WorksListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,30 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Work} from "../../models/work.model";
|
||||
import {WorksService} from "../../services/works.service";
|
||||
import {NgForOf} from "@angular/common";
|
||||
import {FormsModule, NgForm} from "@angular/forms";
|
||||
|
||||
@Component({
|
||||
selector: 'app-works-list',
|
||||
standalone: true,
|
||||
imports: [
|
||||
NgForOf,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './works-list.component.html',
|
||||
styleUrl: './works-list.component.css'
|
||||
})
|
||||
export class WorksListComponent {
|
||||
works: Work[] = [];
|
||||
|
||||
constructor(protected workService: WorksService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.workService.getWorks().subscribe((response: Work[]) => this.works = response)
|
||||
}
|
||||
|
||||
onSubmit(form: NgForm) {
|
||||
this.workService.postWork(form);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export interface Work {
|
||||
id_work: number,
|
||||
link: string,
|
||||
user_id: number,
|
||||
language_id: number,
|
||||
content: string
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Work} from "../models/work.model";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {Observable} from "rxjs";
|
||||
import {NgForm} from "@angular/forms";
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WorksService {
|
||||
API_URL = 'http://127.0.0.1:3000'
|
||||
|
||||
private works: Work[] = [];
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
getWorks(): Observable<any> {
|
||||
return this.http.get(`${this.API_URL}/works`);
|
||||
}
|
||||
|
||||
postWork(form: NgForm): void {
|
||||
let body = {link: form.value.link, id_user: 1, id_language: 1, code: form.value.content}
|
||||
this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
|
||||
}
|
||||
|
||||
postWorkCode(code: string): void {
|
||||
let body = {link: 'TODO', id_user: 1, id_language: 1, code: code}
|
||||
this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue