Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
feat: add numPost to characters/corporations/alliances
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed Jul 31, 2018
1 parent b38685b commit 2b5aea5
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/modules/alliance/alliance.controller.ts
Expand Up @@ -3,6 +3,7 @@ import { AllianceService } from './alliance.service';
import { DAlliance } from './alliance.dto';
import { ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { FollowService } from '../follow/follow.service';
import { PostService } from '../post/post.service';

@ApiUseTags('alliances')
@Controller('alliances')
Expand All @@ -11,6 +12,7 @@ export class AllianceController {
constructor(
private allianceService: AllianceService,
private followService: FollowService,
private postService: PostService,
) {
}

Expand All @@ -25,7 +27,9 @@ export class AllianceController {
): Promise<DAlliance> {
const alliance = await this.allianceService.get(allianceId);
const followers = await this.followService.getAllianceFollowers(alliance);
return new DAlliance(alliance, followers);
const numPosts = await this.postService.getNumOfPostsByAlliance(alliance);

return new DAlliance(alliance, followers, numPosts);
}

}
5 changes: 4 additions & 1 deletion src/modules/alliance/alliance.dto.ts
Expand Up @@ -59,6 +59,8 @@ export class DAlliance {
icon: DAllianceIcon;
@ApiModelProperty()
followers: DFollow[];
@ApiModelProperty()
numPosts: number;

/* LIVE Data */
@ApiModelProperty()
Expand All @@ -84,7 +86,7 @@ export class DAlliance {
@ApiModelProperty()
corpCount: number;

constructor(alliance: Alliance, followers: Follow[]) {
constructor(alliance: Alliance, followers: Follow[], numPosts: number) {
this.id = alliance.id;
this.name = alliance.name;
this.handle = alliance.handle;
Expand All @@ -93,6 +95,7 @@ export class DAlliance {
this.executorCorporation = new DCorporationShortWithoutAlliance(alliance.executorCorporation);
this.icon = new DAllianceIcon(alliance.icon);
this.followers = followers.map(follow => new DFollow(follow));
this.numPosts = numPosts;

this.hasSupers = alliance.hasSupers;
this.iskDestroyed = alliance.iskDestroyed;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/alliance/alliance.module.ts
Expand Up @@ -7,6 +7,7 @@ import { CorporationModule } from '../corporation/corporation.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AllianceRepository } from './alliance.repository';
import { FollowModule } from '../follow/follow.module';
import { PostModule } from '../post/post.module';

@Module({
imports: [
Expand All @@ -16,6 +17,7 @@ import { FollowModule } from '../follow/follow.module';
ESIModule,
forwardRef(() => CorporationModule),
forwardRef(() => FollowModule),
forwardRef(() => PostModule),
],
controllers: [
AllianceController,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/authentication/authentication.controller.ts
Expand Up @@ -46,7 +46,7 @@ export class AuthenticationController {
const following = await this.followService.getCharacterFollowing(character);
const followers = await this.followService.getCharacterFollowers(character);

return new DCharacter(character, followers, following);
return new DCharacter(character, followers, following, 0);
}

@ApiResponse({
Expand Down
5 changes: 4 additions & 1 deletion src/modules/character/character.controller.ts
Expand Up @@ -3,6 +3,7 @@ import { CharacterService } from './character.service';
import { DCharacter } from './character.dto';
import { ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { FollowService } from '../follow/follow.service';
import { PostService } from '../post/post.service';

@ApiUseTags('characters')
@Controller('characters')
Expand All @@ -11,6 +12,7 @@ export class CharactersController {
constructor(
private characterService: CharacterService,
private followService: FollowService,
private postService: PostService,
) {
}

Expand All @@ -26,8 +28,9 @@ export class CharactersController {
const character = await this.characterService.get(characterId);
const followers = await this.followService.getCharacterFollowers(character);
const following = await this.followService.getCharacterFollowing(character);
const numPosts = await this.postService.getNumOfPostsByCharacter(character);

return new DCharacter(character, followers, following);
return new DCharacter(character, followers, following, numPosts);
}

}
5 changes: 4 additions & 1 deletion src/modules/character/character.dto.ts
Expand Up @@ -90,6 +90,8 @@ export class DCharacter {
followers: DFollow[];
@ApiModelProperty()
following: DFollow[];
@ApiModelProperty()
numPosts: number;

/* LIVE Data*/
@ApiModelProperty()
Expand All @@ -109,7 +111,7 @@ export class DCharacter {
@ApiModelProperty()
soloLosses: number;

constructor(character: Character, followers: Follow[], following: Follow[]) {
constructor(character: Character, followers: Follow[], following: Follow[], numPosts: number) {
this.id = character.id;
this.handle = character.handle;
this.name = character.name;
Expand All @@ -123,6 +125,7 @@ export class DCharacter {
this.corporation = new DCorporationShort(character.corporation);
this.followers = followers.map(follow => new DFollow(follow))
this.following = following.map(follow => new DFollow(follow))
this.numPosts = numPosts;

this.iskDestroyed = character.iskDestroyed;
this.iskLost = character.iskLost;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/character/character.module.ts
Expand Up @@ -7,6 +7,7 @@ import { CorporationModule } from '../corporation/corporation.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CharacterRepository } from './character.repository';
import { FollowModule } from '../follow/follow.module';
import { PostModule } from '../post/post.module';

@Module({
imports: [
Expand All @@ -16,6 +17,7 @@ import { FollowModule } from '../follow/follow.module';
ESIModule,
forwardRef(() => CorporationModule),
forwardRef(() => FollowModule),
forwardRef(() => PostModule),
],
controllers: [
CharactersController,
Expand Down
5 changes: 4 additions & 1 deletion src/modules/corporation/corporation.controller.ts
Expand Up @@ -3,6 +3,7 @@ import { CorporationService } from './corporation.service';
import { DCorporation } from './corporation.dto';
import { ApiResponse, ApiUseTags } from '@nestjs/swagger';
import { FollowService } from '../follow/follow.service';
import { PostService } from '../post/post.service';

@ApiUseTags('corporations')
@Controller('corporations')
Expand All @@ -11,6 +12,7 @@ export class CorporationController {
constructor(
private corporationService: CorporationService,
private followService: FollowService,
private postService: PostService,
) {
}

Expand All @@ -25,8 +27,9 @@ export class CorporationController {
): Promise<DCorporation> {
const corporation = await this.corporationService.get(corporationId);
const followers = await this.followService.getCorporationFollowers(corporation);
const numPosts = await this.postService.getNumOfPostsByCorporation(corporation);

return new DCorporation(corporation, followers);
return new DCorporation(corporation, followers, numPosts);
}

}
5 changes: 4 additions & 1 deletion src/modules/corporation/corporation.dto.ts
Expand Up @@ -89,6 +89,8 @@ export class DCorporation {
icon: DCorporationIcon;
@ApiModelProperty()
followers: DFollow[];
@ApiModelProperty()
numPosts: number;

/* LIVE Data*/
@ApiModelProperty()
Expand All @@ -108,7 +110,7 @@ export class DCorporation {
@ApiModelProperty()
soloLosses: number;

constructor(corporation: Corporation, followers: Follow[]) {
constructor(corporation: Corporation, followers: Follow[], numPosts: number) {
this.id = corporation.id;
this.handle = corporation.handle;
this.name = corporation.name;
Expand All @@ -117,6 +119,7 @@ export class DCorporation {
this.alliance = corporation.alliance ? new DAllianceShort(corporation.alliance) : null;
this.icon = new DCorporationIcon(corporation.icon);
this.followers = followers.map(follow => new DFollow(follow));
this.numPosts = numPosts;

this.iskDestroyed = corporation.iskDestroyed;
this.iskLost = corporation.iskLost;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/corporation/corporation.module.ts
Expand Up @@ -8,6 +8,7 @@ import { AllianceModule } from '../alliance/alliance.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CorporationRepository } from './corporation.repository';
import { FollowModule } from '../follow/follow.module';
import { PostModule } from '../post/post.module';

@Module({
imports: [
Expand All @@ -18,6 +19,7 @@ import { FollowModule } from '../follow/follow.module';
forwardRef(() => CharacterModule),
forwardRef(() => AllianceModule),
forwardRef(() => FollowModule),
forwardRef(() => PostModule),
],
controllers: [
CorporationController,
Expand Down
13 changes: 7 additions & 6 deletions src/modules/post/post.module.ts
@@ -1,4 +1,4 @@
import { Module, OnModuleInit } from '@nestjs/common';
import { Module, OnModuleInit, forwardRef } from '@nestjs/common';
import { PostController } from './post.controller';
import { PostService } from './post.service';
import { AuthenticationModule } from '../authentication/authentication.module';
Expand All @@ -25,14 +25,15 @@ import { WebsocketModule } from '../websocket/websocket.module';

// GooglePubSubModule.forFeature('test-topic', 'test-subscription'),

AuthenticationModule,
CharacterModule,
CorporationModule,
AllianceModule,
HashtagModule,
UniverseLocationModule,
HashtagModule,
NotificationModule,
WebsocketModule,

forwardRef(() => AuthenticationModule),
forwardRef(() => CharacterModule),
forwardRef(() => CorporationModule),
forwardRef(() => AllianceModule),
],
controllers: [
PostController,
Expand Down
18 changes: 18 additions & 0 deletions src/modules/post/post.repository.ts
Expand Up @@ -117,6 +117,24 @@ export class PostRepository extends Repository<Post> {
};
}

public getNumOfPostsByCharacter(
character: Character,
): Promise<number> {
return this.count({ where: { character } })
}

public getNumOfPostsByCorporation(
corporation: Corporation,
): Promise<number> {
return this.count({ where: { corporation } })
}

public getNumOfPostsByAlliance(
alliance: Alliance,
): Promise<number> {
return this.count({ where: { alliance } })
}

/**
* Wrapper for querying posts
* @param {number} limit
Expand Down
18 changes: 18 additions & 0 deletions src/modules/post/post.service.ts
Expand Up @@ -230,6 +230,24 @@ export class PostService {
return this.postRepository.getParticipants(post);
}

public async getNumOfPostsByCharacter(
character: Character,
): Promise<number> {
return this.postRepository.getNumOfPostsByCharacter(character);
}

public async getNumOfPostsByCorporation(
corporation: Corporation,
): Promise<number> {
return this.postRepository.getNumOfPostsByCorporation(corporation);
}

public async getNumOfPostsByAlliance(
alliance: Alliance,
): Promise<number> {
return this.postRepository.getNumOfPostsByAlliance(alliance);
}

/**
* Create post
* @param {Post} post
Expand Down

0 comments on commit 2b5aea5

Please sign in to comment.