Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/#120' into refactor-endpoint-format
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Nov 17, 2018
2 parents 92df7ca + 9c330ae commit 9feeb25
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 202 deletions.
29 changes: 29 additions & 0 deletions src/modules/helpers/DataTypeIdHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class DataTypeIdHelper {
/**
* @param {string[]} params
*/
static build(params) {
return params.join('.');
}
/** @param {string} dataTypeId */
static parse(dataTypeId) {
return dataTypeId.split('.');
}
/**
* @param {string} dataTypeId
* @param {string[]} partialParams
*/
static contain(dataTypeId, partialParams) {
const params = DataTypeIdHelper.parse(dataTypeId);
if (partialParams > params) {
return false;
}
for (let i = 0; i < partialParams.length; i++) {
if (partialParams[i] != params[i]) {
return false;
}
}
return true;
}
}
module.exports = DataTypeIdHelper;
30 changes: 0 additions & 30 deletions src/modules/helpers/EventIdHelper.js

This file was deleted.

11 changes: 6 additions & 5 deletions src/routes/posting/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ApiContext = require('../../modules/ApiContext');
const { RedisEventSender } = require('../../modules/redisEvent');
const DataTypeIdHelper = require('../../modules/helpers/DataTypeIdHelper');
const RedisEventEmitter = require('../../modules/RedisEventEmitter');
const $ = require('cafy').default;
const MongoAdapter = require('../../modules/MongoAdapter');
const { getStringSize } = require('../../modules/helpers/GeneralHelper');
Expand Down Expand Up @@ -53,10 +54,10 @@ exports['create-chat'] = async (apiContext) => {

const serialized = await apiContext.postsService.serialize(postStatus, true);

// event.posting.chat を発行
const eventSender = new RedisEventSender('frost-api');
await eventSender.publish(EventIdHelper.buildEventId(['event', 'posting', 'chat']), {
posting: postStatus
// RedisEvent posting.chat を発行
const eventSender = new RedisEventEmitter('frost-api', false);
await eventSender.emit(DataTypeIdHelper.build(['redis', 'posting', 'chat']), {
posting: serialized
});
await eventSender.dispose();

Expand Down
18 changes: 9 additions & 9 deletions src/routes/user/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ApiContext = require('../../modules/ApiContext');
const MongoAdapter = require('../../modules/MongoAdapter');
const $ = require('cafy').default;
const { RedisEventSender } = require('../../modules/redisEvent');
const RedisEventEmitter = require('../../modules/RedisEventEmitter');
const EventIdHelper = require('../../modules/helpers/EventIdHelper');

/** @param {ApiContext} apiContext */
Expand Down Expand Up @@ -284,9 +284,9 @@ exports.follow = async (apiContext) => {
return;
}

// event.following を発行
const eventSender = new RedisEventSender('frost-api');
await eventSender.publish(EventIdHelper.buildEventId(['event', 'following']), {
// RedisEvent following を発行
const eventSender = new RedisEventEmitter('frost-api', false);
await eventSender.emit(EventIdHelper.buildEventId(['following']), {
following: true,
sourceId: sourceUserId,
targetId: targetUserId
Expand Down Expand Up @@ -343,12 +343,12 @@ exports.unfollow = async (apiContext) => {
console.log(err);
}

// event.following を発行
const eventSender = new RedisEventSender('frost-api');
await eventSender.publish(EventIdHelper.buildEventId(['event', 'following']), {
// RedisEvent following を発行
const eventSender = new RedisEventEmitter('frost-api', false);
await eventSender.emit(EventIdHelper.buildEventId(['following']), {
following: false,
sourceUserId,
targetUserId
sourceId: sourceUserId,
targetId: targetUserId
});
await eventSender.dispose();

Expand Down
Loading

0 comments on commit 9feeb25

Please sign in to comment.