Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Locale;

public record CalendarResponse(
Long id, String title, String url, String type, Long startAt, Long endAt, String writer)
Long calendarId, String title, String url, String type, Long startAt, Long endAt, String writer)
implements AbstractResponseDto {

public static CalendarResponse toResponse(CalendarModel model, String writerName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public DeniedCalendarTypeException(Department department) {

@Override
public String getMessage() {
return String.format("%s 부서는 해당 타입의 칼렌더를 생성할 수 없습니다.", department.name());
return String.format("%s 부서는 해당 타입의 칼렌더를 생성할 수 없습니다.", department.getKoName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class CalendarEntity extends BaseEntity {
@Column(name = ENTITY_PREFIX + "_title", nullable = false)
private String title;

@Column(name = ENTITY_PREFIX + "_url", nullable = false)
@Column(name = ENTITY_PREFIX + "_url", nullable = true)
private String url;

@Column(name = ENTITY_PREFIX + "_start_at", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.blackcompany.eeos.program.application.event;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class CreatedProgramEvent {

private final Long programId;

public static CreatedProgramEvent of(Long programId) {
return new CreatedProgramEvent(programId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.blackcompany.eeos.program.application.event;

import com.blackcompany.eeos.calendar.application.dto.CalendarCreateCommand;
import com.blackcompany.eeos.calendar.application.model.CalendarType;
import com.blackcompany.eeos.calendar.application.usecase.CreateCalendarUsecase;
import com.blackcompany.eeos.program.application.exception.NotFoundProgramException;
import com.blackcompany.eeos.program.application.model.ProgramModel;
import com.blackcompany.eeos.program.application.model.converter.ProgramEntityConverter;
import com.blackcompany.eeos.program.persistence.ProgramRepository;
import java.util.Locale;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
public class CreatedProgramEventListener {

private final CreateCalendarUsecase calendarUsecase;
private final ProgramRepository programRepository;
private final ProgramEntityConverter entityConverter;

@Transactional(propagation = Propagation.REQUIRES_NEW)
@TransactionalEventListener(
value = CreatedProgramEvent.class,
phase = TransactionPhase.AFTER_COMMIT)
public void createCalendar(CreatedProgramEvent event) {
Long programId = event.getProgramId();

ProgramModel program =
entityConverter.from(
programRepository
.findById(programId)
.orElseThrow(() -> new NotFoundProgramException(programId)));

Long programDateMilli = program.getProgramDate().toInstant().toEpochMilli();

CalendarCreateCommand command =
new CalendarCreateCommand(
program.getTitle(),
null,
CalendarType.PRESENTATION.name().toLowerCase(Locale.ROOT),
programDateMilli,
programDateMilli);

calendarUsecase.create(command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.blackcompany.eeos.program.application.dto.converter.ProgramPageResponseConverter;
import com.blackcompany.eeos.program.application.dto.converter.ProgramResponseConverter;
import com.blackcompany.eeos.program.application.dto.converter.QueryAccessRightResponseConverter;
import com.blackcompany.eeos.program.application.event.CreatedProgramEvent;
import com.blackcompany.eeos.program.application.event.DeletedProgramEvent;
import com.blackcompany.eeos.program.application.exception.DeniedProgramEditException;
import com.blackcompany.eeos.program.application.exception.NotFoundProgramException;
Expand Down Expand Up @@ -92,6 +93,8 @@ public CommandProgramResponse create(final Long memberId, final CreateProgramReq
presentTeamUsecase.save(saveId, request.getTeamIds());
quitUsecase.reserveQuitProgram(model.toBuilder().id(saveId).build());

applicationEventPublisher.publishEvent(CreatedProgramEvent.of(saveId));

return responseConverter.from(saveId);
}

Expand Down