Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/warcraft api #99

Merged
merged 18 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion apps/azkaban-gateway/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { MobileModule } from './mobile/mobile.module';
import { CachingModule } from './core/caching.module';
import { TwitchModule } from './twitch/twitch.module';
import { WarcraftModule } from './warcraft/warcraft.module';
import { AuthServiceModule } from './core/auth-service.module';
import { ApiAlertsServiceModule } from './core/apialerts-service.module';
import { CronjobModule } from './cronjobs/cronjob.module';
import { CronjobServiceModule } from './core/cronjob-service.module';

@Module({
imports: [
Expand All @@ -34,7 +38,11 @@ import { WarcraftModule } from './warcraft/warcraft.module';
limit: 10,
},
]),
//
// RabbitMQ Modules
AuthServiceModule,
ApiAlertsServiceModule,
CronjobServiceModule,
// Azkaban Services
CachingModule,
HealthModule,
MetricsModule,
Expand All @@ -46,6 +54,7 @@ import { WarcraftModule } from './warcraft/warcraft.module';
MobileModule,
TwitchModule,
WarcraftModule,
CronjobModule,
],
})
export class AppModule {}
3 changes: 1 addition & 2 deletions apps/azkaban-gateway/src/app/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { AuthGuard } from '../../guards';
import { JwtModule } from '@nestjs/jwt';
import { AuthServiceModule } from '../core/auth-service.module';

@Module({
imports: [JwtModule, AuthServiceModule],
imports: [JwtModule],
controllers: [AuthController],
providers: [AuthGuard, AuthService],
})
Expand Down
22 changes: 9 additions & 13 deletions apps/azkaban-gateway/src/app/core/apialerts-service.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { Module } from '@nestjs/common';
import { ClientsModule } from '@nestjs/microservices';
import {
azkaban_notify_apialerts,
azkaban_vhost,
clientProvider,
} from '@toxictoast/azkaban-broker-rabbitmq';
import { brokerDefaultSettings } from './broker-defaults';
import { RabbitmqModule } from '../../modules';

@Module({
imports: [
ClientsModule.register([
{
name: 'APIALERTS_SERVICE',
...clientProvider({
queueName: azkaban_notify_apialerts,
brokerVHost: azkaban_vhost,
...brokerDefaultSettings,
}),
},
]),
RabbitmqModule.forRoot({
name: 'APIALERTS_SERVICE',
queueName: azkaban_notify_apialerts,
brokerVHost: azkaban_vhost,
...brokerDefaultSettings,
global: true,
}),
],
exports: [ClientsModule],
exports: [RabbitmqModule],
})
export class ApiAlertsServiceModule {}
22 changes: 9 additions & 13 deletions apps/azkaban-gateway/src/app/core/auth-service.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { Module } from '@nestjs/common';
import { ClientsModule } from '@nestjs/microservices';
import {
azkaban_auth,
azkaban_vhost,
clientProvider,
} from '@toxictoast/azkaban-broker-rabbitmq';
import { brokerDefaultSettings } from './broker-defaults';
import { RabbitmqModule } from '../../modules';

@Module({
imports: [
ClientsModule.register([
{
name: 'AUTH_SERVICE',
...clientProvider({
queueName: azkaban_auth,
brokerVHost: azkaban_vhost,
...brokerDefaultSettings,
}),
},
]),
RabbitmqModule.forRoot({
name: 'AUTH_SERVICE',
queueName: azkaban_auth,
brokerVHost: azkaban_vhost,
...brokerDefaultSettings,
global: true,
}),
],
exports: [ClientsModule],
exports: [RabbitmqModule],
})
export class AuthServiceModule {}
22 changes: 9 additions & 13 deletions apps/azkaban-gateway/src/app/core/cronjob-service.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { Module } from '@nestjs/common';
import { ClientsModule } from '@nestjs/microservices';
import {
azkaban_cronjob,
azkaban_vhost,
clientProvider,
} from '@toxictoast/azkaban-broker-rabbitmq';
import { brokerDefaultSettings } from './broker-defaults';
import { RabbitmqModule } from '../../modules';

@Module({
imports: [
ClientsModule.register([
{
name: 'CRONJOB_SERVICE',
...clientProvider({
queueName: azkaban_cronjob,
brokerVHost: azkaban_vhost,
...brokerDefaultSettings,
}),
},
]),
RabbitmqModule.forRoot({
name: 'CRONJOB_SERVICE',
queueName: azkaban_cronjob,
brokerVHost: azkaban_vhost,
...brokerDefaultSettings,
global: true,
}),
],
exports: [ClientsModule],
exports: [RabbitmqModule],
})
export class CronjobServiceModule {}
25 changes: 25 additions & 0 deletions apps/azkaban-gateway/src/app/core/warcraft-api-service.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Module } from '@nestjs/common';
import { ClientsModule } from '@nestjs/microservices';
import {
clientProvider,
warcraft_api,
warcraft_vhost,
} from '@toxictoast/azkaban-broker-rabbitmq';
import { brokerDefaultSettings } from './broker-defaults';

