CoderCamps Week Seven – WebAPI

Wow.  I’m more than halfway through and I’m still standing!  So after last week where we were strictly in the world of C#, this week we’re starting to tie it all together.  On the front-end we have HTML5, CSS (primarily Bootstrap) and AngularJS in starring roles; on the back-end we’re now adding in WebAPI, Entity Framework and databases; along with .NET patterns and security.

Monday was all about WebAPI.  At this point, rather than adding in a “real” database, we opted for a “fake” database (a/k/a “List”) which we put in the server-side controller.  This was so we could get used to accessing data via a data model and server-side controller, and of course communicating from the front-end views, controllers and services all the way through to the data.  Of course, the biggest challenge with all this is that there are many moving pieces.  Our homework should have been very straightforward – replicating what we did in class.  I wanted to use a modal to view details of a selected item, but could not, for the life of me, get my project to work – not even listing the items!

After far too many hours trying to figure it out (I think I spent over 3 hours on this one issue alone – researching, combing through my code), it turned out that the directive I’d been using – $modal – had been completely, irrevocably and permanently deprecated in factor of $uibModal since the weekend.  What I found frustrating about that was that although I’d seen the warnings “$modal is deprecated”, I had no idea that it was about to unceremoniously lose all functionality (and completely break my entire site).  Even worse: the error message was hardly informative – a generic “not recognized” injection error.  I was very glad that this was merely my homework and not a live website!  The lesson from this: pay attention to those warning messages!

Tuesday we spent more time on WebApi and server-side validation; but also spent some time reviewing the flow of data from the browser (e.g. via user input) through the client-side controller, client-side services, and then over to the server-side controller and on to the database; and back again.  Of course, there is the equivalent of client-side services on the server, but this was Tuesday and repositories didn’t get covered until Thursday!  One can only learn so much in one day.  Server-side validation can be done in the controller, but in the interest of following the “lean controller” architecture, it’s good to put it in the data model instead.  Given our homework was pretty light, I took the opportunity to spend some time working on my project getting Google maps implemented and playing with FileStack (formerly known as FilePicker).  I did set up some controllers and models also, although no doubt there will be changes as we work through this week.

Hump-day and it was time to talk about setting up a code first database.  In the past I’ve generally used the database first / EDMX approach, but with Entity Framework 7 on the horizon where it looks like that will be deprecated, it’s good to learn about the Code First approach.  It still requires a good number of steps, however, so I took copious notes and hoped I hadn’t missed anything!  Later in the day we spent time talking about database structures.  Now, bear in mind that this is not a SQL class nor a DBA class of any kind, but even a web developer needs to know something about databases (relational or otherwise).  For myself, I’ve had enough exposure to databases to understand the importance of structuring it correctly, so this was a fairly easy review for me.  Still, it’s a little different implementing a database rather than just looking at someone else’s beautifully designed schema.  I spent a good amount of time working on my project – still working with FileStack (I really want people to be able to upload a photo!) and also creating a table or two in the database for my project using the Code First method, although I have a suspicion that I will need to redo a lot of this as we learn more about actually setting up relationships and Identity (I have yet to create a log-in!)

Thursday was perhaps the toughest day so far.  Understanding one-to-many and many-to-many relationships is not quite the same as creating them using a method you’re not entirely familiar with!  Still, with the help of many, many notes from the lesson, I was able to successfully create the tables, and the relationships, and return both all records and a single record based on the URL.  I couldn’t quite figure out how to bring back only the records matching on the related data (e.g. only the items belonging to certain owners), but hopefully I will get that resolved sooner rather than later.  I also added a delete method.  Given that this was such a heavy day, some humor available here for all us novice coders!

Friday – group project day!  So as with the earlier group  project, we were given a task (in this case to build a simple auction website) and rather than work on it as a single group we divided into two groups of “online” (those of us not physically there in Seattle) and “offline” (those in Seattle).  By the end of the day we had our entire site scaffolded out and simple data access working, leaving us the weekend to continue working on the logic of placing bids (but only if it’s higher than all other bids) and how to close out the auction.

Some of us had more success than others in that over the weekend …. I spent a good chunk of time on my project – getting all the WebAPI controllers and repositories in place along with the various CRUD methods.  My project is beginning to come together!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s