diff --git a/src/app/+community-page/create-community-page/create-community-page.component.ts b/src/app/+community-page/create-community-page/create-community-page.component.ts index b49ea1bbfa..255d88c21b 100644 --- a/src/app/+community-page/create-community-page/create-community-page.component.ts +++ b/src/app/+community-page/create-community-page/create-community-page.component.ts @@ -1,5 +1,8 @@ import { Component } from '@angular/core'; import { Community } from '../../core/shared/community.model'; +import { ComColDataService } from '../../core/data/comcol-data.service'; +import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model'; +import { CommunityDataService } from '../../core/data/community-data.service'; @Component({ selector: 'ds-create-community', @@ -8,10 +11,15 @@ import { Community } from '../../core/shared/community.model'; }) export class CreateCommunityPageComponent { + public constructor(private communityDataService: CommunityDataService) { + + } + onSubmit(data: any) { - Object.assign(new Community(), { - // TODO: Create community object to add to rest + const community = Object.assign(new Community(), { + name: data.name }); + this.communityDataService.create(community); } } diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index 7d1e463dbe..6e06a600cf 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -11,6 +11,8 @@ import { ComColDataService } from './comcol-data.service'; import { CommunityDataService } from './community-data.service'; import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { AuthService } from '../auth/auth.service'; +import { Community } from '../shared/community.model'; @Injectable() export class CollectionDataService extends ComColDataService { @@ -23,8 +25,13 @@ export class CollectionDataService extends ComColDataService, protected cds: CommunityDataService, protected objectCache: ObjectCacheService, - protected halService: HALEndpointService + protected halService: HALEndpointService, + protected authService: AuthService ) { super(); } + + getName(collection: Collection) { + return collection.name; + } } diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index 5b9f10b957..8c912b4353 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -8,7 +8,7 @@ import { ResponseCacheEntry } from '../cache/response-cache.reducer'; import { CommunityDataService } from './community-data.service'; import { DataService } from './data.service'; -import { FindByIDRequest, PutRequest } from './request.models'; +import { FindByIDRequest, PostRequest, PutRequest } from './request.models'; import { NormalizedObject } from '../cache/models/normalized-object.model'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { DSpaceObject } from '../shared/dspace-object.model'; @@ -16,11 +16,15 @@ import { Community } from '../shared/community.model'; import { Collection } from '../shared/collection.model'; import { distinctUntilChanged, map } from 'rxjs/operators'; import { configureRequest } from '../shared/operators'; +import { AuthService } from '../auth/auth.service'; +import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; +import { HttpHeaders } from '@angular/common/http'; export abstract class ComColDataService extends DataService { protected abstract cds: CommunityDataService; protected abstract objectCache: ObjectCacheService; protected abstract halService: HALEndpointService; + protected abstract authService: AuthService; /** * Get the scoped endpoint URL by fetching the object with @@ -66,9 +70,18 @@ export abstract class ComColDataService new PutRequest(this.requestService.generateRequestId(), endpointURL, comcol)), + map((endpointURL: string) => { + const options: HttpOptions = Object.create({}); + const headers = new HttpHeaders(); + headers.append('Authentication', this.authService.buildAuthHeader()); + options.headers = headers; + console.log(options); + return new PostRequest(this.requestService.generateRequestId(), endpointURL + '?name=' + this.getName(comcol), options); + }), configureRequest(this.requestService) ); } + abstract getName(comcol: TDomain): string; + } diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index 88ad3a5287..e02c9bc033 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -11,6 +11,7 @@ import { Community } from '../shared/community.model'; import { ComColDataService } from './comcol-data.service'; import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { AuthService } from '../auth/auth.service'; @Injectable() export class CommunityDataService extends ComColDataService { @@ -23,7 +24,8 @@ export class CommunityDataService extends ComColDataService, protected objectCache: ObjectCacheService, - protected halService: HALEndpointService + protected halService: HALEndpointService, + protected authService: AuthService ) { super(); } @@ -31,4 +33,8 @@ export class CommunityDataService extends ComColDataService