Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leena #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Leena #11

wants to merge 1 commit into from

Conversation

LeenaBhegade
Copy link

No description provided.

@@ -9,3 +9,27 @@ require (
github.com/joho/godotenv v1.4.0
google.golang.org/api v0.60.0
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i was meant to change this

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same thing happened to me here probably @tomw-1 knows better what's happening

@LeenaBhegade LeenaBhegade requested review from tomw-1 and wildeng March 17, 2022 11:05
)

func NewRouter() *martini.ClassicMartini {
libraryController := new(controllers.LibraryController)

router := martini.Classic()

router.Get("/books", libraryController.ListAll)
router.Get("/books/:id", libraryController.GetByKey)
router.Get("/books", initBookInterface, libraryController.ListAll, closeClientConnection)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like the way you organised the routes

query := datastore.NewQuery("Book").Order("Id")

if len(title) > 0 {
query = query.Filter("Title =", title)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you change this to allow the filtering by title and author? @tomw-1 asked me the same thing 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add another Filter for author

return book, nil
}

func (bookImpl BookImplementation) Query(title string) ([]Book, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably have put this in your helper class, I have a feeling that's more appropriate for it to live there. What do you think about it?

Copy link
Author

@LeenaBhegade LeenaBhegade Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I was very close to just extracting all the functions in a datastore file and expose required functions to all models, as with addition of new entities these functions could easily be reused, I might do if i get chance on Wednesday

}

func NewBookImplementation() BookInterface {
ctx := context.Background()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genuine question. because I still have to dig deeper into context, what was your feeling of moving the context from the controller to the model itself? And what happens if you need to create another controller and anothe model? 😄

Copy link
Author

@LeenaBhegade LeenaBhegade Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used context a lot myself but In our example context don't hold any info which is why at that time I just got lazy and left it there. I would have probably initialised context on server initialisation and passed in to controllers where it could hold info on request timeouts etc and is also used beyond model.

if _, err := client.PutMulti(ctx, keys, books); err != nil {

bookInt := models.NewBookImplementation()
if err := bookInt.PutMulti(books); err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳 nice one

@@ -9,3 +9,27 @@ require (
github.com/joho/godotenv v1.4.0
google.golang.org/api v0.60.0
)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same thing happened to me here probably @tomw-1 knows better what's happening

return books, nil
}

func (bookImpl BookImplementation) Put(book Book, insert bool) (int64, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code is perfectly fine, what do you think about having two separate functions that for create and update without the need of passing a boolean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I could for better readability, there I was just trying to not duplicate code

"net/http"
)

func WriteJsonResp(w http.ResponseWriter, data interface{}) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳 nice one, I like the two functions to manage errors and responses

@LeenaBhegade LeenaBhegade changed the title Initial commit Leena Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants