Skip to content

GWI challenge #47

Open
stevenoddity wants to merge 31 commits into
GlobalWebIndex:mainfrom
stevenoddity:main
Open

GWI challenge #47
stevenoddity wants to merge 31 commits into
GlobalWebIndex:mainfrom
stevenoddity:main

Conversation

@stevenoddity

Copy link
Copy Markdown

No description provided.

@dzacharakis dzacharakis left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi @stevenoddity 👋

Thanks for your work on this assignment!

I added some comments on your PR with a few questions. I’d love to hear your feedback when you get a chance.

Thanks,
Dimitris

Comment on lines +21 to +22
defer func() {
if err := recover(); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is recovering from panics in Go generally considered a good practice?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In general no, as it "hides" the issue.


// GetUsers handles the HTTP request to retrieve a list of users.
func GetUsers(w http.ResponseWriter, r *http.Request) {
// This function currently does not implement any logic.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason you’re keeping these?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These were just placeholders for enhancements that I didn't implement.

Comment thread main.go
func main() {
router := routes.RegisterRoutes()
fmt.Println("🚀 Server running on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", middleware.RecoverMiddleware(router)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why did you choose log.Fatal here? Would log.Error have been more appropriate?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

if it fails, the program cannot recover, so that's why I chose it.

Comment thread utils/input_validators.go

// ValidateFavorite validates the given Favorite struct.
// It returns an error if the validation fails, otherwise it returns nil.
func ValidateFavorite(fav *favorite_model.Favorite) error {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this method being used anywhere?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nope, I didn't utilize it at the end.

Comment thread models/asset/asset.go
type Asset struct {
ID int `json:"id"` // Unique identifier for the asset
UserID int `json:"user_id"` // Identifier for the user who owns the asset
Description json.RawMessage `json:"description"` // Description of the asset

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using json.RawMessage for the Description field is a poor design choice. Why? Any better approaches?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It hides the structure of description and it makes quering difficult with slow performance. A better approach would be to define a separate structure from the description.

@@ -0,0 +1,11 @@
package favorite_model

import asset_model "gwi/models/asset"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is an alternative name needed for this import declaration?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I found out that import "gwi/models/asset" works as well.

Comment on lines +5 to +6
asset_model "gwi/models/asset"
favorite_model "gwi/models/favorite"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Don't you find your package structure over-granular? Could you point out a main principle it’s meant to support and how this granularity impacts it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My main goal is the separation of concerns: each package should be responsible of one thing and as much decoupled as possible.
This granularity adds too much noise and it's an overkill for such a small app, but I wanted to demonstrate a more generic approach.

Comment thread models/asset/asset.go
@@ -0,0 +1,10 @@
package asset_model

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What would you change if this had to grew to, let's say, 20 models?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would add a base struct.

@stevenoddity stevenoddity left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hello Dimitris,
Thanks a lot for your time!
I answered your questions and looking forward for a follow-up.

Comment thread main.go
func main() {
router := routes.RegisterRoutes()
fmt.Println("🚀 Server running on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", middleware.RecoverMiddleware(router)))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

if it fails, the program cannot recover, so that's why I chose it.

Comment on lines +21 to +22
defer func() {
if err := recover(); err != nil {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In general no, as it "hides" the issue.

Comment thread models/asset/asset.go
@@ -0,0 +1,10 @@
package asset_model

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would add a base struct.

Comment thread models/asset/asset.go
type Asset struct {
ID int `json:"id"` // Unique identifier for the asset
UserID int `json:"user_id"` // Identifier for the user who owns the asset
Description json.RawMessage `json:"description"` // Description of the asset

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It hides the structure of description and it makes quering difficult with slow performance. A better approach would be to define a separate structure from the description.

@@ -0,0 +1,11 @@
package favorite_model

import asset_model "gwi/models/asset"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I found out that import "gwi/models/asset" works as well.

Comment on lines +5 to +6
asset_model "gwi/models/asset"
favorite_model "gwi/models/favorite"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My main goal is the separation of concerns: each package should be responsible of one thing and as much decoupled as possible.
This granularity adds too much noise and it's an overkill for such a small app, but I wanted to demonstrate a more generic approach.


// GetUsers handles the HTTP request to retrieve a list of users.
func GetUsers(w http.ResponseWriter, r *http.Request) {
// This function currently does not implement any logic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These were just placeholders for enhancements that I didn't implement.

Comment thread utils/input_validators.go

// ValidateFavorite validates the given Favorite struct.
// It returns an error if the validation fails, otherwise it returns nil.
func ValidateFavorite(fav *favorite_model.Favorite) error {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nope, I didn't utilize it at the end.

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