Mads Cordes
5 supporters
TaaDb - Part 2: The beginning

TaaDb - Part 2: The beginning

Apr 30, 2020

The database

To continue where we left of, we had just created a new directory along with a few files. These are the ones we will be fiddling with for this post.

The config

The config will be a humble file, containing a total of six SLoC*, which is not much, if you ask me. Makes it do the job, though!

*Source Lines of Code

This file should contain the proper Key, Token and Board_ID. Though, mine are not set to the proper ones.

Let us do some addiction to our client.go-file too! - During the next minor chapter.

The client

As you might remember, we have three files within the db-dir - or package. I've since the old post, decided we won't make a full CRUD API. In fact we will only be creating the single one. A retriever.

To do this, we will start with a simple import of packages of the client-file.

We are using the first import adlio/trello as a middleware for our API to talk with with Trello API. The next two from gomarkdown/markdown will be used to write on our page - or converting markdown to HTML-strings.

And last, but not least. We will be using iancoleman/strcase as a way to contain naming conventions of cards on Trello.

New client

Let us create a client, so that we can talk with Trello directly - or rather, via HTTP.

We will need a name for what list to use from which board we chose the ID of. Then we will filter through the lists until we find the one with that specific name. If we do not find any lists corresponding to that name, we create a new list with that name. So, be sure to request the correctly spelled names! Lastly, we return list for later usage.

Well, this was quite a mouthful. Let us just hope it works, as we do not have any tests right at this moment.

So, let us explore some more. How about we fetch the data for a whole list? Meaning; getting and returning a slice, which we later will convert into a JSON array.

The getting of pages

Now that we have a list to retrieve data from, we should ask for said data. We do this by getting every card of the list, then initialize a new Markdown-parser with a couple of extensions I like. Now, iterate over the slice, fetch the description of the single card, and append to our slice.

For the last part, we return the sections, we have just converted from the cards.

That is all fine an dandy! But what if a user navigates to a single page? Well...

Fetching a page

The last thing of our package, is to take into concern, that a user might want to see a single page only. If this happens, we are kind of on a bare-bottom. We can only get all the pages - or cards - of a list. We could, of course, simply serve all the pages again and then filter through them on the front.

Or, even better! We could not allow the user to see a single page. Nah, I'm kidding. Let us get to it.

We do mostly the same thing, as in the getting of pages. Alas, we do a pre-filter before we parse our card data. That is pretty clever, if I may say so myself.

Next up

In the next post, we will be exploring how to use and connect this in an HTTP-server. Soon we will even get to the markdown land of HTML were we even will style this supercalifractalistic land with grass and everything!

So I hope you'll come along on the road! I will be posting new blog-posts every now and again, alas, most of them will be members only - which will all be released as a book in the future.

The following posts are also released:

Enjoy this post?

Buy Mads Cordes a mocha

More from Mads Cordes