Skip to content

Commit

Permalink
merge :: create emoji api (#18)
Browse files Browse the repository at this point in the history
* add :: create emoji

* chore :: add format
  • Loading branch information
jyk1029 authored Mar 5, 2024
1 parent 9f1a5ac commit c913b40
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 22 deletions.
22 changes: 22 additions & 0 deletions src/application/domain/emoji/controller/emoji.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Body, Controller, Injectable, Post, UseFilters, UseGuards } from "@nestjs/common";
import { GlobalExceptionFilter } from "../../../../infrastructure/global/filter/global.exception.filter";
import { EmojiService } from "../service/emoji.service";
import { CurrentUser } from "../../../../infrastructure/global/decorator/current-user";
import { UserEntity } from "../../../../infrastructure/domain/user/persistence/user.entity";
import { CreateEmojiRequest } from "../dto/emoji.dto";
import { AuthGuard } from "@nestjs/passport";

@UseFilters(GlobalExceptionFilter)
@Controller('emoji')
export class EmojiController {
constructor(
private emojiService: EmojiService
) {
}

@UseGuards(AuthGuard())
@Post()
async createEmoji(@CurrentUser() user: UserEntity, @Body() request: CreateEmojiRequest) {
await this.emojiService.createEmoji(user, request)
}
}
16 changes: 16 additions & 0 deletions src/application/domain/emoji/dto/emoji.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IsNotEmpty, IsNumber, IsString, Matches } from "class-validator";

export class CreateEmojiRequest {
@IsNotEmpty()
@IsString()
title: string;
@IsNotEmpty()
@IsString()
content: string;
@IsNotEmpty()
@IsString()
imageUrl: string;
@IsNotEmpty()
@IsNumber()
price: number;
}
19 changes: 19 additions & 0 deletions src/application/domain/emoji/service/emoji.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { EmojiEntity } from "../../../../infrastructure/domain/emoji/persistence/emoji.entity";
import { Repository } from "typeorm";
import { CreateEmojiRequest } from "../dto/emoji.dto";

@Injectable()
export class EmojiService {
constructor(
@InjectRepository(EmojiEntity)
private emojiRepository: Repository<EmojiEntity>,
) {
}

async createEmoji(req, request: CreateEmojiRequest) {
let { title, content, imageUrl, price } = request
await this.emojiRepository.save({ title: title, content: content, image: imageUrl, price: price, userId: req })
}
}
9 changes: 6 additions & 3 deletions src/infrastructure/domain/emoji/persistence/emoji.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ export class EmojiEntity {
@Column('varchar', { length: 1000, nullable: false })
content: string;

@Column('varchar', { length: 3000, nullable: false })
image: string;

@Column('int', { nullable: false, default: 0 })
price: string;
price: number;

@ManyToOne(() => UserEntity)
@ManyToOne(() => UserEntity, { lazy: true })
@JoinColumn({ name: 'user_id' })
userId: string;
userId: UserEntity;
}
15 changes: 0 additions & 15 deletions src/infrastructure/domain/emoji/persistence/emoji.image.entity.ts

This file was deleted.

9 changes: 5 additions & 4 deletions src/infrastructure/global/module/emoji.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EmojiEntity } from "../../domain/emoji/persistence/emoji.entity";
import { EmojiImageEntity } from "../../domain/emoji/persistence/emoji.image.entity";
import { EmojiService } from "../../../application/domain/emoji/service/emoji.service";
import { EmojiController } from "../../../application/domain/emoji/controller/emoji.controller";

const EMOJI_REPOSITORY = TypeOrmModule.forFeature([ EmojiEntity, EmojiImageEntity ]);
const EMOJI_REPOSITORY = TypeOrmModule.forFeature([ EmojiEntity ]);

@Global()
@Module({
imports: [ EMOJI_REPOSITORY ],
controllers: [],
providers: [],
controllers: [ EmojiController ],
providers: [ EmojiService ],
exports: [ EMOJI_REPOSITORY ]
})
export class EmojiModule {
Expand Down

0 comments on commit c913b40

Please sign in to comment.