46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import {Injectable} from '@angular/core';
|
|
import {HttpClient} from '@angular/common/http';
|
|
import {Appointment} from '../models/appointment';
|
|
import {environment} from '../../environments/environment';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class AppointmentService {
|
|
baseApi = `${environment.baseApi}/appointments`;
|
|
|
|
constructor(private http: HttpClient) {
|
|
}
|
|
|
|
getAllAppointments() {
|
|
return this.http.get<Appointment[]>(`${this.baseApi}`);
|
|
}
|
|
|
|
getAppointmentsByDate(date: Date) {
|
|
const day = date.getDate().toString().padStart(2, '0')
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
|
const year = date.getFullYear();
|
|
return this.http.get<Appointment[]>(`${this.baseApi}/date?start=${year}-${month}-${day}`, {});
|
|
}
|
|
|
|
addAppointment(appointment: Appointment) {
|
|
return this.http.post(`${this.baseApi}`, appointment);
|
|
}
|
|
|
|
deleteAppointment(appointment: Appointment) {
|
|
return this.http.delete(`${this.baseApi}?id=${appointment.id}`)
|
|
}
|
|
|
|
updateAppointment(appointment: Appointment) {
|
|
return this.http.put(`${this.baseApi}`, appointment);
|
|
}
|
|
|
|
getAppointment(id: string) {
|
|
return this.http.get(`${this.baseApi}/${id}`);
|
|
}
|
|
|
|
getMostRecentAppointment(id: number) {
|
|
return this.http.get(`${this.baseApi}/recent/${id}`);
|
|
}
|
|
}
|