From f3ecf5e6d85e7909ef44f44e8f18b79cf5bed0a2 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 13 Jun 2020 16:49:48 -0700 Subject: start implementing some more mutations --- rust/fatcat-cli/src/entities.rs | 48 +++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/rust/fatcat-cli/src/entities.rs b/rust/fatcat-cli/src/entities.rs index 907061c..bc5c6f3 100644 --- a/rust/fatcat-cli/src/entities.rs +++ b/rust/fatcat-cli/src/entities.rs @@ -138,54 +138,84 @@ impl ApiModelMutate for models::ReleaseEntity { impl ApiModelMutate for models::ContainerEntity { fn mutate(&mut self, mutations: Vec) -> Result<()> { - unimplemented!("mutations") + for m in mutations { + match (m.field.as_str(), m.value) { + ("name", val) => { self.name = val; }, + (field, _) => unimplemented!("setting field {} on a container", field), + } + } + Ok(()) } } impl ApiModelMutate for models::CreatorEntity { fn mutate(&mut self, mutations: Vec) -> Result<()> { - unimplemented!("mutations") + for m in mutations { + match (m.field.as_str(), m.value) { + ("display_name", val) => { self.display_name = val; }, + (field, _) => unimplemented!("setting field {} on a creator", field), + } + } + Ok(()) } } impl ApiModelMutate for models::WorkEntity { - fn mutate(&mut self, mutations: Vec) -> Result<()> { + fn mutate(&mut self, _mutations: Vec) -> Result<()> { unimplemented!("mutations") } } impl ApiModelMutate for models::FileEntity { fn mutate(&mut self, mutations: Vec) -> Result<()> { - unimplemented!("mutations") + for m in mutations { + match (m.field.as_str(), m.value) { + ("mimetype", val) => { self.mimetype = val; }, + (field, _) => unimplemented!("setting field {} on a file", field), + } + } + Ok(()) } } impl ApiModelMutate for models::FilesetEntity { - fn mutate(&mut self, mutations: Vec) -> Result<()> { + fn mutate(&mut self, _mutations: Vec) -> Result<()> { unimplemented!("mutations") } } impl ApiModelMutate for models::WebcaptureEntity { - fn mutate(&mut self, mutations: Vec) -> Result<()> { + fn mutate(&mut self, _mutations: Vec) -> Result<()> { unimplemented!("mutations") } } impl ApiModelMutate for models::Editor { fn mutate(&mut self, mutations: Vec) -> Result<()> { - unimplemented!("mutations") + for m in mutations { + match (m.field.as_str(), m.value) { + ("username", Some(val)) => { self.username = val; }, + (field, _) => unimplemented!("setting field {} on an editor", field), + } + } + Ok(()) } } impl ApiModelMutate for models::Editgroup { fn mutate(&mut self, mutations: Vec) -> Result<()> { - unimplemented!("mutations") + for m in mutations { + match (m.field.as_str(), m.value) { + ("description", val) => { self.description = val; }, + (field, _) => unimplemented!("setting field {} on an editgroup", field), + } + } + Ok(()) } } impl ApiModelMutate for models::ChangelogEntry { - fn mutate(&mut self, mutations: Vec) -> Result<()> { + fn mutate(&mut self, _mutations: Vec) -> Result<()> { unimplemented!("mutations") } } -- cgit v1.2.3