Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created UpdateItem and added necessary trait implementations #18

Merged
merged 13 commits into from
Oct 31, 2024

Conversation

tobypilling
Copy link
Collaborator

I put this together for mark read/unread - can you let me know if you would have approached it differently?

I tried to follow create_item and get_item but wasn't sure how much I should be adjusting common.rs vs keeping things local to update_item.rs

Can you maybe give some guidance?

src/types/common.rs Outdated Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@leftmostcat leftmostcat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brendan has covered most of the things I would, but there are a few other things I'm bringing up here. I use Conventional Comments as a guideline for what's blocking and non-blocking; as such, todo comments will need to be addressed before approval, and I generally expect question comments to be answered as well.

As regards documentation, we should definitely remove the copy-pasted documentation before merging. I'll leave it up to you whether to rewrite it or leave it off for now, as a documentation pass is needed for several areas as it is.

src/types/update_item.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/common.rs Outdated Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
@tobypilling tobypilling force-pushed the tobypilling/update_item branch from 416442d to 188d3da Compare October 23, 2024 20:49
@tobypilling tobypilling force-pushed the tobypilling/update_item branch from cb30763 to 475bd39 Compare October 28, 2024 19:34
Copy link
Collaborator

@leftmostcat leftmostcat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking for quite a few changes here and a lot of them are about style and convention in documentation or ordering of files for consistency. Additionally, there are some slightly bigger changes that are needed because of decisions we made earlier which impact the way the Message struct is used. I will put up a PR into this branch to try to illustrate what I'm expecting rather than flooding this one with suggestions.

@@ -315,7 +327,7 @@ pub enum BaseItemId {
/// The unique identifier of an item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemid>
#[derive(Clone, Debug, Deserialize, XmlSerialize, PartialEq)]
#[derive(Clone, Default, Debug, Deserialize, XmlSerialize, PartialEq)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: Default doesn't make sense here. See next comment.

src/types/common.rs Show resolved Hide resolved
src/types/update_item.rs Outdated Show resolved Hide resolved
AlwaysOverwrite,
}

/// Represents a change to an individual item, including the item ID and updates.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This and the other struct comments throughout the file should follow the noun phrase convention.

pub message: Message, // The new value for the specified field.
}

/// Struct representing updates to be applied to an item.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "Struct representing" is implicit in the declaration already and doesn't really add anything here.

Suggested change
/// Struct representing updates to be applied to an item.
/// A list of changes to fields, with each element representing a single change.


/// Struct representing updates to be applied to an item.
///
/// This struct is used to create an UpdateItem request.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This doesn't really add anything not implied by the type hierarchy.

/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updates-item>
#[derive(Clone, Debug, XmlSerialize)]
pub struct Updates {
pub set_item_field: SetItemField,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: A couple problems here. First is that this only allows for a single field to be changed per update and it should instead be a Vec. Second is that it doesn't allow for append/delete operations. That should be done by using an enum.

pub item_changes: Vec<ItemChange>,
}

/// Struct representing the field update operation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: As below, "Struct representing" doesn't add much here, and the second paragraph could easily be folded into this one to give a more complete description, but as below, this needs additional revision.

Comment on lines 90 to 95
impl UpdateItem {
/// Adds another `ItemChange` to the `UpdateItem` request.
pub fn add_item_change(&mut self, item_change: ItemChange) {
self.item_changes.item_changes.push(item_change);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: There's still not really cause to have this be a separate function. The field to be changed is public, so while this provides a slight shortcut to accessing that field, it also provides limited means of interacting with it. In particular, since we generally create these operation structs all at once, push() isn't very useful as a way of building a list of changes. Instead, we should generally be preferring using Rust iterators and collect().

Comment on lines 90 to 142
impl UpdateItem {
/// Adds another `ItemChange` to the `UpdateItem` request.
pub fn add_item_change(&mut self, item_change: ItemChange) {
self.item_changes.item_changes.push(item_change);
}
}

impl Operation for UpdateItem {
type Response = UpdateItemResponse;
}

impl EnvelopeBodyContents for UpdateItem {
fn name() -> &'static str {
"UpdateItem"
}
}

/// A response to an [`UpdateItem`] request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitemresponse>
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct UpdateItemResponse {
pub response_messages: ResponseMessages,
}

impl OperationResponse for UpdateItemResponse {}

impl EnvelopeBodyContents for UpdateItemResponse {
fn name() -> &'static str {
"UpdateItemResponse"
}
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResponseMessages {
pub update_item_response_message: Vec<UpdateItemResponseMessage>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct UpdateItemResponseMessage {
/// The status of the corresponding request, i.e. whether it succeeded or
/// resulted in an error.
pub response_class: ResponseClass,

pub response_code: Option<ResponseCode>,

pub message_text: Option<String>,

pub items: Items,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I have generally kept the actual definition of the operations at the beginning of the file with operation-specific types declared below. I don't have solid reasoning for this, but it's consistent and puts the named part of the file up front.

Even nitpickier but reflected in that tendency is that, in Rust, I tend to prefer to declare a type and then declare additional types on which it depends below them, e.g.:

struct Foo {
    bar: Bar,
}

struct Bar {}

Copy link
Member

@babolivier babolivier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor documentation nit, otherwise lgtm :)

@@ -177,6 +177,18 @@ pub enum DistinguishedPropertySet {
UnifiedMessaging,
}

/// The action an Exchange server will take upon creating a `Message` item.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The action an Exchange server will take upon creating a `Message` item.
/// The action an Exchange server will take upon creating or updating a `Message` item.

@tobypilling tobypilling merged commit 3b1d4db into main Oct 31, 2024
2 checks passed
@tobypilling tobypilling deleted the tobypilling/update_item branch October 31, 2024 19:19
leftmostcat added a commit that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants