Skip to content

Commit abd4b34

Browse files
authored
Merge pull request #40 from DevKor-github/feat/notification
feat: notifications
2 parents 68c6076 + 2a45ebb commit abd4b34

6 files changed

Lines changed: 85 additions & 2 deletions

File tree

src/notification/controller.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
Controller,
3+
Get,
4+
Query,
5+
DefaultValuePipe,
6+
ParseIntPipe,
7+
Res,
8+
UseGuards,
9+
HttpStatus,
10+
} from '@nestjs/common';
11+
import { Response } from 'express';
12+
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
13+
import { AccessTokenGuard } from '@/auth/guards/access-token.guard';
14+
import { User } from '@/decorators/user.decorator';
15+
import { GetUserNotificationsUseCase } from './usecases/getUserNotifications';
16+
import { GetUserNotificationsResult } from './params';
17+
18+
@ApiTags('Notification')
19+
@ApiBearerAuth()
20+
@Controller('notifications')
21+
export class NotificationController {
22+
constructor(
23+
private readonly getUserNotificationsUseCase: GetUserNotificationsUseCase,
24+
) {}
25+
26+
// 내 푸시 알림 히스토리를 최근순으로 조회합니다.
27+
@Get('me')
28+
@UseGuards(AccessTokenGuard)
29+
@ApiResponse({
30+
status: 200,
31+
description: 'Get my notifications (recent first) with pagination',
32+
type: Object,
33+
})
34+
async getMyNotifications(
35+
@User('id') userId: string,
36+
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
37+
@Query('per_page', new DefaultValuePipe(20), ParseIntPipe) perPage: number,
38+
@Res() res: Response,
39+
) {
40+
const result: GetUserNotificationsResult =
41+
await this.getUserNotificationsUseCase.execute({
42+
userId,
43+
page,
44+
limit: perPage,
45+
});
46+
47+
return res.status(HttpStatus.OK).json(result);
48+
}
49+
}

src/notification/module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Module } from '@nestjs/common';
2+
import { PrismaModule } from '@/prisma/prisma.module';
3+
import { NotificationController } from './controller';
24
import { FCMService } from './infrastructure/fcm';
35
import { NotificationRepository } from './repository';
46
import { CreateWaterNotificationUseCase } from './usecases/createWaterNotification';
@@ -9,8 +11,8 @@ import { UserRepository } from '@/user/repositories/user';
911
import { RestaurantRepository } from '@/restaurant/repositories/restaurant';
1012

1113
@Module({
12-
imports: [],
13-
controllers: [],
14+
imports: [PrismaModule],
15+
controllers: [NotificationController],
1416
providers: [
1517
FCMService,
1618
NotificationRepository,
@@ -20,6 +22,8 @@ import { RestaurantRepository } from '@/restaurant/repositories/restaurant';
2022
CreateFollowNotificationUseCase,
2123
CreateGrowNotificationUseCase,
2224
GetUserNotificationsUseCase,
25+
UserRepository,
26+
RestaurantRepository,
2327
],
2428
exports: [
2529
FCMService,

src/tree/module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { PrismaService } from 'src/prisma/prisma.service';
66
import { AuthModule } from '../auth/module';
77
import { UserRepository } from '@/user/repositories/user';
88
import { AccessTokenGuard } from '@/auth/guards/access-token.guard';
9+
import { NotificationRepository } from '@/notification/repository';
10+
import { FCMService } from '@/notification/infrastructure/fcm';
11+
import { CreateWaterNotificationUseCase } from '@/notification/usecases/createWaterNotification';
12+
import { RestaurantRepository } from '@/restaurant/repositories/restaurant';
913

1014
@Module({
1115
imports: [AuthModule],
@@ -16,6 +20,10 @@ import { AccessTokenGuard } from '@/auth/guards/access-token.guard';
1620
PrismaService,
1721
UserRepository,
1822
AccessTokenGuard,
23+
NotificationRepository,
24+
FCMService,
25+
CreateWaterNotificationUseCase,
26+
RestaurantRepository,
1927
],
2028
exports: [TreeRepository],
2129
})

src/tree/service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { PrismaService } from '@/prisma/prisma.service';
1616
import { TreeDetail } from './types';
1717
import { UserParam } from '@/user/params/user';
1818
import config from '@/config';
19+
import { CreateWaterNotificationUseCase } from '@/notification/usecases/createWaterNotification';
1920
import { UserResponse } from '@/user/dtos/user';
2021

2122
const toTreeDetailResponse = (detail: TreeDetail): TreeDetailResponse => {
@@ -57,6 +58,7 @@ export class TreeService {
5758
constructor(
5859
private readonly treeRepository: TreeRepository,
5960
private readonly prisma: PrismaService,
61+
private readonly waterNotificationUseCase: CreateWaterNotificationUseCase,
6062
) {}
6163

6264
async getFollowersTree(
@@ -165,6 +167,13 @@ export class TreeService {
165167
restaurantId,
166168
user.id,
167169
);
170+
171+
await this.waterNotificationUseCase.execute({
172+
userId: ownerId,
173+
treeType: result.tree.treeType,
174+
restaurantId,
175+
});
176+
168177
return toTreeDetailResponse(result);
169178
}
170179

src/user/module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { GetMyProfileUseCase } from './usecases/getMyProfile';
1616
import { AccessTokenGuard } from '@/auth/guards/access-token.guard';
1717
import { UpdateProfileUseCase } from './usecases/updateProfile';
1818
import { UpdateMbtiAndTagsUseCase } from './usecases/updateMbtiAndTags';
19+
import { CreateFollowNotificationUseCase } from '@/notification/usecases/createFollowNotification';
20+
import { NotificationRepository } from '@/notification/repository';
21+
import { FCMService } from '@/notification/infrastructure/fcm';
1922

2023
import { TreeModule } from '@/tree/module';
2124
import { GetFollowingCountUsecase } from './usecases/getFollowingCount';
@@ -45,6 +48,9 @@ import { CheckFollowingStatusUseCase } from './usecases/checkFollowingStatus';
4548
AccessTokenGuard,
4649
UpdateProfileUseCase,
4750
UpdateMbtiAndTagsUseCase,
51+
CreateFollowNotificationUseCase,
52+
NotificationRepository,
53+
FCMService,
4854
GetFollowerCountUsecase,
4955
GetFollowingCountUsecase,
5056
GetUserProfileUseCase,

src/user/usecases/followUser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import {
66
import { FollowerRepository } from '../repositories/follower';
77
import { UserRepository } from '../repositories/user';
88
import { FollowerStatus } from '@prisma/client';
9+
import { CreateFollowNotificationUseCase } from '@/notification/usecases/createFollowNotification';
910

1011
@Injectable()
1112
export class FollowUserUseCase {
1213
constructor(
1314
private readonly followerRepository: FollowerRepository,
1415
private readonly userRepository: UserRepository,
16+
private readonly notificationUseCase: CreateFollowNotificationUseCase,
1517
) {}
1618

1719
async execute(followerId: string, userId: string): Promise<void> {
@@ -38,5 +40,10 @@ export class FollowUserUseCase {
3840
? FollowerStatus.PENDING
3941
: FollowerStatus.ACCEPTED,
4042
});
43+
44+
await this.notificationUseCase.execute({
45+
followerId,
46+
userId,
47+
});
4148
}
4249
}

0 commit comments

Comments
 (0)