为以下场景组织WEB API方法的最佳方法 [英] Best way to organize WEB API method for following scenario

查看:121
本文介绍了为以下场景组织WEB API方法的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在下面设置了以下实体。



电话(PhoneId,PhoneNumber)

人(PersonId,FirstName,LastName )

公司(CompanyId,CompanyName)

经纪人(BrokerId,BrokerName)



PersonPhone(PhoneId,PersonId ,PhoneType)

CompanyPhone(PhoneId,CompanyId,PhoneType)

BrokerPhone(PhoneId,BrokerId)



As实体名称建议,



1.电话/经纪人/公司维护域名数据。

2. PersonPhone / CompanyPhone / BrokerPhone表格保留不同实体和电话号码的映射。



系统需要允许用户创建/更新上述实体,并为他们添加添加/删除电话号码。



问题:

这种情况​​下Web API的结构应该是什么。



我的困惑是哪个控制器应该处理电话将电话添加到pe rson。



它应该指向PersonController,因为在向Person添加电话时可能会有一些特定的业务逻辑,而像/ api / person / id / addphone这样的路径会使从客户的角度来看感觉。



或者应该将呼叫定向到PhoneController.AddPhoneToPerson方法,在这种情况下路径可能是/ api / phone / attachtoperson / phoneid


哪一个更有意义。

Assume, I have the following entity set below.

Phone(PhoneId, PhoneNumber)
Person(PersonId, FirstName, LastName)
Company(CompanyId, CompanyName)
Broker(BrokerId, BrokerName)

PersonPhone(PhoneId, PersonId, PhoneType)
CompanyPhone(PhoneId, CompanyId, PhoneType)
BrokerPhone(PhoneId, BrokerId)

As entity name suggests,

1. Phone/Broker/Company maintains there domain data.
2. PersonPhone/CompanyPhone/BrokerPhone tables keeps a mapping of differenet entities and there phone numbers.

The system needs to allow user to create/update the aforementioned entities and as well add add/remove phone numbers for them.

Question:
What should be the structure of Web API for this kind of scenario.

My confusion is which controller should handle the call "add a phone to person".

Should it directed to PersonController because there may be some specific business logic when adding phone to Person and a path like /api/person/id/addphone makes sense from client's perspective.

Or the call should be directed to PhoneController.AddPhoneToPerson method in which case the path might be /api/phone/attachtoperson/phoneid

Which one makes more sense.

推荐答案

我想,对我来说,Person控制器需要处理这个问题。



一个人需要知道一部电话 - 但电话不需要知道一个人。



因此,您的手机控制器根本不需要了解人员。
I think, to me, the Person controller needs to handle this.

A Person needs to know about a Phone - but a Phone needs no knowledge of a Person.

So your phone controller shouldn't need to know about Person at all.


这篇关于为以下场景组织WEB API方法的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