Skip to content

Commit

Permalink
feat: #6/공고 삭제 Bloc 이벤트 추가
Browse files Browse the repository at this point in the history
1. OnDeletedJobPosting
  • Loading branch information
Younggun-Kim committed Oct 23, 2024
1 parent 46acf6d commit 052c40b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JobPostingDetailBloc
on<ClearMessage>(_clearMessage);
on<OnGettingDetailData>(_onGettingDetailData);
on<OnClosedJobPosting>(_onClosedJobPosting);
on<OnDeletedJobPosting>(_onDeletedJobPosting);
}

/// 메시지 초기화 이벤트.
Expand Down Expand Up @@ -75,16 +76,57 @@ class JobPostingDetailBloc
jobPostingId: jobPostingId,
);

result.when(success: (JobPostingDetailEntity data) {
emit(state.copyWith(
status: JobPostingDetailStatus.closed,
));
}, fail: (String message) {
emit(state.copyWith(
status: JobPostingDetailStatus.fail,
entity: null,
message: message,
));
});
result.when(
success: (JobPostingDetailEntity data) {
emit(
state.copyWith(
status: JobPostingDetailStatus.closed,
),
);
},
fail: (String message) {
emit(
state.copyWith(
status: JobPostingDetailStatus.fail,
entity: null,
message: message,
),
);
},
);
}

/// 공고 삭제
void _onDeletedJobPosting(
OnDeletedJobPosting event,
Emitter<JobPostingDetailState> emit,
) async {
final String? jobPostingId = state.entity?.id;

if (jobPostingId == null) {
return;
}

emit(state.copyWith(status: JobPostingDetailStatus.loading));

final Either<bool> result = await useCase.deleteJobPosting(
jobPostingId: jobPostingId,
);

result.when(
success: (bool data) {
emit(
state.copyWith(status: JobPostingDetailStatus.deleted),
);
},
fail: (String message) {
emit(
state.copyWith(
status: JobPostingDetailStatus.fail,
message: message,
),
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ class ClearMessage extends JobPostingDetailEvent {}

/// 공고 마감
class OnClosedJobPosting extends JobPostingDetailEvent {}

/// 공고 삭제
class OnDeletedJobPosting extends JobPostingDetailEvent {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ part of 'job_posting_detail_bloc.dart';
/// loading: Api 통신 중
/// success: API 통신 성공
/// fail: API 통신 실패
/// closed: 마감 상태로 변경됨
enum JobPostingDetailStatus { initial, loading, success, fail, closed }
/// closed: 마감 상태
/// deleted: 삭제 상태
enum JobPostingDetailStatus { initial, loading, success, fail, closed, deleted }

extension JobPostingDetailStatusExt on JobPostingDetailStatus {
bool get isInitial => this == JobPostingDetailStatus.initial;
Expand Down

0 comments on commit 052c40b

Please sign in to comment.