@Module({
imports: [
ClientsModule.register([
{
name: 'WARCRAFT_API_SERVICE',
...clientProvider({
queueName: warcraft_api,
brokerVHost: warcraft_vhost,
...brokerDefaultSettings,
}),
},
]),
],
exports: [ClientsModule],
})
export class WarcraftApiServiceModule {}
26 changes: 26 additions & 0 deletions apps/azkaban-gateway/src/app/cronjobs/cronjob.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller, Post, UseGuards } from '@nestjs/common';
import { Groups } from '../../decorators';
import { UserGroups } from '@toxictoast/azkaban-base-helpers';
import { ApiTags } from '@nestjs/swagger';
import { ThrottlerGuard } from '@nestjs/throttler';
import { AuthGuard, GroupsGuard } from '../../guards';
import { CronjobService } from './cronjob.service';

@ApiTags('cronjobs')
@UseGuards(ThrottlerGuard, AuthGuard, GroupsGuard)
@Controller('cronjob')
export class CronjobController {
constructor(private readonly service: CronjobService) {}

@Groups(UserGroups.WARCRAFT_ADMIN, UserGroups.ADMIN)
@Post('warcraft')
async warcraftCronjob(): Promise<void> {
await this.service.warcraftCronjob();
}

@Groups(UserGroups.TWITCH_ADMIN, UserGroups.ADMIN)
@Post('viewer')
async viewerCronjob(): Promise<void> {
await this.service.viewerCronjob();
}
}
11 changes: 11 additions & 0 deletions apps/azkaban-gateway/src/app/cronjobs/cronjob.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { AuthGuard } from '../../guards';
import { JwtModule } from '@nestjs/jwt';
import { CronjobController } from './cronjob.controller';
import { CronjobService } from './cronjob.service';
@Module({
imports: [JwtModule],
controllers: [CronjobController],
providers: [AuthGuard, CronjobService],
})
export class CronjobModule {}
24 changes: 24 additions & 0 deletions apps/azkaban-gateway/src/app/cronjobs/cronjob.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Inject, Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import {
CronjobTopics,
RmqRecordBuilderHelper,
} from '@toxictoast/azkaban-broker-rabbitmq';

@Injectable()
export class CronjobService {
constructor(
@Inject('CRONJOB_SERVICE')
private readonly client: ClientProxy,
) {}

async warcraftCronjob(): Promise<void> {
const payload = RmqRecordBuilderHelper({});
await this.client.emit(CronjobTopics.WARCRAFT, payload).toPromise();
}

async viewerCronjob(): Promise<void> {
const payload = RmqRecordBuilderHelper({});
await this.client.emit(CronjobTopics.VIEWER, payload).toPromise();
}
}
7 changes: 2 additions & 5 deletions apps/azkaban-gateway/src/app/version/version.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { FoodfolioWarehouseServiceModule } from '../core/foodfolio-warehouse-ser
import { FoodfolioShoppingListServiceModule } from '../core/foodfolio-shopping-list-service.module';
import { WebhookServiceModule } from '../core/webhook-service.module';
import { SSEServiceModule } from '../core/sse-service.module';
import { ApiAlertsServiceModule } from '../core/apialerts-service.module';
import { CronjobServiceModule } from '../core/cronjob-service.module';
import { NotificationsServiceModule } from '../core/notifications-service.module';
import { FoodfolioVersionsService } from './foodfolio-versions.service';
import { NotifyVersionsService } from './notify-versions.service';
Expand All @@ -31,15 +29,14 @@ import { TwitchMessageServiceModule } from '../core/twitch-message-service.modul
import { CachingModule } from '../core/caching.module';
import { WarcraftCharacterServiceModule } from '../core/warcraft-character-service.module';
import { WarcraftVersionsService } from './warcraft-versions.service';

import { WarcraftApiServiceModule } from '../core/warcraft-api-service.module';
@Module({
imports: [
CachingModule,
// Azkaban Services
UserServiceModule,
AuthServiceModule,
GroupsServiceModule,
CronjobServiceModule,
// Foodfolio Services
FoodfolioCategoryServiceModule,
FoodfolioCompanyServiceModule,
Expand All @@ -54,7 +51,6 @@ import { WarcraftVersionsService } from './warcraft-versions.service';
// Notification Services
WebhookServiceModule,
SSEServiceModule,
ApiAlertsServiceModule,
NotifyServiceModule,
NotificationsServiceModule,
// Twitch Services
Expand All @@ -63,6 +59,7 @@ import { WarcraftVersionsService } from './warcraft-versions.service';
TwitchMessageServiceModule,
// Warcraft Services
WarcraftCharacterServiceModule,
WarcraftApiServiceModule,
],
controllers: [VersionController],
providers: [
Expand Down
12 changes: 12 additions & 0 deletions apps/azkaban-gateway/src/app/version/warcraft-versions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import {
RmqRecordBuilderHelper,
WarcraftApiTopics,
WarcraftCharacterTopics,
} from '@toxictoast/azkaban-broker-rabbitmq';

Expand All @@ -10,6 +11,8 @@ export class WarcraftVersionsService {
constructor(
@Inject('WARCRAFT_CHARACTER_SERVICE')
private readonly charactersClient: ClientProxy,
@Inject('WARCRAFT_API_SERVICE')
private readonly apiClient: ClientProxy,
) {}

private async getCharactersVersion() {
Expand All @@ -19,11 +22,20 @@ export class WarcraftVersionsService {
.toPromise();
}

private async getApiVersion() {
const payload = RmqRecordBuilderHelper({});
return await this.apiClient
.send(WarcraftApiTopics.VERSION, payload)
.toPromise();
}

async getWarcraftVersions() {
const character = await this.getCharactersVersion();
const api = await this.getApiVersion();
//
return {
character,
api,
};
}
}
Loading