Skip to content

Commit

Permalink
Merge pull request #13261 from youngkiu/sample/synchronize-pluralisat…
Browse files Browse the repository at this point in the history
…ion-docs

sample(04-grpc): synchronize pluralisation docs
  • Loading branch information
kamilmysliwiec authored Feb 27, 2024
2 parents 0539f90 + cad84c6 commit 7fa81fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions sample/04-grpc/src/hero/hero.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { toArray } from 'rxjs/operators';
import { HeroById } from './interfaces/hero-by-id.interface';
import { Hero } from './interfaces/hero.interface';

interface HeroService {
interface HeroesService {
findOne(data: HeroById): Observable<Hero>;
findMany(upstream: Observable<HeroById>): Observable<Hero>;
}
Expand All @@ -20,12 +20,12 @@ export class HeroController implements OnModuleInit {
{ id: 1, name: 'John' },
{ id: 2, name: 'Doe' },
];
private heroService: HeroService;
private heroesService: HeroesService;

constructor(@Inject('HERO_PACKAGE') private readonly client: ClientGrpc) {}

onModuleInit() {
this.heroService = this.client.getService<HeroService>('HeroService');
this.heroesService = this.client.getService<HeroesService>('HeroesService');
}

@Get()
Expand All @@ -35,21 +35,21 @@ export class HeroController implements OnModuleInit {
ids$.next({ id: 2 });
ids$.complete();

const stream = this.heroService.findMany(ids$.asObservable());
const stream = this.heroesService.findMany(ids$.asObservable());
return stream.pipe(toArray());
}

@Get(':id')
getById(@Param('id') id: string): Observable<Hero> {
return this.heroService.findOne({ id: +id });
return this.heroesService.findOne({ id: +id });
}

@GrpcMethod('HeroService')
@GrpcMethod('HeroesService')
findOne(data: HeroById): Hero {
return this.items.find(({ id }) => id === data.id);
}

@GrpcStreamMethod('HeroService')
@GrpcStreamMethod('HeroesService')
findMany(data$: Observable<HeroById>): Observable<Hero> {
const hero$ = new Subject<Hero>();

Expand Down
4 changes: 2 additions & 2 deletions sample/04-grpc/src/hero/hero.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package hero;

service HeroService {
service HeroesService {
rpc FindOne (HeroById) returns (Hero);
rpc FindMany (stream HeroById) returns (stream Hero);
}
Expand All @@ -14,4 +14,4 @@ message HeroById {
message Hero {
int32 id = 1;
string name = 2;
}
}

0 comments on commit 7fa81fe

Please sign in to comment.