From 35ce9cced6b13106e112ceb3316fe67b163b6950 Mon Sep 17 00:00:00 2001 From: BatuhanIlhan Date: Sat, 23 Dec 2023 13:28:57 +0300 Subject: [PATCH] be-619/Add general tag rankings --- app/backend/src/ranking/ranking.controller.ts | 15 +++++++++++---- app/backend/src/ranking/ranking.module.ts | 3 ++- app/backend/src/ranking/ranking.service.ts | 14 +++++--------- app/backend/src/user/user.service.ts | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/backend/src/ranking/ranking.controller.ts b/app/backend/src/ranking/ranking.controller.ts index b20876dd..17a378f8 100644 --- a/app/backend/src/ranking/ranking.controller.ts +++ b/app/backend/src/ranking/ranking.controller.ts @@ -1,6 +1,7 @@ import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; import { RankingService } from './ranking.service'; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { IsUUID } from 'class-validator'; @ApiBearerAuth() @Controller('ranking') @@ -8,9 +9,15 @@ import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; export class RankingController { constructor(private readonly rankingService: RankingService) {} - @Get(':id') - findAll(@Param("id") id : string) { - return this.rankingService.findAll(id); + @Get(':name') + @ApiResponse({ status: 200, description: 'Ranking is fetched successfully.' }) + @ApiResponse({ status: 404, description: 'Ranking is not found.' }) + @ApiResponse({ + status: 500, + description: 'Internal server error, contact with backend team.', + }) + findAll(@Param("name") name : string) { + return this.rankingService.findAll(name); } diff --git a/app/backend/src/ranking/ranking.module.ts b/app/backend/src/ranking/ranking.module.ts index 7eff38b4..7c2120d3 100644 --- a/app/backend/src/ranking/ranking.module.ts +++ b/app/backend/src/ranking/ranking.module.ts @@ -10,13 +10,14 @@ import { Badge } from '../badge/entities/badge.entity'; import { Option } from '../option/entities/option.entity'; import { OptionService } from '../option/option.service'; import { Poll } from '../poll/entities/poll.entity'; +import { Tag } from '../tag/entities/tag.entity'; @Module({ imports: [ TypeOrmModule.forFeature([Ranking,Vote, Option, User, - Badge,Poll]) + Badge,Poll,Tag]) ], controllers: [RankingController], providers: [RankingService,VoteService,OptionService], diff --git a/app/backend/src/ranking/ranking.service.ts b/app/backend/src/ranking/ranking.service.ts index 25b75cab..d2d929ed 100644 --- a/app/backend/src/ranking/ranking.service.ts +++ b/app/backend/src/ranking/ranking.service.ts @@ -1,13 +1,11 @@ import { Injectable } from '@nestjs/common'; -import { CreateRankingDto } from './dto/create-ranking.dto'; -import { UpdateRankingDto } from './dto/update-ranking.dto'; import { Poll } from '../poll/entities/poll.entity'; import { Option } from '../option/entities/option.entity'; import { InjectRepository } from '@nestjs/typeorm'; import { Ranking } from './entities/ranking.entity'; import { Repository } from 'typeorm'; -import { User } from '../user/entities/user.entity'; import { Vote } from '../vote/entities/vote.entity'; +import { Tag } from '../tag/entities/tag.entity'; @Injectable() export class RankingService { @@ -16,11 +14,8 @@ export class RankingService { private readonly rankingRepository: Repository, @InjectRepository(Vote) private readonly voteRepository: Repository, - @InjectRepository(User) - private readonly userRepository: Repository, - @InjectRepository(Poll) - private readonly pollRepository: Repository, - + @InjectRepository(Tag) + private readonly tagRepository: Repository, ){} @@ -46,12 +41,13 @@ export class RankingService { relations:["user"], where:{ option:{ - id:"334483e2-4b39-4c10-896d-47cb1ba1c1e9" + id:option.id } } } ) const userIds: string[] = votes.map((vote) => vote.user.id); + poll.tags.push(await this.tagRepository.findOne({where:{name:"general"}})); poll.tags.forEach( async (tag) => {this.updateScoreByTag(tag.id,userIds)}); diff --git a/app/backend/src/user/user.service.ts b/app/backend/src/user/user.service.ts index 2ba9e8c6..275036cc 100644 --- a/app/backend/src/user/user.service.ts +++ b/app/backend/src/user/user.service.ts @@ -259,7 +259,7 @@ export class UserService { 'isBanned', 'rankings', ], - }); + })}; public async searchUsernames(query: string): Promise { return this.userRepository