66 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-09-18 15:02:21 +09:00
import { Injectable } from '@angular/core';
2019-09-20 16:49:42 +09:00
import { Observable } from 'rxjs';
2019-09-23 15:17:48 +09:00
import { map, take } from 'rxjs/operators';
2019-09-20 16:49:42 +09:00
import { ProtocolService } from '@ucap-webmessenger/protocol';
import {
SVC_TYPE_GROUP,
SSVC_TYPE_GROUP_ADD_REQ,
SSVC_TYPE_GROUP_DEL_REQ,
SSVC_TYPE_GROUP_UPD_REQ,
SSVC_TYPE_GROUP_UPD_REQ2
} from '../types/service';
2019-09-25 16:13:33 +09:00
import { AddRequest, encodeAdd, decodeAdd, AddResponse } from '../models/add';
import { DelRequest, encodeDel, decodeDel, DelResponse } from '../models/del';
2019-09-20 16:49:42 +09:00
import {
2019-09-25 16:13:33 +09:00
UpdateRequest,
encodeUpdate,
decodeUpdate,
encodeUpdate2,
decodeUpdate2,
UpdateResponse
} from '../models/update';
2019-09-18 15:02:21 +09:00
@Injectable({
providedIn: 'root'
})
export class GroupProtocolService {
2019-09-20 16:49:42 +09:00
constructor(private protocolService: ProtocolService) {}
2019-09-25 16:13:33 +09:00
public add(req: AddRequest): Observable<AddResponse> {
2019-09-20 16:49:42 +09:00
return this.protocolService
2019-09-25 16:13:33 +09:00
.call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_ADD_REQ, ...encodeAdd(req))
2019-09-23 15:17:48 +09:00
.pipe(
take(1),
2019-09-25 16:13:33 +09:00
map(res => decodeAdd(res))
2019-09-23 15:17:48 +09:00
);
2019-09-20 16:49:42 +09:00
}
2019-09-25 16:13:33 +09:00
public del(req: DelRequest): Observable<DelResponse> {
2019-09-20 16:49:42 +09:00
return this.protocolService
2019-09-25 16:13:33 +09:00
.call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_DEL_REQ, ...encodeDel(req))
2019-09-23 15:17:48 +09:00
.pipe(
take(1),
2019-09-25 16:13:33 +09:00
map(res => decodeDel(res))
2019-09-23 15:17:48 +09:00
);
2019-09-20 16:49:42 +09:00
}
2019-09-25 16:13:33 +09:00
public update(req: UpdateRequest): Observable<UpdateResponse> {
2019-09-20 16:49:42 +09:00
return this.protocolService
2019-09-25 16:13:33 +09:00
.call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_UPD_REQ, ...encodeUpdate(req))
2019-09-23 15:17:48 +09:00
.pipe(
take(1),
2019-09-25 16:13:33 +09:00
map(res => decodeUpdate(res))
2019-09-23 15:17:48 +09:00
);
2019-09-20 16:49:42 +09:00
}
2019-09-25 16:13:33 +09:00
public update2(req: UpdateRequest): Observable<UpdateResponse> {
2019-09-20 16:49:42 +09:00
return this.protocolService
2019-09-25 16:13:33 +09:00
.call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_UPD_REQ2, ...encodeUpdate2(req))
2019-09-23 15:17:48 +09:00
.pipe(
take(1),
2019-09-25 16:13:33 +09:00
map(res => decodeUpdate2(res))
2019-09-23 15:17:48 +09:00
);
2019-09-20 16:49:42 +09:00
}
2019-09-18 15:02:21 +09:00
}