Interfaces: make names generic
This commit is contained in:
parent
b44fe2e51d
commit
1dd0333bc3
8 changed files with 27 additions and 27 deletions
|
|
@ -2,11 +2,11 @@ import {Component, inject} from '@angular/core';
|
||||||
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
|
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
|
||||||
import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {ShowsApiService} from '../../services/shows/shows-api.service';
|
import {ShowsApiService} from '../../services/shows/shows-api.service';
|
||||||
import {ShowsApiCreation} from '../../interfaces/shows-api-creation';
|
import {ApiCreationResponse} from '../../interfaces/api-creation-response';
|
||||||
import {ToastService} from '../../services/toast/toast.service';
|
import {ToastService} from '../../services/toast/toast.service';
|
||||||
import {Show} from '../../interfaces/show';
|
import {Show} from '../../interfaces/show';
|
||||||
import {formatDate} from '@angular/common';
|
import {formatDate} from '@angular/common';
|
||||||
import {ShowsApiDeletionEdit} from '../../interfaces/shows-api-deletion-edit';
|
import {ApiDeletionEditResponse} from '../../interfaces/api-deletion-edit-response';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-create-edit-modal',
|
selector: 'app-create-edit-modal',
|
||||||
|
|
@ -85,7 +85,7 @@ export class CreateEditModalComponent {
|
||||||
|
|
||||||
if (!this.editMode) {
|
if (!this.editMode) {
|
||||||
this.showsService.sendShow(show).subscribe({
|
this.showsService.sendShow(show).subscribe({
|
||||||
next: (response: ShowsApiCreation) => {
|
next: (response: ApiCreationResponse) => {
|
||||||
show._id = response.newId
|
show._id = response.newId
|
||||||
}, error: err => {
|
}, error: err => {
|
||||||
this.showToast(true, "created")
|
this.showToast(true, "created")
|
||||||
|
|
@ -100,7 +100,7 @@ export class CreateEditModalComponent {
|
||||||
// I add it here
|
// I add it here
|
||||||
show._id = this.show?._id
|
show._id = this.show?._id
|
||||||
this.showsService.updateShow(show).subscribe({
|
this.showsService.updateShow(show).subscribe({
|
||||||
next: (response: ShowsApiDeletionEdit) => {
|
next: (response: ApiDeletionEditResponse) => {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}, error: err => {
|
}, error: err => {
|
||||||
this.showToast(true, "edited")
|
this.showToast(true, "edited")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export interface ShowsApiCreation {
|
export interface ApiCreationResponse {
|
||||||
status: string
|
status: string
|
||||||
message: string
|
message: string
|
||||||
newId: string
|
newId: string
|
||||||
4
src/interfaces/api-deletion-edit-response.ts
Normal file
4
src/interfaces/api-deletion-edit-response.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export interface ApiDeletionEditResponse {
|
||||||
|
status: string
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {Show} from './show';
|
import {Show} from './show';
|
||||||
|
|
||||||
export interface ShowsApiIdResponse {
|
export interface ApiIdResponse {
|
||||||
status: string
|
status: string
|
||||||
show: Show
|
show: Show
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {Show} from './show';
|
import {Show} from './show';
|
||||||
|
|
||||||
export interface ShowsApiResponse {
|
export interface ApiResponse {
|
||||||
status: string
|
status: string
|
||||||
shows: Show[]
|
shows: Show[]
|
||||||
totalShows: number
|
totalShows: number
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
export interface ShowsApiDeletionEdit {
|
|
||||||
status: string
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {Component, inject} from '@angular/core';
|
import {Component, inject} from '@angular/core';
|
||||||
import {ShowsApiService} from '../../services/shows/shows-api.service';
|
import {ShowsApiService} from '../../services/shows/shows-api.service';
|
||||||
import {Show} from '../../interfaces/show';
|
import {Show} from '../../interfaces/show';
|
||||||
import {ShowsApiResponse} from '../../interfaces/shows-api-response';
|
import {ApiResponse} from '../../interfaces/api-response';
|
||||||
import {Toast} from '../../interfaces/toast';
|
import {Toast} from '../../interfaces/toast';
|
||||||
import {ToastService} from '../../services/toast/toast.service';
|
import {ToastService} from '../../services/toast/toast.service';
|
||||||
import {NgbModal, NgbModalRef} from '@ng-bootstrap/ng-bootstrap';
|
import {NgbModal, NgbModalRef} from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
@ -29,7 +29,7 @@ export class ShowsComponent {
|
||||||
let loadToast: Toast = {body: "Loading shows..."};
|
let loadToast: Toast = {body: "Loading shows..."};
|
||||||
this.toastService.show(loadToast);
|
this.toastService.show(loadToast);
|
||||||
this.api.getShows().subscribe({
|
this.api.getShows().subscribe({
|
||||||
next: (response: ShowsApiResponse) => {
|
next: (response: ApiResponse) => {
|
||||||
this.shows = response.shows;
|
this.shows = response.shows;
|
||||||
}, error: (err: any) => {
|
}, error: (err: any) => {
|
||||||
console.error("Error: ", err);
|
console.error("Error: ", err);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {ShowsApiResponse} from '../../interfaces/shows-api-response';
|
import {ApiResponse} from '../../interfaces/api-response';
|
||||||
import {ShowsApiCreation} from '../../interfaces/shows-api-creation';
|
import {ApiIdResponse} from '../../interfaces/api-id-response';
|
||||||
import {ShowsApiIdResponse} from '../../interfaces/shows-api-id-response';
|
import {ApiDeletionEditResponse} from '../../interfaces/api-deletion-edit-response';
|
||||||
import {ShowsApiDeletionEdit} from '../../interfaces/shows-api-deletion-edit';
|
|
||||||
import {Show} from '../../interfaces/show';
|
import {Show} from '../../interfaces/show';
|
||||||
|
import {ApiCreationResponse} from '../../interfaces/api-creation-response';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|
@ -22,23 +22,23 @@ export class ShowsApiService {
|
||||||
this.idEndpoint = this.showsEndpoint + "id/"
|
this.idEndpoint = this.showsEndpoint + "id/"
|
||||||
}
|
}
|
||||||
|
|
||||||
getShows(): Observable<ShowsApiResponse> {
|
getShows(): Observable<ApiResponse> {
|
||||||
return this.http.get<ShowsApiResponse>(this.showsEndpoint)
|
return this.http.get<ApiResponse>(this.showsEndpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
getShow(id: string): Observable<ShowsApiIdResponse> {
|
getShow(id: string): Observable<ApiIdResponse> {
|
||||||
return this.http.get<ShowsApiIdResponse>(this.idEndpoint + id)
|
return this.http.get<ApiIdResponse>(this.idEndpoint + id)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendShow(newShow: Show): Observable<ShowsApiCreation> {
|
sendShow(newShow: Show): Observable<ApiCreationResponse> {
|
||||||
return this.http.post<ShowsApiCreation>(this.showsEndpoint, newShow)
|
return this.http.post<ApiCreationResponse>(this.showsEndpoint, newShow)
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteShw(id: string): Observable<ShowsApiDeletionEdit> {
|
deleteShw(id: string): Observable<ApiDeletionEditResponse> {
|
||||||
return this.http.delete<ShowsApiDeletionEdit>(this.idEndpoint + id)
|
return this.http.delete<ApiDeletionEditResponse>(this.idEndpoint + id)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateShow(show: Show): Observable<ShowsApiDeletionEdit> {
|
updateShow(show: Show): Observable<ApiDeletionEditResponse> {
|
||||||
return this.http.put<ShowsApiDeletionEdit>(this.idEndpoint + show._id, show)
|
return this.http.put<ApiDeletionEditResponse>(this.idEndpoint + show._id, show)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue