refactor: move contact servicesto services folder
This commit is contained in:
@@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { ContactListTable } from './contact-list-table';
|
import { ContactListTable } from './contact-list-table';
|
||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
import { strings } from '../../strings';
|
import { strings } from '../../strings';
|
||||||
import { ContactService } from '../../pages/main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Component, inject, input } from '@angular/core';
|
|||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { ContactActionsBar } from '../contact-actions-bar/contact-actions-bar';
|
import { ContactActionsBar } from '../contact-actions-bar/contact-actions-bar';
|
||||||
import { ContactService } from '../../pages/main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { ContactList } from './contact-list';
|
import { ContactList } from './contact-list';
|
||||||
import { ContactService } from '../../pages/main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
import { strings } from '../../strings';
|
import { strings } from '../../strings';
|
||||||
|
|||||||
@@ -1,21 +1,27 @@
|
|||||||
import { Component, inject, OnInit } from '@angular/core';
|
import { Component, inject, OnInit } from '@angular/core';
|
||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
import { UpperfirstPipe } from "../../pipes/upperfirst-pipe";
|
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
|
||||||
import { ContactSearchBar } from "../contact-search-bar/contact-search-bar";
|
import { ContactSearchBar } from '../contact-search-bar/contact-search-bar';
|
||||||
import { ContactListTable } from "../contact-list-table/contact-list-table";
|
import { ContactListTable } from '../contact-list-table/contact-list-table';
|
||||||
import { ContactService } from '../../pages/main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { AsyncPipe } from '@angular/common';
|
import { AsyncPipe } from '@angular/common';
|
||||||
import { Counter } from "../counter/counter";
|
import { Counter } from '../counter/counter';
|
||||||
import { ContactsFilterPipe } from "../../pipes/contacts-filter-pipe";
|
import { ContactsFilterPipe } from '../../pipes/contacts-filter-pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-contact-list',
|
selector: 'app-contact-list',
|
||||||
imports: [AsyncPipe, UpperfirstPipe, ContactSearchBar, ContactListTable, Counter, ContactsFilterPipe],
|
imports: [
|
||||||
|
AsyncPipe,
|
||||||
|
UpperfirstPipe,
|
||||||
|
ContactSearchBar,
|
||||||
|
ContactListTable,
|
||||||
|
Counter,
|
||||||
|
ContactsFilterPipe,
|
||||||
|
],
|
||||||
templateUrl: './contact-list.html',
|
templateUrl: './contact-list.html',
|
||||||
styleUrl: './contact-list.scss',
|
styleUrl: './contact-list.scss',
|
||||||
})
|
})
|
||||||
export class ContactList implements OnInit{
|
export class ContactList implements OnInit {
|
||||||
|
|
||||||
private readonly contactService = inject(ContactService);
|
private readonly contactService = inject(ContactService);
|
||||||
protected readonly strings = inject(STRINGS_INJECTOR);
|
protected readonly strings = inject(STRINGS_INJECTOR);
|
||||||
protected contacts$ = this.contactService.contacts$;
|
protected contacts$ = this.contactService.contacts$;
|
||||||
@@ -24,5 +30,4 @@ export class ContactList implements OnInit{
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.contactService.getAll().subscribe();
|
this.contactService.getAll().subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { inject } from '@angular/core';
|
import { inject } from '@angular/core';
|
||||||
import { ResolveFn, Router } from '@angular/router';
|
import { ResolveFn, Router } from '@angular/router';
|
||||||
import { ContactService } from '../main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { catchError, map, Observable, of } from 'rxjs';
|
import { catchError, map, Observable, of } from 'rxjs';
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Edit } from './edit';
|
|||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
import { strings } from '../../strings';
|
import { strings } from '../../strings';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { ContactService } from '../main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { map, Observable, take, tap } from 'rxjs';
|
|||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { FormGroupContact } from '../../utils/form-group-contact';
|
import { FormGroupContact } from '../../utils/form-group-contact';
|
||||||
import { AsyncPipe } from '@angular/common';
|
import { AsyncPipe } from '@angular/common';
|
||||||
import { ContactService } from '../main/contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { ContactFormValue } from '../../types/ContactFormValue.type';
|
import { ContactFormValue } from '../../types/ContactFormValue.type';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { Main } from './main';
|
import { Main } from './main';
|
||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
import { strings } from '../../strings';
|
import { strings } from '../../strings';
|
||||||
import { ContactService } from './contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { ContactList } from '../../components/contact-list/contact-list';
|
import { ContactList } from '../../components/contact-list/contact-list';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
@@ -22,7 +22,7 @@ describe('Main', () => {
|
|||||||
imports: [Main],
|
imports: [Main],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: STRINGS_INJECTOR, useValue: strings },
|
{ provide: STRINGS_INJECTOR, useValue: strings },
|
||||||
{ provide: ContactService, useValue: contactService }
|
{ provide: ContactService, useValue: contactService },
|
||||||
],
|
],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
fixture = TestBed.createComponent(Main);
|
fixture = TestBed.createComponent(Main);
|
||||||
@@ -37,8 +37,10 @@ describe('Main', () => {
|
|||||||
it('should call save on contact event', () => {
|
it('should call save on contact event', () => {
|
||||||
contactService.save.and.returnValue(of([]));
|
contactService.save.and.returnValue(of([]));
|
||||||
const saveSpy = spyOn(component, 'save').and.callThrough();
|
const saveSpy = spyOn(component, 'save').and.callThrough();
|
||||||
const CONTACT_MOCK = new ContactDTO()
|
const CONTACT_MOCK = new ContactDTO();
|
||||||
const contactForm: ContactForm = fixture.debugElement.query(By.css('app-contact-form')).componentInstance;
|
const contactForm: ContactForm = fixture.debugElement.query(
|
||||||
|
By.css('app-contact-form')
|
||||||
|
).componentInstance;
|
||||||
contactForm.contact.emit(CONTACT_MOCK);
|
contactForm.contact.emit(CONTACT_MOCK);
|
||||||
expect(saveSpy).toHaveBeenCalledOnceWith(CONTACT_MOCK);
|
expect(saveSpy).toHaveBeenCalledOnceWith(CONTACT_MOCK);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Component, inject } from '@angular/core';
|
|||||||
import { Card } from '../../components/card/card';
|
import { Card } from '../../components/card/card';
|
||||||
import { ContactForm } from '../../components/contact-form/contact-form';
|
import { ContactForm } from '../../components/contact-form/contact-form';
|
||||||
import { ContactList } from '../../components/contact-list/contact-list';
|
import { ContactList } from '../../components/contact-list/contact-list';
|
||||||
import { ContactService } from './contact.service';
|
import { ContactService } from '../../services/contact.service';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../../models/ContactDTO';
|
||||||
import { FormHeader } from '../../components/form-header/form-header';
|
import { FormHeader } from '../../components/form-header/form-header';
|
||||||
import { STRINGS_INJECTOR } from '../../app.config';
|
import { STRINGS_INJECTOR } from '../../app.config';
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { Response } from '../../models/Response';
|
import { Response } from '../models/Response';
|
||||||
import { ContactService } from './contact.service';
|
import { ContactService } from './contact.service';
|
||||||
import { provideHttpClient } from '@angular/common/http';
|
import { provideHttpClient } from '@angular/common/http';
|
||||||
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../models/ContactDTO';
|
||||||
|
|
||||||
describe('ContactService', () => {
|
describe('ContactService', () => {
|
||||||
let service: ContactService;
|
let service: ContactService;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { inject, Injectable } from '@angular/core';
|
import { inject, Injectable } from '@angular/core';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
import { ContactDTO } from '../../models/ContactDTO';
|
import { ContactDTO } from '../models/ContactDTO';
|
||||||
import { Response } from '../../models/Response';
|
import { Response } from '../models/Response';
|
||||||
import { BehaviorSubject, map, switchMap, tap } from 'rxjs';
|
import { BehaviorSubject, map, switchMap, tap } from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
Reference in New Issue
Block a user