autocomit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Contact, ContactRole, CreateContactRequest, CreateContactRoleRequest } from '../../shared/models/contact.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ContactService {
|
||||
private readonly CONTACT_URL = '/api/contacts';
|
||||
private readonly ROLE_URL = '/api/contact-roles';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
// Contact Roles
|
||||
getContactRoles(): Observable<ContactRole[]> {
|
||||
return this.http.get<ContactRole[]>(this.ROLE_URL);
|
||||
}
|
||||
|
||||
createContactRole(data: CreateContactRoleRequest): Observable<ContactRole> {
|
||||
return this.http.post<ContactRole>(this.ROLE_URL, data);
|
||||
}
|
||||
|
||||
// Contacts
|
||||
getContacts(): Observable<Contact[]> {
|
||||
return this.http.get<Contact[]>(this.CONTACT_URL);
|
||||
}
|
||||
|
||||
getContact(id: string): Observable<Contact> {
|
||||
return this.http.get<Contact>(`${this.CONTACT_URL}/${id}`);
|
||||
}
|
||||
|
||||
createContact(data: CreateContactRequest): Observable<Contact> {
|
||||
return this.http.post<Contact>(this.CONTACT_URL, data);
|
||||
}
|
||||
|
||||
addPersonToContact(contactId: string, personId: string, isPrimary: boolean = false): Observable<Contact> {
|
||||
const params = new HttpParams().set('isPrimary', isPrimary.toString());
|
||||
return this.http.post<Contact>(`${this.CONTACT_URL}/${contactId}/persons/${personId}`, null, { params });
|
||||
}
|
||||
|
||||
removePersonFromContact(contactId: string, personId: string): Observable<Contact> {
|
||||
return this.http.delete<Contact>(`${this.CONTACT_URL}/${contactId}/persons/${personId}`);
|
||||
}
|
||||
|
||||
setPrimaryPerson(contactId: string, personId: string): Observable<Contact> {
|
||||
return this.http.patch<Contact>(`${this.CONTACT_URL}/${contactId}/persons/${personId}/primary`, null);
|
||||
}
|
||||
|
||||
deleteContact(id: string): Observable<void> {
|
||||
return this.http.delete<void>(`${this.CONTACT_URL}/${id}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Person, CreatePersonRequest, UpdatePersonRequest } from '../../shared/models/contact.model';
|
||||
import { Page } from '../../shared/models/environment.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PersonService {
|
||||
private readonly API_URL = '/api/persons';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getPersons(
|
||||
name?: string,
|
||||
page: number = 0,
|
||||
size: number = 20,
|
||||
sortBy: string = 'lastName',
|
||||
sortDirection: string = 'asc'
|
||||
): Observable<Page<Person>> {
|
||||
let params = new HttpParams()
|
||||
.set('page', page.toString())
|
||||
.set('size', size.toString())
|
||||
.set('sortBy', sortBy)
|
||||
.set('sortDirection', sortDirection);
|
||||
|
||||
if (name && name.trim()) {
|
||||
params = params.set('name', name.trim());
|
||||
}
|
||||
|
||||
return this.http.get<Page<Person>>(this.API_URL, { params });
|
||||
}
|
||||
|
||||
getPerson(id: string): Observable<Person> {
|
||||
return this.http.get<Person>(`${this.API_URL}/${id}`);
|
||||
}
|
||||
|
||||
createPerson(data: CreatePersonRequest): Observable<Person> {
|
||||
return this.http.post<Person>(this.API_URL, data);
|
||||
}
|
||||
|
||||
updatePerson(id: string, data: UpdatePersonRequest): Observable<Person> {
|
||||
return this.http.put<Person>(`${this.API_URL}/${id}`, data);
|
||||
}
|
||||
|
||||
deletePerson(id: string): Observable<void> {
|
||||
return this.http.delete<void>(`${this.API_URL}/${id}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
export interface ContactRole {
|
||||
id: string;
|
||||
roleName: string;
|
||||
description?: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface Person {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone?: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface PersonInContact {
|
||||
person: Person;
|
||||
isPrimary: boolean;
|
||||
}
|
||||
|
||||
export interface Contact {
|
||||
id: string;
|
||||
contactRole: ContactRole;
|
||||
persons: PersonInContact[];
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface CreatePersonRequest {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone?: string;
|
||||
}
|
||||
|
||||
export interface UpdatePersonRequest {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
}
|
||||
|
||||
export interface CreateContactRequest {
|
||||
contactRoleId: string;
|
||||
personIds: string[];
|
||||
primaryPersonId: string;
|
||||
}
|
||||
|
||||
export interface CreateContactRoleRequest {
|
||||
roleName: string;
|
||||
description?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user