Skip to content

Commit

Permalink
Merge pull request #59 from donghquinn/dev
Browse files Browse the repository at this point in the history
wip: star post
  • Loading branch information
donghquinn authored Mar 4, 2024
2 parents d392487 + cc7daae commit 443894b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/controllers/geek/geek.ctl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common';
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { hadaNewsStarValidator, hadaNewsValidator } from '@validators/hada.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { GeekProvider } from 'providers/news/geek/geek.pvd';
Expand All @@ -23,11 +23,11 @@ export class GeekController {
}

@Post('/star')
async giveStarNews(@Body() request: StarRequest, @Headers('Authorization') clientUuid: string) {
async giveStarNews(@Body() request: StarRequest) {
try {
const { uuid: postUuid } = await hadaNewsStarValidator(request);
const { uuid: postUuid, email } = await hadaNewsStarValidator(request);

const result = await this.geek.giveStar(postUuid, clientUuid);
const result = await this.geek.giveStar(postUuid, email);

return new SetResponse(200, { result });
} catch (error) {
Expand Down
8 changes: 4 additions & 4 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, Headers, Post, Query } from '@nestjs/common';
import { Body, Controller, Get, 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 Down Expand Up @@ -38,11 +38,11 @@ export class HackerController {
}

@Post('/star')
async giveStarNews(@Body() request: StarRequest, @Headers('Authorization') clientUuid: string) {
async giveStarNews(@Body() request: StarRequest) {
try {
const { uuid: PostUuid } = await hackerNewsStarValidator(request);
const { uuid: PostUuid, email } = await hackerNewsStarValidator(request);

const result = await this.hacker.giveStar(PostUuid, clientUuid);
const result = await this.hacker.giveStar(PostUuid, email);

return new SetResponse(200, { result });
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/machine/machine.ctl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Headers, Post, Query } from '@nestjs/common';
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { machineLearningValidator, mlNewsStarValidator } from '@validators/ml.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { MachineLearningProvider } from 'providers/news/ml/machine.pvd';
Expand Down Expand Up @@ -27,11 +27,11 @@ export class MachineLearningController {
}

@Post('/star')
async giveStarNews(@Body() request: StarRequest, @Headers('Authorization') clientUuid: string) {
async giveStarNews(@Body() request: StarRequest) {
try {
const { uuid: postUuid } = await mlNewsStarValidator(request);
const { uuid: postUuid, email } = await mlNewsStarValidator(request);

const result = await this.mlNews.giveStar(postUuid, clientUuid);
const result = await this.mlNews.giveStar(postUuid, email);

return new SetResponse(200, { result });
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions src/providers/news/geek/geek.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ export class GeekProvider {
}
}

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

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

const { uuid: clientUuid } = isLogined;
const { uuid: likedUuid, liked } = await this.prisma.checkHadaNewsIsLiked(postUuid, clientUuid);

if (liked) {
Expand Down
5 changes: 3 additions & 2 deletions src/providers/news/hacker/hacker.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ export class HackersNewsProvider {
}
}

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

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

const { uuid: clientUuid } = isLogined;
const { uuid: likedUuid, isLiked } = await this.prisma.checkHackerNewsIsLiked(postUuid, clientUuid);

if (isLiked) {
Expand Down
5 changes: 3 additions & 2 deletions src/providers/news/ml/machine.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ export class MachineLearningProvider {
}
}

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

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

const { uuid: clientUuid } = isLogined;
const { uuid: likedUuid, isLiked } = await this.prisma.checkIsMlNewsLiked(postUuid, clientUuid);

if (!isLiked) {
Expand Down
5 changes: 4 additions & 1 deletion src/types/request.type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export interface StarRequest {
export interface StarRequest
{
// Post UUID
uuid: string;
email: string;
}
2 changes: 1 addition & 1 deletion src/validators/hacker.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const hackerNewsValidator = async (request: DailyHackerNewsRequest) => {

export const hackerNewsStarValidator = async (request: StarRequest) => {
try {
const scheme = z.object({ uuid: z.string() });
const scheme = z.object({ uuid: z.string(), email: z.string() });

const validated = await scheme.parseAsync(request);

Expand Down
2 changes: 1 addition & 1 deletion src/validators/hada.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const hadaNewsValidator = async (request: DailyHadaNewsRequest) => {

export const hadaNewsStarValidator = async (request: StarRequest) => {
try {
const scheme = z.object({ uuid: z.string() });
const scheme = z.object({ uuid: z.string(), email: z.string() });

const validated = await scheme.parseAsync(request);

Expand Down
2 changes: 1 addition & 1 deletion src/validators/ml.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const machineLearningValidator = async (request: DailyMlNewsRequest) => {

export const mlNewsStarValidator = async (request: StarRequest) => {
try {
const scheme = z.object({ uuid: z.string() });
const scheme = z.object({ uuid: z.string(), email: z.string() });

const validated = await scheme.parseAsync(request);

Expand Down

0 comments on commit 443894b

Please sign in to comment.