Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/#15
Browse files Browse the repository at this point in the history
  • Loading branch information
dannaward committed Jul 17, 2022
2 parents 1a8f054 + a10b52a commit 7aba7c1
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 44 deletions.
43 changes: 43 additions & 0 deletions src/controllers/HomeController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Get, HttpCode, JsonController, Res } from 'routing-controllers';
import { OpenAPI } from 'routing-controllers-openapi';
import { Response } from 'express';
import statusCode from '../modules/statusCode';
import util from '../modules/util';
import message from '../modules/responseMessage';
import { HomeService } from '../services/homeService';
import { logger } from '../utils/Logger';

@JsonController('/home')
export class HomeController {
constructor(private homeService: HomeService) {}

@HttpCode(200)
@Get('')
@OpenAPI({
summary: '홈 데이터 조회',
description: '메인 화면 데이터 반환',
statusCode: '200',
})
public async getData(@Res() res: Response): Promise<Response> {
try {
const list = await this.homeService.fetchList();

return res
.status(statusCode.OK)
.send(
util.success(statusCode.OK, message.FETCH_HOME_DATA_SUCCESS, list)
);
} catch (err) {
logger.error(err);

return res
.status(statusCode.INTERNAL_SERVER_ERROR)
.send(
util.fail(
statusCode.INTERNAL_SERVER_ERROR,
message.INTERNAL_SERVER_ERROR
)
);
}
}
}
26 changes: 26 additions & 0 deletions src/dtos/HomeDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ToyDto } from './ToyDto';

/**
* Home Response Dto
*/
export class ResponseHomeDto {
public trending?: ToyDto[] | null;

public theme?: ThemeDto[] | null;

public noriPick?: ToyDto[] | null;

public senses?: ToyDto[] | null;

public smart?: ToyDto[] | null;
}

export class ThemeDto {
public id: number;

public image: string;

public subtitle: string;

public title: string;
}
25 changes: 25 additions & 0 deletions src/dtos/ToyDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IsNotEmpty } from 'class-validator';
import { Toy } from '../entities/Toy';

/**
* 장난감 Dto
*/
export class ToyDto {
@IsNotEmpty()
public image: string;

@IsNotEmpty()
public siteName: string;

@IsNotEmpty()
public title: string;

@IsNotEmpty()
public price: string;

@IsNotEmpty()
public month: number;

@IsNotEmpty()
public siteUrl: string;
}
12 changes: 6 additions & 6 deletions src/entities/LikeToy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
import { Toy } from "./Toy";
import { User } from "./User";
} from 'typeorm';
import { Toy } from './Toy';
import { User } from './User';

@Entity({ name: "like_toy" })
@Entity({ name: 'like_toy' })
export class LikeToy {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => User, (user) => user.likeToys, {
onDelete: "CASCADE",
onDelete: 'CASCADE',
nullable: false,
})
user: User;

