Skip to content
Open
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 @@ -37,18 +37,25 @@ public void reviewCreatorCertification(ReviewCreatorCertificationCommand command
certificationRepositoryPort.update(certification);

if (certification.isApproved()) {
createCreator(certification);
eventRepositoryPort.save(buildApprovedEvent(certification));
Creator creator = createCreator(certification);
eventRepositoryPort.save(buildApprovedEvent(certification, creator));
}
else {
eventRepositoryPort.save(buildRejectedEvent(certification));
}
}

private CreatorCertificationApprovedEvent buildApprovedEvent(CreatorCertification certification) {
private CreatorCertificationApprovedEvent buildApprovedEvent(CreatorCertification certification, Creator creator) {
return CreatorCertificationApprovedEvent.builder()
.userId(certification.getUserId())
.creatorId(creator.getId())
.certificationId(certification.getId())
.nickname(creator.getNicknameValue())
.tagline(creator.getTagline())
.profileImageUrl(creator.getProfileImageUrl())
.introduction(creator.getIntroduction())
.genres(creator.getGenres())
.status(creator.getStatus())
.occurredAt(certification.getResult().reviewedAt())
.build();
}
Expand All @@ -62,7 +69,7 @@ private CreatorCertificationRejectedEvent buildRejectedEvent(CreatorCertificatio
.build();
}

private void createCreator(CreatorCertification certification) {
private Creator createCreator(CreatorCertification certification) {
if (creatorRepositoryPort.existsByUserId(certification.getUserId())) {
throw new CreatorAlreadyExistsException();
}
Expand All @@ -75,5 +82,7 @@ private void createCreator(CreatorCertification certification) {
.build();

creatorRepositoryPort.save(creator);
return creatorRepositoryPort.findByUserId(certification.getUserId())
.orElseThrow(() -> new IllegalStateException("저장된 크리에이터를 찾을 수 없습니다."));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package kr.magicbox.creator.domain.event;

import com.fasterxml.jackson.annotation.JsonProperty;
import kr.magicbox.creator.domain.enums.CreatorStatus;
import kr.magicbox.creator.domain.enums.MagicGenre;
import kr.magicbox.creator.domain.vo.CreatorCertificationId;
import kr.magicbox.creator.domain.vo.CreatorId;
import kr.magicbox.creator.domain.vo.UserId;
import lombok.Builder;

import java.time.Instant;
import java.util.Set;

@Builder
public record CreatorCertificationApprovedEvent(
@JsonProperty("user_id") UserId userId,
@JsonProperty("creator_id") CreatorId creatorId,
@JsonProperty("certification_id") CreatorCertificationId certificationId,
@JsonProperty("nickname") String nickname,
@JsonProperty("tagline") String tagline,
@JsonProperty("profile_image_url") String profileImageUrl,
@JsonProperty("introduction") String introduction,
@JsonProperty("genres") Set<MagicGenre> genres,
@JsonProperty("status") CreatorStatus status,
@JsonProperty("occurred_at") Instant occurredAt
) implements CreatorDomainEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum CreatorDomainEventType {

CREATOR_CERTIFICATION_APPROVED("creator-certification-approved"),
CREATOR_CERTIFICATION_REJECTED("creator-certification-rejected"),
CREATOR_PROFILE_UPDATED("creator-profile-updated"),
CREATOR_REVOKED("creator-revoked"),
CREATOR_UNBANNED("creator-unbanned");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kr.magicbox.creator.domain.event;

import com.fasterxml.jackson.annotation.JsonProperty;
import kr.magicbox.creator.domain.enums.MagicGenre;
import kr.magicbox.creator.domain.vo.CreatorId;
import lombok.Builder;

import java.time.Instant;
import java.util.Set;

@Builder
public record CreatorProfileUpdatedEvent(
@JsonProperty("creator_id") CreatorId creatorId,
@JsonProperty("before") ProfileSnapshot before,
@JsonProperty("after") ProfileSnapshot after,
@JsonProperty("occurred_at") Instant occurredAt
) implements CreatorDomainEvent {

public record ProfileSnapshot(
@JsonProperty("nickname") String nickname,
@JsonProperty("tagline") String tagline,
@JsonProperty("profile_image_url") String profileImageUrl,
@JsonProperty("introduction") String introduction,
@JsonProperty("genres") Set<MagicGenre> genres
) {}

@Override
public String key() {
return creatorId.value().toString();
}

@Override
public CreatorDomainEventType eventType() {
return CreatorDomainEventType.CREATOR_PROFILE_UPDATED;
}
}
Loading