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 b49ea1bbfa4be5df30bba5e1e9a9e2a3c1b42dd6..255d88c21bdcf2696ca203a9c069716202e7dfc3 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 7d1e463dbea8d8048965ca26af947c408a0c6ba7..6e06a600cfe3f1b677a3ab3133b19e91798471ec 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<NormalizedCollection, Collection> { @@ -23,8 +25,13 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio protected store: Store<CoreState>, 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 5b9f10b957a8ddb14dc59edc9b6e267d4eb65631..8c912b43532f4541cb5ec9288d2a76ae44961423 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<TNormalized extends NormalizedObject, TDomain> extends DataService<TNormalized, TDomain> { 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<TNormalized extends NormalizedObject, TD this.halService.getEndpoint(this.linkPath).pipe( isNotEmptyOperator(), distinctUntilChanged(), - map((endpointURL: string) => 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 88ad3a5287962d3ae0ec5876a138b99538d55df9..e02c9bc033d5524b2337c8710b5c109159b01d3b 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<NormalizedCommunity, Community> { @@ -23,7 +24,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity, protected rdbService: RemoteDataBuildService, protected store: Store<CoreState>, protected objectCache: ObjectCacheService, - protected halService: HALEndpointService + protected halService: HALEndpointService, + protected authService: AuthService ) { super(); } @@ -31,4 +33,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity, getEndpoint() { return this.halService.getEndpoint(this.linkPath); } + + getName(community: Community) { + return community.name; + } }