Skip to content

Commit

Permalink
Merge pull request #66 from donghquinn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
donghquinn authored Mar 7, 2024
2 parents e01e177 + 356a901 commit ae297c7
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 358 deletions.
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ model Client{
name String
password String
password_token String
is_logined Int @default(0)
is_logined Boolean @default(false)
signed_in DateTime @default(now())
logined DateTime @updatedAt
liked_hacker_posts Hacker_Liked[]
Expand Down
104 changes: 2 additions & 102 deletions src/controllers/client/client.ctl.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import { Body, Controller, Post } from '@nestjs/common';
import { clientLoginValidator } from '@validators/client/login.validator';
import { clientLogoutValidator } from '@validators/client/logout.validator';
import { clientMyPageStarNewsValidator, clientMyPageValidator } from '@validators/client/mypage.validator';
import {
searchEmailRequestValidator,
searchPasswordRequestValidator,
validatePasswordTempKeyRequestValidator,
} from '@validators/client/search.validator';
import { clientMyPageValidator } from '@validators/client/mypage.validator';
import { clientSignupValidator } from '@validators/client/signup.validator';
import { changePasswordValidator } from '@validators/client/user.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { ClientProvider } from 'providers/client/client.pvd';
import {
ClientLoginRequest,
ClientLogoutRequest,
ClientMyPageRequest,
ClientMyPageStarNewsRequest,
ClientSignupRequest,
} from 'types/client.type';
import { SearchEmailRequest, SearchPasswordRequest, ValidatePasswordKeyRequest } from 'types/password.type';
import { ClientLoginRequest, ClientLogoutRequest, ClientMyPageRequest, ClientSignupRequest } from 'types/client.type';
import { ChangePasswordRequest } from 'types/user.type';

// TODO User 회원가입 / 로그인 / 로그아웃 / 회원 탈퇴 기능 구현
@Controller('users')
export class ClientController {
constructor(private readonly client: ClientProvider) {}
Expand Down Expand Up @@ -86,93 +73,6 @@ export class ClientController {
}
}

@Post('star/hacker')
async getHackerStarNewsController(@Body() request: ClientMyPageStarNewsRequest) {
try {
const { uuid, page } = await clientMyPageStarNewsValidator(request);

const { totalPosts, hackerNews: hackerStarredNews } = await this.client.myStarredHackerNews(uuid, page);

return new SetResponse(200, {
totalPosts,
hackerStarredNews,
});
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('star/geek')
async getGeekStarNewsController(@Body() request: ClientMyPageStarNewsRequest) {
try {
const { uuid, page } = await clientMyPageStarNewsValidator(request);

const { totalPosts, resultNewsArray: geekStarredNews } = await this.client.myStarredGeekNews(uuid, page);

return new SetResponse(200, {
totalPosts,
geekStarredNews,
});
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('star/ml')
async getMlStarNewsController(@Body() request: ClientMyPageStarNewsRequest) {
try {
const { uuid, page } = await clientMyPageStarNewsValidator(request);

const { totalPosts, mlNews: mlStarredNews } = await this.client.myStarredMlNews(uuid, page);

return new SetResponse(200, {
totalPosts,
mlStarredNews,
});
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('search/email')
async searchEmailController(@Body() request: SearchEmailRequest) {
try {
const { name } = await searchEmailRequestValidator(request);

const email = await this.client.searchEmail(name);

return new SetResponse(200, { email });
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('search/password')
async searchPasswordController(@Body() request: SearchPasswordRequest) {
try {
const { name, email } = await searchPasswordRequestValidator(request);

const message = await this.client.searchPassword(email, name);

return new SetResponse(200, { message });
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('search/password/validate')
async validatePasswordTempKeyController(@Body() request: ValidatePasswordKeyRequest) {
try {
const { tempKey } = await validatePasswordTempKeyRequestValidator(request);

const message = await this.client.validateSearchingPasswordKey(tempKey);

return new SetResponse(200, { message });
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('change/password')
async changePasswordController(@Body() request: ChangePasswordRequest) {
try {
Expand Down
53 changes: 53 additions & 0 deletions src/controllers/client/search.ctl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Body, Controller, Post } from '@nestjs/common';
import {
searchEmailRequestValidator,
searchPasswordRequestValidator,
validatePasswordTempKeyRequestValidator,
} from '@validators/client/search.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { ClientSearchProvider } from 'providers/client/search.pvd';
import { SearchEmailRequest, SearchPasswordRequest, ValidatePasswordKeyRequest } from 'types/password.type';

@Controller('users/search')
export class ClientSearchController {
constructor(private readonly client: ClientSearchProvider) {}

@Post('email')
async searchEmailController(@Body() request: SearchEmailRequest) {
try {
const { name } = await searchEmailRequestValidator(request);

const email = await this.client.searchEmail(name);

return new SetResponse(200, { email });
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('password')
async searchPasswordController(@Body() request: SearchPasswordRequest) {
try {
const { name, email } = await searchPasswordRequestValidator(request);

const message = await this.client.searchPassword(email, name);

return new SetResponse(200, { message });
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('password/validate')
async validatePasswordTempKeyController(@Body() request: ValidatePasswordKeyRequest) {
try {
const { tempKey } = await validatePasswordTempKeyRequestValidator(request);

const message = await this.client.validateSearchingPasswordKey(tempKey);

return new SetResponse(200, { message });
} catch (error) {
return new SetErrorResponse(error);
}
}
}
58 changes: 58 additions & 0 deletions src/controllers/client/star.ctl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Body, Controller, Post } from '@nestjs/common';
import { clientMyPageStarNewsValidator } from '@validators/client/mypage.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { ClientStarProvider } from 'providers/client/star.pvd';
import { ClientMyPageStarNewsRequest } from 'types/client.type';

@Controller('users/star')
export class ClientStarController {
constructor(private readonly client: ClientStarProvider) {}

@Post('star/hacker')
async getHackerStarNewsController(@Body() request: ClientMyPageStarNewsRequest) {
try {
const { uuid, page } = await clientMyPageStarNewsValidator(request);

const { totalPosts, hackerNews: hackerStarredNews } = await this.client.myStarredHackerNews(uuid, page);

return new SetResponse(200, {
totalPosts,
hackerStarredNews,
});
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('star/geek')
async getGeekStarNewsController(@Body() request: ClientMyPageStarNewsRequest) {
try {
const { uuid, page } = await clientMyPageStarNewsValidator(request);

const { totalPosts, resultNewsArray: geekStarredNews } = await this.client.myStarredGeekNews(uuid, page);

return new SetResponse(200, {
totalPosts,
geekStarredNews,
});
} catch (error) {
return new SetErrorResponse(error);
}
}

@Post('star/ml')
async getMlStarNewsController(@Body() request: ClientMyPageStarNewsRequest) {
try {
const { uuid, page } = await clientMyPageStarNewsValidator(request);

const { totalPosts, mlNews: mlStarredNews } = await this.client.myStarredMlNews(uuid, page);

return new SetResponse(200, {
totalPosts,
mlStarredNews,
});
} catch (error) {
return new SetErrorResponse(error);
}
}
}
4 changes: 2 additions & 2 deletions src/controllers/geek/geek.ctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, Post, Query } from '@nestjs/common';
import { geekNewsStarValidator, geekNewsUnStarValidator, geekNewsValidator } from '@validators/geek.validator';
import { SetErrorResponse, SetResponse } from 'dto/response.dto';
import { GeekProvider } from 'providers/news/geek/geek.pvd';
import { DailyHadaNewsRequest } from 'types/geek.type';
import { DailyGeekNewsRequest } from 'types/geek.type';
import { StarRequest } from 'types/request.type';

@Controller('geek')
Expand All @@ -11,7 +11,7 @@ export class GeekController {

@Post('news')
async geekGetLatestNewsController(
@Body() request: DailyHadaNewsRequest,
@Body() request: DailyGeekNewsRequest,
@Query('page') page: number,
@Query('size') size: number,
) {
Expand Down
10 changes: 7 additions & 3 deletions src/modules/client/client.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ClientController } from '@controllers/client/client.ctl';
import { ClientSearchController } from '@controllers/client/search.ctl';
import { ClientStarController } from '@controllers/client/star.ctl';
import { MailerModule } from '@modules/mailer.module';
import { Module } from '@nestjs/common';
import { ClientProvider } from 'providers/client/client.pvd';
import { ClientSearchProvider } from 'providers/client/search.pvd';
import { ClientStarProvider } from 'providers/client/star.pvd';
import { AccountManagerModule } from './account.module';
import { ClientPrismaModule } from './client-prisma.module';

@Module({
providers: [ClientProvider],
@Module( {
controllers: [ClientController, ClientSearchController, ClientStarController],
providers: [ClientProvider, ClientSearchProvider, ClientStarProvider],
imports: [AccountManagerModule, ClientPrismaModule, MailerModule],
controllers: [ClientController],
})
export class ClientModule {}
2 changes: 1 addition & 1 deletion src/providers/client/client-prisma.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class ClientPrismaLibrary extends PrismaClient {
}
}

async updateClientLoginStatus(email: string, clientUuid: string, isLogined: number) {
async updateClientLoginStatus(email: string, clientUuid: string, isLogined: boolean) {
try {
await this.client.update({
data: {
Expand Down
Loading

0 comments on commit ae297c7

Please sign in to comment.