From 1c848e6e1c612af7acc81692b316fed0174668eb Mon Sep 17 00:00:00 2001 From: leejh Date: Mon, 23 Sep 2019 10:14:20 +0900 Subject: [PATCH] add protocol BUDDY all --- .../src/lib/models/buddy-add.ts | 41 ++++++++++++++++ .../src/lib/models/buddy-del.ts | 41 ++++++++++++++++ .../src/lib/models/buddy-update.ts | 47 ++++++++++++++++++ .../lib/services/buddy-protocol.service.ts | 48 ++++++++++++++++++- .../src/lib/types/service.ts | 7 +++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-add.ts create mode 100644 projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-del.ts create mode 100644 projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-update.ts create mode 100644 projects/ucap-webmessenger-protocol-buddy/src/lib/types/service.ts diff --git a/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-add.ts b/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-add.ts new file mode 100644 index 00000000..64416f74 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-add.ts @@ -0,0 +1,41 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage +} from '@ucap-webmessenger/protocol'; + +export interface BuddyAddRequest extends ProtocolRequest { + // 0n. 사용자SEQ(n)... + userSeqs: number[]; +} + +export interface BuddyAddResponse extends ProtocolResponse { + // 0n. 사용자SEQ(n)... + userSeqs: number[]; +} + +export const encodeBuddyAdd: ProtocolEncoder = ( + req: BuddyAddRequest +) => { + const bodyList: PacketBody[] = []; + + for (const userSeq of req.userSeqs) { + bodyList.push({ type: PacketBodyValue.Integer, value: userSeq }); + } + + return bodyList; +}; + +export const decodeBuddyAdd: ProtocolDecoder = ( + message: ProtocolMessage +) => { + const userSeqArray: number[] = [...message.bodyList]; + return { + userSeqs: userSeqArray + } as BuddyAddResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-del.ts b/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-del.ts new file mode 100644 index 00000000..d0860eef --- /dev/null +++ b/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-del.ts @@ -0,0 +1,41 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage +} from '@ucap-webmessenger/protocol'; + +export interface BuddyDelRequest extends ProtocolRequest { + // 0n. 사용자SEQ(n)... + userSeqs: number[]; +} + +export interface BuddyDelResponse extends ProtocolResponse { + // 0n. 사용자SEQ(n)... + userSeqs: number[]; +} + +export const encodeBuddyDel: ProtocolEncoder = ( + req: BuddyDelRequest +) => { + const bodyList: PacketBody[] = []; + + for (const userSeq of req.userSeqs) { + bodyList.push({ type: PacketBodyValue.Integer, value: userSeq }); + } + + return bodyList; +}; + +export const decodeBuddyDel: ProtocolDecoder = ( + message: ProtocolMessage +) => { + const userSeqArray: number[] = [...message.bodyList]; + return { + userSeqs: userSeqArray + } as BuddyDelResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-update.ts b/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-update.ts new file mode 100644 index 00000000..395362a6 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-buddy/src/lib/models/buddy-update.ts @@ -0,0 +1,47 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage +} from '@ucap-webmessenger/protocol'; + +export interface BuddyUpdateRequest extends ProtocolRequest { + // 0. 사용자SEQ(n) + userSeq: number; + // 1. 즐겨찾기여부(y) + favorit: boolean; +} + +export interface BuddyUpdateResponse extends ProtocolResponse { + // 0. 사용자SEQ(n) + userSeq: number; + // 1. 즐겨찾기여부(y) + favorit: boolean; +} + +export const encodeBuddyUpdate: ProtocolEncoder = ( + req: BuddyUpdateRequest +) => { + const bodyList: PacketBody[] = []; + + bodyList.push({ type: PacketBodyValue.Integer, value: req.userSeq }); + bodyList.push({ + type: PacketBodyValue.String, + value: req.favorit ? 'Y' : 'N' + }); + + return bodyList; +}; + +export const decodeBuddyUpdate: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + userSeq: message.bodyList[0], + favorit: message.bodyList[1] === 'Y' ? true : false + } as BuddyUpdateResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-buddy/src/lib/services/buddy-protocol.service.ts b/projects/ucap-webmessenger-protocol-buddy/src/lib/services/buddy-protocol.service.ts index 2a0682d9..0816eb01 100644 --- a/projects/ucap-webmessenger-protocol-buddy/src/lib/services/buddy-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-buddy/src/lib/services/buddy-protocol.service.ts @@ -1,8 +1,54 @@ import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { ProtocolService } from '@ucap-webmessenger/protocol'; + +import { + SVC_TYPE_BUDDY, + SSVC_TYPE_BUDDY_ADD_REQ, + SSVC_TYPE_BUDDY_DEL_REQ, + SSVC_TYPE_BUDDY_UPD_REQ +} from '../types/service'; + +import { + BuddyAddRequest, + encodeBuddyAdd, + decodeBuddyAdd +} from '../models/buddy-add'; +import { + BuddyDelRequest, + encodeBuddyDel, + decodeBuddyDel +} from '../models/buddy-del'; +import { + BuddyUpdateRequest, + decodeBuddyUpdate, + encodeBuddyUpdate +} from '../models/buddy-update'; + @Injectable({ providedIn: 'root' }) export class BuddyProtocolService { - constructor() {} + constructor(private protocolService: ProtocolService) {} + + public buddyAdd(req: BuddyAddRequest): Observable { + return this.protocolService + .call(SVC_TYPE_BUDDY, SSVC_TYPE_BUDDY_ADD_REQ, ...encodeBuddyAdd(req)) + .pipe(map(res => decodeBuddyAdd(res))); + } + + public buddyDel(req: BuddyDelRequest): Observable { + return this.protocolService + .call(SVC_TYPE_BUDDY, SSVC_TYPE_BUDDY_DEL_REQ, ...encodeBuddyDel(req)) + .pipe(map(res => decodeBuddyDel(res))); + } + + public buddyUpdate(req: BuddyUpdateRequest): Observable { + return this.protocolService + .call(SVC_TYPE_BUDDY, SSVC_TYPE_BUDDY_UPD_REQ, ...encodeBuddyUpdate(req)) + .pipe(map(res => decodeBuddyUpdate(res))); + } } diff --git a/projects/ucap-webmessenger-protocol-buddy/src/lib/types/service.ts b/projects/ucap-webmessenger-protocol-buddy/src/lib/types/service.ts new file mode 100644 index 00000000..2574056b --- /dev/null +++ b/projects/ucap-webmessenger-protocol-buddy/src/lib/types/service.ts @@ -0,0 +1,7 @@ +export const SVC_TYPE_BUDDY = 4; // 동료 관리 +export const SSVC_TYPE_BUDDY_ADD_REQ = 1; // 동료추가 +export const SSVC_TYPE_BUDDY_ADD_RES = 2; +export const SSVC_TYPE_BUDDY_DEL_REQ = 11; // 동료삭제 +export const SSVC_TYPE_BUDDY_DEL_RES = 12; +export const SSVC_TYPE_BUDDY_UPD_REQ = 21; // 동료변경 +export const SSVC_TYPE_BUDDY_UPD_RES = 22;