Skip to content

setup - #1

Open
hamid-JTG wants to merge 20 commits into
mainfrom
setup
Open

hamid-JTG wants to merge 20 commits into
mainfrom
setup

Conversation

@hamid-JTG

Copy link
Copy Markdown
Owner

No description provided.

Comment thread main.go
Comment thread go.mod Outdated
Comment thread api/controllers/users.go Outdated
@@ -0,0 +1,16 @@
package controllers

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

have a look at folder structure it is neither layered nor modular

Comment thread internal/models/users/user.go Outdated
Comment thread internal/models/users/user.go Outdated
)

type User struct {
ID uint `gorm:"primarykey"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Explore other alternatives of ID other than unit and check which is to use here

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also what about created at deleted at check how gorm use them

Comment thread internal/models/users/user.go Outdated
Comment on lines +24 to +28
Email string `json:"email" gorm:"unique; not null"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
DateOfBirth time.Time `json:"date_of_birth"`
Gender Gender `json:"gender"`

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 the json tag required?

Comment thread internal/models/users/user.go Outdated
Comment thread db/migrations/0001_create_user_table.go Outdated
if err != nil {
return err
}
return db.Migrator().CreateTable(&users.User{})

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 it the correct approach to use the same model. What if a new field add in the model in future?

Comment thread config/config.go Outdated
Comment on lines +30 to +37
DBHost: viper.GetString("DB_HOST"),
DBPort: viper.GetInt("DB_PORT"),
DBUser: viper.GetString("DB_USER"),
DBPassword: viper.GetString("DB_PASSWORD"),
DBName: viper.GetString("DB_NAME"),
DBSSLMode: viper.GetString("DB_SSL"),
ServerPort: viper.GetString("SERVER_PORT"),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

create a constant file for these

Comment thread db/migrations/0004_alter_enums.go Outdated
Comment on lines +16 to +23
_, err := tx.Exec(`
ALTER TABLE users
DROP COLUMN gender,
DROP COLUMN marital_status;

ALTER TABLE users
ADD COLUMN gender gender,
ADD COLUMN marital_status marital_status;

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 this?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

in db, type of gender and marital_status columns were saved as text, i wanted to make it enum.

Comment thread Makefile
Comment thread config/config.go
var AppConfig Config

func LoadConfig() {
viper.SetConfigFile(".env")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

create a env template file

Comment thread internal/models/users/officeDetails.go Outdated

type OfficeDetail struct {
ID uint `gorm:"primarykey"`
UserID uint `json:"user_id" gorm:"not null;index"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you are not making foreign key relationship

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