Skip to content

Commit

Permalink
Merge pull request #384 from klaus9267/feature-board
Browse files Browse the repository at this point in the history
Feature boardRefactor(minho/board): 게시글 전체조회 수정 #4
  • Loading branch information
klaus9267 authored Mar 8, 2023
2 parents b97776a + 6c34a90 commit 1ceb30f
Show file tree
Hide file tree
Showing 23 changed files with 531 additions and 275 deletions.
5 changes: 3 additions & 2 deletions main-project/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Get,
Patch,
Post,
Param,
UseGuards,
UseInterceptors,
} from '@nestjs/common/decorators';
Expand Down Expand Up @@ -108,8 +109,8 @@ export class AuthController {
}

@ApiGetEmailCode()
@Get('/email-code')
async getEmailCode(@Body() { email }: EmailDto) {
@Get('/email-code/:email')
async getEmailCode(@Param('email') email: string) {
await this.authService.getEmailCode(email);

return { msg: '이메일 인증 코드가 전송되었습니다' };
Expand Down
6 changes: 6 additions & 0 deletions main-project/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export class AuthService {
}

async getEmailCode(email: string): Promise<void> {
const emailFormat =
/^([0-9a-zA-Z_\.-]+)@([0-9a-zA-Z_-]+)(\.[0-9a-zA-Z_-]+){1,2}$/;
if (!emailFormat.test(email)) {
throw new BadRequestException('올바르지 않은 이메일 형식');
}

await this.validateUserNotCreated(email);
const validationKey = this.getEmailValidationKey();
await this.cacheManager.set(email, validationKey, {
Expand Down
19 changes: 7 additions & 12 deletions main-project/src/boards/boards.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
GuestTeam,
BoardPagenation,
GuestTeamPagenation,
GuestProfile,
HostProfile,
} from './interface/boards.interface';
import { BoardFilterDto } from './dto/board-filter.dto';
import { Cron, CronExpression } from '@nestjs/schedule/dist';
Expand Down Expand Up @@ -62,7 +64,6 @@ export class BoardsController {

//Get Methods
@Get()
@UseGuards(JwtAuthGuard)
@UseInterceptors(TransactionInterceptor)
@ApiGetBoards()
async getBoards(
Expand All @@ -86,11 +87,8 @@ export class BoardsController {
@GetUser() userNo: number,
@TransactionDecorator() manager: EntityManager,
): Promise<APIResponse> {
const board: Board<number[], string[]> = await this.boardService.getBoard(
manager,
boardNo,
userNo,
);
const board: Board<number[], string[], HostProfile> =
await this.boardService.getBoard(manager, boardNo, userNo);

return { msg: '게시글 상세조회 성공', response: { board } };
}
Expand All @@ -104,11 +102,8 @@ export class BoardsController {
@GetUser() userNo: number,
@TransactionDecorator() manager: EntityManager,
): Promise<APIResponse> {
const boards: Board<void, void>[] = await this.boardService.getBoardsByUser(
manager,
userNo,
Number(type),
);
const boards: Board<void, void, HostProfile>[] =
await this.boardService.getBoardsByUser(manager, userNo, Number(type));

return { msg: '유저별 게시글 조회 성공', response: { boards } };
}
Expand Down Expand Up @@ -147,7 +142,7 @@ export class BoardsController {
@GetUser() userNo: number,
@TransactionDecorator() manager: EntityManager,
): Promise<APIResponse> {
const guestTeam: GuestTeam<number[]> =
const guestTeam: GuestTeam<number[], GuestProfile> =
await this.boardService.getGuestTeamByTeamNo(
manager,
teamNo,
Expand Down
98 changes: 53 additions & 45 deletions main-project/src/boards/boards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
GuestTeam,
BoardPagenation,
GuestTeamPagenation,
GuestProfile,
HostProfile,
} from './interface/boards.interface';
import { BoardBookmarksRepository } from './repository/board-bookmark.repository';
import { BoardGuestsRepository as BoardGuestsRepository } from './repository/board-guest.repository';
Expand All @@ -31,9 +33,8 @@ import { Friend } from 'src/friends/interface/friend.interface';
import { BoardBookmarks } from './entity/board-bookmark.entity';
import { ConfigService } from '@nestjs/config';
import { SavedNotice } from 'src/notices/interface/notice.interface';
import { Boards } from './entity/board.entity';
import { Notices } from 'src/notices/entity/notices.entity';
import { BoardHosts } from './entity/board-host.entity';
import { BoardGuestTeams } from './entity/board-guest-team.entity';

@Injectable()
export class BoardsService {
Expand All @@ -53,7 +54,7 @@ export class BoardsService {
try {
await queryRunner.manager
.getCustomRepository(BoardsRepository)
.closeBoard();
.closeImpromptuBoard();
await queryRunner.commitTransaction();
} catch (error) {
await queryRunner?.rollbackTransaction();
Expand Down Expand Up @@ -86,8 +87,8 @@ export class BoardsService {
manager: EntityManager,
userNo: number,
type: number,
): Promise<Board<void, void>[]> {
const boards: Board<void, void>[] = await manager
): Promise<Board<void, void, HostProfile>[]> {
const boards: Board<void, void, HostProfile>[] = await manager
.getCustomRepository(BoardsRepository)
.getBoardsByUser(userNo, type);

Expand All @@ -98,12 +99,9 @@ export class BoardsService {
manager: EntityManager,
boardNo: number,
userNo: number,
): Promise<Board<number[], string[]>> {
const board: Board<number[], string[]> = await this.readBoardByNo(
manager,
boardNo,
userNo,
);
): Promise<Board<number[], string[], HostProfile>> {
const board: Board<number[], string[], HostProfile> =
await this.readBoardByNo(manager, boardNo, userNo);

if (!board.no) {
throw new NotFoundException(
Expand All @@ -118,8 +116,8 @@ export class BoardsService {
manager: EntityManager,
boardNo: number,
userNo: number,
): Promise<Board<number[], string[]>> {
const board: Board<number[], string[]> = await manager
): Promise<Board<number[], string[], HostProfile>> {
const board: Board<number[], string[], HostProfile> = await manager
.getCustomRepository(BoardsRepository)
.getBoardByNo(boardNo, userNo);

Expand Down Expand Up @@ -152,8 +150,8 @@ export class BoardsService {
private async readGuestTeamInfo(
manager: EntityManager,
teamNo: number,
): Promise<GuestTeam<number[]>> {
const guestTeam: GuestTeam<number[]> = await manager
): Promise<GuestTeam<number[], GuestProfile>> {
const guestTeam: GuestTeam<number[], GuestProfile> = await manager
.getCustomRepository(BoardGuestTeamsRepository)
.getGuestTeamInfo(teamNo);

Expand All @@ -169,29 +167,46 @@ export class BoardsService {
await this.getBoard(manager, boardNo, userNo);
await this.validateHost(manager, boardNo, userNo);

const guestTeams: GuestTeamPagenation = await this.readGuestTeamsByBoardNo(
manager,
boardNo,
page,
);
const guestTeams: Omit<GuestTeamPagenation, 'acceptedGuestTeamNo'> =
await this.readGuestTeamsByBoardNo(manager, boardNo, page);

if (!guestTeams.guestTeams.length) {
throw new BadRequestException(
`여름 신청내역 조회(getGuestTeamsByBoardNo-service): 신청내역이 없습니다.`,
);
}

return guestTeams;
const acceptedGuestTeamNo: number | null =
await this.readAcceptedGuestTeamNo(manager, boardNo);

const guestTeamsMetaData: GuestTeamPagenation = {
...guestTeams,
acceptedGuestTeamNo,
};

return guestTeamsMetaData;
}

private async readAcceptedGuestTeamNo(
manager: EntityManager,
boardNo: number,
): Promise<number | null> {
const acceptedGuestTeam: Pick<BoardGuestTeams, 'no'> = await manager
.getCustomRepository(BoardGuestTeamsRepository)
.getAcceptedGuestTeamNo(boardNo);

return !acceptedGuestTeam ? null : acceptedGuestTeam.no;
}

async readGuestTeamsByBoardNo(
manager: EntityManager,
boardNo: number,
page: number,
): Promise<GuestTeamPagenation> {
const guestTeamMetaData: GuestTeamPagenation = await manager
.getCustomRepository(BoardGuestTeamsRepository)
.getGuestTeamsByBoardNo(boardNo, page);
): Promise<Omit<GuestTeamPagenation, 'acceptedGuestTeamNo'>> {
const guestTeamMetaData: Omit<GuestTeamPagenation, 'acceptedGuestTeamNo'> =
await manager
.getCustomRepository(BoardGuestTeamsRepository)
.getGuestTeamsByBoardNo(boardNo, page);

return guestTeamMetaData;
}
Expand All @@ -212,14 +227,12 @@ export class BoardsService {
teamNo: number,
boardNo: number,
userNo: number,
): Promise<GuestTeam<number[]>> {
): Promise<GuestTeam<number[], GuestProfile>> {
await this.getBoard(manager, boardNo, userNo);
await this.validateHost(manager, boardNo, userNo);
// await this.validateHost(manager, boardNo, userNo);

const guestTeams: GuestTeam<number[]> = await this.readGuestTeamInfo(
manager,
teamNo,
);
const guestTeams: GuestTeam<number[], GuestProfile> =
await this.readGuestTeamInfo(manager, teamNo);

return guestTeams;
}
Expand Down Expand Up @@ -269,7 +282,7 @@ export class BoardsService {
boardNo: number,
userNo: number,
): Promise<number> {
const { no }: GuestTeam<number[]> = await manager
const { no }: GuestTeam<number[], GuestProfile> = await manager
.getCustomRepository(BoardGuestTeamsRepository)
.getTeamNoByUser(boardNo, userNo);

Expand Down Expand Up @@ -331,7 +344,7 @@ export class BoardsService {
recruitMale,
recruitFemale,
hostMemberNums,
}: Board<number[], string[]> = await this.getBoard(
}: Board<number[], string[], HostProfile> = await this.getBoard(
manager,
boardNo,
userNo,
Expand Down Expand Up @@ -389,7 +402,7 @@ export class BoardsService {

private async setGuestTeam(
manager: EntityManager,
guestTeam: GuestTeam<boolean>,
guestTeam: GuestTeam<boolean, GuestProfile>,
): Promise<number> {
const { insertId }: ResultSetHeader = await manager
.getCustomRepository(BoardGuestTeamsRepository)
Expand Down Expand Up @@ -529,10 +542,8 @@ export class BoardsService {

await this.deleteNotice(manager, noticeNo);

const { isAccepted }: GuestTeam<number[]> = await this.readGuestTeamInfo(
manager,
teamNo,
);
const { isAccepted }: GuestTeam<number[], GuestProfile> =
await this.readGuestTeamInfo(manager, teamNo);

const isAllAccepted: boolean = isAccepted.includes(0) ? false : true;

Expand All @@ -557,11 +568,8 @@ export class BoardsService {
boardNo: number,
userNo: number,
): Promise<void> {
const { hostUserNo }: Board<number[], string[]> = await this.getBoard(
manager,
boardNo,
userNo,
);
const { hostUserNo }: Board<number[], string[], HostProfile> =
await this.getBoard(manager, boardNo, userNo);
this.validateWriter(hostUserNo, userNo);
await this.removeBoard(manager, boardNo);
}
Expand Down Expand Up @@ -820,7 +828,7 @@ export class BoardsService {

private async validateRecruits(
manager: EntityManager,
board: Board<number[], string[]>,
board: Board<number[], string[], HostProfile>,
updateBoardDto: UpdateBoardDto,
): Promise<void> {
const guests: number[] = await this.getAllGuestsByBoardNo(
Expand Down Expand Up @@ -904,7 +912,7 @@ export class BoardsService {
userNo: number,
updateBoardDto: UpdateBoardDto,
): Promise<void> {
const board: Board<number[], string[]> = await this.getBoard(
const board: Board<number[], string[], HostProfile> = await this.getBoard(
manager,
boardNo,
userNo,
Expand Down
10 changes: 10 additions & 0 deletions main-project/src/boards/dto/board-filter.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export class BoardFilterDto {
@IsOptional()
readonly page: number;

@ApiProperty({
example: '5',
description: '가져올 게시글 갯수 ',
required: false,
})
@IsNumber()
@Type(() => Number)
@IsOptional()
readonly take: number;

@ApiProperty({
example: '0 or false / 1 or true ',
description: '모집 현황 - 0 or false / 1 or true',
Expand Down
12 changes: 12 additions & 0 deletions main-project/src/boards/entity/board-guest-team.entity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {
BaseEntity,
Column,
CreateDateColumn,
DeleteDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { BoardGuests } from './board-guest.entity';
import { Boards } from './board.entity';
Expand Down Expand Up @@ -41,4 +44,13 @@ export class BoardGuestTeams extends BaseEntity {
name: 'is_accepted',
})
isAccepted: boolean;

@CreateDateColumn({ name: 'created_date' })
createdDate: Date;

@UpdateDateColumn({ default: null, name: 'updated_date' })
updatedDate: Date;

@DeleteDateColumn({ name: 'deleted_date' })
deletedDate: Date;
}
Loading

0 comments on commit 1ceb30f

Please sign in to comment.