@ManyToOne(() => Toy, (toy) => toy.likeToys, {
onDelete: "CASCADE",
onDelete: 'CASCADE',
nullable: false,
})
toy: Toy;
Expand Down
56 changes: 38 additions & 18 deletions src/entities/Toy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty } from "class-validator";
import { IsNotEmpty } from 'class-validator';
import {
Column,
CreateDateColumn,
Expand All @@ -7,58 +7,59 @@ import {
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
import { LikeToy } from "./LikeToy";
import { ToyCategory } from "./ToyCategory";
import { ToySite } from "./ToySite";
} from 'typeorm';
import { ToyDto } from '../dtos/ToyDto';
import { LikeToy } from './LikeToy';
import { ToyCategory } from './ToyCategory';
import { ToySite } from './ToySite';

@Entity({ name: "toy" })
@Entity({ name: 'toy' })
export class Toy {
@PrimaryGeneratedColumn()
id: number;

@IsNotEmpty()
@Column({ name: "title" })
@Column({ name: 'title' })
title: string;

@IsNotEmpty()
@Column({ name: "price" })
@Column({ name: 'price' })
price: string;

@IsNotEmpty()
@Column({ name: "price_cd" })
@Column({ name: 'price_cd' })
priceCd: number;

@IsNotEmpty()
@Column({ name: "month" })
@Column({ name: 'month' })
month: number;

@IsNotEmpty()
@Column({ name: "min_month" })
@Column({ name: 'min_month' })
minMonth: number;

@IsNotEmpty()
@Column({ name: "max_month" })
@Column({ name: 'max_month' })
maxMonth: number;

@IsNotEmpty()
@Column({ name: "link" })
@Column({ name: 'link' })
link: string;

@IsNotEmpty()
@Column({ name: "play_how" })
@Column({ name: 'play_how' })
playHow: string;

@IsNotEmpty()
@Column({ name: "play_how_cd" })
@Column({ name: 'play_how_cd' })
playHowCd: number;

@IsNotEmpty()
@Column({ name: "image" })
@Column({ name: 'image' })
image: string;

@IsNotEmpty()
@Column({ name: "collection", length: 20 })
@Column({ name: 'collection', length: 20 })
collection: string;

@OneToMany(() => ToyCategory, (toyCategory) => toyCategory.toy, {
Expand All @@ -67,7 +68,7 @@ export class Toy {
toyCategories: ToyCategory;

@ManyToOne(() => ToySite, (toySite) => toySite.toys, {
onDelete: "CASCADE",
onDelete: 'CASCADE',
nullable: false,
})
toySite: ToySite;
Expand All @@ -82,4 +83,23 @@ export class Toy {

@UpdateDateColumn()
updatedAt: Date;

public toDto(toyEntity: Toy[]): ToyDto[] {
const toys: ToyDto[] = [];

for (const toy of toyEntity) {
const toyDto = new ToyDto();

toyDto.image = toy.image;
toyDto.siteName = toy.toySite.toySite;
toyDto.title = toy.title;
toyDto.price = toy.price;
toyDto.month = toy.month;
toyDto.siteUrl = toy.link;

toys.push(toyDto);
}

return toys;
}
}
12 changes: 6 additions & 6 deletions src/entities/ToyCategory.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { IsNotEmpty } from "class-validator";
import { IsNotEmpty } from 'class-validator';
import {
Column,
CreateDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
import { Toy } from "./Toy";
} from 'typeorm';
import { Toy } from './Toy';

@Entity({ name: "toy_category" })
@Entity({ name: 'toy_category' })
export class ToyCategory {
@PrimaryGeneratedColumn()
id: number;

@IsNotEmpty()
@Column({ name: "category", length: 20 })
@Column({ name: 'category', length: 20 })
category: string;

@ManyToOne(() => Toy, (toy) => toy.toyCategorys, {
@ManyToOne(() => Toy, (toy) => toy.toyCategories, {
nullable: false,
})
toy: Toy;
Expand Down
12 changes: 6 additions & 6 deletions src/entities/ToySite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty } from "class-validator";
import { IsNotEmpty } from 'class-validator';
import {
Column,
CreateDateColumn,
Expand All @@ -7,20 +7,20 @@ import {
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
import { Toy } from "./Toy";
} from 'typeorm';
import { Toy } from './Toy';

@Entity({ name: "toy_site" })
@Entity({ name: 'toy_site' })
export class ToySite {
@PrimaryGeneratedColumn()
id: number;

@IsNotEmpty()
@Column({ name: "toy_site", length: 20 })
@Column({ name: 'toy_site', length: 20 })
toySite: string;

@OneToMany(() => Toy, (toy) => toy.toySite, {
onDelete: "CASCADE",
onDelete: 'CASCADE',
nullable: false,
})
toys: Toy;
Expand Down
16 changes: 8 additions & 8 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* NODE_ENV에 따른 .env 파일을 로드한다.
*/
require("dotenv").config({
path: `config/.env.${process.env.NODE_ENV || "development"}`,
require('dotenv').config({
path: `env/.env.${process.env.NODE_ENV || 'development'}`,
});

/**
* 환경 변수
*/
export const env = {
isDevelopment: process.env.NODE_ENV === "development",
isProduction: process.env.NODE_ENV === "production",
isTest: process.env.NODE_ENV === "test",
isDevelopment: process.env.NODE_ENV === 'development',
isProduction: process.env.NODE_ENV === 'production',
isTest: process.env.NODE_ENV === 'test',
app: {
port: Number(process.env.PORT) || 8080,
apiPrefix: process.env.API_PREFIX || "/api",
apiPrefix: process.env.API_PREFIX || '/api',
jwtAccessSecret: process.env.JWT_SECRET_ACCESS_KEY,
jwtRefreshSecret: process.env.JWT_SECRET_REFRESH_KEY,
},
Expand All @@ -24,8 +24,8 @@ export const env = {
usename: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
name: process.env.DATABASE_NAME,
synchronize: process.env.TYPEORM_SYNCHRONIZE === "true",
logging: process.env.TYPEORM_LOGGING === "true",
synchronize: process.env.TYPEORM_SYNCHRONIZE === 'true',
logging: process.env.TYPEORM_LOGGING === 'true',
},
swagger: {
route: process.env.SWAGGER_ROUTE,
Expand Down
3 changes: 3 additions & 0 deletions src/modules/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const message = {
CREATE_USER_FAIL: "유저 생성 실패",
LOGIN_SUCCESS: "로그인 성공",

// 홈
FETCH_HOME_DATA_SUCCESS: "홈 데이터 조회 성공",

// 게시판
READ_BAORD_LIST_SUCCESS: "게시물 목록 조회 성공"
};
Expand Down
5 changes: 5 additions & 0 deletions src/repositories/HomeRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { EntityRepository, Repository } from 'typeorm';
import { Toy } from '../entities/Toy';

@EntityRepository(Toy)
export class HomeRepository extends Repository<Toy> {}
Loading

0 comments on commit 7aba7c1

Please sign in to comment.