-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser.controller.js
More file actions
193 lines (145 loc) · 5.38 KB
/
user.controller.js
File metadata and controls
193 lines (145 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { StatusCodes } from "http-status-codes";
import { UserService } from "../service/user.service.js";
import { UserSignupRequestDto } from "../dto/user.dto.js";
import { UserLoginRequestDto } from "../dto/user.dto.js";
import { UpdateMyprofileDto } from "../dto/user.dto.js";
import { verifyJwt } from "../../jwt.config.js";
// 로그인 요청
export const userLogin = async(req, res, next) => {
try{
const dto = new UserLoginRequestDto(req.body);
const result = await UserService.userLogin(dto);
res.status(StatusCodes.OK).success(result);
}catch(err) {
next(err);
}
}
// 사용자(계정) 추가
export const addUser = async(req, res, next) => {
try{
const {token} = req.body;
let decoded = verifyJwt(token);
const {provider, oauth_id} = decoded;
req.body.provider = provider;
req.body.oauth_id = oauth_id;
// 1. Request body를 dto로 변환
const dto = new UserSignupRequestDto(req.body);
const result = await UserService.addAccount(dto);
// 3. 성공 응답 반환
res.status(StatusCodes.CREATED).success(result);
} catch(err) {
next(err);
}
}
// 사용자 프로필 조회
export const getUserProfile = async(req, res, next) => {
try{
console.log("👊Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId;
console.log("controller accountId -> ", accountId);
const role = req.user.role;
console.log(role);
const result = await UserService.getUserProfile(accountId, role);
res.status(StatusCodes.OK).success(result);
} catch(err){
next(err);
}
}
// 나의 프로필 수정하기
export const UpdateMyprofile = async(req, res, next) => {
try{
console.log("Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId;
console.log("accountId -> : ", accountId);
const role = req.user.role;
const dto = new UpdateMyprofileDto(req.body);
const result = await UserService.updateMyprofile(accountId, dto, role);
res.status(StatusCodes.OK).success(result);
} catch(err){
next(err);
}
}
// 사용자가 선택한 카테고리 조회하기
export const AccessUserCategories = async(req, res, next) => {
try{
console.log("Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId.toString();
console.log("사용자가 선택한 카테고리 조회 accountId -> ", accountId);
const result = await UserService.accessUserCategories(accountId);
res.status(StatusCodes.OK).success(result);
} catch(err) {
next(err);
}
}
// 닉네임 중복 확인
export const CheckUserNickname = async(req, res, next) => {
try{
const {nickname}= req.query;
const result = await UserService.isNicknameDuplicate(nickname);
res.status(StatusCodes.OK).success(result);
} catch(err) {
next(err);
}
}
// 작가 팔로우하기
export const FollowArtist = async(req, res, next) => {
try{
console.log("⭐Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId.toString();
console.log("작가 팔로우하기 accountId : ", accountId);
const artistId = req.params.artistId;
const result = await UserService.FollowArtist(accountId, artistId);
res.status(StatusCodes.CREATED).success(result);
} catch(err) {
next(err);
}
}
// 작가 팔로우 취소하기
export const CancelArtistFollow = async(req, res, next) => {
try{
console.log("💟Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId.toString();
console.log("작가 팔로우 취소하기 accountId : ", accountId);
const artistId = req.params.artistId;
const result = await UserService.CancelArtistFollow(accountId, artistId);
res.status(StatusCodes.OK).success(result);
} catch(err) {
next(err);
}
}
// 사용자가 팔로우 한 작가 조회하기
export const LookUserFollow = async(req, res, next) => {
try{
console.log("🦁Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId.toString();
console.log("팔로우하는 작가 목록 조회 accountId : ", accountId);
const result = await UserService.LookUserFollow(accountId);
res.status(StatusCodes.OK).success(result);
}catch(err) {
next(err);
}
}
// 사용자의 뱃지 조회하기
export const LookUserBadge = async(req, res, next) => {
try{
console.log("🎖️Decoded JWT from req.user:", req.user);
const accountId = req.user.accountId.toString();
console.log("사용자의 뱃지 조회 accountId -> ", accountId);
const result = await UserService.ViewUserBadge(accountId);
res.status(StatusCodes.OK).success(result);
}catch(err) {
next(err);
}
}
// 작가 프로필 조회하기
export const AccessArtistProfile = async(req, res, next) => {
try{
const artistId = req.params.artistId;
const accountId = req.user.accountId;
const userId = req.user.userId;
const result = await UserService.AccessArtistProfile(artistId, accountId, userId);
res.status(StatusCodes.OK).success(result);
} catch(err) {
next(err);
}
}