From 807393ee8f9851507d6f51ec2fb380a104b7df01 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Fri, 3 Mar 2023 14:10:24 +0100 Subject: [PATCH] all route --- README.md | 27 +++++++++++++---------- back/volume/src/users/users.controller.ts | 10 +++++++-- back/volume/src/users/users.service.ts | 10 ++++++--- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4d27c9d..923c56a 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,22 @@ If you not use rootless docker, either rename Makesudo as Makefile or call `make rename .env_sample to .env and customize it to your needs and credentials. ## Back endpoints: -|Method|endpoint|description| +|Method|endpoint|description|account securised?| |:---:|:---:|:---:| -|GET |/log/in |the login using 42 api.| -|GET |/log/inReturn |the 42 api callback.| -|GET |/log/profile |get user 42's datas.| -|GET |/log/out |log out user.| -|GET |/ |return user datas.| -|POST|/ |update user datas.| -|GET |/friends |return users which are friends.| -|GET |/invits |return users which invited user to be friend.| -|POST|/invit/:id |invit user whith ftId: id as friend.| -|GET |/avatar |return the user avatar| -|POST|/avatar |set a user avatar with multipart post upload.| +|GET |/log/in |the login using 42 api.|☑| +|GET |/log/inReturn |the 42 api callback.|☑| +|GET |/log/profile |get connected user 42's datas.|☑| +|GET |/log/out |log out user.|☑| +|GET |/all |return all users publics datas.|☒| +|GET |/online |return all online users's public datas.|☒| +|GET |/:id |return ftId: id's public datas|☒| +|GET |/ |return connected user public datas|☑| +|POST|/ |update user datas.|☑| +|GET |/friends |return users which are friends.|☑| +|GET |/invits |return users which invited user to be friend.|☑| +|POST|/invit/:id |invit user whith ftId: id as friend.|☑| +|GET |/avatar |return the user avatar|☒| +|POST|/avatar |set a user avatar with multipart post upload.|☑| ## Dependencies: diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index 9249c87..ba6c3df 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -33,7 +33,7 @@ import { join } from 'path' export class UsersController { constructor (private readonly usersService: UsersService) {} - @Get() + @Get('all') async getAllUsers (): Promise { return await this.usersService.findUsers() } @@ -44,10 +44,16 @@ export class UsersController { } @Get(':id') - async getUser (@Param('id', ParseIntPipe) ftId: number): Promise { + async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise { return await this.usersService.findUser(ftId) } + @Get() + @UseGuards(AuthenticatedGuard) + async getUser (@FtUser() profile: Profile): Promise { + return await this.usersService.findUser(profile.id) + } + @Post() @UseGuards(AuthenticatedGuard) async create (@Body() payload: UserDto, @FtUser() profile: Profile) { diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index a538bee..379466e 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -20,7 +20,11 @@ export class UsersService { } async findUser (ftId: number): Promise { - return await this.usersRepository.findOneBy({ftId}) + return await this.usersRepository.findOneBy({ ftId }) + } + + async findOnlineUsers (): Promise { + return await this.usersRepository.find({ where: { status: 'online' } }) } async create (userData: UserDto) { @@ -56,7 +60,7 @@ export class UsersService { const user = await this.usersRepository.findOne({ where: { ftId }, relations: { - friends: true, + friends: true } }) return user.friends @@ -66,7 +70,7 @@ export class UsersService { const user = await this.usersRepository.findOne({ where: { ftId }, relations: { - followers: true, + followers: true } }) return user.followers