REST API/数据模型设计 - 用户、帐户或两种模型? [英] REST API / DATA MODEL DESIGN - User , Account or Both Models?

查看:24
本文介绍了REST API/数据模型设计 - 用户、帐户或两种模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑如何正确构建我的应用并为其提供良好且一致的 API,但现在我对用户/帐户模型有一些疑问.

I'm having some thoughts about proper building my app and provide a good and consistent API for it but now I'm having some doubts about the user/accounts model.

这很有趣,但如果您考虑某些应用程序,您会发现它们将您视为用户,但在编辑您的详细信息时,您将重定向到帐户.

It's funny but if you consider some apps you will see that they treat you like user but when editing your details your are redirect to account.

推特就是一个很好的例子.

One good example of this is twitter.

所以我想知道您对构建这种架构的最佳方法有什么看法?

So I would like to know your opinion about what's the best method to build this kind of architecture?

账户真的有必要吗?

为什么要使用帐户或用户?

Why should I use account or user?

如果我决定稍后为该用户实施付款指令,该用户是否应将该信息存储在一个帐户中,该帐户存储其密码和其他重要信息?

If I decide to implement a payment instruction for that user later, should that user store that information inside a account which stores his password and other important information?

抱歉,有时我对这个主题有点迷茫,看起来其他应用程序使用的模型多于必需的模型,所以我不确定:(

sorry but I'm kind of lost on this subject sometimes it looks that other apps use more models than the necessary, so I'm not sure :(

我想我必须像这样关联模型:

I was thinking I'm have to associated models like this:

 User has_one :account

但我仍然不确定哪些信息会进入用户和帐户.

But I still not sure what kind of information goes into the User and Account.

预先感谢您的帮助

干杯

推荐答案

这实际上取决于应用程序.以电话为例.一个家庭或公司可能有一部或多部电话一起计费,因此电话号码与帐号不同.

It really depends on the application. Look at telephones for example. One household or company may have one or more telephones billed together, so telephone number is not the same as account number.

对于许多 Web 应用程序,一个用户有一个帐户,反之亦然.我可以开几个账户,一个是马克电脑人",一个是马克钢琴家"等等.所以用户不是一个真实的人,而是更像是一个角色,或者我扮演的角色.如果我的音乐事业真的腾飞,我可能会聘请公关人员来管理我的马克钢琴家"帐户.在这种情况下,应用程序可以将用户"和帐户"联系在一起:每个角色"一个帐户.这非常适合免费应用.

For many web applications, there is one account for one user and vice versa. I can open several accounts, one as "Mark the computer guy", one as "Mark the pianist" and so on. So a user is not a real person but more like a persona, or a character I play. If my music career really takes off I might hire a P.R. person to manage my "Mark the pianist" account. In this case the application could tie "user" and "account" together: one account for each "persona". This is good for a free app.

再举一个不同的例子,看看需要花钱的网络托管服务.我可能会创建一个帐户,然后设置多个可以登录的用户:我、我的 Web 开发人员、我的系统管理员等.因此,多个用户可以使用一个帐户.

For a different example, look at a web hosting service that costs money. I might create one account and then set up several users who can log on: me, my web developer, my systems administrator, etc. So there's one account for several users.

这篇关于REST API/数据模型设计 - 用户、帐户或两种模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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