From 8345897d43dbfc6c209a137483e2b3e1fc7c5f37 Mon Sep 17 00:00:00 2001 From: happy-juny <38745815+Istiopaxx@users.noreply.github.com> Date: Sat, 6 Jan 2024 21:21:03 +0900 Subject: [PATCH] [Refactor]: unify all notation to camelCase (#114) * [refactor]: fix snake_case to camelCase * [refactor]: change test directory structure --- .../src/{controllers => }/auth.controller.ts | 10 +- api/libs/auth/src/auth.module.ts | 6 +- .../auth/src/{services => }/auth.service.ts | 40 ++-- .../mongo.session.entity.ts | 2 +- .../{entities => domain}/session.entity.ts | 8 +- api/libs/auth/src/dto/auth-response.dto.ts | 2 +- api/libs/auth/src/dto/filter-auth.dto.ts | 0 api/libs/auth/src/dto/oauth.dto.ts | 12 +- api/libs/auth/src/dto/token.dto.ts | 8 +- .../auth/src/guards/register-auth.guard.ts | 4 +- .../auth/src/guards/session-auth.guard.ts | 4 +- .../repositories/auth.repository.interface.ts | 3 +- .../auth/src/repositories/auth.repository.ts | 8 +- .../src/repositories/mongo.auth.repository.ts | 2 +- .../integration}/auth.controller.spec.ts | 8 +- .../mongo.auth.repository.spec.ts | 2 +- .../unit}/auth.service.spec.ts | 28 +-- api/libs/common/src/dto/pagenation.dto.ts | 6 +- .../src/{types => domain}/food-type.enum.ts | 0 .../{entities => domain}/ingredient.entity.ts | 4 +- .../mongo/mongo.ingredient.entity.ts | 0 .../mongo/mongo.user-ingredient.entity.ts | 6 +- .../{types => domain}/store-method.enum.ts | 0 .../user-ingredient.entity.ts | 14 +- .../src/dto/filter-ingredient.dto.ts | 12 +- .../src/dto/ingredient-response.dto.ts | 2 +- .../src/dto/modify-ingredient.dto.ts | 16 +- api/libs/ingredient/src/ingredient.module.ts | 6 +- .../mongo.user-ingredient.repository.ts | 8 +- .../user-ingredient.repository.interface.ts | 12 +- .../user-ingredient.repository.ts | 2 +- .../user-ingredient.controller.ts | 16 +- .../{services => }/user-ingredient.service.ts | 22 +- .../mongo.user-ingredient.repository.spec.ts | 2 +- .../user-ingredient.controller.spec.ts | 2 +- .../unit}/user-ingredient.service.spec.ts | 2 +- .../{entity => domain}/device-token.entity.ts | 8 +- .../mongo/mongo.device-token.entity.ts | 2 +- .../mongo/mongo.noti.entity.ts | 2 +- .../src/{entity => domain}/noti.entity.ts | 6 +- .../noti/src/dto/device-token-response.dto.ts | 2 +- .../noti/src/dto/filter-device-token.dto.ts | 2 +- api/libs/noti/src/dto/filter-noti.dto.ts | 2 +- .../noti/src/dto/modify-device-token.dto.ts | 4 +- api/libs/noti/src/dto/modify-noti.dto.ts | 4 +- api/libs/noti/src/dto/noti-response.dto.ts | 2 +- .../src/{controller => }/noti.controller.ts | 18 +- api/libs/noti/src/noti.module.ts | 6 +- .../device-token.repository.interface.ts | 4 +- .../src/repository/device-token.repository.ts | 2 +- .../mongo/mongo.device-token.repository.ts | 2 +- .../repository/mongo/mongo.noti.repository.ts | 2 +- .../repository/noti.repository.interface.ts | 4 +- .../noti/src/repository/noti.repository.ts | 2 +- .../noti/src/service/device-token.service.ts | 2 +- api/libs/noti/src/service/noti.service.ts | 2 +- .../unit}/device-token.service.spec.ts | 4 +- .../unit}/noti.service.spec.ts | 4 +- .../controllers/recipe-bookmark.controller.ts | 6 +- .../src/controllers/recipe.controller.ts | 12 +- .../mongo/mongo.recipe-bookmark.entity.ts | 0 .../mongo/mongo.recipe-view-log.entity.ts | 0 .../mongo/mongo.recipe.entity.ts | 42 ++-- .../src/domain/recipe-bookmark.entity.ts | 31 +++ .../src/domain/recipe-view-log.entity.ts | 34 ++++ api/libs/recipe/src/domain/recipe.entity.ts | 42 ++++ .../filter-recipe-bookmark.dto.ts | 29 +-- .../modify-recipe-bookmark.dto.ts | 4 +- .../recipe-bookmark-response.dto.ts | 2 +- .../modify-recipe-view-log.dto.ts | 6 +- .../recipe-viewer-identifier.ts | 11 +- .../src/dto/recipe/create-mongo-recipe.dto.ts | 68 +++++++ .../src/dto/recipe/create-recipe.dto.ts | 54 +++++ .../src/dto/recipe/filter-recipe.dto.ts | 92 ++++----- .../dto/recipe/ingredient-requirement.dto.ts | 22 ++ .../src/dto/recipe/modify-recipe.dto.ts | 171 ---------------- .../src/dto/recipe/recipe-response.dto.ts | 2 +- .../recipe/src/dto/recipe/recipe-step.dto.ts | 44 ++++ .../src/dto/recipe/update-mongo-recipe.dto.ts | 15 ++ .../src/dto/recipe/update-recipe.dto.ts | 19 ++ .../src/entities/recipe-bookmark.entity.ts | 9 - .../src/entities/recipe-view-log.entity.ts | 10 - api/libs/recipe/src/entities/recipe.entity.ts | 14 -- api/libs/recipe/src/recipe.module.ts | 5 +- .../mongo.recipe-bookmark.repository.ts | 4 +- .../recipe-bookmark.interface.ts | 4 +- .../recipe-bookmark.repository.ts | 12 +- .../mongo.recipe-view-log.repository.ts | 38 ++-- .../recipe-view-log.repository.interface.ts | 6 +- .../recipe-view-log.repository.ts | 50 ++--- .../recipe/mongo.recipe.repository.ts | 8 +- .../recipe/recipe.repository.interface.ts | 11 +- .../repositories/recipe/recipe.repository.ts | 34 ++-- .../src/services/recipe-bookmark.service.ts | 2 +- .../recipe/src/services/recipe.service.ts | 46 +---- .../mongo.recipe-bookmark.repository.spec.ts | 2 +- .../mongo.recipe-view-log.repository.spec.ts | 2 +- .../mongo.recipe.repository.spec.ts | 2 +- .../recipe-bookmark.controller.spec.ts | 2 +- .../integration}/recipe.controller.spec.ts | 2 +- .../unit}/recipe-bookmark.service.spec.ts | 10 +- .../unit}/recipe.service.spec.ts | 91 +++++---- .../user/src/{types => domain}/diet.enum.ts | 0 .../{entities => domain}/mongo.user.entity.ts | 4 +- .../src/{entities => domain}/user.entity.ts | 4 +- api/libs/user/src/dto/filter-user.dto.ts | 2 +- api/libs/user/src/dto/modify-user.dto.ts | 2 +- api/libs/user/src/dto/user-response.dto.ts | 2 +- .../src/repositories/mongo.user.repository.ts | 2 +- .../repositories/user.repository.interface.ts | 5 +- .../user/src/repositories/user.repository.ts | 6 +- .../src/{controllers => }/user.controller.ts | 18 +- api/libs/user/src/user.module.ts | 6 +- .../user/src/{services => }/user.service.ts | 6 +- .../mongo.user.repository.spec.ts | 2 +- .../integration}/user.controller.spec.ts | 8 +- .../unit}/user.service.spec.ts | 8 +- api/prisma/schema.prisma | 190 +++++++++--------- 118 files changed, 897 insertions(+), 803 deletions(-) rename api/libs/auth/src/{controllers => }/auth.controller.ts (91%) rename api/libs/auth/src/{services => }/auth.service.ts (77%) rename api/libs/auth/src/{entities => domain}/mongo.session.entity.ts (95%) rename api/libs/auth/src/{entities => domain}/session.entity.ts (58%) delete mode 100644 api/libs/auth/src/dto/filter-auth.dto.ts rename api/libs/auth/{src/controllers => test/integration}/auth.controller.spec.ts (70%) rename api/libs/auth/{src/repositories => test/integration}/mongo.auth.repository.spec.ts (87%) rename api/libs/auth/{src/services => test/unit}/auth.service.spec.ts (83%) rename api/libs/ingredient/src/{types => domain}/food-type.enum.ts (100%) rename api/libs/ingredient/src/{entities => domain}/ingredient.entity.ts (83%) rename api/libs/ingredient/src/{entities => domain}/mongo/mongo.ingredient.entity.ts (100%) rename api/libs/ingredient/src/{entities => domain}/mongo/mongo.user-ingredient.entity.ts (91%) rename api/libs/ingredient/src/{types => domain}/store-method.enum.ts (100%) rename api/libs/ingredient/src/{entities => domain}/user-ingredient.entity.ts (52%) rename api/libs/ingredient/src/repositories/{mongo => }/mongo.user-ingredient.repository.ts (73%) rename api/libs/ingredient/src/{controllers => }/user-ingredient.controller.ts (89%) rename api/libs/ingredient/src/{services => }/user-ingredient.service.ts (72%) rename api/libs/ingredient/{src/repositories/mongo => test/integration}/mongo.user-ingredient.repository.spec.ts (77%) rename api/libs/ingredient/{src/controllers => test/integration}/user-ingredient.controller.spec.ts (80%) rename api/libs/ingredient/{src/services => test/unit}/user-ingredient.service.spec.ts (80%) rename api/libs/noti/src/{entity => domain}/device-token.entity.ts (60%) rename api/libs/noti/src/{entity => domain}/mongo/mongo.device-token.entity.ts (93%) rename api/libs/noti/src/{entity => domain}/mongo/mongo.noti.entity.ts (92%) rename api/libs/noti/src/{entity => domain}/noti.entity.ts (68%) rename api/libs/noti/src/{controller => }/noti.controller.ts (79%) rename api/libs/noti/{src/service => test/unit}/device-token.service.spec.ts (73%) rename api/libs/noti/{src/service => test/unit}/noti.service.spec.ts (81%) rename api/libs/recipe/src/{entities => domain}/mongo/mongo.recipe-bookmark.entity.ts (100%) rename api/libs/recipe/src/{entities => domain}/mongo/mongo.recipe-view-log.entity.ts (100%) rename api/libs/recipe/src/{entities => domain}/mongo/mongo.recipe.entity.ts (51%) create mode 100644 api/libs/recipe/src/domain/recipe-bookmark.entity.ts create mode 100644 api/libs/recipe/src/domain/recipe-view-log.entity.ts create mode 100644 api/libs/recipe/src/domain/recipe.entity.ts create mode 100644 api/libs/recipe/src/dto/recipe/create-mongo-recipe.dto.ts create mode 100644 api/libs/recipe/src/dto/recipe/create-recipe.dto.ts create mode 100644 api/libs/recipe/src/dto/recipe/ingredient-requirement.dto.ts delete mode 100644 api/libs/recipe/src/dto/recipe/modify-recipe.dto.ts create mode 100644 api/libs/recipe/src/dto/recipe/recipe-step.dto.ts create mode 100644 api/libs/recipe/src/dto/recipe/update-mongo-recipe.dto.ts create mode 100644 api/libs/recipe/src/dto/recipe/update-recipe.dto.ts delete mode 100644 api/libs/recipe/src/entities/recipe-bookmark.entity.ts delete mode 100644 api/libs/recipe/src/entities/recipe-view-log.entity.ts delete mode 100644 api/libs/recipe/src/entities/recipe.entity.ts rename api/libs/recipe/{src/repositories/recipe-bookmark => test/integration}/mongo.recipe-bookmark.repository.spec.ts (75%) rename api/libs/recipe/{src/repositories/recipe-view-log => test/integration}/mongo.recipe-view-log.repository.spec.ts (75%) rename api/libs/recipe/{src/repositories/recipe => test/integration}/mongo.recipe.repository.spec.ts (77%) rename api/libs/recipe/{src/controllers => test/integration}/recipe-bookmark.controller.spec.ts (79%) rename api/libs/recipe/{src/controllers => test/integration}/recipe.controller.spec.ts (80%) rename api/libs/recipe/{src/services => test/unit}/recipe-bookmark.service.spec.ts (91%) rename api/libs/recipe/{src/services => test/unit}/recipe.service.spec.ts (86%) rename api/libs/user/src/{types => domain}/diet.enum.ts (100%) rename api/libs/user/src/{entities => domain}/mongo.user.entity.ts (93%) rename api/libs/user/src/{entities => domain}/user.entity.ts (84%) rename api/libs/user/src/{controllers => }/user.controller.ts (92%) rename api/libs/user/src/{services => }/user.service.ts (91%) rename api/libs/user/{src/repositories => test/integration}/mongo.user.repository.spec.ts (85%) rename api/libs/user/{src/controllers => test/integration}/user.controller.spec.ts (74%) rename api/libs/user/{src/services => test/unit}/user.service.spec.ts (93%) diff --git a/api/libs/auth/src/controllers/auth.controller.ts b/api/libs/auth/src/auth.controller.ts similarity index 91% rename from api/libs/auth/src/controllers/auth.controller.ts rename to api/libs/auth/src/auth.controller.ts index 780b344..acd505c 100644 --- a/api/libs/auth/src/controllers/auth.controller.ts +++ b/api/libs/auth/src/auth.controller.ts @@ -8,13 +8,13 @@ import { Req, } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { AuthService } from '../services/auth.service'; -import { GoogleLoginDto, KakaoLoginDto } from '../dto/oauth.dto'; +import { AuthService } from './auth.service'; +import { GoogleLoginDto, KakaoLoginDto } from './dto/oauth.dto'; import { ApiGet, ApiPostOk, } from '@app/common/decorators/http-method.decorator'; -import { User } from '@app/user/entities/mongo.user.entity'; +import { User } from '@app/user/domain/mongo.user.entity'; import { ReqUser } from '@app/common/decorators/req-user.decorator'; import { CreateUserApiDto, CreateUserDto } from '@app/user/dto/modify-user.dto'; import { Auth, RegisterAuth } from '@app/common/decorators/auth.decorator'; @@ -22,9 +22,9 @@ import { LogoutResponseDto, OAuthLoginResponseDto, RegisterResponseDto, -} from '../dto/auth-response.dto'; +} from './dto/auth-response.dto'; import { FindOneUserResponseDto } from '@app/user/dto/user-response.dto'; -import { UserInfo } from '../types/user-info.type'; +import { UserInfo } from './types/user-info.type'; @ApiTags('Auth') @Controller('auth') diff --git a/api/libs/auth/src/auth.module.ts b/api/libs/auth/src/auth.module.ts index b009c81..cbac759 100644 --- a/api/libs/auth/src/auth.module.ts +++ b/api/libs/auth/src/auth.module.ts @@ -1,6 +1,6 @@ import { Global, Module } from '@nestjs/common'; -import { AuthController } from './controllers/auth.controller'; -import { AuthService } from './services/auth.service'; +import { AuthController } from './auth.controller'; +import { AuthService } from './auth.service'; import { MongooseModule } from '@nestjs/mongoose'; import { AuthRepository } from './repositories/auth.repository'; import { JwtModule } from '@nestjs/jwt'; @@ -11,7 +11,7 @@ import { Session, SessionSchema, SessionSchemaFactory, -} from './entities/mongo.session.entity'; +} from './domain/mongo.session.entity'; @Global() @Module({ diff --git a/api/libs/auth/src/services/auth.service.ts b/api/libs/auth/src/auth.service.ts similarity index 77% rename from api/libs/auth/src/services/auth.service.ts rename to api/libs/auth/src/auth.service.ts index f775353..57fcb1e 100644 --- a/api/libs/auth/src/services/auth.service.ts +++ b/api/libs/auth/src/auth.service.ts @@ -1,17 +1,21 @@ -import { User } from '@app/user/entities/user.entity'; -import { UserService } from '@app/user/services/user.service'; +import { User } from '@app/user/domain/user.entity'; +import { UserService } from '@app/user/user.service'; import { Injectable, NotFoundException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; -import { AuthRepository } from '../repositories/auth.repository'; +import { AuthRepository } from './repositories/auth.repository'; import { CreateUserDto } from '@app/user/dto/modify-user.dto'; import { HttpService } from '@nestjs/axios'; -import { GoogleLoginDto, OAuthLoginSessionDto } from '../dto/oauth.dto'; +import { + GoogleLoginDto, + KakaoLoginDto, + OAuthLoginSessionDto, +} from './dto/oauth.dto'; import { GoogleApiResponseType, KakaoApiResponseType, -} from '../types/oauth.type'; -import { UserInfo } from '../types/user-info.type'; -import { LoginSessionDto } from '../dto/token.dto'; +} from './types/oauth.type'; +import { UserInfo } from './types/user-info.type'; +import { LoginSessionDto } from './dto/token.dto'; import { v4 as uuidv4 } from 'uuid'; import { Logable } from '@app/common/log/log.decorator'; @@ -47,14 +51,14 @@ export class AuthService { @Logable() async login(user: User): Promise { - const session_token = uuidv4(); + const sessionToken = uuidv4(); await this.authRepository.create({ - user_id: user.id, - session_token, + userId: user.id, + sessionToken, }); return { user, - session_token, + sessionToken, }; } @@ -63,9 +67,9 @@ export class AuthService { const { email, username } = userInfo; const user = await this.userService.findByEmail(email); return { - is_exist: !!user, + isExist: !!user, ...(!!user ? await this.login(user) : {}), - register_token: !!user + registerToken: !!user ? undefined : this.jwtService.sign({ sub: email, username }), }; @@ -75,13 +79,13 @@ export class AuthService { async googleLogin( googleLoginDto: GoogleLoginDto, ): Promise { - const { access_token } = googleLoginDto; + const { accessToken } = googleLoginDto; const { data }: { data: GoogleApiResponseType } = await this.httpService.axiosRef.get( 'https://www.googleapis.com/oauth2/v2/userinfo', { headers: { - Authorization: `Bearer ${access_token}`, + Authorization: `Bearer ${accessToken}`, }, }, ); @@ -91,13 +95,13 @@ export class AuthService { @Logable() async kakaoLogin( - kakaoLoginDto: GoogleLoginDto, + kakaoLoginDto: KakaoLoginDto, ): Promise { - const { access_token } = kakaoLoginDto; + const { accessToken } = kakaoLoginDto; const { data }: { data: KakaoApiResponseType } = await this.httpService.axiosRef.get('https://kapi.kakao.com/v2/user/me', { headers: { - Authorization: `Bearer ${access_token}`, + Authorization: `Bearer ${accessToken}`, }, }); const { email } = data.kakao_account; diff --git a/api/libs/auth/src/entities/mongo.session.entity.ts b/api/libs/auth/src/domain/mongo.session.entity.ts similarity index 95% rename from api/libs/auth/src/entities/mongo.session.entity.ts rename to api/libs/auth/src/domain/mongo.session.entity.ts index e8ad9a5..85b368d 100644 --- a/api/libs/auth/src/entities/mongo.session.entity.ts +++ b/api/libs/auth/src/domain/mongo.session.entity.ts @@ -2,7 +2,7 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { schemaOptions } from '@app/common/utils/schema-option'; import { HydratedDocument, Schema as MongooseSchema } from 'mongoose'; import { ConfigService } from '@nestjs/config'; -import { User } from '@app/user/entities/mongo.user.entity'; +import { User } from '@app/user/domain/mongo.user.entity'; export type SessionDocument = HydratedDocument; diff --git a/api/libs/auth/src/entities/session.entity.ts b/api/libs/auth/src/domain/session.entity.ts similarity index 58% rename from api/libs/auth/src/entities/session.entity.ts rename to api/libs/auth/src/domain/session.entity.ts index 4001e4d..16f7559 100644 --- a/api/libs/auth/src/entities/session.entity.ts +++ b/api/libs/auth/src/domain/session.entity.ts @@ -2,8 +2,8 @@ import { Session as SessionType } from '@prisma/client'; export class Session implements SessionType { id: number; - session_token: string; - user_id: number; - created_at: Date; - updated_at: Date; + sessionToken: string; + userId: number; + createdAt: Date; + updatedAt: Date; } diff --git a/api/libs/auth/src/dto/auth-response.dto.ts b/api/libs/auth/src/dto/auth-response.dto.ts index b5af25a..22319f6 100644 --- a/api/libs/auth/src/dto/auth-response.dto.ts +++ b/api/libs/auth/src/dto/auth-response.dto.ts @@ -1,5 +1,5 @@ import { OkResponse } from '@app/common/dto/success-response.dto'; -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { LoginSessionDto } from './token.dto'; import { OAuthLoginSessionDto } from './oauth.dto'; diff --git a/api/libs/auth/src/dto/filter-auth.dto.ts b/api/libs/auth/src/dto/filter-auth.dto.ts deleted file mode 100644 index e69de29..0000000 diff --git a/api/libs/auth/src/dto/oauth.dto.ts b/api/libs/auth/src/dto/oauth.dto.ts index 9e0bbbb..44c54bd 100644 --- a/api/libs/auth/src/dto/oauth.dto.ts +++ b/api/libs/auth/src/dto/oauth.dto.ts @@ -1,21 +1,21 @@ -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { IsNotEmpty, IsString } from 'class-validator'; export class GoogleLoginDto { @IsString() @IsNotEmpty() - access_token: string; + accessToken: string; } export class KakaoLoginDto { @IsString() @IsNotEmpty() - access_token: string; + accessToken: string; } export class OAuthLoginSessionDto { - is_exist: boolean; - session_token?: string; + isExist: boolean; + sessionToken?: string; user?: User; - register_token?: string; + registerToken?: string; } diff --git a/api/libs/auth/src/dto/token.dto.ts b/api/libs/auth/src/dto/token.dto.ts index 40fa56f..db7089b 100644 --- a/api/libs/auth/src/dto/token.dto.ts +++ b/api/libs/auth/src/dto/token.dto.ts @@ -1,16 +1,16 @@ -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { IsInt, IsUUID } from 'class-validator'; export class LoginSessionDto { - session_token: string; + sessionToken: string; user: User; } export class CreateSessionDto { @IsUUID() - session_token: string; + sessionToken: string; @IsInt() - user_id: number; + userId: number; } diff --git a/api/libs/auth/src/guards/register-auth.guard.ts b/api/libs/auth/src/guards/register-auth.guard.ts index 64fc800..4d08619 100644 --- a/api/libs/auth/src/guards/register-auth.guard.ts +++ b/api/libs/auth/src/guards/register-auth.guard.ts @@ -6,8 +6,8 @@ import { UnauthorizedException, } from '@nestjs/common'; import { Request } from 'express'; -import { AuthService } from '../services/auth.service'; -import { UserService } from '@app/user/services/user.service'; +import { AuthService } from '../auth.service'; +import { UserService } from '@app/user/user.service'; @Injectable() export class RegisterAuthGuard implements CanActivate { diff --git a/api/libs/auth/src/guards/session-auth.guard.ts b/api/libs/auth/src/guards/session-auth.guard.ts index d89486f..a1e3ae4 100644 --- a/api/libs/auth/src/guards/session-auth.guard.ts +++ b/api/libs/auth/src/guards/session-auth.guard.ts @@ -7,7 +7,7 @@ import { import { Request } from 'express'; import { Reflector } from '@nestjs/core'; import { IS_PUBLIC_KEY } from '@app/common/decorators/public.decorator'; -import { AuthService } from '../services/auth.service'; +import { AuthService } from '../auth.service'; @Injectable() export class SessionAuthGuard implements CanActivate { @@ -32,7 +32,7 @@ export class SessionAuthGuard implements CanActivate { try { const session = await this.authService.findBySessionToken(sessionToken); request['user'] = session.user; - request['sessionToken'] = session.session_token; + request['sessionToken'] = session.sessionToken; } catch { throw new UnauthorizedException(); } diff --git a/api/libs/auth/src/repositories/auth.repository.interface.ts b/api/libs/auth/src/repositories/auth.repository.interface.ts index 7e97f7f..b2b6cef 100644 --- a/api/libs/auth/src/repositories/auth.repository.interface.ts +++ b/api/libs/auth/src/repositories/auth.repository.interface.ts @@ -1,6 +1,6 @@ import { Session as PrismaSession } from '@prisma/client'; import { CreateSessionDto } from '../dto/token.dto'; -import { Session as MongoSession } from '../entities/mongo.session.entity'; +import { Session as MongoSession } from '../domain/mongo.session.entity'; import { ICrudRepository } from '@app/common/repository/crud.repository'; type Session = PrismaSession | MongoSession; @@ -8,5 +8,6 @@ type Session = PrismaSession | MongoSession; export interface IAuthRepository extends ICrudRepository { findBySessionToken(session: string): Promise; + deleteBySessionToken(session: string): Promise; } diff --git a/api/libs/auth/src/repositories/auth.repository.ts b/api/libs/auth/src/repositories/auth.repository.ts index dc67380..3a54248 100644 --- a/api/libs/auth/src/repositories/auth.repository.ts +++ b/api/libs/auth/src/repositories/auth.repository.ts @@ -30,13 +30,13 @@ export class AuthRepository ttl: 24 * 60 * 60 * 1000, keyGenerator: (session: string) => `session:${session}`, }) - async findBySessionToken(session: string): Promise { + async findBySessionToken(session: string) { return await this.prisma.session.findUnique({ - where: { session_token: session }, + where: { sessionToken: session }, include: { user: { include: { - device_tokens: true, + deviceTokens: true, }, }, }, @@ -50,7 +50,7 @@ export class AuthRepository }) async deleteBySessionToken(session: string): Promise { return await this.prisma.session.delete({ - where: { session_token: session }, + where: { sessionToken: session }, }); } } diff --git a/api/libs/auth/src/repositories/mongo.auth.repository.ts b/api/libs/auth/src/repositories/mongo.auth.repository.ts index e94899a..1743c44 100644 --- a/api/libs/auth/src/repositories/mongo.auth.repository.ts +++ b/api/libs/auth/src/repositories/mongo.auth.repository.ts @@ -1,6 +1,6 @@ import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; -import { Session, SessionDocument } from '../entities/mongo.session.entity'; +import { Session, SessionDocument } from '../domain/mongo.session.entity'; import { CreateSessionDto } from '../dto/token.dto'; import { Logable } from '@app/common/log/log.decorator'; import { Cacheable } from '@app/common/cache/cache.service'; diff --git a/api/libs/auth/src/controllers/auth.controller.spec.ts b/api/libs/auth/test/integration/auth.controller.spec.ts similarity index 70% rename from api/libs/auth/src/controllers/auth.controller.spec.ts rename to api/libs/auth/test/integration/auth.controller.spec.ts index 164a850..ba7e71a 100644 --- a/api/libs/auth/src/controllers/auth.controller.spec.ts +++ b/api/libs/auth/test/integration/auth.controller.spec.ts @@ -1,8 +1,8 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { AuthService } from '../services/auth.service'; -import { AuthController } from './auth.controller'; -import { AuthRepository } from '../repositories/mongo.auth.repository'; -import { UserService } from '@app/user/services/user.service'; +import { AuthService } from '@app/auth/auth.service'; +import { AuthController } from '@app/auth/auth.controller'; +import { AuthRepository } from '@app/auth/repositories/mongo.auth.repository'; +import { UserService } from '@app/user/user.service'; describe('AuthController', () => { let controller: AuthController; diff --git a/api/libs/auth/src/repositories/mongo.auth.repository.spec.ts b/api/libs/auth/test/integration/mongo.auth.repository.spec.ts similarity index 87% rename from api/libs/auth/src/repositories/mongo.auth.repository.spec.ts rename to api/libs/auth/test/integration/mongo.auth.repository.spec.ts index b989cce..648a3de 100644 --- a/api/libs/auth/src/repositories/mongo.auth.repository.spec.ts +++ b/api/libs/auth/test/integration/mongo.auth.repository.spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { AuthRepository } from './mongo.auth.repository'; +import { AuthRepository } from '@app/auth/repositories/mongo.auth.repository'; describe('AuthRepository', () => { let authRepository: AuthRepository; diff --git a/api/libs/auth/src/services/auth.service.spec.ts b/api/libs/auth/test/unit/auth.service.spec.ts similarity index 83% rename from api/libs/auth/src/services/auth.service.spec.ts rename to api/libs/auth/test/unit/auth.service.spec.ts index 03ce70c..2a0c417 100644 --- a/api/libs/auth/src/services/auth.service.spec.ts +++ b/api/libs/auth/test/unit/auth.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@automock/jest'; -import { AuthService } from './auth.service'; -import { AuthRepository } from '../repositories/auth.repository'; -import { UserService } from '@app/user/services/user.service'; +import { AuthService } from '@app/auth/auth.service'; +import { AuthRepository } from '@app/auth/repositories/auth.repository'; +import { UserService } from '@app/user/user.service'; import { JwtService } from '@nestjs/jwt'; -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { CreateUserDto } from '@app/user/dto/modify-user.dto'; -import { LoginSessionDto } from '../dto/token.dto'; -import { Session } from '../entities/session.entity'; -import { OAuthLoginSessionDto } from '../dto/oauth.dto'; +import { LoginSessionDto } from '@app/auth/dto/token.dto'; +import { Session } from '@app/auth/domain/session.entity'; +import { OAuthLoginSessionDto } from '@app/auth/dto/oauth.dto'; jest.mock('uuid', () => ({ v4: () => 'mock-uuid', @@ -52,7 +52,7 @@ describe('AuthService', () => { }; const sessToken = 'mock-uuid'; const loginSessionDto: LoginSessionDto = { - session_token: sessToken, + sessionToken: sessToken, user, }; authRepository.create.mockResolvedValueOnce(new Session()); @@ -60,8 +60,8 @@ describe('AuthService', () => { const result = await service.login(user); expect(authRepository.create).toHaveBeenCalledWith({ - user_id: user.id, - session_token: sessToken, + userId: user.id, + sessionToken: sessToken, }); expect(result).toEqual(loginSessionDto); }); @@ -76,11 +76,11 @@ describe('AuthService', () => { user.username = username; const loginSessionDto: LoginSessionDto = { - session_token: 'sessToken', + sessionToken: 'sessToken', user, }; const oAuthLoginSessionDto: OAuthLoginSessionDto = { - is_exist: true, + isExist: true, ...loginSessionDto, }; userService.findByEmail.mockResolvedValue(user); @@ -97,8 +97,8 @@ describe('AuthService', () => { const email = 'test@test.com'; const username = 'test'; const expectedResponse = { - is_exist: false, - register_token: 'register_token', + isExist: false, + registerToken: 'register_token', }; jwtService.sign.mockReturnValue('register_token'); userService.findByEmail.mockResolvedValue(undefined); diff --git a/api/libs/common/src/dto/pagenation.dto.ts b/api/libs/common/src/dto/pagenation.dto.ts index 7ee387c..99ebc47 100644 --- a/api/libs/common/src/dto/pagenation.dto.ts +++ b/api/libs/common/src/dto/pagenation.dto.ts @@ -23,9 +23,5 @@ export class PagenationResponseDto { count: number; - has_next: boolean; - - // has_prev: boolean; - - // total_page?: number; + hasNext: boolean; } diff --git a/api/libs/ingredient/src/types/food-type.enum.ts b/api/libs/ingredient/src/domain/food-type.enum.ts similarity index 100% rename from api/libs/ingredient/src/types/food-type.enum.ts rename to api/libs/ingredient/src/domain/food-type.enum.ts diff --git a/api/libs/ingredient/src/entities/ingredient.entity.ts b/api/libs/ingredient/src/domain/ingredient.entity.ts similarity index 83% rename from api/libs/ingredient/src/entities/ingredient.entity.ts rename to api/libs/ingredient/src/domain/ingredient.entity.ts index b9f3df1..c809dab 100644 --- a/api/libs/ingredient/src/entities/ingredient.entity.ts +++ b/api/libs/ingredient/src/domain/ingredient.entity.ts @@ -6,6 +6,6 @@ export class Ingredient implements IngredientType { description: string; thumbnail: string; icon: string; - created_at: Date; - updated_at: Date; + createdAt: Date; + updatedAt: Date; } diff --git a/api/libs/ingredient/src/entities/mongo/mongo.ingredient.entity.ts b/api/libs/ingredient/src/domain/mongo/mongo.ingredient.entity.ts similarity index 100% rename from api/libs/ingredient/src/entities/mongo/mongo.ingredient.entity.ts rename to api/libs/ingredient/src/domain/mongo/mongo.ingredient.entity.ts diff --git a/api/libs/ingredient/src/entities/mongo/mongo.user-ingredient.entity.ts b/api/libs/ingredient/src/domain/mongo/mongo.user-ingredient.entity.ts similarity index 91% rename from api/libs/ingredient/src/entities/mongo/mongo.user-ingredient.entity.ts rename to api/libs/ingredient/src/domain/mongo/mongo.user-ingredient.entity.ts index 323d1af..24b2ea2 100644 --- a/api/libs/ingredient/src/entities/mongo/mongo.user-ingredient.entity.ts +++ b/api/libs/ingredient/src/domain/mongo/mongo.user-ingredient.entity.ts @@ -1,9 +1,9 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Schema as MongooseSchema } from 'mongoose'; -import { FoodType } from '../../types/food-type.enum'; -import { StoreMethod } from '../../types/store-method.enum'; +import { FoodType } from '../food-type.enum'; +import { StoreMethod } from '../store-method.enum'; import { schemaOptions } from '@app/common/utils/schema-option'; -import { User } from '@app/user/entities/mongo.user.entity'; +import { User } from '@app/user/domain/mongo.user.entity'; import { ConfigService } from '@nestjs/config'; export type UserIngredientDocument = HydratedDocument; diff --git a/api/libs/ingredient/src/types/store-method.enum.ts b/api/libs/ingredient/src/domain/store-method.enum.ts similarity index 100% rename from api/libs/ingredient/src/types/store-method.enum.ts rename to api/libs/ingredient/src/domain/store-method.enum.ts diff --git a/api/libs/ingredient/src/entities/user-ingredient.entity.ts b/api/libs/ingredient/src/domain/user-ingredient.entity.ts similarity index 52% rename from api/libs/ingredient/src/entities/user-ingredient.entity.ts rename to api/libs/ingredient/src/domain/user-ingredient.entity.ts index c2b0bab..d45a975 100644 --- a/api/libs/ingredient/src/entities/user-ingredient.entity.ts +++ b/api/libs/ingredient/src/domain/user-ingredient.entity.ts @@ -3,13 +3,13 @@ import { UserIngredient as UserIngredientType, $Enums } from '@prisma/client'; export class UserIngredient implements UserIngredientType { id: number; name: string; - ingredient_id: number; - user_id: number; - food_type: $Enums.FoodType; - store_method: $Enums.StoreMethod; + ingredientId: number; + userId: number; + foodType: $Enums.FoodType; + storeMethod: $Enums.StoreMethod; count: number; - days_before_expiration: number; + daysBeforeExpiration: number; icon: string; - created_at: Date; - updated_at: Date; + createdAt: Date; + updatedAt: Date; } diff --git a/api/libs/ingredient/src/dto/filter-ingredient.dto.ts b/api/libs/ingredient/src/dto/filter-ingredient.dto.ts index 64bb31c..1feafae 100644 --- a/api/libs/ingredient/src/dto/filter-ingredient.dto.ts +++ b/api/libs/ingredient/src/dto/filter-ingredient.dto.ts @@ -8,8 +8,8 @@ import { Max, Min, } from 'class-validator'; -import { FoodType } from '../types/food-type.enum'; -import { StoreMethod } from '../types/store-method.enum'; +import { FoodType } from '../domain/food-type.enum'; +import { StoreMethod } from '../domain/store-method.enum'; export class FilterUserIngredientDto { @IsString() @@ -20,15 +20,15 @@ export class FilterUserIngredientDto { @IsString() @IsMongoId() @IsOptional() - user_id?: string; + userId?: string; @IsEnum(FoodType) @IsOptional() - food_type?: FoodType; + foodType?: FoodType; @IsEnum(StoreMethod) @IsOptional() - store_method?: StoreMethod; + storeMethod?: StoreMethod; @IsNumber() @Min(1) @@ -40,5 +40,5 @@ export class FilterUserIngredientDto { @Min(0) @Max(365) @IsOptional() - days_before_expiration?: number; + daysBeforeExpiration?: number; } diff --git a/api/libs/ingredient/src/dto/ingredient-response.dto.ts b/api/libs/ingredient/src/dto/ingredient-response.dto.ts index 9daa7b9..b604610 100644 --- a/api/libs/ingredient/src/dto/ingredient-response.dto.ts +++ b/api/libs/ingredient/src/dto/ingredient-response.dto.ts @@ -3,7 +3,7 @@ import { OkResponse, } from '@app/common/dto/success-response.dto'; import { BarcodeInfos } from 'proto/image_process/BarcodeInfos'; -import { UserIngredient } from '../entities/mongo/mongo.user-ingredient.entity'; +import { UserIngredient } from '@app/ingredient/domain/mongo/mongo.user-ingredient.entity'; export class CreateUserIngredientResponseDto extends CreatedResponse { data: UserIngredient; diff --git a/api/libs/ingredient/src/dto/modify-ingredient.dto.ts b/api/libs/ingredient/src/dto/modify-ingredient.dto.ts index dc137f4..df882d6 100644 --- a/api/libs/ingredient/src/dto/modify-ingredient.dto.ts +++ b/api/libs/ingredient/src/dto/modify-ingredient.dto.ts @@ -10,8 +10,8 @@ import { Max, Min, } from 'class-validator'; -import { FoodType } from '../types/food-type.enum'; -import { StoreMethod } from '../types/store-method.enum'; +import { FoodType } from '../domain/food-type.enum'; +import { StoreMethod } from '../domain/store-method.enum'; export class CreateUserIngredientDto { @IsString() @@ -21,19 +21,19 @@ export class CreateUserIngredientDto { @IsMongoId() @IsNotEmpty() @IsOptional() - ingredient_id?: string; + ingredientId?: string; @IsMongoId() @IsNotEmpty() @IsOptional() @ApiHideProperty() - user_id?: string; + userId?: string; @IsEnum(FoodType) - food_type: FoodType; + foodType: FoodType; @IsEnum(StoreMethod) - store_method: StoreMethod; + storeMethod: StoreMethod; @IsNumber() @Min(1) @@ -43,7 +43,7 @@ export class CreateUserIngredientDto { @IsNumber() @Min(0) @Max(365) - days_before_expiration: number; + daysBeforeExpiration: number; } export class UpdateUserIngredientDto extends PartialType( @@ -54,5 +54,5 @@ export class GetIngredientInfoDto { @IsString() @IsUrl() @IsNotEmpty() - image_url: string; + imageUrl: string; } diff --git a/api/libs/ingredient/src/ingredient.module.ts b/api/libs/ingredient/src/ingredient.module.ts index 066a257..f7e0132 100644 --- a/api/libs/ingredient/src/ingredient.module.ts +++ b/api/libs/ingredient/src/ingredient.module.ts @@ -1,12 +1,12 @@ import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; -import { UserIngredientController } from './controllers/user-ingredient.controller'; +import { UserIngredientController } from './user-ingredient.controller'; import { UserIngredient, UserIngredientSchemaFactory, -} from './entities/mongo/mongo.user-ingredient.entity'; +} from '@app/ingredient/domain/mongo/mongo.user-ingredient.entity'; import { UserIngredientRepository } from './repositories/user-ingredient.repository'; -import { UserIngredientService } from './services/user-ingredient.service'; +import { UserIngredientService } from './user-ingredient.service'; import { ConfigService } from '@nestjs/config'; import { join } from 'path'; import { ClientsModule, Transport } from '@nestjs/microservices'; diff --git a/api/libs/ingredient/src/repositories/mongo/mongo.user-ingredient.repository.ts b/api/libs/ingredient/src/repositories/mongo.user-ingredient.repository.ts similarity index 73% rename from api/libs/ingredient/src/repositories/mongo/mongo.user-ingredient.repository.ts rename to api/libs/ingredient/src/repositories/mongo.user-ingredient.repository.ts index 10fc167..cc98614 100644 --- a/api/libs/ingredient/src/repositories/mongo/mongo.user-ingredient.repository.ts +++ b/api/libs/ingredient/src/repositories/mongo.user-ingredient.repository.ts @@ -1,17 +1,17 @@ import { Injectable } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; -import { FilterUserIngredientDto } from '../../dto/filter-ingredient.dto'; +import { FilterUserIngredientDto } from '../dto/filter-ingredient.dto'; import { CreateUserIngredientDto, UpdateUserIngredientDto, -} from '../../dto/modify-ingredient.dto'; +} from '../dto/modify-ingredient.dto'; import { UserIngredient, UserIngredientDocument, -} from '../../entities/mongo/mongo.user-ingredient.entity'; +} from '@app/ingredient/domain/mongo/mongo.user-ingredient.entity'; import { CrudMongoRepository } from '@app/common/repository/crud-mongo.repository'; -import { IUserIngredientRepository } from '../user-ingredient.repository.interface'; +import { IUserIngredientRepository } from './user-ingredient.repository.interface'; @Injectable() export class UserIngredientRepository diff --git a/api/libs/ingredient/src/repositories/user-ingredient.repository.interface.ts b/api/libs/ingredient/src/repositories/user-ingredient.repository.interface.ts index aac7956..62b01bc 100644 --- a/api/libs/ingredient/src/repositories/user-ingredient.repository.interface.ts +++ b/api/libs/ingredient/src/repositories/user-ingredient.repository.interface.ts @@ -1,6 +1,6 @@ import { ICrudRepository } from '@app/common/repository/crud.repository'; -import { UserIngredient as MongoUserIngredient } from '../entities/mongo/mongo.user-ingredient.entity'; -import { UserIngredient as PrismaUserIngredient } from '../entities/user-ingredient.entity'; +import { UserIngredient as MongoUserIngredient } from '@app/ingredient/domain/mongo/mongo.user-ingredient.entity'; +import { UserIngredient as PrismaUserIngredient } from '../domain/user-ingredient.entity'; import { CreateUserIngredientDto, UpdateUserIngredientDto, @@ -9,14 +9,6 @@ import { FilterUserIngredientDto } from '../dto/filter-ingredient.dto'; type UserIngredient = MongoUserIngredient | PrismaUserIngredient; -// export interface IUserIngredientRepository -// extends ICrudRepository< -// UserIngredient, -// CreateUserIngredientDto, -// UpdateUserIngredientDto, -// FilterUserIngredientDto -// > {} - export type IUserIngredientRepository = ICrudRepository< UserIngredient, CreateUserIngredientDto, diff --git a/api/libs/ingredient/src/repositories/user-ingredient.repository.ts b/api/libs/ingredient/src/repositories/user-ingredient.repository.ts index 3723e4f..3c46098 100644 --- a/api/libs/ingredient/src/repositories/user-ingredient.repository.ts +++ b/api/libs/ingredient/src/repositories/user-ingredient.repository.ts @@ -1,5 +1,5 @@ import { CrudPrismaRepository } from '@app/common/repository/crud-prisma.repository'; -import { UserIngredient } from '../entities/user-ingredient.entity'; +import { UserIngredient } from '../domain/user-ingredient.entity'; import { CreateUserIngredientDto, UpdateUserIngredientDto, diff --git a/api/libs/ingredient/src/controllers/user-ingredient.controller.ts b/api/libs/ingredient/src/user-ingredient.controller.ts similarity index 89% rename from api/libs/ingredient/src/controllers/user-ingredient.controller.ts rename to api/libs/ingredient/src/user-ingredient.controller.ts index 5fa9d89..08bda55 100644 --- a/api/libs/ingredient/src/controllers/user-ingredient.controller.ts +++ b/api/libs/ingredient/src/user-ingredient.controller.ts @@ -29,19 +29,19 @@ import { FindOneUserIngredientResponseDto, GetIngredientInfoResponseDto, UpdateUserIngredientResponseDto, -} from '../dto/ingredient-response.dto'; +} from './dto/ingredient-response.dto'; import { CreateUserIngredientDto, GetIngredientInfoDto, UpdateUserIngredientDto, -} from '../dto/modify-ingredient.dto'; -import { UserIngredientService } from '../services/user-ingredient.service'; -import { FoodType } from '../types/food-type.enum'; -import { StoreMethod } from '../types/store-method.enum'; -import { FilterUserIngredientDto } from '../dto/filter-ingredient.dto'; +} from './dto/modify-ingredient.dto'; +import { UserIngredientService } from './user-ingredient.service'; +import { FoodType } from './domain/food-type.enum'; +import { StoreMethod } from './domain/store-method.enum'; +import { FilterUserIngredientDto } from './dto/filter-ingredient.dto'; import { queryBuilder } from '@app/common/utils/query-builder'; import { ReqUser } from '@app/common/decorators/req-user.decorator'; -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; @ApiTags('Ingredient') @Controller('ingredient') @@ -60,7 +60,7 @@ export class UserIngredientController { @Body() createIngredientDto: CreateUserIngredientDto, @ReqUser() user: User, ) { - createIngredientDto.user_id = user.id.toString(); + createIngredientDto.userId = user.id.toString(); return this.ingredientService.create(createIngredientDto); } diff --git a/api/libs/ingredient/src/services/user-ingredient.service.ts b/api/libs/ingredient/src/user-ingredient.service.ts similarity index 72% rename from api/libs/ingredient/src/services/user-ingredient.service.ts rename to api/libs/ingredient/src/user-ingredient.service.ts index 820c842..dcc67f7 100644 --- a/api/libs/ingredient/src/services/user-ingredient.service.ts +++ b/api/libs/ingredient/src/user-ingredient.service.ts @@ -1,21 +1,16 @@ import { Metadata } from '@grpc/grpc-js'; -import { - Inject, - Injectable, - NotFoundException, - OnModuleInit, -} from '@nestjs/common'; +import { Inject, Injectable, OnModuleInit } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { ClientGrpc } from '@nestjs/microservices'; -import { BarcodeInfos } from 'proto/image_process/BarcodeInfos'; +import { BarcodeInfos } from '../../../proto/image_process/BarcodeInfos'; import { lastValueFrom, Observable } from 'rxjs'; -import { FilterUserIngredientDto } from '../dto/filter-ingredient.dto'; +import { FilterUserIngredientDto } from './dto/filter-ingredient.dto'; import { CreateUserIngredientDto, UpdateUserIngredientDto, -} from '../dto/modify-ingredient.dto'; -import { UserIngredient } from '../entities/user-ingredient.entity'; -import { UserIngredientRepository } from '../repositories/user-ingredient.repository'; +} from './dto/modify-ingredient.dto'; +import { UserIngredient } from './domain/user-ingredient.entity'; +import { UserIngredientRepository } from './repositories/user-ingredient.repository'; import { CrudService } from '@app/common/crud.service'; interface ImageProcessService { @@ -36,6 +31,7 @@ export class UserIngredientService implements OnModuleInit { private imageProcessService: ImageProcessService; + constructor( private readonly userIngredientRepository: UserIngredientRepository, private readonly jwtService: JwtService, @@ -50,7 +46,7 @@ export class UserIngredientService } async getIngredientInfoFromBarcode( - getIngredientInfoDto: { image_url: string }, + getIngredientInfoDto: { imageUrl: string }, cred: string, ) { const metadata = new Metadata(); @@ -59,7 +55,7 @@ export class UserIngredientService const ret = await lastValueFrom( this.imageProcessService.getBarcodeInfoFromUrl( { - image_url: getIngredientInfoDto.image_url, + image_url: getIngredientInfoDto.imageUrl, }, metadata, ), diff --git a/api/libs/ingredient/src/repositories/mongo/mongo.user-ingredient.repository.spec.ts b/api/libs/ingredient/test/integration/mongo.user-ingredient.repository.spec.ts similarity index 77% rename from api/libs/ingredient/src/repositories/mongo/mongo.user-ingredient.repository.spec.ts rename to api/libs/ingredient/test/integration/mongo.user-ingredient.repository.spec.ts index 3d07aaa..324fdb5 100644 --- a/api/libs/ingredient/src/repositories/mongo/mongo.user-ingredient.repository.spec.ts +++ b/api/libs/ingredient/test/integration/mongo.user-ingredient.repository.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { UserIngredientRepository } from './mongo.user-ingredient.repository'; +import { UserIngredientRepository } from '@app/ingredient/repositories/mongo.user-ingredient.repository'; describe('IngredientRepository', () => { let repository: UserIngredientRepository; diff --git a/api/libs/ingredient/src/controllers/user-ingredient.controller.spec.ts b/api/libs/ingredient/test/integration/user-ingredient.controller.spec.ts similarity index 80% rename from api/libs/ingredient/src/controllers/user-ingredient.controller.spec.ts rename to api/libs/ingredient/test/integration/user-ingredient.controller.spec.ts index c0b49d7..1f98439 100644 --- a/api/libs/ingredient/src/controllers/user-ingredient.controller.spec.ts +++ b/api/libs/ingredient/test/integration/user-ingredient.controller.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { UserIngredientController } from './user-ingredient.controller'; +import { UserIngredientController } from '@app/ingredient/user-ingredient.controller'; describe('IngredientController', () => { let controller: UserIngredientController; diff --git a/api/libs/ingredient/src/services/user-ingredient.service.spec.ts b/api/libs/ingredient/test/unit/user-ingredient.service.spec.ts similarity index 80% rename from api/libs/ingredient/src/services/user-ingredient.service.spec.ts rename to api/libs/ingredient/test/unit/user-ingredient.service.spec.ts index 8bcabd4..846d918 100644 --- a/api/libs/ingredient/src/services/user-ingredient.service.spec.ts +++ b/api/libs/ingredient/test/unit/user-ingredient.service.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { UserIngredientService } from './user-ingredient.service'; +import { UserIngredientService } from '@app/ingredient/user-ingredient.service'; describe('IngredientService', () => { let service: UserIngredientService; diff --git a/api/libs/noti/src/entity/device-token.entity.ts b/api/libs/noti/src/domain/device-token.entity.ts similarity index 60% rename from api/libs/noti/src/entity/device-token.entity.ts rename to api/libs/noti/src/domain/device-token.entity.ts index ec3d460..6fd521b 100644 --- a/api/libs/noti/src/entity/device-token.entity.ts +++ b/api/libs/noti/src/domain/device-token.entity.ts @@ -2,8 +2,8 @@ import { DeviceToken as DeviceTokenType } from '@prisma/client'; export class DeviceToken implements DeviceTokenType { id: number; - user_id: number; - fcm_device_token: string; - created_at: Date; - updated_at: Date; + userId: number; + fcmDeviceToken: string; + createdAt: Date; + updatedAt: Date; } diff --git a/api/libs/noti/src/entity/mongo/mongo.device-token.entity.ts b/api/libs/noti/src/domain/mongo/mongo.device-token.entity.ts similarity index 93% rename from api/libs/noti/src/entity/mongo/mongo.device-token.entity.ts rename to api/libs/noti/src/domain/mongo/mongo.device-token.entity.ts index ae14d58..b7ce6c0 100644 --- a/api/libs/noti/src/entity/mongo/mongo.device-token.entity.ts +++ b/api/libs/noti/src/domain/mongo/mongo.device-token.entity.ts @@ -1,5 +1,5 @@ import { schemaOptions } from '@app/common/utils/schema-option'; -import { User } from '@app/user/entities/mongo.user.entity'; +import { User } from '@app/user/domain/mongo.user.entity'; import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Schema as MongooseSchema } from 'mongoose'; diff --git a/api/libs/noti/src/entity/mongo/mongo.noti.entity.ts b/api/libs/noti/src/domain/mongo/mongo.noti.entity.ts similarity index 92% rename from api/libs/noti/src/entity/mongo/mongo.noti.entity.ts rename to api/libs/noti/src/domain/mongo/mongo.noti.entity.ts index e20ea9d..4bca8e7 100644 --- a/api/libs/noti/src/entity/mongo/mongo.noti.entity.ts +++ b/api/libs/noti/src/domain/mongo/mongo.noti.entity.ts @@ -1,5 +1,5 @@ import { schemaOptions } from '@app/common/utils/schema-option'; -import { User } from '@app/user/entities/mongo.user.entity'; +import { User } from '@app/user/domain/mongo.user.entity'; import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Schema as MongooseSchema } from 'mongoose'; diff --git a/api/libs/noti/src/entity/noti.entity.ts b/api/libs/noti/src/domain/noti.entity.ts similarity index 68% rename from api/libs/noti/src/entity/noti.entity.ts rename to api/libs/noti/src/domain/noti.entity.ts index 2c70bc3..c2ff1f5 100644 --- a/api/libs/noti/src/entity/noti.entity.ts +++ b/api/libs/noti/src/domain/noti.entity.ts @@ -2,8 +2,8 @@ import { Noti as NotiType } from '@prisma/client'; export class Noti implements NotiType { id: number; - user_id: number; + userId: number; content: string; - created_at: Date; - updated_at: Date; + createdAt: Date; + updatedAt: Date; } diff --git a/api/libs/noti/src/dto/device-token-response.dto.ts b/api/libs/noti/src/dto/device-token-response.dto.ts index ce983bc..7bdadf1 100644 --- a/api/libs/noti/src/dto/device-token-response.dto.ts +++ b/api/libs/noti/src/dto/device-token-response.dto.ts @@ -1,5 +1,5 @@ import { CreatedResponse } from '@app/common/dto/success-response.dto'; -import { DeviceToken } from '../entity/device-token.entity'; +import { DeviceToken } from '@app/noti/domain/device-token.entity'; export class CreateDeviceTokenResponseDto extends CreatedResponse { data: DeviceToken; diff --git a/api/libs/noti/src/dto/filter-device-token.dto.ts b/api/libs/noti/src/dto/filter-device-token.dto.ts index ca8b4a5..b4776cf 100644 --- a/api/libs/noti/src/dto/filter-device-token.dto.ts +++ b/api/libs/noti/src/dto/filter-device-token.dto.ts @@ -2,5 +2,5 @@ import { IsInt } from 'class-validator'; export class FilterDeviceTokenDto { @IsInt() - user_id: number; + userId: number; } diff --git a/api/libs/noti/src/dto/filter-noti.dto.ts b/api/libs/noti/src/dto/filter-noti.dto.ts index 3c5b4b8..b4df3df 100644 --- a/api/libs/noti/src/dto/filter-noti.dto.ts +++ b/api/libs/noti/src/dto/filter-noti.dto.ts @@ -2,5 +2,5 @@ import { IsInt } from 'class-validator'; export class FilterNotiDto { @IsInt() - user_id: number; + userId: number; } diff --git a/api/libs/noti/src/dto/modify-device-token.dto.ts b/api/libs/noti/src/dto/modify-device-token.dto.ts index 12abc29..6c48b60 100644 --- a/api/libs/noti/src/dto/modify-device-token.dto.ts +++ b/api/libs/noti/src/dto/modify-device-token.dto.ts @@ -5,10 +5,10 @@ import { IsInt, IsNotEmpty, IsString } from 'class-validator'; export class CreateDeviceTokenDto { @IsString() @IsNotEmpty() - fcm_device_token: string; + fcmDeviceToken: string; @ApiHideProperty() @Optional() @IsInt() - user_id: number; + userId: number; } diff --git a/api/libs/noti/src/dto/modify-noti.dto.ts b/api/libs/noti/src/dto/modify-noti.dto.ts index e569a58..1fb0894 100644 --- a/api/libs/noti/src/dto/modify-noti.dto.ts +++ b/api/libs/noti/src/dto/modify-noti.dto.ts @@ -5,7 +5,7 @@ import { IsInt, IsNotEmpty, IsString } from 'class-validator'; export class CreateNotiDto { @Transform(({ value }) => parseInt(value)) @IsInt() - user_id: number; + userId: number; @IsString() @IsNotEmpty() @@ -13,5 +13,5 @@ export class CreateNotiDto { } export class UpdateNotiDto extends PartialType( - OmitType(CreateNotiDto, ['user_id'] as const), + OmitType(CreateNotiDto, ['userId'] as const), ) {} diff --git a/api/libs/noti/src/dto/noti-response.dto.ts b/api/libs/noti/src/dto/noti-response.dto.ts index f5cd3e7..ade4545 100644 --- a/api/libs/noti/src/dto/noti-response.dto.ts +++ b/api/libs/noti/src/dto/noti-response.dto.ts @@ -3,7 +3,7 @@ import { NoContentResponse, OkResponse, } from '@app/common/dto/success-response.dto'; -import { Noti } from '../entity/noti.entity'; +import { Noti } from '@app/noti/domain/noti.entity'; export class CreateNotiResponseDto extends CreatedResponse { data: Noti; diff --git a/api/libs/noti/src/controller/noti.controller.ts b/api/libs/noti/src/noti.controller.ts similarity index 79% rename from api/libs/noti/src/controller/noti.controller.ts rename to api/libs/noti/src/noti.controller.ts index 609f2ab..b943632 100644 --- a/api/libs/noti/src/controller/noti.controller.ts +++ b/api/libs/noti/src/noti.controller.ts @@ -7,9 +7,9 @@ import { ParseIntPipe, Post, } from '@nestjs/common'; -import { NotiService } from '../service/noti.service'; -import { DeviceTokenService } from '../service/device-token.service'; -import { CreateNotiDto, UpdateNotiDto } from '../dto/modify-noti.dto'; +import { NotiService } from './service/noti.service'; +import { DeviceTokenService } from './service/device-token.service'; +import { CreateNotiDto, UpdateNotiDto } from './dto/modify-noti.dto'; import { ApiDeleteNoContent, ApiGet, @@ -22,12 +22,12 @@ import { FindNotisResponseDto, FindOneNotiResponseDto, UpdateNotiResponseDto, -} from '../dto/noti-response.dto'; -import { CreateDeviceTokenDto } from '../dto/modify-device-token.dto'; -import { CreateDeviceTokenResponseDto } from '../dto/device-token-response.dto'; +} from './dto/noti-response.dto'; +import { CreateDeviceTokenDto } from './dto/modify-device-token.dto'; +import { CreateDeviceTokenResponseDto } from './dto/device-token-response.dto'; import { ApiTags } from '@nestjs/swagger'; import { ReqUser } from '@app/common/decorators/req-user.decorator'; -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; @ApiTags('Noti') @Controller('noti') @@ -44,7 +44,7 @@ export class NotiController { @Body() createDeviceTokenDto: CreateDeviceTokenDto, @ReqUser() user: User, ) { - createDeviceTokenDto.user_id = user.id; + createDeviceTokenDto.userId = user.id; return await this.deviceTokenService.create(createDeviceTokenDto); } @@ -63,7 +63,7 @@ export class NotiController { @Get() async findAllNotis(@ReqUser() user: User) { return await this.notiService.findAll({ - user_id: user.id, + userId: user.id, }); } diff --git a/api/libs/noti/src/noti.module.ts b/api/libs/noti/src/noti.module.ts index ea964c6..4a9d3c7 100644 --- a/api/libs/noti/src/noti.module.ts +++ b/api/libs/noti/src/noti.module.ts @@ -8,12 +8,12 @@ import { NotiRepository } from './repository/noti.repository'; import { DeviceTokenRepository } from './repository/device-token.repository'; import { DeviceTokenService } from './service/device-token.service'; import { MongooseModule } from '@nestjs/mongoose'; -import { Noti, NotiSchema } from './entity/mongo/mongo.noti.entity'; +import { Noti, NotiSchema } from '@app/noti/domain/mongo/mongo.noti.entity'; import { DeviceToken, DeviceTokenSchema, -} from './entity/mongo/mongo.device-token.entity'; -import { NotiController } from './controller/noti.controller'; +} from '@app/noti/domain/mongo/mongo.device-token.entity'; +import { NotiController } from './noti.controller'; // export const FCM_MESSAGING = Symbol('FCM_MESSAGING'); diff --git a/api/libs/noti/src/repository/device-token.repository.interface.ts b/api/libs/noti/src/repository/device-token.repository.interface.ts index cec75dc..5539ac4 100644 --- a/api/libs/noti/src/repository/device-token.repository.interface.ts +++ b/api/libs/noti/src/repository/device-token.repository.interface.ts @@ -1,5 +1,5 @@ -import { DeviceToken as MongoDeviceToken } from '../entity/mongo/mongo.device-token.entity'; -import { DeviceToken as PrismaDeviceToken } from '../entity/device-token.entity'; +import { DeviceToken as MongoDeviceToken } from '@app/noti/domain/mongo/mongo.device-token.entity'; +import { DeviceToken as PrismaDeviceToken } from '@app/noti/domain/device-token.entity'; import { CreateDeviceTokenDto } from '../dto/modify-device-token.dto'; import { FilterDeviceTokenDto } from '../dto/filter-device-token.dto'; import { ICrudRepository } from '@app/common/repository/crud.repository'; diff --git a/api/libs/noti/src/repository/device-token.repository.ts b/api/libs/noti/src/repository/device-token.repository.ts index 5bbd791..18e6222 100644 --- a/api/libs/noti/src/repository/device-token.repository.ts +++ b/api/libs/noti/src/repository/device-token.repository.ts @@ -1,6 +1,6 @@ import { CrudPrismaRepository } from '@app/common/repository/crud-prisma.repository'; import { Injectable } from '@nestjs/common'; -import { DeviceToken } from '../entity/device-token.entity'; +import { DeviceToken } from '@app/noti/domain/device-token.entity'; import { CreateDeviceTokenDto } from '../dto/modify-device-token.dto'; import { FilterDeviceTokenDto } from '../dto/filter-device-token.dto'; import { PrismaService } from '@app/common/prisma/prisma.service'; diff --git a/api/libs/noti/src/repository/mongo/mongo.device-token.repository.ts b/api/libs/noti/src/repository/mongo/mongo.device-token.repository.ts index ceb3528..2437954 100644 --- a/api/libs/noti/src/repository/mongo/mongo.device-token.repository.ts +++ b/api/libs/noti/src/repository/mongo/mongo.device-token.repository.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { DeviceToken, DeviceTokenDocument, -} from '../../entity/mongo/mongo.device-token.entity'; +} from '@app/noti/domain/mongo/mongo.device-token.entity'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; import { CrudMongoRepository } from '@app/common/repository/crud-mongo.repository'; diff --git a/api/libs/noti/src/repository/mongo/mongo.noti.repository.ts b/api/libs/noti/src/repository/mongo/mongo.noti.repository.ts index 12ba44c..517e649 100644 --- a/api/libs/noti/src/repository/mongo/mongo.noti.repository.ts +++ b/api/libs/noti/src/repository/mongo/mongo.noti.repository.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; import { InjectModel } from '@nestjs/mongoose'; import { CrudMongoRepository } from '@app/common/repository/crud-mongo.repository'; -import { Noti, NotiDocument } from '../../entity/mongo/mongo.noti.entity'; +import { Noti, NotiDocument } from '@app/noti/domain/mongo/mongo.noti.entity'; import { CreateNotiDto, UpdateNotiDto } from '../../dto/modify-noti.dto'; import { FilterNotiDto } from '../../dto/filter-noti.dto'; diff --git a/api/libs/noti/src/repository/noti.repository.interface.ts b/api/libs/noti/src/repository/noti.repository.interface.ts index ec03968..229dd00 100644 --- a/api/libs/noti/src/repository/noti.repository.interface.ts +++ b/api/libs/noti/src/repository/noti.repository.interface.ts @@ -1,8 +1,8 @@ import { ICrudRepository } from '@app/common/repository/crud.repository'; import { FilterNotiDto } from '../dto/filter-noti.dto'; import { CreateNotiDto, UpdateNotiDto } from '../dto/modify-noti.dto'; -import { Noti as MongoNoti } from '../entity/mongo/mongo.noti.entity'; -import { Noti as PrismaNoti } from '../entity/noti.entity'; +import { Noti as MongoNoti } from '@app/noti/domain/mongo/mongo.noti.entity'; +import { Noti as PrismaNoti } from '@app/noti/domain/noti.entity'; type Noti = MongoNoti | PrismaNoti; diff --git a/api/libs/noti/src/repository/noti.repository.ts b/api/libs/noti/src/repository/noti.repository.ts index 4b7e9cc..d8c9076 100644 --- a/api/libs/noti/src/repository/noti.repository.ts +++ b/api/libs/noti/src/repository/noti.repository.ts @@ -1,7 +1,7 @@ import { CrudPrismaRepository } from '@app/common/repository/crud-prisma.repository'; import { FilterNotiDto } from '../dto/filter-noti.dto'; import { CreateNotiDto, UpdateNotiDto } from '../dto/modify-noti.dto'; -import { Noti } from '../entity/noti.entity'; +import { Noti } from '@app/noti/domain/noti.entity'; import { INotiRepository } from './noti.repository.interface'; import { PrismaService } from '@app/common/prisma/prisma.service'; import { Injectable } from '@nestjs/common'; diff --git a/api/libs/noti/src/service/device-token.service.ts b/api/libs/noti/src/service/device-token.service.ts index 6990a5a..d00b62e 100644 --- a/api/libs/noti/src/service/device-token.service.ts +++ b/api/libs/noti/src/service/device-token.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { DeviceTokenRepository } from '../repository/device-token.repository'; import { CreateDeviceTokenDto } from '../dto/modify-device-token.dto'; -import { DeviceToken } from '../entity/device-token.entity'; +import { DeviceToken } from '@app/noti/domain/device-token.entity'; import { CrudService } from '@app/common/crud.service'; import { FilterDeviceTokenDto } from '../dto/filter-device-token.dto'; diff --git a/api/libs/noti/src/service/noti.service.ts b/api/libs/noti/src/service/noti.service.ts index b856230..ae6f83b 100644 --- a/api/libs/noti/src/service/noti.service.ts +++ b/api/libs/noti/src/service/noti.service.ts @@ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Messaging } from 'firebase-admin/messaging'; // import { FCM_MESSAGING } from '../noti.module'; import { CrudService } from '@app/common/crud.service'; -import { Noti } from '../entity/noti.entity'; +import { Noti } from '@app/noti/domain/noti.entity'; import { CreateNotiDto, UpdateNotiDto } from '../dto/modify-noti.dto'; import { NotiRepository } from '../repository/noti.repository'; import { FilterNotiDto } from '../dto/filter-noti.dto'; diff --git a/api/libs/noti/src/service/device-token.service.spec.ts b/api/libs/noti/test/unit/device-token.service.spec.ts similarity index 73% rename from api/libs/noti/src/service/device-token.service.spec.ts rename to api/libs/noti/test/unit/device-token.service.spec.ts index 4f4d869..63988bf 100644 --- a/api/libs/noti/src/service/device-token.service.spec.ts +++ b/api/libs/noti/test/unit/device-token.service.spec.ts @@ -1,6 +1,6 @@ import { TestBed } from '@automock/jest'; -import { DeviceTokenService } from './device-token.service'; -import { DeviceTokenRepository } from '../repository/device-token.repository'; +import { DeviceTokenService } from '@app/noti/service/device-token.service'; +import { DeviceTokenRepository } from '@app/noti/repository/device-token.repository'; describe('DeviceTokenService Test', () => { let service: DeviceTokenService; diff --git a/api/libs/noti/src/service/noti.service.spec.ts b/api/libs/noti/test/unit/noti.service.spec.ts similarity index 81% rename from api/libs/noti/src/service/noti.service.spec.ts rename to api/libs/noti/test/unit/noti.service.spec.ts index 297bd52..2fd1a4d 100644 --- a/api/libs/noti/src/service/noti.service.spec.ts +++ b/api/libs/noti/test/unit/noti.service.spec.ts @@ -1,6 +1,6 @@ import { TestBed } from '@automock/jest'; -import { NotiService } from './noti.service'; -import { NotiRepository } from '../repository/noti.repository'; +import { NotiService } from '@app/noti/service/noti.service'; +import { NotiRepository } from '@app/noti/repository/noti.repository'; import { Messaging } from 'firebase-admin/messaging'; describe('NotiService Test', () => { diff --git a/api/libs/recipe/src/controllers/recipe-bookmark.controller.ts b/api/libs/recipe/src/controllers/recipe-bookmark.controller.ts index 8a27fcd..d5d0718 100644 --- a/api/libs/recipe/src/controllers/recipe-bookmark.controller.ts +++ b/api/libs/recipe/src/controllers/recipe-bookmark.controller.ts @@ -22,7 +22,7 @@ import { } from '../dto/recipe-bookmark/recipe-bookmark-response.dto'; import { CreateRecipeBookmarkDto } from '../dto/recipe-bookmark/modify-recipe-bookmark.dto'; import { ReqUser } from '@app/common/decorators/req-user.decorator'; -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { FilterRecipeBookmarkDto } from '../dto/recipe-bookmark/filter-recipe-bookmark.dto'; @ApiTags('RecipeBookmark') @@ -37,7 +37,7 @@ export class RecipeBookmarkController { @Body() createRecipeBookmarkDto: CreateRecipeBookmarkDto, @ReqUser() user: User, ) { - createRecipeBookmarkDto.user_id = user.id; + createRecipeBookmarkDto.userId = user.id; return await this.recipeBookmarkService.create(createRecipeBookmarkDto); } @@ -54,7 +54,7 @@ export class RecipeBookmarkController { @Query() filterRecipeBookmarkDto: FilterRecipeBookmarkDto, @ReqUser() user: User, ) { - filterRecipeBookmarkDto.user_id = user.id; + filterRecipeBookmarkDto.userId = user.id; return await this.recipeBookmarkService.findAllRecipeBookmarked( filterRecipeBookmarkDto, ); diff --git a/api/libs/recipe/src/controllers/recipe.controller.ts b/api/libs/recipe/src/controllers/recipe.controller.ts index 8b7fa34..52ad279 100644 --- a/api/libs/recipe/src/controllers/recipe.controller.ts +++ b/api/libs/recipe/src/controllers/recipe.controller.ts @@ -6,7 +6,7 @@ import { ApiPostCreated, } from '@app/common/decorators/http-method.decorator'; import { ReqUser } from '@app/common/decorators/req-user.decorator'; -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { Body, Controller, @@ -14,18 +14,14 @@ import { Get, HttpCode, HttpStatus, + Ip, Param, + ParseIntPipe, Patch, Post, Query, - Ip, - ParseIntPipe, } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { - CreateMongoRecipeDto, - UpdateRecipeDto, -} from '../dto/recipe/modify-recipe.dto'; import { CreateRecipeResponseDto, FindOneRecipeResponseDto, @@ -41,6 +37,8 @@ import { } from '../dto/recipe/filter-recipe.dto'; import { Public } from '@app/common/decorators/public.decorator'; import { RecipeViewerIdentifier } from '../dto/recipe-view-log/recipe-viewer-identifier'; +import { CreateMongoRecipeDto } from '@app/recipe/dto/recipe/create-mongo-recipe.dto'; +import { UpdateRecipeDto } from '@app/recipe/dto/recipe/update-recipe.dto'; @ApiTags('Recipe') @Controller('recipe') diff --git a/api/libs/recipe/src/entities/mongo/mongo.recipe-bookmark.entity.ts b/api/libs/recipe/src/domain/mongo/mongo.recipe-bookmark.entity.ts similarity index 100% rename from api/libs/recipe/src/entities/mongo/mongo.recipe-bookmark.entity.ts rename to api/libs/recipe/src/domain/mongo/mongo.recipe-bookmark.entity.ts diff --git a/api/libs/recipe/src/entities/mongo/mongo.recipe-view-log.entity.ts b/api/libs/recipe/src/domain/mongo/mongo.recipe-view-log.entity.ts similarity index 100% rename from api/libs/recipe/src/entities/mongo/mongo.recipe-view-log.entity.ts rename to api/libs/recipe/src/domain/mongo/mongo.recipe-view-log.entity.ts diff --git a/api/libs/recipe/src/entities/mongo/mongo.recipe.entity.ts b/api/libs/recipe/src/domain/mongo/mongo.recipe.entity.ts similarity index 51% rename from api/libs/recipe/src/entities/mongo/mongo.recipe.entity.ts rename to api/libs/recipe/src/domain/mongo/mongo.recipe.entity.ts index 1f1aaa4..395f417 100644 --- a/api/libs/recipe/src/entities/mongo/mongo.recipe.entity.ts +++ b/api/libs/recipe/src/domain/mongo/mongo.recipe.entity.ts @@ -5,8 +5,6 @@ import { schemaOptions } from '@app/common/utils/schema-option'; export type RecipeDocument = HydratedDocument; export class IngredientRequirement { - ingredient_id: Types.ObjectId; - name: string; amount: string; @@ -30,8 +28,8 @@ export class Recipe { }) id: Types.ObjectId; - @Prop({ required: false, index: true }) - mysql_id: number; + @Prop({ required: false, index: true, path: 'mysql_id' }) + mysqlId: number; @Prop({ required: true }) name: string; @@ -39,32 +37,36 @@ export class Recipe { @Prop({ required: true }) description: string; - @Prop({ required: false }) - owner_id: number; + @Prop({ required: false, index: true, path: 'owner_id' }) + ownerId: number; - @Prop({ required: true, type: Array }) - ingredient_requirements: Array; + @Prop({ + required: true, + type: Array, + path: 'ingredient_requirements', + }) + ingredientRequirements: Array; - @Prop({ required: true, type: Array }) - recipe_steps: Array; + @Prop({ required: true, type: Array, path: 'recipe_steps' }) + recipeSteps: Array; @Prop({ required: true }) thumbnail: string; - @Prop({ required: true }) - recipe_raw_text: string; + @Prop({ required: true, type: String, path: 'recipe_raw_text' }) + recipeRawText: string; - @Prop({ required: true }) - origin_url: string; + @Prop({ required: true, type: String, path: 'origin_url' }) + originUrl: string; - @Prop({ required: true, default: 0 }) - view_count: number; + @Prop({ required: true, type: Number, path: 'view_count', default: 0 }) + viewCount: number; - @Prop({ required: false }) - created_at: Date; + @Prop({ required: false, path: 'created_at' }) + createdAt: Date; - @Prop({ required: false }) - updated_at: Date; + @Prop({ required: false, path: 'updated_at' }) + updatedAt: Date; } export const RecipeSchema = SchemaFactory.createForClass(Recipe); diff --git a/api/libs/recipe/src/domain/recipe-bookmark.entity.ts b/api/libs/recipe/src/domain/recipe-bookmark.entity.ts new file mode 100644 index 0000000..2b3c3b5 --- /dev/null +++ b/api/libs/recipe/src/domain/recipe-bookmark.entity.ts @@ -0,0 +1,31 @@ +import { RecipeBookmark as RecipeBookmarkType } from '@prisma/client'; +import { Recipe } from './recipe.entity'; +import { User } from '@app/user/domain/user.entity'; + +export class RecipeBookmark implements RecipeBookmarkType { + id: number; + recipeId: number; + recipe: Recipe; + userId: number; + user: User; + createdAt: Date; + updatedAt: Date; + + constructor(props: { + id: number; + recipeId: number; + recipe: Recipe; + userId: number; + user: User; + createdAt: Date; + updatedAt: Date; + }) { + this.id = props.id; + this.recipeId = props.recipeId; + this.recipe = props.recipe; + this.userId = props.userId; + this.user = props.user; + this.createdAt = props.createdAt; + this.updatedAt = props.updatedAt; + } +} diff --git a/api/libs/recipe/src/domain/recipe-view-log.entity.ts b/api/libs/recipe/src/domain/recipe-view-log.entity.ts new file mode 100644 index 0000000..1a32661 --- /dev/null +++ b/api/libs/recipe/src/domain/recipe-view-log.entity.ts @@ -0,0 +1,34 @@ +import { User } from '@app/user/domain/user.entity'; +import { RecipeViewLog as RecipeViewLogType } from '@prisma/client'; +import { Recipe } from './recipe.entity'; + +export class RecipeViewLog implements RecipeViewLogType { + id: number; + recipeId: number; + recipe?: Recipe; + userId: number; + user?: User | null; + userIp: string; + createdAt: Date; + updatedAt: Date; + + constructor(props: { + id: number; + recipeId: number; + recipe: Recipe; + userId: number; + user: User; + userIp: string; + createdAt: Date; + updatedAt: Date; + }) { + this.id = props.id; + this.recipeId = props.recipeId; + this.recipe = props.recipe; + this.userId = props.userId; + this.user = props.user; + this.userIp = props.userIp; + this.createdAt = props.createdAt; + this.updatedAt = props.updatedAt; + } +} diff --git a/api/libs/recipe/src/domain/recipe.entity.ts b/api/libs/recipe/src/domain/recipe.entity.ts new file mode 100644 index 0000000..829c7fc --- /dev/null +++ b/api/libs/recipe/src/domain/recipe.entity.ts @@ -0,0 +1,42 @@ +import { User } from '@app/user/domain/user.entity'; +import { Recipe as RecipeType } from '@prisma/client'; + +export class Recipe implements RecipeType { + id: number; + mongoId: string | null; + name: string; + description: string; + ownerId: number | null; + owner?: User | null; + thumbnail: string; + originUrl: string; + viewCount: number; + createdAt: Date; + updatedAt: Date; + + constructor(props: { + id: number; + mongoId: string | null; + name: string; + description: string; + ownerId: number | null; + owner: User | null; + thumbnail: string; + originUrl: string; + viewCount: number; + createdAt: Date; + updatedAt: Date; + }) { + this.id = props.id; + this.mongoId = props.mongoId; + this.name = props.name; + this.description = props.description; + this.ownerId = props.ownerId; + this.owner = props.owner; + this.thumbnail = props.thumbnail; + this.originUrl = props.originUrl; + this.viewCount = props.viewCount; + this.createdAt = props.createdAt; + this.updatedAt = props.updatedAt; + } +} diff --git a/api/libs/recipe/src/dto/recipe-bookmark/filter-recipe-bookmark.dto.ts b/api/libs/recipe/src/dto/recipe-bookmark/filter-recipe-bookmark.dto.ts index f049049..14f2a3b 100644 --- a/api/libs/recipe/src/dto/recipe-bookmark/filter-recipe-bookmark.dto.ts +++ b/api/libs/recipe/src/dto/recipe-bookmark/filter-recipe-bookmark.dto.ts @@ -4,26 +4,27 @@ import { PagenationResponseDto, } from '@app/common/dto/pagenation.dto'; import { ApiHideProperty } from '@nestjs/swagger'; -import { Recipe } from '../../entities/recipe.entity'; +import { Recipe } from '@app/recipe/domain/recipe.entity'; export class FilterRecipeBookmarkDto extends PagenationDto { @ApiHideProperty() @IsOptional() @IsInt() - user_id?: number; + userId?: number; } export interface IRecipeBookmarkListViewResponseDto extends Omit< Recipe, - | 'mongo_id' - | 'owner_id' - | 'recipe_raw_text' - | 'origin_url' - | 'recipe_steps' - | 'ingredient_requirements' + | 'mongoId' + | 'ownerId' + | 'owner' + | 'recipeRawText' + | 'originUrl' + | 'recipeSteps' + | 'ingredientRequirements' > { - recipe_bookmark_id: number; + recipeBookmarkId: number; } export class RecipeBookmarkListViewResponseDto @@ -33,10 +34,10 @@ export class RecipeBookmarkListViewResponseDto name: string; description: string; thumbnail: string; - view_count: number; - recipe_bookmark_id: number; - created_at: Date; - updated_at: Date; + viewCount: number; + recipeBookmarkId: number; + createdAt: Date; + updatedAt: Date; } export class RecipeBookmarksResponseDto extends PagenationResponseDto { @@ -60,7 +61,7 @@ export class RecipeBookmarksAndCountDto { results: this.recipes, page, count: this.recipes.length, - has_next: this.count > (page - 1) * limit + this.recipes.length, + hasNext: this.count > (page - 1) * limit + this.recipes.length, }; } } diff --git a/api/libs/recipe/src/dto/recipe-bookmark/modify-recipe-bookmark.dto.ts b/api/libs/recipe/src/dto/recipe-bookmark/modify-recipe-bookmark.dto.ts index dadd4ad..c312c77 100644 --- a/api/libs/recipe/src/dto/recipe-bookmark/modify-recipe-bookmark.dto.ts +++ b/api/libs/recipe/src/dto/recipe-bookmark/modify-recipe-bookmark.dto.ts @@ -5,8 +5,8 @@ export class CreateRecipeBookmarkDto { @ApiHideProperty() @IsOptional() @IsInt() - user_id?: number; + userId?: number; @IsInt() - recipe_id: number; + recipeId: number; } diff --git a/api/libs/recipe/src/dto/recipe-bookmark/recipe-bookmark-response.dto.ts b/api/libs/recipe/src/dto/recipe-bookmark/recipe-bookmark-response.dto.ts index afe8ba5..9f33b22 100644 --- a/api/libs/recipe/src/dto/recipe-bookmark/recipe-bookmark-response.dto.ts +++ b/api/libs/recipe/src/dto/recipe-bookmark/recipe-bookmark-response.dto.ts @@ -3,7 +3,7 @@ import { OkResponse, } from '@app/common/dto/success-response.dto'; import { RecipeBookmarksResponseDto } from './filter-recipe-bookmark.dto'; -import { RecipeBookmark } from '../../entities/recipe-bookmark.entity'; +import { RecipeBookmark } from '@app/recipe/domain/recipe-bookmark.entity'; export class CreateRecipeBookmarkResponseDto extends CreatedResponse { data: RecipeBookmark; diff --git a/api/libs/recipe/src/dto/recipe-view-log/modify-recipe-view-log.dto.ts b/api/libs/recipe/src/dto/recipe-view-log/modify-recipe-view-log.dto.ts index 27c251e..ad570ed 100644 --- a/api/libs/recipe/src/dto/recipe-view-log/modify-recipe-view-log.dto.ts +++ b/api/libs/recipe/src/dto/recipe-view-log/modify-recipe-view-log.dto.ts @@ -3,12 +3,12 @@ import { IsIP, IsInt, IsOptional } from 'class-validator'; export class CreateRecipeViewLogDto { @IsOptional() @IsInt() - user_id?: number; + userId?: number; @IsOptional() @IsIP() - user_ip: string; + userIp: string; @IsInt() - recipe_id: number; + recipeId: number; } diff --git a/api/libs/recipe/src/dto/recipe-view-log/recipe-viewer-identifier.ts b/api/libs/recipe/src/dto/recipe-view-log/recipe-viewer-identifier.ts index 0a00a0a..55cad98 100644 --- a/api/libs/recipe/src/dto/recipe-view-log/recipe-viewer-identifier.ts +++ b/api/libs/recipe/src/dto/recipe-view-log/recipe-viewer-identifier.ts @@ -1,14 +1,13 @@ -import { User } from '@app/user/entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { IsIP } from 'class-validator'; export class RecipeViewerIdentifier { + user: User; + @IsIP() + ip: string; + constructor(user: User, ip: string) { this.user = user; this.ip = ip; } - - user: User; - - @IsIP() - ip: string; } diff --git a/api/libs/recipe/src/dto/recipe/create-mongo-recipe.dto.ts b/api/libs/recipe/src/dto/recipe/create-mongo-recipe.dto.ts new file mode 100644 index 0000000..2c35f6d --- /dev/null +++ b/api/libs/recipe/src/dto/recipe/create-mongo-recipe.dto.ts @@ -0,0 +1,68 @@ +import { + ArrayNotEmpty, + IsArray, + IsInt, + IsMongoId, + IsNotEmpty, + IsOptional, + IsString, + IsUrl, + Min, + ValidateNested, +} from 'class-validator'; +import { IngredientRequirementDto } from './ingredient-requirement.dto'; +import { RecipeStepDto } from './recipe-step.dto'; +import { CreateRecipeDto } from './create-recipe.dto'; + +export class CreateMongoRecipeDto { + @IsString() + @IsNotEmpty() + name: string; + + @IsInt() + @Min(1) + @IsOptional() + mysqlId?: number; + + @IsString() + @IsNotEmpty() + description: string; + + @IsMongoId() + @IsString() + @IsOptional() + owner: string; + + @ValidateNested() + @ArrayNotEmpty() + @IsArray() + ingredientRequirements: IngredientRequirementDto[]; + + @ValidateNested() + @ArrayNotEmpty() + @IsArray() + recipeSteps: RecipeStepDto[]; + + @IsUrl() + @IsString() + thumbnail: string; + + @IsString() + @IsNotEmpty() + recipeRawText: string; + + @IsUrl() + @IsString() + originUrl: string; + + toCreateRecipeDto(mongoId: string): CreateRecipeDto { + return new CreateRecipeDto( + this.name, + mongoId, + null, + this.description, + this.thumbnail, + this.originUrl, + ); + } +} diff --git a/api/libs/recipe/src/dto/recipe/create-recipe.dto.ts b/api/libs/recipe/src/dto/recipe/create-recipe.dto.ts new file mode 100644 index 0000000..ac61e60 --- /dev/null +++ b/api/libs/recipe/src/dto/recipe/create-recipe.dto.ts @@ -0,0 +1,54 @@ +import { + IsInt, + IsMongoId, + IsNotEmpty, + IsOptional, + IsString, + IsUrl, +} from 'class-validator'; + +export class CreateRecipeDto { + constructor( + name: string, + mongoId: string, + ownerId: number, + description: string, + thumbnail: string, + originUrl: string, + ) { + this.name = name; + this.mongoId = mongoId; + this.ownerId = ownerId; + this.description = description; + this.thumbnail = thumbnail; + this.originUrl = originUrl; + } + + @IsString() + @IsNotEmpty() + name: string; + + @IsOptional() + @IsMongoId() + mongoId?: string; + + @IsOptional() + @IsInt() + ownerId?: number; + + @IsString() + @IsNotEmpty() + description: string; + + @IsUrl() + @IsString() + thumbnail: string; + + @IsUrl() + @IsString() + originUrl: string; + + @IsOptional() + @IsInt() + viewCount?: number = 0; +} diff --git a/api/libs/recipe/src/dto/recipe/filter-recipe.dto.ts b/api/libs/recipe/src/dto/recipe/filter-recipe.dto.ts index 529a7f2..a939d7e 100644 --- a/api/libs/recipe/src/dto/recipe/filter-recipe.dto.ts +++ b/api/libs/recipe/src/dto/recipe/filter-recipe.dto.ts @@ -10,46 +10,42 @@ import { IsOptional, IsString, } from 'class-validator'; -import { Recipe } from '../../entities/recipe.entity'; -import { Recipe as MongoRecipe } from '../../entities/mongo/mongo.recipe.entity'; +import { Recipe } from '@app/recipe/domain/recipe.entity'; +import { Recipe as MongoRecipe } from '@app/recipe/domain/mongo/mongo.recipe.entity'; import { ApiHideProperty, OmitType } from '@nestjs/swagger'; export class FilterRecipeDto extends PagenationDto { - constructor( - page: number, - limit: number, - name?: string, - owner_id?: number, - created_at?: Date, - updated_at?: Date, - ) { - super(page, limit); - this.name = name; - this.owner_id = owner_id; - this.created_at = created_at; - this.updated_at = updated_at; - } - @IsString() @IsNotEmpty() @IsOptional() name?: string; - @IsNotEmpty() @IsOptional() owner_id?: number; - @IsDate() @IsOptional() created_at?: Date; - @IsDate() @IsOptional() updated_at?: Date; - @IsInt() @IsOptional() mysql_id?: number; + + constructor( + page: number, + limit: number, + name?: string, + owner_id?: number, + created_at?: Date, + updated_at?: Date, + ) { + super(page, limit); + this.name = name; + this.owner_id = owner_id; + this.created_at = created_at; + this.updated_at = updated_at; + } } export enum TextSearchSortBy { @@ -70,53 +66,47 @@ export class TextSearchRecipeDto extends PagenationDto { } export class RecipeDto extends OmitType(MongoRecipe, [ - 'recipe_raw_text', - 'origin_url', + 'recipeRawText', + 'originUrl', ]) {} export class RecipeListViewResponseDto implements IRecipeListViewResponseDto { + id: number; + name: string; + thumbnail: string; + description: string; + viewCount: number; + createdAt: Date; + updatedAt: Date; + @ApiHideProperty() + originUrl?: string; + @ApiHideProperty() + mongoId?: string; + @ApiHideProperty() + mysqlId?: number; + constructor( id: number = null, name: string = null, thumbnail: string = null, description: string = null, - view_count: number = null, - created_at: Date = null, - updated_at: Date = null, + viewCount: number = null, + createdAt: Date = null, + updatedAt: Date = null, ) { this.id = id; this.name = name; this.thumbnail = thumbnail; this.description = description; - this.view_count = view_count; - this.created_at = created_at; - this.updated_at = updated_at; + this.viewCount = viewCount; + this.createdAt = createdAt; + this.updatedAt = updatedAt; } - - id: number; - name: string; - thumbnail: string; - description: string; - view_count: number; - created_at: Date; - updated_at: Date; - - @ApiHideProperty() - origin_url?: string; - @ApiHideProperty() - mongo_id?: string; - @ApiHideProperty() - mysql_id?: number; } export type IRecipeListViewResponseDto = Omit< Recipe, - | 'mongo_id' - | 'owner_id' - | 'recipe_raw_text' - | 'origin_url' - | 'recipe_steps' - | 'ingredient_requirements' + 'mongoId' | 'ownerId' | 'owner' | 'originUrl' >; export class RecipesResponseDto extends PagenationResponseDto { @@ -137,7 +127,7 @@ export class RecipesAndCountDto { results: this.recipes, page, count: this.recipes.length, - has_next: this.count > (page - 1) * limit + this.recipes.length, + hasNext: this.count > (page - 1) * limit + this.recipes.length, }; } } diff --git a/api/libs/recipe/src/dto/recipe/ingredient-requirement.dto.ts b/api/libs/recipe/src/dto/recipe/ingredient-requirement.dto.ts new file mode 100644 index 0000000..463b4a5 --- /dev/null +++ b/api/libs/recipe/src/dto/recipe/ingredient-requirement.dto.ts @@ -0,0 +1,22 @@ +import { IsMongoId, IsNotEmpty, IsOptional, IsString } from 'class-validator'; + +export class IngredientRequirementDto { + constructor(ingredientId: string, name: string, amount: string) { + this.ingredientId = ingredientId; + this.name = name; + this.amount = amount ?? '적당량'; + } + + @IsMongoId() + @IsOptional() + @IsString() + ingredientId?: string; + + @IsString() + @IsNotEmpty() + name: string; + + @IsString() + @IsNotEmpty() + amount: string; +} diff --git a/api/libs/recipe/src/dto/recipe/modify-recipe.dto.ts b/api/libs/recipe/src/dto/recipe/modify-recipe.dto.ts deleted file mode 100644 index c7dbe89..0000000 --- a/api/libs/recipe/src/dto/recipe/modify-recipe.dto.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { OmitType, PartialType } from '@nestjs/swagger'; -import { - ArrayNotEmpty, - IsArray, - IsDate, - IsInt, - IsMongoId, - IsNotEmpty, - IsOptional, - IsString, - IsUrl, - Min, - ValidateNested, -} from 'class-validator'; - -class IngredientRequirementDto { - constructor(ingredient_id: string, name: string, amount: string) { - this.ingredient_id = ingredient_id; - this.name = name; - this.amount = amount ?? '적당량'; - } - - @IsMongoId() - @IsOptional() - @IsString() - ingredient_id?: string; - - @IsString() - @IsNotEmpty() - name: string; - - @IsString() - @IsNotEmpty() - amount: string; -} - -export class RecipeStepDto { - constructor( - description: string, - images: string[], - ingredients: IngredientRequirementDto[], - ) { - this.description = description; - this.images = images; - this.ingredients = - ingredients?.map( - (item) => - new IngredientRequirementDto( - item.ingredient_id, - item.name, - item.amount, - ), - ) ?? []; - } - @IsString() - @IsNotEmpty() - description: string; - - @IsArray() - @IsUrl( - {}, - { - each: true, - }, - ) - images: string[]; - - @ValidateNested() - @IsArray() - ingredients: IngredientRequirementDto[]; -} - -export class CreateMongoRecipeDto { - @IsString() - @IsNotEmpty() - name: string; - - @IsInt() - @Min(1) - @IsOptional() - mysql_id?: number; - - @IsString() - @IsNotEmpty() - description: string; - - @IsMongoId() - @IsString() - @IsOptional() - owner: string; - - @ValidateNested() - @ArrayNotEmpty() - @IsArray() - ingredient_requirements: IngredientRequirementDto[]; - - @ValidateNested() - @ArrayNotEmpty() - @IsArray() - recipe_steps: RecipeStepDto[]; - - @IsUrl() - @IsString() - thumbnail: string; - - @IsString() - @IsNotEmpty() - recipe_raw_text: string; - - @IsUrl() - @IsString() - origin_url: string; -} - -export class CreateRecipeDto { - @IsString() - @IsNotEmpty() - name: string; - - @IsOptional() - @IsMongoId() - mongo_id?: string; - - @IsOptional() - @IsInt() - owner_id?: number; - - @IsString() - @IsNotEmpty() - description: string; - - @IsUrl() - @IsString() - thumbnail: string; - - @IsUrl() - @IsString() - origin_url: string; - - @IsOptional() - @IsInt() - view_count?: number; -} - -export class UpdateRecipeDto extends PartialType( - OmitType(CreateRecipeDto, ['owner_id'] as const), -) { - @IsOptional() - @IsInt() - view_count?: number; - - @IsOptional() - @IsMongoId() - mongo_id?: string; - - @IsOptional() - @IsDate() - created_at?: Date; -} - -export class UpdateMongoRecipeDto extends PartialType( - OmitType(CreateMongoRecipeDto, ['owner'] as const), -) { - @IsOptional() - @IsInt() - view_count?: number; - - @IsOptional() - @IsInt() - mysql_id?: number; -} diff --git a/api/libs/recipe/src/dto/recipe/recipe-response.dto.ts b/api/libs/recipe/src/dto/recipe/recipe-response.dto.ts index 3b3b61c..55a5fab 100644 --- a/api/libs/recipe/src/dto/recipe/recipe-response.dto.ts +++ b/api/libs/recipe/src/dto/recipe/recipe-response.dto.ts @@ -2,7 +2,7 @@ import { CreatedResponse, OkResponse, } from '@app/common/dto/success-response.dto'; -import { Recipe } from '../../entities/recipe.entity'; +import { Recipe } from '@app/recipe/domain/recipe.entity'; import { RecipeDto, RecipeListViewResponseDto, diff --git a/api/libs/recipe/src/dto/recipe/recipe-step.dto.ts b/api/libs/recipe/src/dto/recipe/recipe-step.dto.ts new file mode 100644 index 0000000..9a7b19e --- /dev/null +++ b/api/libs/recipe/src/dto/recipe/recipe-step.dto.ts @@ -0,0 +1,44 @@ +import { + IsArray, + IsNotEmpty, + IsString, + IsUrl, + ValidateNested, +} from 'class-validator'; +import { IngredientRequirementDto } from './ingredient-requirement.dto'; + +export class RecipeStepDto { + constructor( + description: string, + images: string[], + ingredients: IngredientRequirementDto[], + ) { + this.description = description; + this.images = images; + this.ingredients = + ingredients?.map( + (item) => + new IngredientRequirementDto( + item.ingredientId, + item.name, + item.amount, + ), + ) ?? []; + } + @IsString() + @IsNotEmpty() + description: string; + + @IsArray() + @IsUrl( + {}, + { + each: true, + }, + ) + images: string[]; + + @ValidateNested() + @IsArray() + ingredients: IngredientRequirementDto[]; +} diff --git a/api/libs/recipe/src/dto/recipe/update-mongo-recipe.dto.ts b/api/libs/recipe/src/dto/recipe/update-mongo-recipe.dto.ts new file mode 100644 index 0000000..61f871e --- /dev/null +++ b/api/libs/recipe/src/dto/recipe/update-mongo-recipe.dto.ts @@ -0,0 +1,15 @@ +import { OmitType, PartialType } from '@nestjs/swagger'; +import { IsInt, IsOptional } from 'class-validator'; +import { CreateMongoRecipeDto } from './create-mongo-recipe.dto'; + +export class UpdateMongoRecipeDto extends PartialType( + OmitType(CreateMongoRecipeDto, ['owner'] as const), +) { + @IsOptional() + @IsInt() + viewCount?: number; + + @IsOptional() + @IsInt() + mysqlId?: number; +} diff --git a/api/libs/recipe/src/dto/recipe/update-recipe.dto.ts b/api/libs/recipe/src/dto/recipe/update-recipe.dto.ts new file mode 100644 index 0000000..d28c50a --- /dev/null +++ b/api/libs/recipe/src/dto/recipe/update-recipe.dto.ts @@ -0,0 +1,19 @@ +import { OmitType, PartialType } from '@nestjs/swagger'; +import { CreateRecipeDto } from './create-recipe.dto'; +import { IsDate, IsInt, IsMongoId, IsOptional } from 'class-validator'; + +export class UpdateRecipeDto extends PartialType( + OmitType(CreateRecipeDto, ['ownerId'] as const), +) { + @IsOptional() + @IsInt() + viewCount?: number; + + @IsOptional() + @IsMongoId() + mongoId?: string; + + @IsOptional() + @IsDate() + createdAt?: Date; +} diff --git a/api/libs/recipe/src/entities/recipe-bookmark.entity.ts b/api/libs/recipe/src/entities/recipe-bookmark.entity.ts deleted file mode 100644 index 3783902..0000000 --- a/api/libs/recipe/src/entities/recipe-bookmark.entity.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { RecipeBookmark as RecipeBookmarkType } from '@prisma/client'; - -export class RecipeBookmark implements RecipeBookmarkType { - id: number; - recipe_id: number; - user_id: number; - created_at: Date; - updated_at: Date; -} diff --git a/api/libs/recipe/src/entities/recipe-view-log.entity.ts b/api/libs/recipe/src/entities/recipe-view-log.entity.ts deleted file mode 100644 index 8c8421e..0000000 --- a/api/libs/recipe/src/entities/recipe-view-log.entity.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { RecipeViewLog as RecipeViewLogType } from '@prisma/client'; - -export class RecipeViewLog implements RecipeViewLogType { - id: number; - recipe_id: number; - user_id: number; - user_ip: string; - created_at: Date; - updated_at: Date; -} diff --git a/api/libs/recipe/src/entities/recipe.entity.ts b/api/libs/recipe/src/entities/recipe.entity.ts deleted file mode 100644 index bcbdad6..0000000 --- a/api/libs/recipe/src/entities/recipe.entity.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Recipe as RecipeType } from '@prisma/client'; - -export class Recipe implements RecipeType { - id: number; - mongo_id: string; - name: string; - description: string; - owner_id: number; - thumbnail: string; - origin_url: string; - view_count: number; - created_at: Date; - updated_at: Date; -} diff --git a/api/libs/recipe/src/recipe.module.ts b/api/libs/recipe/src/recipe.module.ts index 383e2ae..e503b60 100644 --- a/api/libs/recipe/src/recipe.module.ts +++ b/api/libs/recipe/src/recipe.module.ts @@ -1,6 +1,9 @@ import { Module, Provider } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; -import { Recipe, RecipeSchema } from './entities/mongo/mongo.recipe.entity'; +import { + Recipe, + RecipeSchema, +} from '@app/recipe/domain/mongo/mongo.recipe.entity'; import { RecipeService } from './services/recipe.service'; import { RecipeController } from './controllers/recipe.controller'; import { RecipeBookmarkController } from './controllers/recipe-bookmark.controller'; diff --git a/api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.ts b/api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.ts index 1a92caf..37614c3 100644 --- a/api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.ts +++ b/api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.ts @@ -2,7 +2,7 @@ import { CrudMongoRepository } from '@app/common/repository/crud-mongo.repositor import { RecipeBookmark, RecipeBookmarkDocument, -} from '../../entities/mongo/mongo.recipe-bookmark.entity'; +} from '@app/recipe/domain/mongo/mongo.recipe-bookmark.entity'; import { CreateRecipeBookmarkDto } from '../../dto/recipe-bookmark/modify-recipe-bookmark.dto'; import { FilterRecipeBookmarkDto, @@ -35,7 +35,7 @@ export class RecipeBookmarkRepository ): Promise { const { page, limit } = filterRecipeBookmarkDto; const filterDto = deleteProps( - transferObjectId(filterRecipeBookmarkDto, ['user_id']), + transferObjectId(filterRecipeBookmarkDto, ['userId']), ['page', 'limit'], ); const filteredAggrPipe = this.recipeBookmarkModel diff --git a/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.interface.ts b/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.interface.ts index d416528..9775aaf 100644 --- a/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.interface.ts +++ b/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.interface.ts @@ -1,6 +1,6 @@ import { ICrudRepository } from '@app/common/repository/crud.repository'; -import { RecipeBookmark as PrismaRecipeBookmark } from '../../entities/recipe-bookmark.entity'; -import { RecipeBookmark as MongoRecipeBookmark } from '../../entities/mongo/mongo.recipe-bookmark.entity'; +import { RecipeBookmark as PrismaRecipeBookmark } from '@app/recipe/domain/recipe-bookmark.entity'; +import { RecipeBookmark as MongoRecipeBookmark } from '@app/recipe/domain/mongo/mongo.recipe-bookmark.entity'; import { CreateRecipeBookmarkDto } from '@app/recipe/dto/recipe-bookmark/modify-recipe-bookmark.dto'; import { FilterRecipeBookmarkDto, diff --git a/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.repository.ts b/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.repository.ts index 63ddcbe..d3aa8b7 100644 --- a/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.repository.ts +++ b/api/libs/recipe/src/repositories/recipe-bookmark/recipe-bookmark.repository.ts @@ -1,6 +1,6 @@ import { PrismaService } from '@app/common/prisma/prisma.service'; import { Injectable } from '@nestjs/common'; -import { RecipeBookmark } from '../../entities/recipe-bookmark.entity'; +import { RecipeBookmark } from '@app/recipe/domain/recipe-bookmark.entity'; import { CreateRecipeBookmarkDto } from '../../dto/recipe-bookmark/modify-recipe-bookmark.dto'; import { FilterRecipeBookmarkDto, @@ -39,13 +39,13 @@ export class RecipeBookmarkRepository name: true, description: true, thumbnail: true, - view_count: true, - created_at: true, - updated_at: true, + viewCount: true, + createdAt: true, + updatedAt: true, }, }, }, - orderBy: { created_at: 'desc' }, + orderBy: { createdAt: 'desc' }, skip: (page - 1) * limit, take: limit, }); @@ -58,7 +58,7 @@ export class RecipeBookmarkRepository ]); return new RecipeBookmarksAndCountDto( recipeBookmarks.map((recipeBookmark) => ({ - recipe_bookmark_id: recipeBookmark.id, + recipeBookmarkId: recipeBookmark.id, ...recipeBookmark.recipe, })), count, diff --git a/api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.ts b/api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.ts index 9932f39..44cdd85 100644 --- a/api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.ts +++ b/api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.ts @@ -2,7 +2,7 @@ import { CrudMongoRepository } from '@app/common/repository/crud-mongo.repositor import { RecipeViewLog, RecipeViewLogDocument, -} from '../../entities/mongo/mongo.recipe-view-log.entity'; +} from '@app/recipe/domain/mongo/mongo.recipe-view-log.entity'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { CreateRecipeViewLogDto } from '../../dto/recipe-view-log/modify-recipe-view-log.dto'; @@ -38,7 +38,7 @@ export class RecipeViewLogRepository this.redisClient.zIncrBy( 'recipe-view-count', 1, - createRecipeViewLogDto.recipe_id.toString(), + createRecipeViewLogDto.recipeId.toString(), ), ]) )[0]; @@ -65,21 +65,6 @@ export class RecipeViewLogRepository ); } - private async findAllViewedRecipesInPast1Month() { - return await this.recipeViewLogModel - .aggregate() - .match({ - created_at: { - $gte: calcPast1MonthDate(), - }, - }) - .group({ - _id: '$recipe_id', - count: { $sum: 1 }, - }) - .exec(); - } - async findAll5MostViewedRecipesInPast1Month(): Promise< RecipeListViewResponseDto[] > { @@ -104,8 +89,8 @@ export class RecipeViewLogRepository recipe.thumbnail, recipe.description, recipeIdsWithViews[index].score, - recipe.created_at, - recipe.updated_at, + recipe.createdAt, + recipe.updatedAt, ); }); } @@ -143,4 +128,19 @@ export class RecipeViewLogRepository }) .exec(); } + + private async findAllViewedRecipesInPast1Month() { + return await this.recipeViewLogModel + .aggregate() + .match({ + created_at: { + $gte: calcPast1MonthDate(), + }, + }) + .group({ + _id: '$recipe_id', + count: { $sum: 1 }, + }) + .exec(); + } } diff --git a/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.interface.ts b/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.interface.ts index af4d23c..3fb81f8 100644 --- a/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.interface.ts +++ b/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.interface.ts @@ -1,6 +1,6 @@ import { ICrudRepository } from '@app/common/repository/crud.repository'; -import { RecipeViewLog as MongoRecipeViewLog } from '@app/recipe/entities/mongo/mongo.recipe-view-log.entity'; -import { RecipeViewLog as PrismaRecipeViewLog } from '@app/recipe/entities/recipe-view-log.entity'; +import { RecipeViewLog as MongoRecipeViewLog } from '@app/recipe/domain/mongo/mongo.recipe-view-log.entity'; +import { RecipeViewLog as PrismaRecipeViewLog } from '@app/recipe/domain/recipe-view-log.entity'; import { CreateRecipeViewLogDto } from '@app/recipe/dto/recipe-view-log/modify-recipe-view-log.dto'; import { RecipeListViewResponseDto } from '@app/recipe/dto/recipe/filter-recipe.dto'; @@ -9,6 +9,8 @@ type RecipeViewLog = MongoRecipeViewLog | PrismaRecipeViewLog; export interface IRecipeViewLogRepository extends ICrudRepository { checkIfRecipeViewCountKeyExists(): Promise; + setAllViewedRecipesInPast1Month(): Promise; + findAll5MostViewedRecipesInPast1Month(): Promise; } diff --git a/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.ts b/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.ts index fc60a95..4947bb8 100644 --- a/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.ts +++ b/api/libs/recipe/src/repositories/recipe-view-log/recipe-view-log.repository.ts @@ -1,5 +1,5 @@ import { CreateRecipeViewLogDto } from '@app/recipe/dto/recipe-view-log/modify-recipe-view-log.dto'; -import { RecipeViewLog } from '@app/recipe/entities/recipe-view-log.entity'; +import { RecipeViewLog } from '@app/recipe/domain/recipe-view-log.entity'; import { IRecipeViewLogRepository } from './recipe-view-log.repository.interface'; import { PrismaService } from '@app/common/prisma/prisma.service'; import { CrudPrismaRepository } from '@app/common/repository/crud-prisma.repository'; @@ -40,7 +40,7 @@ export class RecipeViewLogRepository this.redisClient.zIncrBy( 'recipe-view-count', 1, - createRecipeViewLogDto.recipe_id.toString(), + createRecipeViewLogDto.recipeId.toString(), ), ]) )[0]; @@ -53,10 +53,10 @@ export class RecipeViewLogRepository async setAllViewedRecipesInPast1Month() { const recipesWithCount = await this.prisma.recipeViewLog.groupBy({ - by: ['recipe_id'], + by: ['recipeId'], _count: true, where: { - created_at: { + createdAt: { gte: calcPast1MonthDate(), }, }, @@ -65,7 +65,7 @@ export class RecipeViewLogRepository recipesWithCount.map((recipeWithCount) => { return this.redisClient.ZADD('recipe-view-count', { score: recipeWithCount._count, - value: recipeWithCount.recipe_id.toString(), + value: recipeWithCount.recipeId.toString(), }); }), ); @@ -80,31 +80,31 @@ export class RecipeViewLogRepository const [viewLogsWithRecipe, count] = await Promise.all([ this.prisma.recipeViewLog.findMany({ where: { - user_id: userId, + userId: userId, }, orderBy: { - created_at: 'desc', + createdAt: 'desc', }, skip: (page - 1) * limit, take: limit, select: { - recipe_id: true, + recipeId: true, recipe: { select: { id: true, name: true, thumbnail: true, description: true, - view_count: true, - created_at: true, - updated_at: true, + viewCount: true, + createdAt: true, + updatedAt: true, }, }, }, }), this.prisma.recipeViewLog.count({ where: { - user_id: userId, + userId: userId, }, }), ]); @@ -115,9 +115,9 @@ export class RecipeViewLogRepository viewLogWithRecipe.recipe.name, viewLogWithRecipe.recipe.thumbnail, viewLogWithRecipe.recipe.description, - viewLogWithRecipe.recipe.view_count, - viewLogWithRecipe.recipe.created_at, - viewLogWithRecipe.recipe.updated_at, + viewLogWithRecipe.recipe.viewCount, + viewLogWithRecipe.recipe.createdAt, + viewLogWithRecipe.recipe.updatedAt, ), ); return new RecipesAndCountDto(recipes, count); @@ -147,39 +147,39 @@ export class RecipeViewLogRepository recipe.thumbnail, recipe.description, recipeIdsWithViews[index].score, - recipe.created_at, - recipe.updated_at, + recipe.createdAt, + recipe.updatedAt, ); }); } const recipeIds = await this.prisma.recipeViewLog.groupBy({ - by: ['recipe_id'], + by: ['recipeId'], _count: { - created_at: true, + createdAt: true, }, orderBy: { _count: { - created_at: 'desc', + createdAt: 'desc', }, }, take: 5, where: { - created_at: { + createdAt: { gte: calcPast1MonthDate(), }, }, }); return await Promise.all( recipeIds.map(async (recipeId) => { - const recipe = await this.recipeRepository.findOne(recipeId.recipe_id); + const recipe = await this.recipeRepository.findOne(recipeId.recipeId); return new RecipeListViewResponseDto( recipe.id, recipe.name, recipe.thumbnail, recipe.description, - recipeId._count.created_at, - recipe.created_at, - recipe.updated_at, + recipeId._count.createdAt, + recipe.createdAt, + recipe.updatedAt, ); }), ); diff --git a/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts b/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts index 6c978c2..edf7aa6 100644 --- a/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts +++ b/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts @@ -9,18 +9,16 @@ import { TextSearchRecipeDto, TextSearchSortBy, } from '../../dto/recipe/filter-recipe.dto'; -import { - CreateMongoRecipeDto, - UpdateMongoRecipeDto, -} from '../../dto/recipe/modify-recipe.dto'; +import { UpdateMongoRecipeDto } from '../../dto/recipe/update-mongo-recipe.dto'; import { Recipe, RecipeDocument, -} from '../../entities/mongo/mongo.recipe.entity'; +} from '@app/recipe/domain/mongo/mongo.recipe.entity'; import { deleteNull } from '@app/common/utils/delete-null'; import { deleteProps } from '@app/common/utils/delete-props'; import { Logable } from '@app/common/log/log.decorator'; import { Cacheable } from '@app/common/cache/cache.service'; +import { CreateMongoRecipeDto } from '@app/recipe/dto/recipe/create-mongo-recipe.dto'; @Injectable() export class MongoRecipeRepository { diff --git a/api/libs/recipe/src/repositories/recipe/recipe.repository.interface.ts b/api/libs/recipe/src/repositories/recipe/recipe.repository.interface.ts index b592504..c300ca9 100644 --- a/api/libs/recipe/src/repositories/recipe/recipe.repository.interface.ts +++ b/api/libs/recipe/src/repositories/recipe/recipe.repository.interface.ts @@ -1,16 +1,14 @@ -import { Recipe as PrismaRecipe } from '../../entities/recipe.entity'; -import { Recipe as MongoRecipe } from '../../entities/mongo/mongo.recipe.entity'; +import { Recipe as PrismaRecipe } from '@app/recipe/domain/recipe.entity'; +import { Recipe as MongoRecipe } from '@app/recipe/domain/mongo/mongo.recipe.entity'; import { ICrudRepository } from '@app/common/repository/crud.repository'; -import { - CreateRecipeDto, - UpdateRecipeDto, -} from '../../dto/recipe/modify-recipe.dto'; import { FilterRecipeDto, RecipeListViewResponseDto, RecipesAndCountDto, TextSearchRecipeDto, } from '../../dto/recipe/filter-recipe.dto'; +import { CreateRecipeDto } from '@app/recipe/dto/recipe/create-recipe.dto'; +import { UpdateRecipeDto } from '@app/recipe/dto/recipe/update-recipe.dto'; type Recipe = PrismaRecipe | MongoRecipe; @@ -24,6 +22,7 @@ export interface IRecipeRepository findAllByFullTextSearch( textSearchRecipeDto: TextSearchRecipeDto, ): Promise; + findTopViewed(): Promise; findAllByIds(ids: number[]): Promise; diff --git a/api/libs/recipe/src/repositories/recipe/recipe.repository.ts b/api/libs/recipe/src/repositories/recipe/recipe.repository.ts index e0dbd19..5867781 100644 --- a/api/libs/recipe/src/repositories/recipe/recipe.repository.ts +++ b/api/libs/recipe/src/repositories/recipe/recipe.repository.ts @@ -1,11 +1,7 @@ import { PrismaService } from '@app/common/prisma/prisma.service'; import { CrudPrismaRepository } from '@app/common/repository/crud-prisma.repository'; import { Injectable } from '@nestjs/common'; -import { Recipe } from '../../entities/recipe.entity'; -import { - CreateRecipeDto, - UpdateRecipeDto, -} from '../../dto/recipe/modify-recipe.dto'; +import { Recipe } from '@app/recipe/domain/recipe.entity'; import { FilterRecipeDto, RecipeListViewResponseDto, @@ -15,6 +11,8 @@ import { import { deleteNull } from '@app/common/utils/delete-null'; import { IRecipeRepository } from './recipe.repository.interface'; import { deleteProps } from '@app/common/utils/delete-props'; +import { CreateRecipeDto } from '@app/recipe/dto/recipe/create-recipe.dto'; +import { UpdateRecipeDto } from '@app/recipe/dto/recipe/update-recipe.dto'; @Injectable() export class RecipeRepository @@ -44,12 +42,12 @@ export class RecipeRepository name: true, description: true, thumbnail: true, - view_count: true, - created_at: true, - updated_at: true, - mongo_id: true, + viewCount: true, + createdAt: true, + updatedAt: true, + mongoId: true, }, - orderBy: { created_at: 'desc' }, + orderBy: { createdAt: 'desc' }, skip: (page - 1) * limit, take: limit, }); @@ -62,7 +60,7 @@ export class RecipeRepository async findOneByMongoId(mongoId: string): Promise { return this.prisma.recipe.findUnique({ - where: { mongo_id: mongoId }, + where: { mongoId: mongoId }, }); } @@ -74,7 +72,7 @@ export class RecipeRepository async findTopViewed() { return this.prisma.recipe.findMany({ - orderBy: { view_count: 'desc' }, + orderBy: { viewCount: 'desc' }, take: 10, }); } @@ -87,9 +85,9 @@ export class RecipeRepository name: true, description: true, thumbnail: true, - view_count: true, - created_at: true, - updated_at: true, + viewCount: true, + createdAt: true, + updatedAt: true, }, }); } @@ -97,17 +95,17 @@ export class RecipeRepository async increaseViewCount(id: number): Promise { return this.prisma.recipe.update({ where: { id }, - data: { view_count: { increment: 1 } }, + data: { viewCount: { increment: 1 } }, }); } async deleteOne(id: number): Promise { const deleteRecipe = this.prisma.recipe.delete({ where: { id } }); const deleteRecipeViewLog = this.prisma.recipeViewLog.deleteMany({ - where: { recipe_id: id }, + where: { recipeId: id }, }); const deleteRecipeBookmark = this.prisma.recipeBookmark.deleteMany({ - where: { recipe_id: id }, + where: { recipeId: id }, }); return ( await this.prisma.$transaction([ diff --git a/api/libs/recipe/src/services/recipe-bookmark.service.ts b/api/libs/recipe/src/services/recipe-bookmark.service.ts index 70d39e7..caa15a7 100644 --- a/api/libs/recipe/src/services/recipe-bookmark.service.ts +++ b/api/libs/recipe/src/services/recipe-bookmark.service.ts @@ -3,7 +3,7 @@ import { FilterRecipeBookmarkDto } from '../dto/recipe-bookmark/filter-recipe-bo import { CreateRecipeBookmarkDto } from '../dto/recipe-bookmark/modify-recipe-bookmark.dto'; import { RecipeBookmarkRepository } from '../repositories/recipe-bookmark/recipe-bookmark.repository'; import { Injectable } from '@nestjs/common'; -import { RecipeBookmark } from '../entities/recipe-bookmark.entity'; +import { RecipeBookmark } from '@app/recipe/domain/recipe-bookmark.entity'; import { RecipesResponseDto } from '../dto/recipe/filter-recipe.dto'; import { Logable } from '@app/common/log/log.decorator'; diff --git a/api/libs/recipe/src/services/recipe.service.ts b/api/libs/recipe/src/services/recipe.service.ts index e0a9fbe..0b4cfb8 100644 --- a/api/libs/recipe/src/services/recipe.service.ts +++ b/api/libs/recipe/src/services/recipe.service.ts @@ -12,20 +12,17 @@ import { RecipesResponseDto, TextSearchRecipeDto, } from '../dto/recipe/filter-recipe.dto'; -import { - CreateMongoRecipeDto, - CreateRecipeDto, - UpdateRecipeDto, -} from '../dto/recipe/modify-recipe.dto'; import { MongoRecipeRepository } from '../repositories/recipe/mongo.recipe.repository'; import { RecipeRepository } from '../repositories/recipe/recipe.repository'; import { RecipeViewerIdentifier } from '../dto/recipe-view-log/recipe-viewer-identifier'; import { Logable } from '@app/common/log/log.decorator'; import { RecipeViewLogRepository } from '../repositories/recipe-view-log/recipe-view-log.repository'; import { Cacheable } from '@app/common/cache/cache.service'; -import { Recipe } from '../entities/recipe.entity'; +import { Recipe } from '@app/recipe/domain/recipe.entity'; import { deleteProps } from '@app/common/utils/delete-props'; import { deleteNull } from '@app/common/utils/delete-null'; +import { CreateMongoRecipeDto } from '../dto/recipe/create-mongo-recipe.dto'; +import { UpdateRecipeDto } from '../dto/recipe/update-recipe.dto'; @Injectable() export class RecipeService implements OnApplicationBootstrap { @@ -48,11 +45,11 @@ export class RecipeService implements OnApplicationBootstrap { ...createRecipeDto, mongo_id: mongoRecipe.id.toString(), }, - ['recipe_steps', 'ingredient_requirements', 'recipe_raw_text'], + ['recipeSteps', 'ingredientRequirements', 'recipeRawText'], ), ); await this.mongoRecipeRepository.update(mongoRecipe.id.toString(), { - mysql_id: recipe.id, + mysqlId: recipe.id, }); return recipe; } @@ -135,9 +132,9 @@ export class RecipeService implements OnApplicationBootstrap { ]); if (!ret[0] || !ret[1]) throw new NotFoundException('Recipe not found'); const recipeViewLog = await this.recipeViewLogRepository.create({ - recipe_id: id, - user_id: identifier.user ? identifier.user.id : undefined, - user_ip: identifier.ip, + recipeId: id, + userId: identifier.user ? identifier.user.id : undefined, + userIp: identifier.ip, }); return true; } @@ -167,32 +164,5 @@ export class RecipeService implements OnApplicationBootstrap { async onApplicationBootstrap() { await this.setAllViewedRecipesInPast1Month(); - - // while (hasNext) { - // const ret = ( - // await this.mongoRecipeRepository.findAllRecipe({ - // page: ++page, - // limit: 10, - // mysql_id: null, - // }) - // ).toRecipesResponseDto(page, 10); - // const { results, has_next } = ret; - // if (results.length === 0) return; - // hasNext = has_next; - - // const mysqlRecipes = await Promise.all( - // results.map(async (recipe) => { - // return this.recipeRepository.findOneByMongoId(recipe.id as any); - // }), - // ); - - // await Promise.all( - // mysqlRecipes.map(async (recipe) => { - // return this.mongoRecipeRepository.update(recipe.mongo_id, { - // mysql_id: recipe.id, - // }); - // }), - // ); - // } } } diff --git a/api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.spec.ts b/api/libs/recipe/test/integration/mongo.recipe-bookmark.repository.spec.ts similarity index 75% rename from api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.spec.ts rename to api/libs/recipe/test/integration/mongo.recipe-bookmark.repository.spec.ts index ff0e211..fdb4b7a 100644 --- a/api/libs/recipe/src/repositories/recipe-bookmark/mongo.recipe-bookmark.repository.spec.ts +++ b/api/libs/recipe/test/integration/mongo.recipe-bookmark.repository.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { RecipeBookmarkRepository } from './mongo.recipe-bookmark.repository'; +import { RecipeBookmarkRepository } from '@app/recipe/repositories/recipe-bookmark/mongo.recipe-bookmark.repository'; describe('RecipeBookmarkRepository', () => { let repository: RecipeBookmarkRepository; diff --git a/api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.spec.ts b/api/libs/recipe/test/integration/mongo.recipe-view-log.repository.spec.ts similarity index 75% rename from api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.spec.ts rename to api/libs/recipe/test/integration/mongo.recipe-view-log.repository.spec.ts index 7e49fb4..0e3e02e 100644 --- a/api/libs/recipe/src/repositories/recipe-view-log/mongo.recipe-view-log.repository.spec.ts +++ b/api/libs/recipe/test/integration/mongo.recipe-view-log.repository.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { RecipeViewLogRepository } from './mongo.recipe-view-log.repository'; +import { RecipeViewLogRepository } from '@app/recipe/repositories/recipe-view-log/mongo.recipe-view-log.repository'; describe('RecipeBookmarkRepository', () => { let repository: RecipeViewLogRepository; diff --git a/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.spec.ts b/api/libs/recipe/test/integration/mongo.recipe.repository.spec.ts similarity index 77% rename from api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.spec.ts rename to api/libs/recipe/test/integration/mongo.recipe.repository.spec.ts index a47f10e..476b85a 100644 --- a/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.spec.ts +++ b/api/libs/recipe/test/integration/mongo.recipe.repository.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { MongoRecipeRepository } from './mongo.recipe.repository'; +import { MongoRecipeRepository } from '@app/recipe/repositories/recipe/mongo.recipe.repository'; describe('RecipeRepository', () => { let repository: MongoRecipeRepository; diff --git a/api/libs/recipe/src/controllers/recipe-bookmark.controller.spec.ts b/api/libs/recipe/test/integration/recipe-bookmark.controller.spec.ts similarity index 79% rename from api/libs/recipe/src/controllers/recipe-bookmark.controller.spec.ts rename to api/libs/recipe/test/integration/recipe-bookmark.controller.spec.ts index 6cbebfb..3fc8611 100644 --- a/api/libs/recipe/src/controllers/recipe-bookmark.controller.spec.ts +++ b/api/libs/recipe/test/integration/recipe-bookmark.controller.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { RecipeBookmarkController } from './recipe-bookmark.controller'; +import { RecipeBookmarkController } from '@app/recipe/controllers/recipe-bookmark.controller'; describe('RecipeBookmarkController', () => { let controller: RecipeBookmarkController; diff --git a/api/libs/recipe/src/controllers/recipe.controller.spec.ts b/api/libs/recipe/test/integration/recipe.controller.spec.ts similarity index 80% rename from api/libs/recipe/src/controllers/recipe.controller.spec.ts rename to api/libs/recipe/test/integration/recipe.controller.spec.ts index 1ae861c..35d99a6 100644 --- a/api/libs/recipe/src/controllers/recipe.controller.spec.ts +++ b/api/libs/recipe/test/integration/recipe.controller.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@automock/jest'; -import { RecipeController } from './recipe.controller'; +import { RecipeController } from '@app/recipe/controllers/recipe.controller'; describe('RecipeController', () => { let controller: RecipeController; diff --git a/api/libs/recipe/src/services/recipe-bookmark.service.spec.ts b/api/libs/recipe/test/unit/recipe-bookmark.service.spec.ts similarity index 91% rename from api/libs/recipe/src/services/recipe-bookmark.service.spec.ts rename to api/libs/recipe/test/unit/recipe-bookmark.service.spec.ts index d506307..9fe78ef 100644 --- a/api/libs/recipe/src/services/recipe-bookmark.service.spec.ts +++ b/api/libs/recipe/test/unit/recipe-bookmark.service.spec.ts @@ -1,12 +1,12 @@ import { TestBed } from '@automock/jest'; -import { RecipeBookmarkRepository } from '../repositories/recipe-bookmark/recipe-bookmark.repository'; -import { RecipeBookmarkService } from './recipe-bookmark.service'; +import { RecipeBookmarkRepository } from '@app/recipe/repositories/recipe-bookmark/recipe-bookmark.repository'; +import { RecipeBookmarkService } from '@app/recipe/services/recipe-bookmark.service'; import { FilterRecipeBookmarkDto, RecipeBookmarkListViewResponseDto, RecipeBookmarksAndCountDto, RecipeBookmarksResponseDto, -} from '../dto/recipe-bookmark/filter-recipe-bookmark.dto'; +} from '@app/recipe/dto/recipe-bookmark/filter-recipe-bookmark.dto'; describe('RecipeBookmarkService', () => { let service: RecipeBookmarkService; @@ -37,13 +37,13 @@ describe('RecipeBookmarkService', () => { results: recipeBookmarksAndCountLast.recipes, page: 1, count: 2, - has_next: true, + hasNext: true, }; const recipeBookmarksResponseDtoNotLast: RecipeBookmarksResponseDto = { results: recipeBookmarksAndCountNotLast.recipes, page: 1, count: 2, - has_next: false, + hasNext: false, }; beforeEach(async () => { diff --git a/api/libs/recipe/src/services/recipe.service.spec.ts b/api/libs/recipe/test/unit/recipe.service.spec.ts similarity index 86% rename from api/libs/recipe/src/services/recipe.service.spec.ts rename to api/libs/recipe/test/unit/recipe.service.spec.ts index f451f37..bd18475 100644 --- a/api/libs/recipe/src/services/recipe.service.spec.ts +++ b/api/libs/recipe/test/unit/recipe.service.spec.ts @@ -5,22 +5,20 @@ import { RecipesAndCountDto, RecipesResponseDto, TextSearchRecipeDto, -} from '../dto/recipe/filter-recipe.dto'; -import { - CreateMongoRecipeDto, - UpdateRecipeDto, -} from '../dto/recipe/modify-recipe.dto'; -import { MongoRecipeRepository } from '../repositories/recipe/mongo.recipe.repository'; -import { RecipeRepository } from '../repositories/recipe/recipe.repository'; -import { RecipeService } from './recipe.service'; +} from '@app/recipe/dto/recipe/filter-recipe.dto'; +import { MongoRecipeRepository } from '@app/recipe/repositories/recipe/mongo.recipe.repository'; +import { RecipeRepository } from '@app/recipe/repositories/recipe/recipe.repository'; +import { RecipeService } from '@app/recipe/services/recipe.service'; import { TestBed } from '@automock/jest'; -import { RecipeViewLogRepository } from '../repositories/recipe-view-log/recipe-view-log.repository'; -import { RecipeViewLog } from '../entities/recipe-view-log.entity'; -import { User } from '@app/user/entities/user.entity'; -import { Recipe } from '../entities/recipe.entity'; -import { Recipe as MongoRecipe } from '../entities/mongo/mongo.recipe.entity'; -import { RecipeViewerIdentifier } from '../dto/recipe-view-log/recipe-viewer-identifier'; +import { RecipeViewLogRepository } from '@app/recipe/repositories/recipe-view-log/recipe-view-log.repository'; +import { RecipeViewLog } from '@app/recipe/domain/recipe-view-log.entity'; +import { User } from '@app/user/domain/user.entity'; +import { Recipe } from '@app/recipe/domain/recipe.entity'; +import { Recipe as MongoRecipe } from '@app/recipe/domain/mongo/mongo.recipe.entity'; +import { RecipeViewerIdentifier } from '@app/recipe/dto/recipe-view-log/recipe-viewer-identifier'; import { Types } from 'mongoose'; +import { CreateMongoRecipeDto } from '@app/recipe/dto/recipe/create-mongo-recipe.dto'; +import { UpdateRecipeDto } from '@app/recipe/dto/recipe/update-recipe.dto'; describe('RecipeService', () => { let service: RecipeService; @@ -51,14 +49,38 @@ describe('RecipeService', () => { results: recipesAndCountLast.recipes, page: 1, count: 2, - has_next: true, + hasNext: true, }; const recipesResponseDtoNotLast: RecipesResponseDto = { results: recipesAndCountNotLast.recipes, page: 1, count: 2, - has_next: false, + hasNext: false, }; + const user = new User(); + const recipe = new Recipe({ + id: 1, + name: 'test', + mongoId: 'test', + description: 'test', + ownerId: user.id, + owner: user, + thumbnail: 'test', + originUrl: 'test', + viewCount: 1, + createdAt: new Date(), + updatedAt: new Date(), + }); + const recipeViewLog = new RecipeViewLog({ + id: 1, + recipeId: recipe.id, + recipe, + userId: user.id, + user: user, + userIp: '::1', + createdAt: new Date(), + updatedAt: new Date(), + }); beforeEach(async () => { const { unit, unitRef } = TestBed.create(RecipeService).compile(); @@ -79,11 +101,10 @@ describe('RecipeService', () => { it('should create a new recipe', async () => { const createRecipeDto = {} as CreateMongoRecipeDto; const mongoId = new Types.ObjectId(); - const recipe: Recipe = { ...new Recipe(), id: 1 }, - mongoRecipe: MongoRecipe = { - ...new MongoRecipe(), - id: mongoId, - }; + const mongoRecipe: MongoRecipe = { + ...new MongoRecipe(), + id: mongoId, + }; recipeRepository.create.mockResolvedValue(recipe); mongoRecipeRepository.create.mockResolvedValue(mongoRecipe); @@ -224,13 +245,13 @@ describe('RecipeService', () => { describe('findOne', () => { it('should return a recipe', async () => { - const recipe = new RecipeDto(); - mongoRecipeRepository.findOneByMysqlId.mockResolvedValue(recipe); - recipeRepository.increaseViewCount.mockResolvedValue(new Recipe()); + const recipeDto = new RecipeDto(); + mongoRecipeRepository.findOneByMysqlId.mockResolvedValue(recipeDto); + recipeRepository.increaseViewCount.mockResolvedValue(recipe); mongoRecipeRepository.increaseViewCountByMySqlId.mockResolvedValue( new MongoRecipe(), ); - recipeViewLogRepository.create.mockResolvedValue(new RecipeViewLog()); + recipeViewLogRepository.create.mockResolvedValue(recipeViewLog); const result = await service.findOne(1, { ip: '::1', @@ -242,12 +263,12 @@ describe('RecipeService', () => { expect(recipeRepository.increaseViewCount).toHaveBeenCalledWith(1); expect(recipeViewLogRepository.create).toHaveBeenCalledWith({ - recipe_id: 1, - user_id: 1, - user_ip: '::1', + recipeId: 1, + userId: 1, + userIp: '::1', }); expect(mongoRecipeRepository.findOneByMysqlId).toHaveBeenCalledWith(1); - expect(result).toEqual(recipe); + expect(result).toEqual(recipeDto); }); }); @@ -319,11 +340,11 @@ describe('RecipeService', () => { describe('viewRecipe', () => { it('should return true', async () => { - recipeRepository.increaseViewCount.mockResolvedValue(new Recipe()); + recipeRepository.increaseViewCount.mockResolvedValue(recipe); mongoRecipeRepository.increaseViewCountByMySqlId.mockResolvedValue( new MongoRecipe(), ); - recipeViewLogRepository.create.mockResolvedValue(new RecipeViewLog()); + recipeViewLogRepository.create.mockResolvedValue(recipeViewLog); const result = await service.viewRecipe(1, { ip: '::1', @@ -335,9 +356,9 @@ describe('RecipeService', () => { expect(recipeRepository.increaseViewCount).toHaveBeenCalledWith(1); expect(recipeViewLogRepository.create).toHaveBeenCalledWith({ - recipe_id: 1, - user_id: 1, - user_ip: '::1', + recipeId: 1, + userId: 1, + userIp: '::1', }); expect(result).toEqual(true); }); @@ -395,7 +416,6 @@ describe('RecipeService', () => { describe('update', () => { it('should update well', async () => { - const recipe = new Recipe(); recipeRepository.update.mockResolvedValue(recipe); const result = await service.update(1, {} as UpdateRecipeDto); @@ -415,7 +435,6 @@ describe('RecipeService', () => { describe('deleteOne', () => { it('should delete well', async () => { - const recipe = new Recipe(); recipeRepository.deleteOne.mockResolvedValue(recipe); mongoRecipeRepository.deleteOneByMysqlId.mockResolvedValue( new MongoRecipe(), diff --git a/api/libs/user/src/types/diet.enum.ts b/api/libs/user/src/domain/diet.enum.ts similarity index 100% rename from api/libs/user/src/types/diet.enum.ts rename to api/libs/user/src/domain/diet.enum.ts diff --git a/api/libs/user/src/entities/mongo.user.entity.ts b/api/libs/user/src/domain/mongo.user.entity.ts similarity index 93% rename from api/libs/user/src/entities/mongo.user.entity.ts rename to api/libs/user/src/domain/mongo.user.entity.ts index 33e2d4d..916a36c 100644 --- a/api/libs/user/src/entities/mongo.user.entity.ts +++ b/api/libs/user/src/domain/mongo.user.entity.ts @@ -2,8 +2,8 @@ import { schemaOptions } from '@app/common/utils/schema-option'; import { ConfigService } from '@nestjs/config'; import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Schema as MongooseSchema } from 'mongoose'; -import { Diet } from '../types/diet.enum'; -import { DeviceToken } from '@app/noti/entity/mongo/mongo.device-token.entity'; +import { Diet } from './diet.enum'; +import { DeviceToken } from '@app/noti/domain/mongo/mongo.device-token.entity'; export type UserDocument = HydratedDocument; diff --git a/api/libs/user/src/entities/user.entity.ts b/api/libs/user/src/domain/user.entity.ts similarity index 84% rename from api/libs/user/src/entities/user.entity.ts rename to api/libs/user/src/domain/user.entity.ts index ba2b0c3..37ae642 100644 --- a/api/libs/user/src/entities/user.entity.ts +++ b/api/libs/user/src/domain/user.entity.ts @@ -7,6 +7,6 @@ export class User implements UserType { introduction: string; diet: $Enums.Diet; thumbnail: string; - created_at: Date; - updated_at: Date; + createdAt: Date; + updatedAt: Date; } diff --git a/api/libs/user/src/dto/filter-user.dto.ts b/api/libs/user/src/dto/filter-user.dto.ts index 15c84e4..41386c3 100644 --- a/api/libs/user/src/dto/filter-user.dto.ts +++ b/api/libs/user/src/dto/filter-user.dto.ts @@ -1,4 +1,4 @@ -import { Diet } from '../types/diet.enum'; +import { Diet } from '../domain/diet.enum'; export class FilterUserDto { nickname?: string; diff --git a/api/libs/user/src/dto/modify-user.dto.ts b/api/libs/user/src/dto/modify-user.dto.ts index f5da928..b659de3 100644 --- a/api/libs/user/src/dto/modify-user.dto.ts +++ b/api/libs/user/src/dto/modify-user.dto.ts @@ -1,6 +1,6 @@ import { IntersectionType, OmitType, PartialType } from '@nestjs/swagger'; import { IsEmail, IsEnum, IsOptional, IsString, IsUrl } from 'class-validator'; -import { Diet } from '../types/diet.enum'; +import { Diet } from '../domain/diet.enum'; export class CreateUserApiDto { @IsString() diff --git a/api/libs/user/src/dto/user-response.dto.ts b/api/libs/user/src/dto/user-response.dto.ts index 924d5e1..71a7eb9 100644 --- a/api/libs/user/src/dto/user-response.dto.ts +++ b/api/libs/user/src/dto/user-response.dto.ts @@ -1,5 +1,5 @@ import { SuccessResponse } from '@app/common/dto/success-response.dto'; -import { User } from '../entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; export class CreateUserResponseDto extends SuccessResponse { data: User; diff --git a/api/libs/user/src/repositories/mongo.user.repository.ts b/api/libs/user/src/repositories/mongo.user.repository.ts index 1878bbb..9611d10 100644 --- a/api/libs/user/src/repositories/mongo.user.repository.ts +++ b/api/libs/user/src/repositories/mongo.user.repository.ts @@ -3,7 +3,7 @@ import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; import { CreateUserDto, UpdateUserDto } from '../dto/modify-user.dto'; import { FilterUserDto } from '../dto/filter-user.dto'; -import { User, UserDocument } from '../entities/mongo.user.entity'; +import { User, UserDocument } from '@app/user/domain/mongo.user.entity'; import { Logable } from '@app/common/log/log.decorator'; import { Cacheable } from '@app/common/cache/cache.service'; import { IUserRepository } from './user.repository.interface'; diff --git a/api/libs/user/src/repositories/user.repository.interface.ts b/api/libs/user/src/repositories/user.repository.interface.ts index 5b492a1..2bb6f6a 100644 --- a/api/libs/user/src/repositories/user.repository.interface.ts +++ b/api/libs/user/src/repositories/user.repository.interface.ts @@ -1,6 +1,6 @@ import { ICrudRepository } from '@app/common/repository/crud.repository'; -import { User as MongoUser } from '../entities/mongo.user.entity'; -import { User as PrismaUser } from '../entities/user.entity'; +import { User as MongoUser } from '@app/user/domain/mongo.user.entity'; +import { User as PrismaUser } from '@app/user/domain/user.entity'; import { CreateUserDto, UpdateUserDto } from '../dto/modify-user.dto'; import { FilterUserDto } from '../dto/filter-user.dto'; @@ -9,5 +9,6 @@ type User = MongoUser | PrismaUser; export interface IUserRepository extends ICrudRepository { findByEmail(email: string): Promise; + findByUsername(username: string): Promise; } diff --git a/api/libs/user/src/repositories/user.repository.ts b/api/libs/user/src/repositories/user.repository.ts index 7447e76..095fa53 100644 --- a/api/libs/user/src/repositories/user.repository.ts +++ b/api/libs/user/src/repositories/user.repository.ts @@ -2,7 +2,7 @@ import { PrismaService } from '@app/common/prisma/prisma.service'; import { CrudPrismaRepository } from '@app/common/repository/crud-prisma.repository'; import { Injectable } from '@nestjs/common'; import { IUserRepository } from './user.repository.interface'; -import { User } from '../entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; import { CreateUserDto, UpdateUserDto } from '../dto/modify-user.dto'; import { FilterUserDto } from '../dto/filter-user.dto'; import { Logable } from '@app/common/log/log.decorator'; @@ -31,9 +31,9 @@ export class UserRepository return await this.prisma.user.findUnique({ where: { id }, include: { - device_tokens: { + deviceTokens: { select: { - fcm_device_token: true, + fcmDeviceToken: true, }, }, }, diff --git a/api/libs/user/src/controllers/user.controller.ts b/api/libs/user/src/user.controller.ts similarity index 92% rename from api/libs/user/src/controllers/user.controller.ts rename to api/libs/user/src/user.controller.ts index 3d45b36..1b788eb 100644 --- a/api/libs/user/src/controllers/user.controller.ts +++ b/api/libs/user/src/user.controller.ts @@ -1,24 +1,24 @@ import { - Controller, Body, - Param, - Post, - HttpCode, + Controller, + Delete, Get, - Patch, + HttpCode, HttpStatus, - Delete, + Param, ParseIntPipe, + Patch, + Post, } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { CreateUserDto, UpdateUserDto } from '../dto/modify-user.dto'; -import { UserService } from '../services/user.service'; +import { CreateUserDto, UpdateUserDto } from './dto/modify-user.dto'; +import { UserService } from './user.service'; import { CreateUserResponseDto, FindAllUserResponseDto, FindOneUserResponseDto, UpdateUserResponseDto, -} from '../dto/user-response.dto'; +} from './dto/user-response.dto'; import { ApiDeleteNoContent, ApiGet, diff --git a/api/libs/user/src/user.module.ts b/api/libs/user/src/user.module.ts index cb2d68c..f1e17a3 100644 --- a/api/libs/user/src/user.module.ts +++ b/api/libs/user/src/user.module.ts @@ -1,12 +1,12 @@ import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; -import { UserController } from './controllers/user.controller'; +import { UserController } from './user.controller'; import { User, UserSchema, UserSchemaFactory, -} from './entities/mongo.user.entity'; -import { UserService } from './services/user.service'; +} from '@app/user/domain/mongo.user.entity'; +import { UserService } from './user.service'; import { UserRepository } from './repositories/user.repository'; import { ConfigService } from '@nestjs/config'; diff --git a/api/libs/user/src/services/user.service.ts b/api/libs/user/src/user.service.ts similarity index 91% rename from api/libs/user/src/services/user.service.ts rename to api/libs/user/src/user.service.ts index 99ad8aa..2510eb1 100644 --- a/api/libs/user/src/services/user.service.ts +++ b/api/libs/user/src/user.service.ts @@ -3,11 +3,11 @@ import { Injectable, NotFoundException, } from '@nestjs/common'; -import { CreateUserDto, UpdateUserDto } from '../dto/modify-user.dto'; -import { UserRepository } from '../repositories/user.repository'; +import { CreateUserDto, UpdateUserDto } from './dto/modify-user.dto'; +import { UserRepository } from './repositories/user.repository'; import { Logable } from '@app/common/log/log.decorator'; import { ConfigService } from '@nestjs/config'; -import { User } from '../entities/user.entity'; +import { User } from '@app/user/domain/user.entity'; @Injectable() export class UserService { diff --git a/api/libs/user/src/repositories/mongo.user.repository.spec.ts b/api/libs/user/test/integration/mongo.user.repository.spec.ts similarity index 85% rename from api/libs/user/src/repositories/mongo.user.repository.spec.ts rename to api/libs/user/test/integration/mongo.user.repository.spec.ts index 2ff2f6e..4b7c88a 100644 --- a/api/libs/user/src/repositories/mongo.user.repository.spec.ts +++ b/api/libs/user/test/integration/mongo.user.repository.spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { UserRepository } from './mongo.user.repository'; +import { UserRepository } from '@app/user/repositories/mongo.user.repository'; describe('UserRepository', () => { let userRepository: UserRepository; diff --git a/api/libs/user/src/controllers/user.controller.spec.ts b/api/libs/user/test/integration/user.controller.spec.ts similarity index 74% rename from api/libs/user/src/controllers/user.controller.spec.ts rename to api/libs/user/test/integration/user.controller.spec.ts index da3cad7..9f2a0b6 100644 --- a/api/libs/user/src/controllers/user.controller.spec.ts +++ b/api/libs/user/test/integration/user.controller.spec.ts @@ -1,8 +1,8 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { UserService } from '../services/user.service'; -import { UserController } from './user.controller'; -import { UserRepository } from '../repositories/user.repository'; -import { AuthService } from '@app/auth/services/auth.service'; +import { UserService } from '@app/user/user.service'; +import { UserController } from '@app/user/user.controller'; +import { UserRepository } from '@app/user/repositories/user.repository'; +import { AuthService } from '@app/auth/auth.service'; import { ConfigService } from '@nestjs/config'; describe('UserController', () => { diff --git a/api/libs/user/src/services/user.service.spec.ts b/api/libs/user/test/unit/user.service.spec.ts similarity index 93% rename from api/libs/user/src/services/user.service.spec.ts rename to api/libs/user/test/unit/user.service.spec.ts index d363887..0c327e9 100644 --- a/api/libs/user/src/services/user.service.spec.ts +++ b/api/libs/user/test/unit/user.service.spec.ts @@ -1,9 +1,9 @@ import { TestBed } from '@automock/jest'; import { BadRequestException } from '@nestjs/common'; -import { CreateUserDto } from '../dto/modify-user.dto'; -import { UserRepository } from '../repositories/user.repository'; -import { UserService } from './user.service'; -import { User } from '../entities/user.entity'; +import { CreateUserDto } from '@app/user/dto/modify-user.dto'; +import { UserRepository } from '@app/user/repositories/user.repository'; +import { UserService } from '@app/user/user.service'; +import { User } from '@app/user/domain/user.entity'; describe('UserService', () => { let service: UserService; diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma index 0747cd4..1b4d45a 100644 --- a/api/prisma/schema.prisma +++ b/api/prisma/schema.prisma @@ -10,14 +10,14 @@ datasource mysql { } model DeviceToken { - id Int @id @default(autoincrement()) - fcm_device_token String - user_id Int - user User @relation(fields: [user_id], references: [id]) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - - @@index([user_id]) + id Int @id @default(autoincrement()) + fcmDeviceToken String @map("fcm_device_token") + userId Int @map("user_id") + user User @relation(fields: [userId], references: [id]) + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + @@index([userId]) @@map("device_tokens") } @@ -27,123 +27,123 @@ model Ingredient { name String @unique() thumbnail String icon String - created_at DateTime @default(now()) - updated_at DateTime @updatedAt + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") Useringredient UserIngredient[] @@map("ingredients") } model Noti { - id Int @id @default(autoincrement()) - user_id Int - user User @relation(fields: [user_id], references: [id]) - content String - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - - @@index([user_id]) + id Int @id @default(autoincrement()) + userId Int @map("user_id") + user User @relation(fields: [userId], references: [id]) + content String + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + @@index([userId]) @@map("notis") } model RecipeBookmark { - id Int @id @default(autoincrement()) - user_id Int - user User @relation(fields: [user_id], references: [id]) - recipe_id Int - recipe Recipe @relation(fields: [recipe_id], references: [id]) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - - @@index([user_id]) - @@index([recipe_id]) + id Int @id @default(autoincrement()) + userId Int @map("user_id") + user User @relation(fields: [userId], references: [id]) + recipeId Int @map("recipeId") + recipe Recipe @relation(fields: [recipeId], references: [id]) + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + @@index([userId]) + @@index([recipeId]) @@map("recipe_bookmarks") } model Recipe { - id Int @id @default(autoincrement()) - mongo_id String? @unique - name String - description String - owner_id Int? - owner User? @relation(fields: [owner_id], references: [id]) - thumbnail String - origin_url String - view_count Int @default(0) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - recipe_bookmark RecipeBookmark[] - recipe_view_log RecipeViewLog[] - - @@index([owner_id]) + id Int @id @default(autoincrement()) + mongoId String? @unique + name String + description String + ownerId Int? + owner User? @relation(fields: [ownerId], references: [id]) + thumbnail String + originUrl String + viewCount Int @default(0) + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + recipeBookmark RecipeBookmark[] + recipeViewLog RecipeViewLog[] + + @@index([ownerId]) @@map("recipes") } model RecipeViewLog { - id Int @id @default(autoincrement()) - recipe_id Int - recipe Recipe @relation(fields: [recipe_id], references: [id]) - user_id Int? - user User? @relation(fields: [user_id], references: [id]) - user_ip String - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - - @@index([created_at]) - @@index([recipe_id]) - @@index([user_id]) + id Int @id @default(autoincrement()) + recipeId Int @map("recipe_id") + recipe Recipe @relation(fields: [recipeId], references: [id]) + userId Int? @map("user_id") + user User? @relation(fields: [userId], references: [id]) + userIp String @map("user_ip") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + @@index([createdAt]) + @@index([recipeId]) + @@index([userId]) @@map("recipe_view_logs") } model Session { - id Int @id @default(autoincrement()) - session_token String @unique() - user_id Int - user User @relation(fields: [user_id], references: [id]) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - - @@index([created_at]) - @@index([user_id]) + id Int @id @default(autoincrement()) + sessionToken String @unique() @map("session_token") + userId Int @map("user_id") + user User @relation(fields: [userId], references: [id]) + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + @@index([createdAt]) + @@index([userId]) @@map("sessions") } model UserIngredient { - id Int @id @default(autoincrement()) - count Int - days_before_expiration Int - food_type FoodType @default(ETC) - icon String - name String - store_method StoreMethod @default(REFRIGERATE) - ingredient_id Int - ingredient Ingredient @relation(fields: [ingredient_id], references: [id]) - user_id Int - user User @relation(fields: [user_id], references: [id]) - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - - @@index([ingredient_id]) - @@index([user_id]) + id Int @id @default(autoincrement()) + count Int + daysBeforeExpiration Int @map("days_before_expiration") + foodType FoodType @default(ETC) @map("food_type") + icon String + name String + storeMethod StoreMethod @default(REFRIGERATE) @map("store_method") + ingredientId Int @map("ingredient_id") + ingredient Ingredient @relation(fields: [ingredientId], references: [id]) + userId Int @map("user_id") + user User @relation(fields: [userId], references: [id]) + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + @@index([ingredientId]) + @@index([userId]) @@map("user_ingredients") } model User { - id Int @id @default(autoincrement()) - username String @unique() - email String @unique() - introduction String @default("") - diet Diet @default(NORMAL) - thumbnail String @default("") - device_tokens DeviceToken[] - created_at DateTime @default(now()) - updated_at DateTime @updatedAt - notis Noti[] - recipe_bookmarks RecipeBookmark[] - recipe_view_logs RecipeViewLog[] - sessions Session[] - user_ingredients UserIngredient[] - recipes Recipe[] + id Int @id @default(autoincrement()) + username String @unique() + email String @unique() + introduction String @default("") + diet Diet @default(NORMAL) + thumbnail String @default("") + deviceTokens DeviceToken[] + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + notis Noti[] + recipeBookmarks RecipeBookmark[] + recipeViewLogs RecipeViewLog[] + sessions Session[] + userIngredients UserIngredient[] + recipes Recipe[] @@map("users") }