Skip to content

Commit

Permalink
#75 [feat] : 유저는 생성한 이벤트를 삭제할 수 있다
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Oct 9, 2024
1 parent d7c9520 commit bce05c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/main/java/side/onetime/controller/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ public ResponseEntity<ApiResponse<List<EventDto.GetUserParticipatedEventsRespons
List<EventDto.GetUserParticipatedEventsResponse> getUserParticipatedEventsResponses = eventService.getUserParticipatedEvents(authorizationHeader);
return ApiResponse.onSuccess(SuccessStatus._GET_USER_PARTICIPATED_EVENTS, getUserParticipatedEventsResponses);
}

// 유저가 생성한 이벤트 삭제 API
@DeleteMapping("/{event_id}")
public ResponseEntity<ApiResponse<SuccessStatus>> removeUserCreatedEvent(
@RequestHeader("Authorization") String authorizationHeader,
@PathVariable("event_id") String eventId) {

eventService.removeUserCreatedEvent(authorizationHeader, eventId);
return ApiResponse.onSuccess(SuccessStatus._REMOVE_USER_CREATED_EVENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum SuccessStatus implements BaseCode {
_GET_PARTICIPANTS(HttpStatus.OK, "200", "참여자 조회에 성공했습니다."),
_GET_MOST_POSSIBLE_TIME(HttpStatus.OK, "200", "가장 많이 되는 시간 조회에 성공했습니다."),
_GET_USER_PARTICIPATED_EVENTS(HttpStatus.OK, "200", "유저 참여 이벤트 목록 조회에 성공했습니다."),
_REMOVE_USER_CREATED_EVENT(HttpStatus.OK, "200", "유저가 생성한 이벤트 삭제에 성공했습니다."),
// Member
_REGISTER_MEMBER(HttpStatus.CREATED, "201", "멤버 등록에 성공했습니다."),
_LOGIN_MEMBER(HttpStatus.OK, "200", "멤버 로그인에 성공했습니다."),
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/side/onetime/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import side.onetime.domain.*;
import side.onetime.domain.enums.EventStatus;
import side.onetime.dto.EventDto;
import side.onetime.exception.EventErrorResult;
import side.onetime.exception.EventException;
import side.onetime.exception.ScheduleErrorResult;
import side.onetime.exception.ScheduleException;
import side.onetime.exception.*;
import side.onetime.domain.enums.Category;
import side.onetime.repository.*;
import side.onetime.util.DateUtil;
Expand Down Expand Up @@ -282,4 +279,21 @@ public List<EventDto.GetUserParticipatedEventsResponse> getUserParticipatedEvent
})
.collect(Collectors.toList());
}

// 유저가 생성한 이벤트 삭제 메서드
@Transactional
public void removeUserCreatedEvent(String authorizationHeader, String eventId) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
Event event = eventRepository.findByEventId(UUID.fromString(eventId))
.orElseThrow(() -> new EventException(EventErrorResult._NOT_FOUND_EVENT));

EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event)
.orElseThrow(() -> new EventParticipationException(EventParticipationErrorResult._NOT_FOUND_EVENT_PARTICIPATION));
if (!EventStatus.CREATOR.equals(eventParticipation.getEventStatus())) {
// 해당 이벤트의 생성자가 아닌 경우
throw new EventParticipationException(EventParticipationErrorResult._IS_NOT_USERS_CREATED_EVENT_PARTICIPATION);
}

eventRepository.delete(event);
}
}

0 comments on commit bce05c7

Please sign in to comment.