Skip to content

Commit

Permalink
[Refactor] 동시성 처리 (#82)
Browse files Browse the repository at this point in the history
* feat : 동시성 처리

* fix : 알람 읽지 않은 목록만 보여주기로 수정
  • Loading branch information
purin48 authored May 15, 2024
1 parent c1399c0 commit ca8833a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package today.meevote.domain.voting_schedule.service;

import lombok.RequiredArgsConstructor;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import today.meevote.contextholder.MemberContextHolder;
Expand All @@ -11,6 +12,7 @@
import today.meevote.exception.rest.RestException;
import today.meevote.response.FailureInfo;

import java.sql.SQLException;
import java.util.List;

@Service
Expand Down Expand Up @@ -57,10 +59,13 @@ public void addPlaceToVote(long scheduleId, CreatePlaceDto addPlaceToVoteDto) {
if(!votingScheduleDao.isExistMemberSchedule(email, scheduleId))
throw new RestException(FailureInfo.NOT_EXIST_MEMBER_SCHEDULE);

if(votingScheduleDao.isDuplicatePlaceToVote(scheduleId, addPlaceToVoteDto))
// SQLException - 동시성 제어 / 유니크 키 제약 조건 위반 처리
try {
votingScheduleDao.addPlaceToVote(scheduleId, addPlaceToVoteDto);
} catch (DuplicateKeyException e) {
// ORA-00001: unique 키 위배
throw new RestException(FailureInfo.ALREADY_EXIST_PLACE_TO_VOTE);

votingScheduleDao.addPlaceToVote(scheduleId, addPlaceToVoteDto);
}
}

public void toggleVotePlace(long placeToVoteId) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/today/meevote/response/FailureInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum FailureInfo {
NOT_EXIST_SCHEDULE("S02", "존재하지 않는 일정입니다."),
NOT_EXIST_DELETE_SCHEDULE("S03", "삭제가 불가능한 일정입니다. 확인 후 다시 시도해주세요."),
NOT_OUT_MEMBER_SCHEDULE("S04", "나가기가 불가능한 일정입니다. 확인 후 다시 시도해주세요."),
ALREADY_EXIST_GROUP_MEMBER("S05", "이미 존재하는 그룹일정입니다."),
NOT_SCHEDULE_OWNER("S98", "해당 일정의 소유자가 아닙니다."),
NOT_EXIST_MEMBER_SCHEDULE("S99", "해당 일정의 멤버가 아닙니다."),

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mapper/notifyMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
LEFT JOIN schedule_place sp ON n.schedule_id = sp.schedule_id
WHERE
n.email = #{email}
AND n.is_read = 0
ORDER BY n.is_read ASC, n.notify_id DESC
</select>

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/sql/sql_0515
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- 컬럼 길이 줄이기
ALTER TABLE place_to_vote MODIFY place_name NVARCHAR2(1000);
ALTER TABLE place_to_vote MODIFY lat NVARCHAR2(1000);
ALTER TABLE place_to_vote MODIFY lng NVARCHAR2(1000);

-- 복합 유니크 인덱스 생성
CREATE UNIQUE INDEX uq_place_to_vote
ON place_to_vote (schedule_id, lat, lng);

-- place_to_vote 테이블에 새로운 유니크 제약 조건을 추가
ALTER TABLE place_to_vote
ADD CONSTRAINT uq_place_to_vote UNIQUE (schedule_id, lat, lng);

0 comments on commit ca8833a

Please sign in to comment.