Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 어드민 이벤트 수정 기능 구현(#28) #31

Merged
merged 7 commits into from
Aug 6, 2024

Conversation

blaxsior
Copy link
Collaborator

@blaxsior blaxsior commented Aug 5, 2024

#️⃣ 연관 이슈

ex) #28

📝 작업 내용

이벤트 수정 로직 선택

프론트엔드 팀원과의 논의에 따라 이벤트 수정 기능을 "요청 - db 스냅샷 비교" 방식 기반으로 구현했습니다.

관리자 수정 기능을 구현하는 방법은 큰 그림에서는 2가지 방법 존재합니다.

  1. fcfs event / draw event 등을 각 api를 호출하여 변경할 수 있도록 구현
  2. 이벤트 관련 정보를 단일 api로 변경할 수 있도록 구현

1번의 경우 클라이언트 측에서 api를 여러 번 호출하는 것이 불편하다는 의견이 있어 2번 방식으로 구현하기로 했습니다.

단일 api를 이용하여 백엔드가 수정 기능을 만드는 법은 2가지를 생각했습니다.

  1. status 플래그를 둬서 각 행의 상태를 식별할 수 있게 하고, 서버 측에서는 해당 플래그를 기반으로 갱신한다.
  2. 서버 측 스냅샷(db)와 비교해서 차이를 기반으로 create / update / delete을 식별해서 갱신한다.

프론트엔드 측에서는 1번 방안보다 2번 방안이 좀 더 편리하다고 하여 2번 방안을 구현해보기로 했습니다.

구현 논리: dto(클라이언트 측 데이터) 와 entity(서버 측 데이터, 스냅샷)에 대해 set 논리를 도입하여 create / update / delete 대상이 되는 데이터를 식별하여 처리합니다.

  1. create: 프론트엔드에서 전달된 id가 있는 데이터는 업데이트 된 것으로 간주
  2. update: 프론트엔드에서 전달된 id가 없는 데이터는 추가되는 것으로 간주
  3. delete: 프론트엔드에서 전달되지 않은 데이터는 삭제된 것으로 간주

image

필요 이상으로 갱신 난이도가 복잡해질 경우, 이벤트 데이터를 완전 delete 후 다시 얻는 방식도 고려하고 있습니다.

EventFieldMapper 확장 기반으로 기능 구현

이전에 event 타입 확장에 대응하기 위해 구현한 EventTypeMapper의 인터페이스를 확장, 2개 기능을 구현했습니다. 선착순, 추첨 이벤트 모두 구현한 상태입니다.

  1. get / 이벤트 edit을 위한 초기 데이터 제공: 이벤트에 대한 현재 데이터를 제공합니다. 해당 데이터를 기반으로 수정을 진행합니다.
  2. post / 이벤트 edit 기능: dto - entity 스냅샷 비교 논리를 기반으로 수정 기능을 구현했습니다.

@blaxsior blaxsior added the feat 기능 구현 label Aug 5, 2024
@blaxsior blaxsior self-assigned this Aug 5, 2024
Copy link
Collaborator

@win-luck win-luck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어드민 특성상 다채로운 수정이 많아서 굉장히 번거로우셨을 텐데 고생 많으셨습니다!

Comment on lines 84 to 106
@Transactional
public EventDto getEventInfo(String eventId) {
Optional<EventMetadata> metadataOpt = emRepository.findFirstByEventId(eventId);
EventMetadata metadata = metadataOpt
.orElseThrow(() -> new EventException(ErrorCode.EVENT_NOT_FOUND));

EventFieldMapper mapper = mapperMatcher.getMapper(metadata.getEventType());
if(mapper == null) throw new EventException(ErrorCode.INVALID_EVENT_TYPE);

EventDto eventDto = EventDto.builder()
.id(metadata.getId())
.eventId(metadata.getEventId())
.name(metadata.getName())
.description(metadata.getDescription())
.url(metadata.getUrl())
.startTime(metadata.getStartTime())
.endTime(metadata.getEndTime())
.eventType(metadata.getEventType())
.build();

mapper.fetchToDto(metadata, eventDto);
return eventDto;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조회 메서드인 만큼 readOnly=true 옵션을 붙여주셔도 좋을 것 같아요!

@win-luck win-luck linked an issue Aug 6, 2024 that may be closed by this pull request
2 tasks
@blaxsior blaxsior merged commit 952ff7a into dev Aug 6, 2024
1 check passed
@win-luck win-luck deleted the feature/28-admin-edit-event branch August 13, 2024 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 기능 구현
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] 어드민 이벤트 수정 기능 구현(#28)
2 participants