Skip to content

Commit b405d5d

Browse files
authored
v1 : 마무리 (#72)
* style: reformat `v0.sql` * feat: write v0 to v1 migration sql * fix: remove fk contraints first * fix: redirect when 401 * fix: split attendance login * refactor: attend using email not id
1 parent 017670f commit b405d5d

File tree

8 files changed

+189
-231
lines changed

8 files changed

+189
-231
lines changed

sql/v0.sql

+77-214
Original file line numberDiff line numberDiff line change
@@ -1,220 +1,83 @@
1-
create table
2-
if not exists gdsc.event
3-
(
4-
id
5-
bigint
6-
auto_increment
7-
primary
8-
key,
9-
title
10-
varchar
11-
(
12-
255
13-
) NOT NULL,
14-
content text NOT NULL,
15-
location varchar
16-
(
17-
255
18-
) NOT NULL,
19-
end_at datetime
20-
(
21-
6
22-
) NOT NULL,
23-
start_at datetime
24-
(
25-
6
26-
) NOT NULL,
27-
retrospect_content text NOT NULL
28-
);
1+
create table if not exists gdsc.event
2+
(
3+
id bigint auto_increment primary key,
4+
title varchar(255) NOT NULL,
5+
content text NOT NULL,
6+
location varchar(255) NOT NULL,
7+
end_at datetime(6) NOT NULL,
8+
start_at datetime(6) NOT NULL,
9+
retrospect_content text NOT NULL
10+
);
2911

30-
create table
31-
if not exists gdsc.event_image
32-
(
33-
id
34-
bigint
35-
auto_increment
36-
primary
37-
key,
38-
event_id
39-
bigint
40-
NOT
41-
NULL,
42-
url
43-
varchar
44-
(
45-
255
46-
) NOT NULL,
47-
CONSTRAINT FOREIGN KEY
48-
(
49-
event_id
50-
) REFERENCES gdsc.event
51-
(
52-
id
53-
) ON UPDATE CASCADE
54-
ON DELETE CASCADE
55-
);
12+
create table if not exists gdsc.event_image
13+
(
14+
id bigint auto_increment primary key,
15+
event_id bigint NOT NULL,
16+
url varchar(255) NOT NULL,
17+
CONSTRAINT FOREIGN KEY (event_id)
18+
REFERENCES gdsc.event (id)
19+
ON UPDATE CASCADE
20+
ON DELETE CASCADE
21+
);
5622

57-
create table
58-
if not exists gdsc.attendance
59-
(
60-
id
61-
bigint
62-
auto_increment
63-
primary
64-
key,
65-
event_id
66-
bigint
67-
NOT
68-
NULL,
69-
active_qr_uuid
70-
varchar
71-
(
72-
255
73-
) NULL,
74-
CONSTRAINT FOREIGN KEY
75-
(
76-
event_id
77-
) REFERENCES gdsc.event
78-
(
79-
id
80-
) ON UPDATE CASCADE
81-
ON DELETE CASCADE
82-
);
23+
create table if not exists gdsc.attendance
24+
(
25+
id bigint auto_increment primary key,
26+
event_id bigint NOT NULL,
27+
active_qr_uuid varchar(255) NULL,
28+
CONSTRAINT FOREIGN KEY (event_id)
29+
REFERENCES gdsc.event (id)
30+
ON UPDATE CASCADE
31+
ON DELETE CASCADE
32+
);
8333

84-
create table
85-
if not exists gdsc.email_task
86-
(
87-
task_id
88-
bigint
89-
auto_increment
90-
primary
91-
key,
92-
is_sent
93-
boolean
94-
DEFAULT
95-
FALSE,
96-
send_at
97-
datetime
98-
(
99-
6
100-
) NOT NULL,
101-
email_content text NOT NULL,
102-
email_subject varchar
103-
(
104-
255
105-
) NOT NULL
106-
);
34+
create table if not exists gdsc.email_task
35+
(
36+
task_id bigint auto_increment primary key,
37+
is_sent boolean DEFAULT FALSE,
38+
send_at datetime(6) NOT NULL,
39+
email_content text NOT NULL,
40+
email_subject varchar(255) NOT NULL
41+
);
10742

108-
create table
109-
if not exists gdsc.email_receivers
110-
(
111-
task_id
112-
bigint
113-
NOT
114-
NULL,
115-
receiver_email
116-
varchar
117-
(
118-
255
119-
) NOT NULL,
120-
receiver_name varchar
121-
(
122-
255
123-
) NOT NULL,
124-
CONSTRAINT FOREIGN KEY
125-
(
126-
task_id
127-
) REFERENCES gdsc.email_task
128-
(
129-
task_id
130-
) ON UPDATE CASCADE
131-
ON DELETE CASCADE
132-
);
43+
create table if not exists gdsc.email_receivers
44+
(
45+
task_id bigint NOT NULL,
46+
receiver_email varchar(255) NOT NULL,
47+
receiver_name varchar(255) NOT NULL,
48+
CONSTRAINT FOREIGN KEY (task_id)
49+
REFERENCES gdsc.email_task (task_id)
50+
ON UPDATE CASCADE
51+
ON DELETE CASCADE
52+
);
13353

134-
create table
135-
if not exists gdsc.member
136-
(
137-
id
138-
bigint
139-
auto_increment
140-
primary
141-
key,
142-
member_id
143-
varchar
144-
(
145-
255
146-
) UNIQUE NOT NULL,
147-
member_name varchar
148-
(
149-
255
150-
) NOT NULL,
151-
password varchar
152-
(
153-
255
154-
) NOT NULL,
155-
member_role enum
156-
(
157-
'ADMIN',
158-
'LEAD',
159-
'MEMBER'
160-
) NOT NULL,
161-
batch varchar
162-
(
163-
255
164-
) NOT NULL,
165-
department varchar
166-
(
167-
255
168-
) NOT NULL,
169-
member_email varchar
170-
(
171-
255
172-
) NOT NULL,
173-
is_activated boolean DEFAULT TRUE,
174-
is_deleted boolean DEFAULT FALSE,
175-
soft_deleted_at datetime
176-
(
177-
6
178-
) NULL
179-
);
54+
create table if not exists gdsc.member
55+
(
56+
id bigint auto_increment primary key,
57+
member_id varchar(255) UNIQUE NOT NULL,
58+
member_name varchar(255) NOT NULL,
59+
password varchar(255) NOT NULL,
60+
member_role enum ( 'ADMIN', 'LEAD', 'MEMBER' ) NOT NULL,
61+
batch varchar(255) NOT NULL,
62+
department varchar(255) NOT NULL,
63+
member_email varchar(255) NOT NULL,
64+
is_activated boolean DEFAULT TRUE,
65+
is_deleted boolean DEFAULT FALSE,
66+
soft_deleted_at datetime(6) NULL
67+
);
18068

181-
create table
182-
if not exists gdsc.participant
183-
(
184-
id
185-
bigint
186-
auto_increment
187-
primary
188-
key,
189-
member_id
190-
bigint
191-
NOT
192-
NULL,
193-
attendance_id
194-
bigint
195-
NOT
196-
NULL,
197-
attendance
198-
boolean
199-
DEFAULT
200-
FALSE,
201-
CONSTRAINT
202-
FOREIGN
203-
KEY
204-
(
205-
member_id
206-
) REFERENCES gdsc.member
207-
(
208-
id
209-
) ON UPDATE CASCADE
210-
ON DELETE CASCADE,
211-
CONSTRAINT FOREIGN KEY
212-
(
213-
attendance_id
214-
) REFERENCES gdsc.attendance
215-
(
216-
id
217-
)
218-
ON UPDATE CASCADE
219-
ON DELETE CASCADE
220-
);
69+
create table if not exists gdsc.participant
70+
(
71+
id bigint auto_increment primary key,
72+
member_id bigint NOT NULL,
73+
attendance_id bigint NOT NULL,
74+
attendance boolean DEFAULT FALSE,
75+
CONSTRAINT FOREIGN KEY (member_id)
76+
REFERENCES gdsc.member (id)
77+
ON UPDATE CASCADE
78+
ON DELETE CASCADE,
79+
CONSTRAINT FOREIGN KEY (attendance_id)
80+
REFERENCES gdsc.attendance (id)
81+
ON UPDATE CASCADE
82+
ON DELETE CASCADE
83+
);

sql/v1.sql

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- 1. Add new required columns to attendance table
2+
ALTER TABLE gdsc.attendance
3+
ADD COLUMN title varchar(255) NULL,
4+
ADD COLUMN attendance_time datetime(6) NULL;
5+
6+
-- 2. Migrate data from event table to attendance table
7+
UPDATE gdsc.attendance a
8+
JOIN gdsc.event e ON a.event_id = e.id
9+
SET a.title = e.title,
10+
a.attendance_time = e.start_at;
11+
12+
-- 3. Modify member table
13+
-- 3.1. Rename member_id to student_id
14+
ALTER TABLE gdsc.member
15+
RENAME COLUMN member_id TO student_id;
16+
17+
-- 3.2. Modify ENUM to include new value and update data
18+
ALTER TABLE gdsc.member
19+
MODIFY COLUMN member_role enum ('ADMIN', 'CORE', 'LEAD', 'MEMBER') NOT NULL;
20+
21+
UPDATE gdsc.member
22+
SET member_role = 'CORE'
23+
WHERE member_role = 'ADMIN';
24+
25+
-- 4. Add attendance_type column and migrate data
26+
ALTER TABLE gdsc.participant
27+
ADD COLUMN attendance_type enum ('ATTEND', 'ABSENT', 'LATE') NOT NULL DEFAULT 'ABSENT';
28+
29+
UPDATE gdsc.participant
30+
SET attendance_type = IF(attendance = TRUE, 'ATTEND', 'ABSENT');
31+
32+
-- 5. Drop constraints and clean up tables
33+
-- 5.1. Remove foreign key constraints
34+
ALTER TABLE gdsc.attendance
35+
DROP FOREIGN KEY attendance_ibfk_1;
36+
37+
-- 5.2. Drop event-related tables
38+
DROP TABLE gdsc.event_image;
39+
DROP TABLE gdsc.event;
40+
41+
-- 5.3 Drop unused columns
42+
ALTER TABLE gdsc.attendance
43+
DROP COLUMN event_id;
44+
ALTER TABLE gdsc.member
45+
DROP COLUMN password,
46+
MODIFY COLUMN member_role enum ('CORE', 'LEAD', 'MEMBER') NOT NULL;
47+
ALTER TABLE gdsc.participant
48+
DROP COLUMN attendance;
49+
50+
-- 6. Make migrated columns non-nullable
51+
ALTER TABLE gdsc.attendance
52+
MODIFY COLUMN title varchar(255) NOT NULL,
53+
MODIFY COLUMN attendance_time datetime(6) NOT NULL;
54+
55+
-- 7. Migration complete

src/main/java/gdsc/konkuk/platformcore/application/attendance/AttendanceService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ public class AttendanceService {
3131
private final ParticipantService participantService;
3232

3333
@Transactional
34-
public Participant attend(Long memberId, Long attendanceId, String qrUuid) {
34+
public Participant attend(String memberEmail, Long attendanceId, String qrUuid) {
3535
Member member =
3636
memberRepository
37-
.findById(memberId)
37+
.findByEmail(memberEmail)
3838
.orElseThrow(
3939
() -> UserNotFoundException.of(MemberErrorCode.USER_NOT_FOUND));
4040
Attendance attendance = findAttendanceById(attendanceRepository, attendanceId);

src/main/java/gdsc/konkuk/platformcore/application/auth/CustomAuthenticationSuccessHandler.java

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public void onAuthenticationSuccess(
3636

3737
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
3838
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
39+
40+
// TODO: Admin이 아닌 여러 클라이언트를 사용하게 될 경우, authorization code를 통한 POST 로그인으로 변경 필요
3941
response.sendRedirect(SPA_ADMIN_LOGIN_REDIRECT_URL + "#" + token);
4042
}
4143
}

src/main/java/gdsc/konkuk/platformcore/application/auth/JwtAuthenticationFilter.java

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
3535
log.error("[ERROR] : 인증 정보가 유효하지 않습니다.", e);
3636
SecurityContextHolder.clearContext();
3737
} catch (IllegalArgumentException ignored) {
38-
SecurityContextHolder.clearContext();
3938
}
4039

4140
filterChain.doFilter(request, response);

0 commit comments

Comments
 (0)