Edit: Thank you for the answers. They are helpful. My last question is, is it possible to do this via REST?
To start, I realize these have already been somewhat answered in the following two links, so please do not close this as a duplicate. I am legitimately confused!
MVC vs. 3-tier architecture?
MVC Vs n-tier architecture
From what I understand, the MVC design is for the "presentation" tier in the 3-tier architecture to allow for GUI creation. I get that. However, where I am confused is how the data model in the GUI is supposed to interact with the "Tier 2" application logic. This is how I am envisioning it:
So from what I gather, whenever a user interacts with the GUI, and the Model is updated, is it the model's responsibility to then talk to the rest of the architecture via a web server API?
Your controller contains the lightweight application logic, which is needed to coordinate work between model and view. For example, your controller has the responsibility to get the data from a service/data source, and map the resulting model into a view model that is given to your view.
Views should also contain as little logic as possible. As the view model is created specifically for a view, the only responsibility of the view is to render itself using the view model's data.
The model you are referring to is indeed the result of what you get back from the back-end. It could be proxy entities returned by a WCF service, data entities returned by a web API or entity framework objects if you access the database directly (all depends on what architecture you want to use). This model is then used to construct a view model, which your view uses to render itself.
Depends on how you wanna structure your project.
For example: Sometimes we don't want to expose our model classes (entities). So, we create DTO classes to receive information from UI, that will be handle by controllers and pass them to business logic that translate them to entities. It's used a lot in SOA solutions, where we can expose ours services.
Example: UI request -> Controllers with DTO -> BLL (translate to real model classes) -> Repository/DAO -> DB.
Discussion of tiers is really orthogonal to discussion of MVC.
MVC doesn't really talk about how the model is supposed to talk to outside services/data layers. There are some good discussions here about it. There is debate as to whether data access/persistence should be in your model layer, or your controller layer. I much prefer it in my model layer.
I also prefer the Anemic Domain Model, so I tend to put the actual talking to the DAO layer in the service part of the model, not the domain objects. But putting it into the model objects works well too, you just want to separate your persistence layer from your business logic layer with the DAO pattern.
The point is though, both your tiers need their own Model, and their own DAO layers. The DAO layer of the Presentation Tier will talk to the Business Tier. The DAO layer of the Business Tier will talk to your Database/Storage Tiers.
This isolates each tier from changes in the other tiers.
Related
I'm new to the Django framework and I don't quite understand how to connect the payment system to the site, at the same time, so that part of the payment for the product goes to the balance of the user who exposed it, and 10%-20% of the amount goes to the balance of the service. And what is the best way to connect a payment system for individuals.faces?
So, you need to answer yourself a few questions like:
What payment provider I need? It need to be paypal, stripe or...?
If I know what payment provider I need, is there package for django (or python) for it?
If yes, it is up-to-date?
If no, were there updates to API or solutions described in payment provider documentation?
Are they better in any term?
Depending on these answers, you could go straightforward to implementing payments using external library (for e.g. https://django-paypal.readthedocs.io/en/latest/) or just implement it yourself. In my situation when I implemented paypal payments in e_commerce store I just went with paypal buttons because they were looking better, and they, so far work more nicely.
What also you must mostly implement is something that Paypal calls IPN (instant payment notifications). Stripe, and for example TPay also has IPN-like mechanisms. The IPN is simply an view (functional or generic) that handles payments using data with usually md5 verification, where you update status of order to COMPLETED or et cetera.
The lack of security validation can make endpoint vulnerable to custom requests made by postman, curl or any kind of HTTP-testing tool.
For models - you should write them yourself or use provided by package. This usually means that with multiple payments you store one model per provider with ForeignKey to Order global model that collects all the data. You could use also abstract models for implementing multiple models with similar fields, but this causes some database query issues for additional logic handling (you can't query abstract models, so you need to parse stuff using forloops when you need it instead of using filters).
Frontend is also depending what you will use, but remember about not having price as hidden input :)
The thread is much bigger as it seems, but I hope I gave you point-of-view of the topic.
Im building a webapp in django and really beating myself over the design im going to use. This is a big project and it needs to be scalable and so the design is critical.
My app will have two main types of users, each of them have to see some similar elements, but their 'Flow' through the website and the interaction with it should be different depending on the user type.
I read the answer here and considered using this skeleton project. But non of them address the fact that I have 2 different types of users.
And so my question is:
is it best practice to have a user/profile app, then app for each one of the entities. or on the other hand have a user app that contains all user related and have user groups deciding which kind of user it is, then the main app will decide which flow to show the user depending on its group.
Any other design best practices will be great.
I have a trouble about reactjs and restful web service api architecture. In the common case this would not be a problem but if i have situation like this.
I have React web consumes api data from many database table (these tables are related) on server in one page (in react it would be split into multiple components)
But i learnt that in term of restful web service we should have 1 url for 1 resource which is a database table. if we need related resource we could use nested url. let me give an example. I have 4 database tables which is Bill, Work Order, Sale Job and Product. with these relationships. Bill has one Work Order, Work Order has many Sale Jobs and Sale Job has one Product.
if i need all data for this react page i need at least 4 http requests. with url nested approach, like below.
1. /api/bills/1
2. /api/bills/1/workOrder
3. /api/bills/1/workOrder/saleTxns
4. /api/bills/1/workOrder/saleTxns/product
or another way is to just let bill url have all nested data i need for this react page (which is gigantic) so i can just have 1 http request and pass all data into each component.
So my question is which approach is better.
split into multiple chunk of data.
so then. Will it be root component job to
fetch data and pass into child component. or each component fetch its own
data.
just load 1 gigantic request.
is this will be bad practice for restful web
service? cause it looks like i design url /api/bills/1 for just this react
web page. so if i have more platform like ios, android then i need to have
more url for it?
maybe like.
/web/api/bills/1?reactView1=true,
/web/api/bills/1?reactView2=true,
/ios/api/bills/1
/android/api/bills/1
I cannot say which approach is better based on your information. What I can say, however, is this:
As Eric Stein says, there is no requirement to allow only one url to correspond with one database table.
If this is a common operation in your front end, it makes sense to develop an API endpoint such, that it responds with all the information nested below the specified bill. It saves you some front end code / nasty callback logic.
That being said, doing 4 requests should not be the end of the world either. If this fits the rest of your application better, and you developed the logic in a decent way, this shouldn't be too much of a problem.
Which component should handle which action is again really up to how your application is designed and how you want to continue to build it out. Don't be too afraid to just start with one approach, maybe you should change it later. It's code after all, not concrete.
While working on a new application I came across a new, for me, scenario. Our identity system is a stand alone application with it's own data store only accessible though REST APIs. This is the theme we're moving forward with, independent apps that talk to each other through APIs.
Some entities in my new app have natural associations with identity entities on the IDM app.I can store a reference to that entity's Id as reported to my app through its API. I'm thinking it would be better to store the full URL where I can GET the entity.
Does anyone have suggestions on which way to go?
MyEntity
- User: IDM issued ID
or
MyEntity
- User: https://idm-server.com/users/{id}
Thanks in advance
I feel like exposing an edmx class as a parameter to a web service is not a good idea. I feel like it's wrong design. eg.
[WebMethod]
MyWebservice(int customerID, UserProfile profile){
}
now UserProfile is a class generated by Edmx framework. You might argue if the profile object is an input then it will not get a proper id (edmx id) because it will be created out of the context (since the web service can be called from any external consumer).
But i'm also looking for more explanation why exposing edmx class as a web service is not a good design. If you think it's ok, please tell me.
thanks
It's generally considered good design practice to keep the data contracts of a web service and the data model objects associated with a database separate, so that if required you could change the entity model used at the back of a web service, without having to change the interface that you expose to consumers of the service.