开发者

Service Request/Response Contract Guideline For Multiple Results

I have a Customer service that allows consumers to retrieve Customers by the following criteria: CustomerId, DriversLicense, EmailAddress, PhoneNumber. My question is how would one go about structure a request/response for this service? I would like the ability to request multiple of these criteria and return a proper response. Keep in mind the service will return null for customers not found given the specified criteria.

A few choices jump to mind, but I'm trying to figure what is really the proper way to design a consumable service:

1) Have an explicit contract for each use case:

// psuedo code for operations - proper request/response patterns apply normally
Customer  GetCustomerByCustomerId(string customerId);
Customer[] GetCustomersByCustomerIds(str开发者_如何学Going[] customerId);
Customer GetCustomerByEmail(string emailAddress);
// .. etc. etc.

2) Have a single request that encapsulates all of it; however, phone number is not a unique identifier.

// psuedo code for operations
Customer[] GetCustomers(string customerId, string email, string phone, string dl);

Customer[] GetCustomers(string[] customerIds, string[] emails, string[] phoneNumbers, string[] dls);

I see explicit as being the more readable option, but it's nice to be able to submit all of that information to a service at once and it decides what to do with it. The problem with #1 is that it's redundant, but I think it covers every use case. The issue with #2 is that a client may be confused as to what customer belongs to which request. Thanks for the help!


One quick solution is to use the transfer object itself as search criterion. This is very similar to query-by-example.

For example, rewrite the methods as

Customer[] getCustomers(Customer customerFilter) {
    Query q; // = new query on customer table
    if(customerFilter.isSetCustomerID()) {
        // add where clause to the query: 
        //     Customer.CUSTOMER_ID = customerFilter.getCustomerID()
    }
    // for each field
}

Customer[] getCustomers(Customer[] customerFilters) {
    Query q; // = new query on customer table
    // add where clause to the query for each field: 
        //    Customer.CUSTOMER_ID IN 
        //       [customerFilter : customerFilters].getCustomerID()

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