Skip to content
Snippets Groups Projects
Commit 53296305 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4949 define postfachService

parent bf78133c
No related branches found
No related tags found
No related merge requests found
import { ApiRootResource, ApiRootService } from '@alfa-client/api-root-shared';
import { InjectionToken, Provider } from '@angular/core';
import { Inject, InjectionToken, Provider } from '@angular/core';
import { ResourceListService } from 'libs/tech-shared/src/lib/resource/list-resource.service';
import { ListResourceServiceConfig } from 'libs/tech-shared/src/lib/resource/resource.model';
import { SettingsItemResource, SettingsListLinkRel, SettingsListResource } from './settings.model';
import { ResourceService } from 'libs/tech-shared/src/lib/resource/resource.service';
import {
ListResourceServiceConfig,
ResourceServiceConfig,
} from 'libs/tech-shared/src/lib/resource/resource.model';
import {
SettingsItemResource,
SettingsListLinkRel,
SettingsListResource,
SettingsService,
} from './settings.model';
import { ResourceRepository } from 'libs/tech-shared/src/lib/resource/resource.repository';
import { Postfach, PostfachLinkRel, PostfachResource } from './postfach/postfach.model';
import { Resource } from '@ngxp/rest';
import { Observable } from 'rxjs';
import { StateResource } from '@alfa-client/tech-shared';
export const SettingServiceToken: InjectionToken<
ResourceListService<ApiRootResource, SettingsListResource, SettingsItemResource>
......@@ -21,10 +34,34 @@ export const SettingsServiceProvider: Provider = {
export function createSettingsServiceConfig(
apiRootService: ApiRootService,
): ListResourceServiceConfig<ApiRootResource> {
console.info('create service Config');
console.info('Create Settingsservice...');
return {
baseResource: apiRootService.getApiRoot(),
createLinkRel: SettingsListLinkRel.CREATE,
listLinkRel: SettingsListLinkRel.LIST,
};
}
export const PostfachServiceToken: InjectionToken<ResourceService<PostfachResource>> =
new InjectionToken(null);
export const PostfachServiceProvider: Provider = {
provide: SettingServiceToken,
useFactory: (
settingsListService: SettingsService,
repository: ResourceRepository<PostfachResource>,
) => new ResourceService(createPostfachServiceConfig(settingsListService), repository),
deps: [SettingServiceToken, ResourceRepository],
};
export function createPostfachServiceConfig(
settingsListService: SettingsService,
): ResourceServiceConfig<PostfachResource> {
console.info('Create Postfachservice...');
return {
resource: <Observable<StateResource<PostfachResource>>>settingsListService.getSelected(),
editLinkRel: PostfachLinkRel.EDIT,
deleteLinkRel: PostfachLinkRel.DELETE,
getLinkRel: PostfachLinkRel.GET,
};
}
......@@ -5,12 +5,12 @@ import { TechSharedModule } from '@alfa-client/tech-shared';
import { NavigationItemComponent } from './shared/navigation-item/navigation-item.component';
import { RouterModule } from '@angular/router';
import { NavigationContainerComponent } from './navigation-container/navigation-container.component';
import { SettingsServiceProvider } from './admin-settings-provider';
import { PostfachServiceProvider, SettingsServiceProvider } from './admin-settings-provider';
@NgModule({
declarations: [NavigationItemComponent, NavigationContainerComponent],
imports: [CommonModule, TechSharedModule, RouterModule],
exports: [PostfachModule, NavigationItemComponent, NavigationContainerComponent],
providers: [SettingsServiceProvider],
providers: [SettingsServiceProvider, PostfachServiceProvider],
})
export class AdminSettingsModule {}
import { FormBuilder } from '@angular/forms';
import { PostfachFormService } from './postfach.formservice';
import { PostfachService } from '../../postfach.model';
import { Mock, useFromMock } from '@alfa-client/test-utils';
describe('PostfachFormService', () => {
let formService: PostfachFormService;
let postfachService: Mock<PostfachService> = null; //TODO richtig mocken
const formBuilder: FormBuilder = new FormBuilder();
beforeEach(() => {
formService = new PostfachFormService(formBuilder);
formService = new PostfachFormService(formBuilder, useFromMock(postfachService));
});
it('should create', () => {
......
......@@ -3,10 +3,12 @@ import {
StateResource,
createEmptyStateResource,
} from '@alfa-client/tech-shared';
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { Resource } from '@ngxp/rest';
import { Observable, of } from 'rxjs';
import { PostfachServiceToken } from '../../../admin-settings-provider';
import { PostfachService } from '../../postfach.model';
@Injectable()
export class PostfachFormService extends AbstractFormService {
......@@ -17,7 +19,10 @@ export class PostfachFormService extends AbstractFormService {
public static readonly GEMEINDESCHLUESSEL_FIELD: string = 'gemeindeschluessel';
public static readonly SIGNATUR_FIELD: string = 'signatur';
constructor(formBuilder: UntypedFormBuilder) {
constructor(
formBuilder: UntypedFormBuilder,
@Inject(PostfachServiceToken) private postfachService: PostfachService,
) {
super(formBuilder);
}
......@@ -33,6 +38,7 @@ export class PostfachFormService extends AbstractFormService {
}
protected doSubmit(): Observable<StateResource<Resource>> {
//Hier dann postfachService.save() aufrufen
console.info('FormValue: ', this.getFormValue());
return of(createEmptyStateResource<Resource>());
}
......
......@@ -21,7 +21,9 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { Resource } from '@ngxp/rest';
import { ResourceService } from 'libs/tech-shared/src/lib/resource/resource.service';
export interface Absender {
name: string;
......@@ -35,3 +37,13 @@ export interface Postfach {
absender: Absender;
signatur: string;
}
export interface PostfachResource extends Postfach, Resource {}
export enum PostfachLinkRel {
EDIT = '',
GET = '',
DELETE = '',
}
export declare type PostfachService = ResourceService<PostfachResource>;
......@@ -4,13 +4,13 @@ import { StateResource, createEmptyStateResource, createStateResource } from './
import { Resource, getUrl, hasLink } from '@ngxp/rest';
import { ResourceRepository } from './resource.repository';
export class ResourceService<B extends Resource, T extends Resource> {
export class ResourceService<T extends Resource> {
selectedResource: BehaviorSubject<StateResource<T>> = new BehaviorSubject(
createEmptyStateResource(),
);
constructor(
private config: ResourceServiceConfig<B>,
private config: ResourceServiceConfig<T>,
private repository: ResourceRepository<T>,
) {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment