The API that we want to create is
- create meeting
- add participant
- check cards
- see result meeting(
Those API’s were simpler for the console application,because of the single participant involved.
There are also some technical problems and some architectural ones.
Let’s start with technical: nestjs suggest ( as per sample project with contacts) to add a route like:
@Put(':id/addParticipant') async addParticipant(@Param('id') id: any,@Body() nameParticipant: string): Promise<Meeting> { // console.log(`userName : ${JSON.stringify(cm.userName)} meetingName: ${JSON.stringify(cm.meetingName)}`); return this.meetingsService.AddParticipant(id,nameParticipant); }
However,this is not available to be tested via Swagger – so we modify to
export class AddParticipant { @ApiModelProperty() meetingId: any; @ApiModelProperty() nameParticipant: string; } //CODE OF THE CONTROLLER OMITTED @Put('addParticipant') async addParticipant(@Body() addParticipant: AddParticipant): Promise<Meeting> { // console.log(`userName : ${JSON.stringify(cm.userName)} meetingName: ${JSON.stringify(cm.meetingName)}`); return this.meetingsService.AddParticipant(addParticipant.meetingId,addParticipant.nameParticipant); }
Also,when we handle in the meeting service the CheckCard we discover to be missing something for the original DDD model . For example,we need a FindCard and FindParticipantAfterName .
public checkCard(idMeeting: any,idCard: number,nameParticipant:string ): Meeting{ const m = this.meetings.find(it => it.Id === idMeeting ); // TODO: throw if meeting is null const c = m.FindCard(idCard); // TODO: throw if card is null const p = m.FindParticipantAfterName(nameParticipant); // TODO: throw if participant is null m.CheckCardByParticipant(c,p); return m; }
For the architectural ones:
- The service that we just created should be tested and put into the right project. It could belong to the bingo-meeting-objects.
- The controller has some classes that should be tested. However,the classes involving in the @Body have swagger attributes,so they cannot be moved into bingo-meeting-objects .
export class AddParticipant { //bingo-meeting-objects should not have reference to swagger properties @ApiModelProperty() meetingId: any; @ApiModelProperty() nameParticipant: string; }
Download the actual code from https://github.com/alexandru360/PresentationBingoCards/releases/tag/api_final
Leave a Reply