Skip to content

Commit

Permalink
1차 문제 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoldu committed Nov 11, 2023
1 parent d3cfff7 commit 44fc517
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 27 deletions.
6 changes: 6 additions & 0 deletions src/product/DbConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class DbConnection {
async query(sql: string, params: string[]) {
console.log(sql);
return 1;
}
}
65 changes: 49 additions & 16 deletions src/product/Product.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
export class Product {
private readonly id: string;
private readonly name: string;
private readonly price: number;
private readonly status: string;
private readonly description: string;
private readonly createdAt: Date;
private readonly updatedAt: Date;
private readonly deletedAt: Date;
private readonly _id: string;
private readonly _name: string;
private readonly _price: number;
private readonly _status: string;
private readonly _description: string;
private readonly _createdAt: Date;
private readonly _updatedAt: Date;
private readonly _deletedAt: Date;

constructor(id: string, name: string, price: number, status: string, description: string, createdAt: Date, updatedAt: Date, deletedAt: Date) {
this.id = id;
this.name = name;
this.price = price;
this.status = status;
this.description = description;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.deletedAt = deletedAt;
this._id = id;
this._name = name;
this._price = price;
this._status = status;
this._description = description;
this._createdAt = createdAt;
this._updatedAt = updatedAt;
this._deletedAt = deletedAt;
}

static newInstance (id: string, name: string, price: number, description: string) {
Expand All @@ -31,4 +31,37 @@ export class Product {
null
)
}


get id(): string {
return this._id;
}

get name(): string {
return this._name;
}

get price(): number {
return this._price;
}

get status(): string {
return this._status;
}

get description(): string {
return this._description;
}

get createdAt(): Date {
return this._createdAt;
}

get updatedAt(): Date {
return this._updatedAt;
}

get deletedAt(): Date {
return this._deletedAt;
}
}
25 changes: 14 additions & 11 deletions src/product/ProductService.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import { Product } from "./Product";
import {Product} from "./Product";
import {ProductCreateDto} from "./ProductCreateDto";
import {DbConnection} from "./DbConnection";

export class ProductService {
private readonly dbConnection: DbConnection;

constructor(dbConnection: DbConnection) {
this.dbConnection = dbConnection;
}

async create_1 (createDtos: ProductCreateDto[]) {
const promiseList = [];
const results = [];
const results: Product[] = [];
for(const dto of createDtos) {
const entity = dto.toEntity(generateId());
const queryParams = [];

const query = `INSERT INTO ${ CLASS_TABLE_NAME }` +
`(${ Object.keys(entity).map(k => convertCamelToSnakeName(k)) }) ` +
`VALUES ( ${convertUuidToBinParam()}, ${convertUuidToBinParam()}, ${convertUuidToBinParam()}, ?, ?, ?, ?, ?, ?, NOW(), NOW() )`;
const query =
`INSERT INTO product (${ Object.keys(entity) }) `
+ 'VALUES (?, ?, ?, ?, ?, NOW(), NOW() )';

queryParams.push(
entity.id,
entity.categoryId,
entity.teacherId,
entity.nameHash,
entity.name,
entity.price,
entity.state,
entity.isDeleted,
entity.status,
entity.description
);
promiseList.push(this.dbConnection.query(query, queryParams))
results.push(ClassDto.fromEntity(entity));
results.push(entity);
}

await Promise.all(promiseList);
Expand Down

0 comments on commit 44fc517

Please sign in to comment.