Skip to content

Commit

Permalink
Merge pull request #785 from bounswe/feature/770/BE/username-id-endpoint
Browse files Browse the repository at this point in the history
getUserIdByUsername
  • Loading branch information
omersafakbebek authored Dec 23, 2023
2 parents 5169999 + d97b585 commit 5827dad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ludos/backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ export class UserController {
);
return suggestedGames;
}

@ApiOperation({ summary: 'Get User Id By Username' })
@ApiNotFoundResponse({ description: 'User is not found!' })
@Get('/:username')
public async getUserIdByUsername(@Param('userId') username: string) {
return await this.userService.getUserIdByUsername(username);
}

}
12 changes: 12 additions & 0 deletions ludos/backend/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,16 @@ export class UserService {

return suggestedGamesResponse;
}

public async getUserIdByUsername(username: string): Promise<string | null> {
const user = await this.userRepository.findUserByUsername(username);

if (user) {
return user.id;
}

return null;
}


}

0 comments on commit 5827dad

Please sign in to comment.