Skip to content

Commit

Permalink
Done changes related to apply versioning in api.
Browse files Browse the repository at this point in the history
  • Loading branch information
yugank1991 committed May 10, 2019
1 parent f2cb16a commit 7fb9c25
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 57 deletions.
4 changes: 4 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"source": "/app/**",
"function": "app"
},
{
"source": "/v1/**",
"function": "v1"
},
{
"source": "/robots.txt",
"destination": "/robots.txt"
Expand Down
2 changes: 1 addition & 1 deletion functions/app-functions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports.app = require('./server/functions/app').app;
exports.v1 = require('./server/functions/app').app;
exports.onFirestoreQuestionWrite = require('./server/functions/db/firebase.functions').onQuestionWrite;
exports.onFirestoreInvitationWrite = require('./server/functions/db/firebase.functions').onInvitationWrite;
exports.onFirestoreGameCreate = require('./server/functions/db/firebase.functions').onGameCreate;
Expand Down
10 changes: 4 additions & 6 deletions functions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ class App {
this.app.use(bodyParser.json());
this.app.use('/images', express.static(__dirname + '/../../images'));
this.app.use((req, res, next) => {
// console.log('before', req.url);
if (req.url.indexOf(`/${appConstants.API_PREFIX}/`) === -1) {
req.url = `/${appConstants.API_PREFIX}${req.url}`; // prepend '/' to keep query params if any
}
// console.log('after', req.url);
next();
// console.log('before', req.url);
req.url = `/${appConstants.API_PREFIX}${req.url}`; // prepend '/' to keep query params if any
// console.log('after', req.url);
next();
});
// Routes
this.app.use(router);
Expand Down
4 changes: 2 additions & 2 deletions functions/controllers/game.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Account, Game, GameOperations, HeaderConstants, interceptorConstants, PlayerQnA, ResponseMessagesConstants
Account, Game, GameOperations, HeaderConstants, interceptorConstants, PlayerQnA, ResponseMessagesConstants, appConstants
} from '../../projects/shared-library/src/lib/shared/model';
import { AccountService } from '../services/account.service';
import { AppSettings } from '../services/app-settings.service';
Expand Down Expand Up @@ -114,7 +114,7 @@ export class GameController {
static async createSocialContent(req, res) {

const websiteUrl = Utils.getWebsiteUrl();
const imageUrl = `${websiteUrl}/app/game/social-image/${req.params.userId}/${req.params.socialId}`;
const imageUrl = `${websiteUrl}/${appConstants.API_VERSION}/game/social-image/${req.params.userId}/${req.params.socialId}`;

const htmlContent = `<!DOCTYPE html>
<html>
Expand Down
36 changes: 18 additions & 18 deletions functions/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ class Router {

this.router = express.Router();

// '/app/question'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.QUESTION}`, questionRoutes);
// '/app/v1/question'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.QUESTION}`, questionRoutes);

// '/app/subscription'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.SUBSCRIPTION}`, subscriptionRoutes);
// '/app/v1/subscription'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.SUBSCRIPTION}`, subscriptionRoutes);

// '/app/game'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.GAME}`, gameRoutes);
// '/app/v1/game'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.GAME}`, gameRoutes);

// '/app/general'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.GENERAL}`, generalRoutes);
// '/app/v1/general'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.GENERAL}`, generalRoutes);

// '/app/migration'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.MIGRATION}`, migrationRoutes);
// '/app/v1/migration'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.MIGRATION}`, migrationRoutes);

// '/app/scheduler'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.SCHEDULER}`, schedulerRoutes);
// '/app/v1/scheduler'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.SCHEDULER}`, schedulerRoutes);

// '/app/friend'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.FRIEND}`, friendRoutes);
// '/app/v1/friend'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.FRIEND}`, friendRoutes);

// '/app/user'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.USER}`, userRoutes);
// '/app/v1/user'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.USER}`, userRoutes);

// '/app/achievement'
this.router.use(`/${appConstants.API_PREFIX}/${RoutesConstants.ACHIEVEMENT}`, achievementRulesRoutes);
// '/app/v1/achievement'
this.router.use(`/${appConstants.API_PREFIX}/${appConstants.API_VERSION}/${RoutesConstants.ACHIEVEMENT}`, achievementRulesRoutes);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AchievementService {
}

getAchievements(): Observable<AchievementRule[]> {
const url = `${CONFIG.functionsUrl}/app/achievement`;
const url = `${CONFIG.functionsUrl}/achievement`;
return this.http.get<AchievementRule[]>(url);
}

Expand Down
16 changes: 8 additions & 8 deletions projects/shared-library/src/lib/core/services/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class GameService {
}

createNewGame(gameOptions: GameOptions, user: User): Observable<string> {
const url: string = CONFIG.functionsUrl + '/app/game';
const url = `${CONFIG.functionsUrl}/game`;
const payload = { gameOptions: gameOptions, userId: user.userId };
return this.http.post<string>(url, payload);
}
Expand Down Expand Up @@ -123,13 +123,13 @@ export class GameService {
}

getNextQuestion(game: Game): Observable<Question> {
const url: string = CONFIG.functionsUrl + '/app/question/next/';
const url = `${CONFIG.functionsUrl}/question/next/`;
return this.http.post<Question>(url + game.gameId, {});
}


addPlayerQnAToGame(gameId: string, playerQnA: PlayerQnA): Observable<any> {
const url = `${CONFIG.functionsUrl}/app/game/${gameId}`;
const url = `${CONFIG.functionsUrl}/game/${gameId}`;
const payload = {
playerQnA: playerQnA,
operation: GameOperations.CALCULATE_SCORE
Expand All @@ -139,21 +139,21 @@ export class GameService {


setGameOver(gameId: string) {
return this.http.put(`${CONFIG.functionsUrl}/app/game/${gameId}`,
return this.http.put(`${CONFIG.functionsUrl}/game/${gameId}`,
{
operation: GameOperations.GAME_OVER
});
}

updateGameRound(gameId: string) {
return this.http.put(`${CONFIG.functionsUrl}/app/game/${gameId}`,
return this.http.put(`${CONFIG.functionsUrl}/game/${gameId}`,
{
operation: GameOperations.UPDATE_ROUND
});
}

rejectGameInvitation(gameId: string) {
return this.http.put(`${CONFIG.functionsUrl}/app/game/${gameId}`,
return this.http.put(`${CONFIG.functionsUrl}/game/${gameId}`,
{
operation: GameOperations.REJECT_GAME
});
Expand Down Expand Up @@ -229,7 +229,7 @@ export class GameService {

checkUserQuestion(playerQnA: PlayerQnA): Observable<any> {

return this.http.post(`${CONFIG.functionsUrl}/app/question/${playerQnA.questionId}`,
return this.http.post(`${CONFIG.functionsUrl}/question/${playerQnA.questionId}`,
{
playerQnA: playerQnA
});
Expand Down Expand Up @@ -275,7 +275,7 @@ export class GameService {
let playerQnA = new PlayerQnA();
playerQnA = game.playerQnAs.filter(info => info.questionId === Object.keys(report.questions)[0])[0];
playerQnA.isReported = true;
const url = `${CONFIG.functionsUrl}/app/game/${game.gameId}`;
const url = `${CONFIG.functionsUrl}/game/${game.gameId}`;
const payload = {
playerQnA: playerQnA,
operation: GameOperations.REPORT_STATUS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export class QuestionService {

// Elasticsearch
getQuestionOfTheDay(isNextQuestion: boolean): Observable<Question> {
let url: string = CONFIG.functionsUrl + '/app/question/day';
let url = `${CONFIG.functionsUrl}/question/day`;
url = (isNextQuestion) ? `${url}/next` : `${url}/current`;
return this.http.get<Question>(url);
}

getQuestions(startRow: number, pageSize: number, criteria: SearchCriteria): Observable<SearchResults> {
const url: string = CONFIG.functionsUrl + '/app/question/';
const url = `${CONFIG.functionsUrl}/question/`;

return this.http.post<SearchResults>(url + startRow + '/' + pageSize, criteria);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class SocialService {
}

getTotalSubscription(): Observable<Subscribers> {
const url: string = CONFIG.functionsUrl + '/app/subscription/count';
const url = `${CONFIG.functionsUrl}/subscription/count`;
return this.http.get<Subscribers>(url);
}

Expand Down
14 changes: 7 additions & 7 deletions projects/shared-library/src/lib/core/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class UserService {
}

saveUserProfile(user: User): Observable<any> {
const url = `${CONFIG.functionsUrl}/app/user/profile`;
const url = `${CONFIG.functionsUrl}/user/profile`;
user.roles = (!user.roles) ? {} : user.roles;
const dbUser = Object.assign({}, user); // object to be saved
delete dbUser.authState;
Expand All @@ -58,12 +58,12 @@ export class UserService {


loadOtherUserProfile(userId: string): Observable<User> {
const url = `${CONFIG.functionsUrl}/app/user/${userId}`;
const url = `${CONFIG.functionsUrl}/user/${userId}`;
return this.http.get<User>(url);
}

loadOtherUserProfileWithExtendedInfo(userId: string): Observable<User> {
const url = `${CONFIG.functionsUrl}/app/user/extendedInfo/${userId}`;
const url = `${CONFIG.functionsUrl}/user/extendedInfo/${userId}`;
return this.http.get<User>(url);
}

Expand All @@ -83,12 +83,12 @@ export class UserService {
}

saveUserInvitations(obj: any): Observable<string> {
const url = `${CONFIG.functionsUrl}/app/friend/invitation`;
const url = `${CONFIG.functionsUrl}/friend/invitation`;
return this.http.post<any>(url, obj);
}

checkInvitationToken(obj: any): Observable<any> {
const url = `${CONFIG.functionsUrl}/app/friend`;
const url = `${CONFIG.functionsUrl}/friend`;
return this.http.post<any>(url, obj);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ export class UserService {
}

rejectGameInvitation(gameId: string) {
return this.http.put(`${CONFIG.functionsUrl}/app/game/${gameId}`,
return this.http.put(`${CONFIG.functionsUrl}/game/${gameId}`,
{
operation: GameOperations.REJECT_GAME
});
Expand All @@ -157,7 +157,7 @@ export class UserService {
}

addUserLives(userId: string) {
const url = `${CONFIG.functionsUrl}/app/user/update-lives`;
const url = `${CONFIG.functionsUrl}/user/update-lives`;
return this.http.post<any>(url, { userId: userId });
}
}
2 changes: 1 addition & 1 deletion projects/shared-library/src/lib/core/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Utils {
getImageUrl(user: User, width: Number, height: Number, size: string) {

if (user && user.profilePicture && user.profilePicture !== '') {
return `${CONFIG.functionsUrl}/app/user/profile/${user.userId}/${user.profilePicture}/${width}/${height}`;
return `${CONFIG.functionsUrl}/user/profile/${user.userId}/${user.profilePicture}/${width}/${height}`;
} else {
if (isPlatformBrowser(this.platformId) === false && isPlatformServer(this.platformId) === false) {
return `~/assets/images/avatar-${size}.png`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
import { IConfig } from './iconfig';
import { appConstants } from 'shared-library/shared/model';

export const environment = {
production: true
Expand All @@ -15,5 +16,5 @@ export const CONFIG: IConfig = {
storageBucket: 'rwa-trivia-dev-e57fc.appspot.com',
messagingSenderId: '701588063269'
},
'functionsUrl': 'https://rwa-trivia-dev-e57fc.firebaseapp.com'
'functionsUrl': `https://rwa-trivia-dev-e57fc.firebaseapp.com/${appConstants.API_VERSION}`
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IConfig } from './iconfig';
import { appConstants } from 'shared-library/shared/model';
export const environment = {
production: true
};
Expand All @@ -12,5 +13,5 @@ export const CONFIG: IConfig = {
storageBucket: 'rwa-trivia.appspot.com',
messagingSenderId: '479350787602'
},
'functionsUrl': 'https://bitwiser.io'
'functionsUrl': `https://bitwiser.io/${appConstants.API_VERSION}`
};
3 changes: 2 additions & 1 deletion projects/shared-library/src/lib/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
import { IConfig } from './iconfig';
import { appConstants } from 'shared-library/shared/model';

export const environment = {
production: false
Expand All @@ -15,5 +16,5 @@ export const CONFIG: IConfig = {
storageBucket: 'rwa-trivia-dev-e57fc.appspot.com',
messagingSenderId: '701588063269'
},
'functionsUrl': 'https://rwa-trivia-dev-e57fc.firebaseapp.com'
'functionsUrl': `https://rwa-trivia-dev-e57fc.firebaseapp.com/${appConstants.API_VERSION}`
};
3 changes: 2 additions & 1 deletion projects/shared-library/src/lib/shared/model/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export enum UserControllerConstants {
}

export enum appConstants {
API_PREFIX = 'app'
API_PREFIX = 'app',
API_VERSION = 'v1'
}

export enum interceptorConstants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { gamePlayState } from '../../store';
import { GameOver } from './game-over';
import { ReportGameComponent } from './../report-game/report-game.component';
import { Image } from "tns-core-modules/ui/image";
import { appConstants } from 'shared-library/shared/model';

@Component({
selector: 'game-over',
Expand Down Expand Up @@ -49,7 +50,7 @@ export class GameOverComponent extends GameOver implements OnInit, OnDestroy {
if (uploadTask.task.snapshot.state === 'success') {
const path = uploadTask.task.snapshot.metadata.fullPath.split('/');
// tslint:disable-next-line:max-line-length
const url = `https://${this.windowRef.nativeWindow.location.hostname}/app/game/social/${this.user.userId}/${path[path.length - 1]}`;
const url = `https://${this.windowRef.nativeWindow.location.hostname}/${appConstants.API_VERSION}/game/social/${this.user.userId}/${path[path.length - 1]}`;
this.socialFeedData.share_status = true;
this.socialFeedData.link = url;
this.loaderStatus = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AppState, appState } from '../../../store';
import { gamePlayState } from '../../store';
import { ReportGameComponent } from '../report-game/report-game.component';
import { GameOver } from './game-over';
import { appConstants } from 'shared-library/shared/model';

@Component({
selector: 'game-over',
Expand Down Expand Up @@ -63,7 +64,7 @@ export class GameOverComponent extends GameOver implements OnInit, OnDestroy {
if (uploadTask.task.snapshot.state === 'success') {
const path = uploadTask.task.snapshot.metadata.fullPath.split('/');
// tslint:disable-next-line:max-line-length
const url = `https://${this.windowRef.nativeWindow.location.hostname}/app/game/social/${this.user.userId}/${path[path.length - 1]}`;
const url = `https://${this.windowRef.nativeWindow.location.hostname}/${appConstants.API_VERSION}/game/social/${this.user.userId}/${path[path.length - 1]}`;
this.socialFeedData.share_status = true;
this.socialFeedData.link = url;
this.loaderStatus = false;
Expand Down
4 changes: 2 additions & 2 deletions scheduler/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export enum schedulerConstants {
port = 443,
devFunctionsAppName = 'rwa-trivia-dev-e57fc',
prodFunctionsAppName = 'rwa-trivia',
gameOverApiPath = '/app/scheduler/game-over/scheduler',
turnChangeApiPath = '/app/scheduler/turn/scheduler',
gameOverApiPath = 'scheduler/game-over/scheduler',
turnChangeApiPath = 'scheduler/turn/scheduler',
prod = 'prod',
authToken = '1234567'
}
5 changes: 3 additions & 2 deletions scheduler/schedulers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { schedulerConstants } from './constants';
import { appConstants } from 'shared-library/shared/model';

const cron = require('node-cron');
const https = require('https');
Expand All @@ -16,7 +17,7 @@ export class GameScheduler {
host: `${schedulerConstants.domainZone}-${envAppName}${schedulerConstants.extensionName}`,
port: schedulerConstants.port,
method: 'POST',
path: schedulerConstants.gameOverApiPath,
path: `/${appConstants.API_VERSION}/${schedulerConstants.gameOverApiPath}`,
headers: {
'token': token
}
Expand Down Expand Up @@ -54,7 +55,7 @@ export class GameScheduler {
host: `${schedulerConstants.domainZone}-${envAppName}${schedulerConstants.extensionName}`,
port: schedulerConstants.port,
method: 'POST',
path: schedulerConstants.turnChangeApiPath,
path: `/${appConstants.API_VERSION}/${schedulerConstants.turnChangeApiPath}`,
headers: {
'token': token
}
Expand Down

0 comments on commit 7fb9c25

Please sign in to comment.