Skip to content

Commit 01b2f14

Browse files
authored
Merge pull request #158 from umc-commit/fix/front-user-artist-google
[FIX] 뱃지 발급 코드 추가 + migration 추가 + 프로필 조회의 리뷰 부분에 image 응답 추가
2 parents 5785914 + a38887e commit 01b2f14

File tree

7 files changed

+277
-6
lines changed

7 files changed

+277
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE `users` MODIFY `description` VARCHAR(1000) NULL DEFAULT '입력된 소개가 없습니다.';

prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ model User {
3535
id BigInt @id @default(autoincrement())
3636
nickname String @db.VarChar(50)
3737
accountId BigInt @map("account_id") @unique
38-
description String? @db.VarChar(1000)
38+
description String? @db.VarChar(1000) @default("입력된 소개가 없습니다.")
3939
profileImage String? @map("profile_image") @db.VarChar(255)
4040
createdAt DateTime @default(now()) @map("created_at")
4141
updatedAt DateTime @updatedAt @map("updated_at")

src/commission/controller/commission.controller.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import
77
SubmitCommissionRequestDto
88
} from "../dto/commission.dto.js";
99
import { parseWithBigInt, stringifyWithBigInt } from "../../bigintJson.js";
10+
import { BadgeRepository } from "../../user/repository/badge.repository.js";
1011

