Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Warnings:

- You are about to drop the column `speaker` on the `Talk` table. All the data in the column will be lost.
- Added the required column `speakerId` to the `Talk` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "Talk" DROP COLUMN "speaker",
ADD COLUMN "speakerId" TEXT NOT NULL;

-- AddForeignKey
ALTER TABLE "Talk" ADD CONSTRAINT "Talk_speakerId_fkey" FOREIGN KEY ("speakerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
6 changes: 4 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ model Talk {
title String
subject TalkSubject
description String
speaker String
level TalkLevel @default(INTERMEDIATE)
startTime DateTime
endTime DateTime
speakerId String
speaker User @relation(fields: [speakerId], references: [id])
roomId String
room Room @relation(fields: [roomId], references: [id])
level TalkLevel @default(INTERMEDIATE)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Expand All @@ -75,4 +76,5 @@ model User {
type UserType @default(SPEAKER)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Talk Talk[]
}
20 changes: 12 additions & 8 deletions src/adapters/api/controller/talk.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ import { CreateTalkMapper } from '../mapper/create-talk.mapper';
import { GetAllTalksByStatusRequest } from '../request/get-all-talks-by-status.request';
import { GetAllTalksByStatusUseCase } from '../../../core/usecases/get-all-talks-by-status.use-case';
import { TalkStatus } from '../../../core/domain/type/TalkStatus';
import { GetAllTalksWithRoomDetailResponse } from '../response/get-all-talks-with-room-detail.response';
import { GetAllTalksWithRoomDetailMapper } from '../mapper/get-all-talks-with-room-detail.mapper';
import { GetAllTalksWithDetailResponse } from '../response/get-all-talks-with-detail.response';
import { GetAllTalksWithDetailMapper } from '../mapper/get-all-talks-with-detail.mapper';
import { UserType } from '../../../core/domain/type/UserType';
import { Roles } from '../decorator/roles.decorator';
import { Public } from '../decorator/public.decorator';
import { UpdateTalkRequest } from '../request/update-talk.request';
import { UpdateTalkMapper } from '../mapper/update-talk.mapper';
import { UpdateTalkCreationRequestUseCase } from '../../../core/usecases/update-talk-creation-request.use-case';
import { UpdateTalkResponse } from '../response/update-talk.response';
import { CurrentUser } from '../decorator/current-user.decorator';
import { ProfileRequest } from '../request/profile.request';

@Controller('/talks')
export class TalkController {
Expand All @@ -59,19 +61,19 @@ export class TalkController {
@ApiOperation({ summary: 'Get all talks by status' })
@ApiOkResponse({
description: 'List of all talks',
type: GetAllTalksWithRoomDetailResponse,
type: GetAllTalksWithDetailResponse,
})
@ApiInternalServerErrorResponse({
description: 'Internal server error',
})
async getAllTalks(
@Query('status')
status: TalkStatus,
): Promise<GetAllTalksWithRoomDetailResponse> {
): Promise<GetAllTalksWithDetailResponse> {
const request: GetAllTalksByStatusRequest = { status };
const talksWithRoomDetail =
const talksWithDetail =
await this.getAllTalksByStatusUseCase.execute(request);
return GetAllTalksWithRoomDetailMapper.fromDomain(talksWithRoomDetail);
return GetAllTalksWithDetailMapper.fromDomain(talksWithDetail);
}

@Roles(UserType.PLANNER, UserType.SPEAKER)
Expand Down Expand Up @@ -99,9 +101,10 @@ export class TalkController {
description: 'Unauthorized access',
})
async createTalk(
@CurrentUser() user: ProfileRequest,
@Body() body: CreateTalkRequest,
): Promise<CreateTalkResponse> {
const command = CreateTalkMapper.toDomain(body);
const command = CreateTalkMapper.toDomain(user.id, body);
const talk = await this.createTalkUseCase.execute(command);
return CreateTalkMapper.fromDomain(talk);
}
Expand Down Expand Up @@ -131,10 +134,11 @@ export class TalkController {
description: 'Unauthorized access',
})
async updateTalk(
@CurrentUser() user: ProfileRequest,
@Param('talkId') talkId: string,
@Body() body: UpdateTalkRequest,
): Promise<UpdateTalkResponse> {
const command = UpdateTalkMapper.toDomain(talkId, body);
const command = UpdateTalkMapper.toDomain(user, talkId, body);
const talk = await this.updateTalkUseCase.execute(command);
return UpdateTalkMapper.fromDomain(talk);
}
Expand Down
9 changes: 6 additions & 3 deletions src/adapters/api/mapper/create-talk.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { CreateTalkResponse } from '../response/create-talk.response';
import { Talk } from '../../../core/domain/model/Talk';

export class CreateTalkMapper {
static toDomain(request: CreateTalkRequest): CreateTalkCommand {
static toDomain(
speakerId: string,
request: CreateTalkRequest,
): CreateTalkCommand {
return {
title: request.title,
subject: request.subject,
description: request.description,
speaker: request.speaker,
speakerId: speakerId,
roomId: request.roomId,
level: request.level,
startTime: new Date(request.startTime),
Expand All @@ -24,7 +27,7 @@ export class CreateTalkMapper {
title: talk.title,
subject: talk.subject,
description: talk.description,
speaker: talk.speaker,
speakerId: talk.speakerId,
roomId: talk.roomId,
level: talk.level,
startTime: talk.startTime.toISOString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { GetAllTalksWithRoomDetailResponse } from '../response/get-all-talks-with-room-detail.response';
import { TalkWithRoomDetail } from '../../../core/domain/model/TalkWithRoomDetail';
import { GetAllTalksWithDetailResponse } from '../response/get-all-talks-with-detail.response';
import { TalkWithDetail } from '../../../core/domain/model/TalkWithDetail';

export class GetAllTalksWithRoomDetailMapper {
export class GetAllTalksWithDetailMapper {
static fromDomain(
talksWithRoomDetail: TalkWithRoomDetail[],
): GetAllTalksWithRoomDetailResponse {
talksWithDetail: TalkWithDetail[],
): GetAllTalksWithDetailResponse {
return {
talks: talksWithRoomDetail.map((talk) => ({
talks: talksWithDetail.map((talk) => ({
id: talk.id,
status: talk.status,
title: talk.title,
subject: talk.subject,
description: talk.description,
speaker: talk.speaker,
level: talk.level,
startTime: talk.startTime.toISOString(),
endTime: talk.endTime.toISOString(),
Expand All @@ -21,6 +20,11 @@ export class GetAllTalksWithRoomDetailMapper {
name: talk.room.name,
capacity: talk.room.capacity,
},
speaker: {
id: talk.speaker.id,
email: talk.speaker.email,
type: talk.speaker.type,
},
createdAt: talk.createdAt,
updatedAt: talk.updatedAt,
})),
Expand Down
8 changes: 5 additions & 3 deletions src/adapters/api/mapper/update-talk.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { Talk } from '../../../core/domain/model/Talk';
import { UpdateTalkRequest } from '../request/update-talk.request';
import { UpdateTalkCommand } from '../../../core/usecases/update-talk-creation-request.use-case';
import { UpdateTalkResponse } from '../response/update-talk.response';
import { ProfileRequest } from '../request/profile.request';

export class UpdateTalkMapper {
static toDomain(
currentUser: ProfileRequest,
talkId: string,
request: UpdateTalkRequest,
): UpdateTalkCommand {
return {
talkId: talkId,
currentUser,
talkId,
title: request.title,
subject: request.subject,
description: request.description,
speaker: request.speaker,
roomId: request.roomId,
level: request.level,
startTime: new Date(request.startTime),
Expand All @@ -28,7 +30,7 @@ export class UpdateTalkMapper {
title: talk.title,
subject: talk.subject,
description: talk.description,
speaker: talk.speaker,
speakerId: talk.speakerId,
roomId: talk.roomId,
level: talk.level,
startTime: talk.startTime.toISOString(),
Expand Down
8 changes: 0 additions & 8 deletions src/adapters/api/request/create-talk.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export class CreateTalkRequest {
@MaxLength(512)
description: string;

@ApiProperty()
@IsString()
@MinLength(2)
@MaxLength(64)
speaker: string;

@ApiProperty()
@IsUUID()
roomId: string;
Expand All @@ -53,7 +47,6 @@ export class CreateTalkRequest {
title: string,
subject: TalkSubject,
description: string,
speaker: string,
roomId: string,
level: TalkLevel,
startTime: string,
Expand All @@ -62,7 +55,6 @@ export class CreateTalkRequest {
this.title = title;
this.subject = subject;
this.description = description;
this.speaker = speaker;
this.roomId = roomId;
this.level = level;
this.startTime = startTime;
Expand Down
8 changes: 0 additions & 8 deletions src/adapters/api/request/update-talk.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export class UpdateTalkRequest {
@MaxLength(512)
description: string;

@ApiProperty()
@IsString()
@MinLength(2)
@MaxLength(64)
speaker: string;

@ApiProperty()
@IsUUID()
roomId: string;
Expand All @@ -53,7 +47,6 @@ export class UpdateTalkRequest {
title: string,
subject: TalkSubject,
description: string,
speaker: string,
roomId: string,
level: TalkLevel,
startTime: string,
Expand All @@ -62,7 +55,6 @@ export class UpdateTalkRequest {
this.title = title;
this.subject = subject;
this.description = description;
this.speaker = speaker;
this.roomId = roomId;
this.level = level;
this.startTime = startTime;
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/api/response/create-talk.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CreateTalkResponse {
description: string;

@ApiProperty()
speaker: string;
speakerId: string;

@ApiProperty()
roomId: string;
Expand All @@ -46,7 +46,7 @@ export class CreateTalkResponse {
title: string,
subject: TalkSubject,
description: string,
speaker: string,
speakerId: string,
roomId: string,
level: TalkLevel,
startTime: string,
Expand All @@ -59,7 +59,7 @@ export class CreateTalkResponse {
this.title = title;
this.subject = subject;
this.description = description;
this.speaker = speaker;
this.speakerId = speakerId;
this.roomId = roomId;
this.level = level;
this.startTime = startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';
import { TalkStatus } from '../../../core/domain/type/TalkStatus';
import { TalkSubject } from '../../../core/domain/type/TalkSubject';
import { TalkLevel } from '../../../core/domain/type/TalkLevel';
import { UserType } from '../../../core/domain/type/UserType';

class RoomDetail {
@ApiProperty()
Expand All @@ -20,7 +21,24 @@ class RoomDetail {
}
}

class TalksWithRoomDetail {
class SpeakerDetail {
@ApiProperty()
id: string;

@ApiProperty()
email: string;

@ApiProperty({ enum: UserType })
type: UserType;

constructor(id: string, email: string, type: UserType) {
this.id = id;
this.email = email;
this.type = type;
}
}

class TalksWithDetail {
@ApiProperty()
id: string;

Expand All @@ -36,9 +54,6 @@ class TalksWithRoomDetail {
@ApiProperty()
description: string;

@ApiProperty()
speaker: string;

@ApiProperty({ enum: TalkLevel })
level: TalkLevel;

Expand All @@ -51,6 +66,9 @@ class TalksWithRoomDetail {
@ApiProperty({ type: () => RoomDetail })
room: RoomDetail;

@ApiProperty({ type: () => SpeakerDetail })
speaker: SpeakerDetail;

@ApiProperty()
createdAt: Date;

Expand All @@ -63,11 +81,11 @@ class TalksWithRoomDetail {
title: string,
subject: TalkSubject,
description: string,
speaker: string,
level: TalkLevel,
startTime: string,
endTime: string,
room: RoomDetail,
speaker: SpeakerDetail,
createdAt: Date,
updatedAt: Date,
) {
Expand All @@ -76,21 +94,21 @@ class TalksWithRoomDetail {
this.title = title;
this.subject = subject;
this.description = description;
this.speaker = speaker;
this.level = level;
this.startTime = startTime;
this.endTime = endTime;
this.room = room;
this.speaker = speaker;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}
}

export class GetAllTalksWithRoomDetailResponse {
@ApiProperty({ type: [TalksWithRoomDetail] })
talks: TalksWithRoomDetail[];
export class GetAllTalksWithDetailResponse {
@ApiProperty({ type: [TalksWithDetail] })
talks: TalksWithDetail[];

constructor(talks: TalksWithRoomDetail[]) {
constructor(talks: TalksWithDetail[]) {
this.talks = talks;
}
}
Loading