Skip to content

Commit

Permalink
add recommend endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Nov 14, 2023
1 parent 02db2a7 commit b425fb6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/popo/introduce/club/intro.club.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UseGuards,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Between } from 'typeorm';
import { Between, Not } from 'typeorm';
import * as moment from 'moment';

import { IntroClubService } from './intro.club.service';
Expand Down Expand Up @@ -55,7 +55,20 @@ export class IntroClubController {
get() {
return this.introClubService.find({ order: { name: 'ASC' } });
}


@Get('recommend/:uuid')
async getRecommended(@Param('uuid') uuid: string) {
const club = await this.introClubService.findOneByUuid(uuid);

const clubType = club.clubType;
const clubs = await this.introClubService.find({
where: { clubType: clubType, uuid: Not(uuid) },
});

const shuffled = clubs.sort(() => 0.5 - Math.random());
return shuffled.slice(0, 3);
}

@Get('today')
getTodayVisited() {
return this.introClubService.find({
Expand Down Expand Up @@ -87,7 +100,7 @@ export class IntroClubController {
throw new BadRequestException('Not Exist');
}
}

@Get(':uuid')
getOneByUuid(@Param('uuid') uuid: string) {
return this.introClubService.findOneByUuid(uuid);
Expand Down

0 comments on commit b425fb6

Please sign in to comment.