1112
// 커미션 게시글 상세글 조회
1213
export const getCommissionDetail = async (req, res, next) => {
@@ -87,6 +88,8 @@ export const uploadRequestImage = async (req, res, next) => {
8788
export const submitCommissionRequest = async (req, res, next) => {
8889
try {
8990
const userId = req.user.userId;
91+
const accountId = req.user.accountId;
92+
9093
const dto = new SubmitCommissionRequestDto({
9194
commissionId: BigInt(req.params.commissionId),
9295
formAnswer: req.body.formAnswer
@@ -95,6 +98,8 @@ export const submitCommissionRequest = async (req, res, next) => {
9598
const result = await CommissionService.submitCommissionRequest(userId, dto);
9699
const responseData = parseWithBigInt(stringifyWithBigInt(result));
97100

101+
await BadgeRepository.GiveCommissionApplyBadges(userId, accountId);
102+
98103
res.status(StatusCodes.OK).success(responseData);
99104
} catch (err) {
100105
next(err);

src/review/controller/review.controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ReviewUpdateDto
1515
} from '../dto/review.dto.js'; // DTO 클래스 import
1616
import reviewService from '../service/review.service.js';
17+
import { BadgeRepository } from "../../user/repository/badge.repository.js";
1718

1819
class ReviewController {
1920

@@ -60,6 +61,9 @@ class ReviewController {
6061
// 현재 로그인한 사용자 ID (BigInt 변환)
6162
const userId = BigInt(req.user.userId);
6263

64+
// accountId 조회
65+
const accountId = BigInt(req.user.accountId);
66+
6367
// 요청 본문 데이터를 DTO 클래스로 구조화
6468
const reviewDto = new ReviewCreateDto(req.body);
6569

@@ -71,6 +75,9 @@ class ReviewController {
7175
// BigInt를 JSON 문자열로 변환 후 다시 파싱하여 일반 객체로 변환
7276
const finalData = JSON.parse(stringifyWithBigInt(responseData));
7377

78+
// 리뷰 뱃지 발급
79+
await BadgeRepository.GiveReviewBadges(userId, accountId);
80+
7481
// 클라이언트에 응답 전송 (201 Created)
7582
res.status(StatusCodes.CREATED).json({
7683
resultType: "SUCCESS",

src/user/controller/user.controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { UserSignupRequestDto } from "../dto/user.dto.js";
44
import { UserLoginRequestDto } from "../dto/user.dto.js";
55
import { UpdateMyprofileDto } from "../dto/user.dto.js";
66
import { verifyJwt } from "../../jwt.config.js";
7+
import { BadgeRepository } from "../repository/badge.repository.js";
78

89
// 로그인 요청
910

@@ -122,6 +123,8 @@ export const FollowArtist = async(req, res, next) => {
122123

123124
const result = await UserService.FollowArtist(accountId, artistId);
124125

126+
await BadgeRepository.GiveFollowerBadges(artistId, accountId);
127+
125128
res.status(StatusCodes.CREATED).success(result);
126129
} catch(err) {
127130
next(err);

src/user/repository/badge.repository.js

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,252 @@ export const BadgeRepository = {
5858
}
5959
});
6060
}
61+
,
62+
// 팔로워 뱃지 부여하기
63+
async GiveFollowerBadges(artistId, accountId){
64+
const followerCount = await prisma.follow.count({
65+
where:{artistId}
66+
})
67+
68+
if(followerCount >= 5){
69+
const existingBadge = await prisma.userBadge.findFirst({
70+
where:{
71+
accountId,
72+
badgeId:1
73+
}
74+
});
75+
76+
if(!existingBadge){
77+
await prisma.userBadge.create({
78+
data:{
79+
accountId,
80+
badgeId:1,
81+
earnedAt:new Date(),
82+
}
83+
})
84+
}
85+
}
86+
87+
if(followerCount >= 10){
88+
const existingBadge = await prisma.userBadge.findFirst({
89+
where:{
90+
accountId,
91+
badgeId:2
92+
}
93+
});
94+
95+
if(!existingBadge){
96+
await prisma.userBadge.create({
97+
data:{
98+
accountId,
99+
badgeId:2,
100+
earnedAt:new Date(),
101+
}
102+
})
103+
}
104+
}
105+
if(followerCount >= 20){
106+
const existingBadge = await prisma.userBadge.findFirst({
107+
where:{
108+
accountId,
109+
badgeId:3
110+
}
111+
});
112+
113+
if(!existingBadge){
114+
await prisma.userBadge.create({
115+
data:{
116+
accountId,
117+
badgeId:3,
118+
earnedAt:new Date(),
119+
}
120+
})
121+
}
122+
}
123+
if(followerCount >= 100){
124+
const existingBadge = await prisma.userBadge.findFirst({
125+
where:{
126+
accountId,
127+
badgeId:4
128+
}
129+
});
130+
131+
if(!existingBadge){
132+
await prisma.userBadge.create({
133+
data:{
134+
accountId,
135+
badgeId:4,
136+
earnedAt:new Date(),
137+
}
138+
})
139+
}
140+
}
141+
},
142+
// 커미션 신청 뱃지 부여
143+
async GiveCommissionApplyBadges(userId, accountId){
144+
const ApplyCommissionCount = await prisma.request.count({
145+
where:{
146+
userId
147+
}
148+
})
149+
150+
if(ApplyCommissionCount >= 1){
151+
const existingBadge = await prisma.userBadge.findFirst({
152+
where:{
153+
accountId,
154+
badgeId:5
155+
}
156+
});
157+
158+
if(!existingBadge){
159+
await prisma.userBadge.create({
160+
data:{
161+
accountId,
162+
badgeId:5,
163+
earnedAt:new Date(),
164+
}
165+
})
166+
}
167+
}
168+
169+
if(ApplyCommissionCount >= 5){
170+
const existingBadge = await prisma.userBadge.findFirst({
171+
where:{
172+
accountId,
173+
badgeId:6
174+
}
175+
});
176+
177+
if(!existingBadge){
178+
await prisma.userBadge.create({
179+
data:{
180+
accountId,
181+
badgeId:6,
182+
earnedAt:new Date(),
183+
}
184+
})
185+
}
186+
}
187+
if(ApplyCommissionCount >= 15){
188+
const existingBadge = await prisma.userBadge.findFirst({
189+
where:{
190+
accountId,
191+
badgeId:7
192+
}
193+
});
194+
195+
if(!existingBadge){
196+
await prisma.userBadge.create({
197+
data:{
198+
accountId,
199+
badgeId:7,
200+
earnedAt:new Date(),
201+
}
202+
})
203+
}
204+
}
205+
if(ApplyCommissionCount >= 50){
206+
const existingBadge = await prisma.userBadge.findFirst({
207+
where:{
208+
accountId,
209+
badgeId:8
210+
}
211+
});
212+
213+
if(!existingBadge){
214+
await prisma.userBadge.create({
215+
data:{
216+
accountId,
217+
badgeId:8,
218+
earnedAt:new Date(),
219+
}
220+
})
221+
}
222+
}
223+
},
224+
// 후기 작성 뱃지 부여
225+
async GiveReviewBadges(userId, accountId){
226+
const ReviewCount = await prisma.review.count({
227+
where:{
228+
userId
229+
}
230+
})
231+
232+
if(ReviewCount >= 1){
233+
const existingBadge = await prisma.userBadge.findFirst({
234+
where:{
235+
accountId,
236+
badgeId:9
237+
}
238+
});
239+
240+
if(!existingBadge){
241+
await prisma.userBadge.create({
242+
data:{
243+
accountId,
244+
badgeId:9,
245+
earnedAt:new Date(),
246+
}
247+
})
248+
}
249+
}
250+
251+
if(ReviewCount >= 5){
252+
const existingBadge = await prisma.userBadge.findFirst({
253+
where:{
254+
accountId,
255+
badgeId:10
256+
}
257+
});
258+
259+
if(!existingBadge){
260+
await prisma.userBadge.create({
261+
data:{
262+
accountId,
263+
badgeId:10,
264+
earnedAt:new Date(),
265+
}
266+
})
267+
}
268+
}
269+
if(ReviewCount >= 15){
270+
const existingBadge = await prisma.userBadge.findFirst({
271+
where:{
272+
accountId,
273+
badgeId:11
274+
}
275+
});
276+
277+
if(!existingBadge){
278+
await prisma.userBadge.create({
279+
data:{
280+
accountId,
281+
badgeId:11,
282+
earnedAt:new Date(),
283+
}
284+
})
285+
}
286+
}
287+
if(ReviewCount >= 50){
288+
const existingBadge = await prisma.userBadge.findFirst({
289+
where:{
290+
accountId,
291+
badgeId:12
292+
}
293+
});
294+
295+
if(!existingBadge){
296+
await prisma.userBadge.create({
297+
data:{
298+
accountId,
299+
badgeId:12,
300+
earnedAt:new Date(),
301+
}
302+
})
303+
}
304+
}
305+
}
306+
61307

62308
};
63309

src/user/service/user.service.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import axios from "axios";
44
import { signJwt } from "../../jwt.config.js";
55
import { BadgeRepository } from "../repository/badge.repository.js";
66
import { CommissionRepository } from "../../commission/repository/commission.repository.js";
7-
7+
import { ReviewRepository } from "../../../src/request/repository/request.repository.js"
88

99

1010
export const UserService = {
@@ -128,7 +128,7 @@ export const UserService = {
128128
earnedAt: userBadge.earnedAt,
129129
badge: userBadge.badge
130130
}));
131-
131+
132132
const reviews = (await UserRepository.UserReviewList(userId)) ?? [];
133133

134134

@@ -276,6 +276,8 @@ export const UserService = {
276276
throw new UserAlreadyFollowArtist();
277277

278278
const result = await UserRepository.FollowArtist(accountId, artistId);
279+
280+
await BadgeRepository.GiveFollowerBadges(artistId, accountId);
279281

280282
return {
281283
message:"해당 작가 팔로우를 성공했습니다.",
@@ -354,18 +356,23 @@ export const UserService = {
354356
throw new ArtistNotFound();
355357

356358
const rawReviews = await UserRepository.ArtistReviews(artistId);
359+
357360

358-
const reviews = rawReviews.map((r) => {
361+
const reviews = rawReviews.map(async (r) => {
362+
359363
const start = r.request.inProgressAt ? new Date(r.request.inProgressAt) : null;
360364
const end = r.request.completedAt ? new Date(r.request.completedAt) : null;
361365

366+
362367
let workingTime = null;
363368
if (start && end) {
364369
const diffMs = end - start;
365370
const hours = Math.floor(diffMs / (1000 * 60 * 60));
366371
workingTime = hours < 24 ? `${hours}시간` : `${Math.floor(hours / 24)}일`;
367372
}
368-
373+
374+
const images = await ReviewRepository.getImagesByTarget('review', r.id);
375+
369376
return {
370377
id: r.id,
371378
rate: r.rate,
@@ -375,7 +382,8 @@ export const UserService = {
375382
workingTime: workingTime,
376383
writer: {
377384
nickname: r.user.nickname
378-
}
385+
},
386+
reviewImage: images
379387
}});
380388

381389
// 작가가 등록한 커미션 목록

0 commit comments

Comments
 (0)