Skip to content

Commit

Permalink
Merge pull request #46 from donghquinn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
donghquinn authored Feb 17, 2024
2 parents d270c7d + 556d9f8 commit 7c2a9ba
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/controllers/geek/geek.ctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export class GeekController {
constructor(private readonly geek: GeekProvider) {}

@Post('/news')
async getHadaNews(@Body() request: DailyHadaNewsRequest) {
async getHadaNews(@Body() request: DailyHadaNewsRequest, @Query('page') page: number, @Query('size') size: number) {
try {
const { today } = await hadaNewsValidator(request);

const result = await this.geek.getNews(today);
const result = await this.geek.getNews(today, page, size);

return new SetResponse(200, { result });
} catch (error) {
Expand Down
10 changes: 7 additions & 3 deletions src/controllers/hacker/hacker.ctl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Post, Headers, Query } from '@nestjs/common';
import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common';
import { hackerNewsStarValidator, hackerNewsValidator } from '@validators/hacker.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { HackersNewsProvider } from 'providers/news/hacker/hacker.pvd';
Expand All @@ -21,11 +21,15 @@ export class HackerController {
}

@Post('/news')
async getHackerNews(@Body() request: DailyHackerNewsRequest) {
async getHackerNews(
@Body() request: DailyHackerNewsRequest,
@Query('page') page: number,
@Query('size') size: number,
) {
try {
const { today } = await hackerNewsValidator(request);

const result = await this.hacker.bringTodayHackerPosts(today);
const result = await this.hacker.bringTodayHackerPosts(today, page, size);

return new SetResponse(200, { result });
} catch (error) {
Expand Down
14 changes: 9 additions & 5 deletions src/controllers/machine/machine.ctl.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { MachineLearningProvider } from 'providers/news/ml/machine.pvd';
import { Body, Controller, Get, Post, Headers, Query } from '@nestjs/common';
import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common';
import { machineLearningValidator, mlNewsStarValidator } from '@validators/ml.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { StarRequest } from 'types/request.type';
import { MachineLearningProvider } from 'providers/news/ml/machine.pvd';
import { DailyMlNewsRequest } from 'types/ml.type';
import { StarRequest } from 'types/request.type';

@Controller('ml')
export class MachineLearningController {
constructor(private readonly mlNews: MachineLearningProvider) {}

@Post('/latest')
async getLatestMlNewsController(@Body() request: DailyMlNewsRequest) {
async getLatestMlNewsController(
@Body() request: DailyMlNewsRequest,
@Query('page') page: number,
@Query('size') size: number,
) {
try {
const { today } = await machineLearningValidator(request);

const result = await this.mlNews.bringLatestMachineLearningNews(today);
const result = await this.mlNews.bringLatestMachineLearningNews(today, page, size);

return new SetResponse(200, { result });
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion src/providers/news/geek/geek-prisma.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NewsLogger } from '@utils/logger.util';

@Injectable()
export class GeekPrismaLibrary extends PrismaClient {
async bringHadaNews(startDate: Date, endDate: Date) {
async bringHadaNews(startDate: Date, endDate: Date, page: number, size: number) {
try {
const result = await this.geek.findMany({
select: { uuid: true, post: true, link: true, descLink: true, founded: true, liked: true },
Expand All @@ -17,6 +17,8 @@ export class GeekPrismaLibrary extends PrismaClient {
},
},
orderBy: { rank: 'desc' },
take: size,
skip: (page - 1) * size,
});

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/providers/news/geek/geek.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class GeekProvider {
this.resultNewsArray = [];
}

async getNews(today: string) {
async getNews(today: string, page: number, size: number) {
try {
const yesterday = moment(today).subtract(1, 'day').toDate();

Expand All @@ -30,7 +30,7 @@ export class GeekProvider {
end: endDate,
});

const result = await this.prisma.bringHadaNews(startDate, endDate);
const result = await this.prisma.bringHadaNews(startDate, endDate, page, size);

for (let i = 0; i <= result.length - 1; i += 1) {
const isUrlUndefined = result[i].descLink.split('.io/')[1];
Expand Down Expand Up @@ -82,7 +82,7 @@ export class GeekProvider {

async giveStar(postUuid: string, clientUuid: string) {
try {
const isLogined = this.account.getItem(clientUuid);
const isLogined = await this.account.getItem(clientUuid);

if (!isLogined) throw new HadaError('[GEEK] Give Star on the Stars', 'No Logined User Found.');

Expand Down
4 changes: 3 additions & 1 deletion src/providers/news/hacker/hacker-prisma.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NewsLogger } from '@utils/logger.util';

@Injectable()
export class HackerPrismaLibrary extends PrismaClient {
async bringHackerNews(startDate: Date, endDate: Date) {
async bringHackerNews(startDate: Date, endDate: Date, page: number, size: number) {
try {
const result = await this.hackers.findMany({
select: { uuid: true, post: true, link: true, founded: true, liked: true },
Expand All @@ -17,6 +17,8 @@ export class HackerPrismaLibrary extends PrismaClient {
},
},
orderBy: { rank: 'desc' },
take: size,
skip: (page - 1) * size,
});

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/providers/news/hacker/hacker.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class HackersNewsProvider {
}
}

async bringTodayHackerPosts(today: string) {
async bringTodayHackerPosts(today: string, page: number, size: number) {
try {
const yesterday = moment(today).subtract(1, 'day').toDate();

Expand All @@ -45,7 +45,7 @@ export class HackersNewsProvider {
end: endDate,
});

const result = await this.prisma.bringHackerNews(startDate, endDate);
const result = await this.prisma.bringHackerNews(startDate, endDate, page, size);

return result;
} catch (error) {
Expand All @@ -63,7 +63,7 @@ export class HackersNewsProvider {

async giveStar(postUuid: string, clientUuid: string) {
try {
const isLogined = this.account.getItem(clientUuid);
const isLogined = await this.account.getItem(clientUuid);

if (!isLogined) throw new HackerError('[Hackers] Give Star on the Stars', 'No Logined User Found.');

Expand Down
6 changes: 3 additions & 3 deletions src/providers/news/ml/machine.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MachineLearningProvider {
private readonly account: AccountManager,
) {}

async bringLatestMachineLearningNews(today: string) {
async bringLatestMachineLearningNews(today: string, page: number, size: number) {
try {
const yesterday = moment(today).subtract(1, 'day').toDate();

Expand All @@ -24,7 +24,7 @@ export class MachineLearningProvider {
start: startDate,
end: endDate,
});
const result = await this.prisma.bringMlNews(startDate, endDate);
const result = await this.prisma.bringMlNews(startDate, endDate, page, size);

return result;
} catch (error) {
Expand All @@ -42,7 +42,7 @@ export class MachineLearningProvider {

async giveStar(postUuid: string, clientUuid: string) {
try {
const isLogined = this.account.getItem(clientUuid);
const isLogined = await this.account.getItem(clientUuid);

if (!isLogined) throw new MachineLearningError('[ML] Give Star on the Stars', 'No Logined User Found.');

Expand Down
4 changes: 3 additions & 1 deletion src/providers/news/ml/ml-prisma.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NewsLogger } from '@utils/logger.util';

@Injectable()
export class MlPrismaLibrary extends PrismaClient {
async bringMlNews(startDate: Date, endDate: Date) {
async bringMlNews(startDate: Date, endDate: Date, page: number, size: number) {
try {
const result = await this.machineNews.findMany({
select: {
Expand All @@ -22,6 +22,8 @@ export class MlPrismaLibrary extends PrismaClient {
lte: endDate,
},
},
take: size,
skip: (page - 1) * size,
});

return result;
Expand Down

0 comments on commit 7c2a9ba

Please sign in to comment.