refactor(application): strip comments, DRY ownership check + parse_content_type
This commit is contained in:
@@ -1,38 +1,26 @@
|
||||
use domain::events::DomainEvent;
|
||||
use domain::models::Channel;
|
||||
use domain::value_objects::{ChannelId, UserId};
|
||||
use domain::{DomainError, DomainResult};
|
||||
use domain::DomainResult;
|
||||
|
||||
use super::commands::UpdateChannelCommand;
|
||||
use super::deps::ChannelCommandDeps;
|
||||
use super::find_owned_channel;
|
||||
|
||||
/// Update an existing channel.
|
||||
///
|
||||
/// Flow: find channel -> verify ownership -> snapshot config if changed ->
|
||||
/// apply updates -> save -> publish event -> return.
|
||||
pub async fn execute(deps: &ChannelCommandDeps, cmd: UpdateChannelCommand) -> DomainResult<Channel> {
|
||||
let channel_id = ChannelId::from(cmd.channel_id);
|
||||
let owner_id = UserId::from(cmd.owner_id);
|
||||
|
||||
let mut channel = deps
|
||||
.channel_query
|
||||
.find_by_id(channel_id)
|
||||
.await?
|
||||
.ok_or(DomainError::ChannelNotFound(cmd.channel_id))?;
|
||||
let mut channel =
|
||||
find_owned_channel(deps.channel_query.as_ref(), channel_id, owner_id, cmd.channel_id)
|
||||
.await?;
|
||||
|
||||
// Ownership check
|
||||
if channel.owner_id() != owner_id {
|
||||
return Err(DomainError::forbidden("You don't own this channel"));
|
||||
}
|
||||
|
||||
// Auto-snapshot the current config before overwriting
|
||||
if cmd.schedule_config.is_some() {
|
||||
deps.channel_command
|
||||
.save_config_snapshot(channel_id, channel.schedule_config(), None)
|
||||
.await?;
|
||||
}
|
||||
|
||||
// Apply partial updates
|
||||
if let Some(name) = cmd.name {
|
||||
channel.set_name(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user