1515
1616 <transition name =" fade-content" >
1717 <div v-if =" show" class =" form-container" >
18- <label for =" baekjoon-id" class =" form-label" >백준 아이디</label >
19- <input
20- type =" text"
21- id =" baekjoon-id"
22- class =" form-input"
23- v-model =" baekjoonId"
24- placeholder =" Enter your Baekjoon ID"
25- />
26-
27- <label for =" nickname" class =" form-label" >닉네임</label >
28- <input
29- type =" text"
30- id =" nickname"
31- class =" form-input"
32- v-model =" nickname"
33- placeholder =" Enter your nickname"
34- />
18+ <div class =" form-section" >
19+ <label for =" baekjoon-id" class =" form-label" >백준 아이디</label >
20+ <input
21+ type =" text"
22+ id =" baekjoon-id"
23+ class =" form-input"
24+ v-model =" baekjoonId"
25+ placeholder =" 백준에서 사용하는 아이디를 입력하세요"
26+ />
27+ <small class =" form-hint" >백준 온라인 저지에서 사용하는 실제 아이디를 입력해주세요</small >
28+ </div >
29+
30+ <div class =" form-section" >
31+ <label for =" display-nickname" class =" form-label" >표시될 닉네임</label >
32+ <input
33+ type =" text"
34+ id =" display-nickname"
35+ class =" form-input"
36+ v-model =" displayNickname"
37+ placeholder =" 랭킹에 표시될 닉네임을 입력하세요"
38+ />
39+ <small class =" form-hint" >백준킹 랭킹에서 표시될 별도의 닉네임입니다 (백준 아이디와 다를 수 있음)</small >
40+ </div >
3541
3642 <button class =" submit-btn" @click =" startEvent" >시작하기</button >
3743 </div >
4147
4248<script >
4349import { onMounted , ref } from " vue" ;
44- import axios from " axios " ;
50+ import { API_ROOT } from " @/api.js " ;
4551
4652export default {
4753 name: " SignEvent" ,
@@ -55,49 +61,65 @@ export default {
5561 data () {
5662 return {
5763 baekjoonId: " " ,
58- nickname : " "
64+ displayNickname : " "
5965 };
6066 },
6167 methods: {
62- startEvent () {
63- if (! this .baekjoonId || ! this .nickname ) {
68+ async startEvent () {
69+ if (! this .baekjoonId || ! this .displayNickname ) {
6470 alert (" 모든 항목을 입력해주세요!" );
6571 return ;
6672 }
6773
6874 const payload = {
69- username : this .baekjoonId , // 백엔드 DTO의 username 필드에 매핑
70- nickname : this .nickname
75+ baekjoonId : this .baekjoonId ,
76+ displayName : this .displayNickname
7177 };
7278
73- axios
74- .post (" https://czportal.site/api/infos/post" , payload)
75- .then (response => {
79+ try {
80+ const response = await fetch (` ${ API_ROOT } /baekjoon/create-profile` , {
81+ method: " POST" ,
82+ headers: {
83+ " Content-Type" : " application/json" ,
84+ ... (localStorage .getItem (" token" ) && {
85+ Authorization: ` Bearer ${ localStorage .getItem (" token" )} `
86+ })
87+ },
88+ body: JSON .stringify (payload)
89+ });
90+
91+ const result = await response .json ();
92+
93+ if (response .ok ) {
7694 alert (" 정보가 성공적으로 등록되었습니다." );
77- console .log (response .data );
78- })
79- .catch (error => {
80- // error.response.data가 존재하는 경우 에러코드에 따른 예외처리
81- if (error .response && error .response .data && error .response .data .code ) {
82- const code = error .response .data .code ;
83- switch (code) {
95+ console .log (result);
96+ } else {
97+ // 에러 코드에 따른 예외처리
98+ if (result .code ) {
99+ switch (result .code ) {
84100 case " MEMBER4003" :
85101 alert (" 사용자가 없습니다." );
86102 break ;
87103 case " MEMBER4002" :
88- alert (" 닉네임은 필수 입니다 ." );
104+ alert (" 닉네임은 필수입니다 ." );
89105 break ;
90106 case " MEMBER4004" :
91107 alert (" 이미 존재하는 사용자입니다." );
92108 break ;
109+ case " MEMBER4001" :
110+ alert (" 백준 아이디가 유효하지 않습니다." );
111+ break ;
93112 default :
94- alert (" 정보 등록 중 오류가 발생했습니다. 백준 아이디를 확인해주세요!" );
113+ alert (result . message || " 정보 등록 중 오류가 발생했습니다. 백준 아이디를 확인해주세요!" );
95114 }
96115 } else {
97116 alert (" 정보 등록 중 오류가 발생했습니다. 백준 아이디를 확인해주세요!" );
98117 }
99- console .error (error);
100- });
118+ }
119+ } catch (error) {
120+ console .error (" API 호출 오류:" , error);
121+ alert (" 네트워크 오류가 발생했습니다. 잠시 후 다시 시도해주세요." );
122+ }
101123 }
102124 }
103125};
@@ -138,21 +160,36 @@ export default {
138160 display : flex ;
139161 flex-direction : column ;
140162 align-items : center ;
141- gap : clamp (12 px , 4vw , 16 px );
163+ gap : clamp (16 px , 4vw , 20 px );
142164 background : #1e1e1e ;
143165 padding : clamp (20px , 5vw , 30px );
144166 border-radius : 12px ;
145167 box-shadow : 0 4px 12px rgba (255 , 85 , 125 , 0.3 );
146168 width : clamp (260px , 80vw , 360px );
147169}
148170
171+ .form-section {
172+ width : 100% ;
173+ margin-bottom : clamp (8px , 2vw , 12px );
174+ }
175+
149176.form-label {
150177 font-size : clamp (0.9rem , 4vw , 1rem );
151178 color : #ff557d ;
152179 text-align : left ;
153180 width : 100% ;
154181 font-weight : 500 ;
155- margin-bottom : -10px ;
182+ margin-bottom : 6px ;
183+ display : block ;
184+ }
185+
186+ .form-hint {
187+ display : block ;
188+ font-size : clamp (0.75rem , 3vw , 0.85rem );
189+ color : rgba (255 , 255 , 255 , 0.6 );
190+ margin-top : 4px ;
191+ line-height : 1.3 ;
192+ text-align : left ;
156193}
157194
158195.form-input {
0 commit comments