-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: entity and repo for main models of auth service
- Loading branch information
Showing
43 changed files
with
672 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package entity | ||
|
||
import "github.com/jackc/pgx/v5" | ||
|
||
type Role struct { | ||
ID string | ||
Name string | ||
} | ||
|
||
func (r Role) TableName() string { | ||
return "roles" | ||
} | ||
|
||
func (r Role) AllFields() []string { | ||
return []string{"id", "name"} | ||
} | ||
|
||
func (r Role) InsertOrUpdateFields() []string { | ||
return []string{"name"} | ||
} | ||
|
||
func (r Role) EntityToInsertValues(impl *Role) []interface{} { | ||
return []interface{}{ | ||
impl.Name, | ||
} | ||
} | ||
|
||
func (r Role) ReadItem(row pgx.Row) (Role, error) { | ||
var role Role | ||
err := row.Scan(&role.ID, &role.Name) | ||
if err != nil { | ||
return Role{}, err | ||
} | ||
return role, nil | ||
} | ||
|
||
func (r Role) ReadList(rows pgx.Rows) ([]Role, error) { | ||
var roles []Role | ||
for rows.Next() { | ||
role, err := r.ReadItem(rows) | ||
if err != nil { | ||
return nil, err | ||
} | ||
roles = append(roles, role) | ||
} | ||
return roles, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package entity | ||
|
||
import ( | ||
"database/sql" | ||
"github.com/jackc/pgx/v5" | ||
"time" | ||
) | ||
|
||
type User struct { | ||
ID string | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
DeletedAt sql.Null[time.Time] | ||
|
||
LoggedAt sql.Null[time.Time] | ||
ConfirmedAt sql.Null[time.Time] | ||
|
||
Login string // index | ||
Email string // index | ||
|
||
PasswordHash string | ||
|
||
DeletedBy sql.Null[string] | ||
AccessTemplateID sql.Null[int] | ||
UpdateAfter sql.Null[int64] | ||
} | ||
|
||
func (u User) TableName() string { | ||
return "users" | ||
} | ||
|
||
func (u User) AllFields() []string { | ||
return []string{"id", "created_at", "updated_at", "deleted_at", "logged_at", "confirmed_at", "login", | ||
"email", "password_hash", "deleted_by", "access_template_id", "update_after"} | ||
} | ||
|
||
func (u User) InsertOrUpdateFields() []string { | ||
return []string{"logged_at", "confirmed_at", "login", "email", "password_hash", "deleted_by", | ||
"access_template_id", "update_after"} | ||
} | ||
|
||
func (u User) EntityToInsertValues(impl *User) []interface{} { | ||
return []interface{}{ | ||
impl.LoggedAt, impl.ConfirmedAt, impl.Login, impl.Email, impl.PasswordHash, impl.DeletedBy, | ||
impl.AccessTemplateID, impl.UpdateAfter, | ||
} | ||
} | ||
|
||
func (u User) ReadItem(row pgx.Row) (User, error) { | ||
var user User | ||
err := row.Scan(&user.ID, &user.CreatedAt, &user.UpdatedAt, &user.DeletedAt, &user.LoggedAt, &user.ConfirmedAt, | ||
&user.Login, &user.Email, &user.PasswordHash, &user.DeletedBy, &user.AccessTemplateID, &user.UpdateAfter) | ||
if err != nil { | ||
return User{}, err | ||
} | ||
return user, nil | ||
} | ||
|
||
func (u User) ReadList(rows pgx.Rows) ([]User, error) { | ||
var users []User | ||
for rows.Next() { | ||
user, err := u.ReadItem(rows) | ||
if err != nil { | ||
return nil, err | ||
} | ||
users = append(users, user) | ||
} | ||
return users, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package entity | ||
|
||
import "github.com/jackc/pgx/v5" | ||
|
||
type UserProfile struct { | ||
ID string | ||
UserID string | ||
FirstName string | ||
LastName string | ||
SecondName string | ||
Locale string | ||
Gender int | ||
Phone string | ||
Notes string | ||
} | ||
|
||
func (u UserProfile) TableName() string { | ||
return "user_profiles" | ||
} | ||
|
||
func (u UserProfile) AllFields() []string { | ||
return []string{"id", "user_id", "first_name", "last_name", "second_name", "locale", | ||
"gender", "phone", "notes"} | ||
} | ||
|
||
func (u UserProfile) InsertOrUpdateFields() []string { | ||
return []string{"user_id", "first_name", "last_name", "second_name", "locale", "gender", "phone", "notes"} | ||
} | ||
|
||
func (u UserProfile) EntityToInsertValues(impl *UserProfile) []interface{} { | ||
return []interface{}{ | ||
impl.UserID, impl.FirstName, impl.LastName, impl.SecondName, impl.Locale, impl.Gender, | ||
impl.Phone, impl.Notes} | ||
} | ||
|
||
func (u UserProfile) ReadItem(row pgx.Row) (UserProfile, error) { | ||
var userProfile UserProfile | ||
err := row.Scan(&userProfile.ID, &userProfile.UserID, &userProfile.FirstName, &userProfile.LastName, | ||
&userProfile.SecondName, &userProfile.Locale, &userProfile.Gender, &userProfile.Phone, &userProfile.Notes) | ||
|
||
if err != nil { | ||
return UserProfile{}, err | ||
} | ||
return userProfile, nil | ||
} | ||
|
||
func (u UserProfile) ReadList(rows pgx.Rows) ([]UserProfile, error) { | ||
var userProfiles []UserProfile | ||
for rows.Next() { | ||
userProfile, err := u.ReadItem(rows) | ||
if err != nil { | ||
return nil, err | ||
} | ||
userProfiles = append(userProfiles, userProfile) | ||
} | ||
return userProfiles, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package entity | ||
|
||
import ( | ||
"github.com/jackc/pgx/v5" | ||
"time" | ||
) | ||
|
||
type UserRole struct { | ||
ID string | ||
UserID string | ||
RoleID string | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
} | ||
|
||
func (ur UserRole) TableName() string { | ||
return "user_roles" | ||
} | ||
|
||
func (ur UserRole) AllFields() []string { | ||
return []string{"id", "user_id", "role_id", "created_at", "updated_at"} | ||
} | ||
|
||
func (ur UserRole) InsertOrUpdateFields() []string { | ||
return []string{"user_id", "role_id", "created_at", "updated_at"} | ||
} | ||
|
||
func (ur UserRole) EntityToInsertValues(impl *UserRole) []interface{} { | ||
return []interface{}{ | ||
impl.UserID, impl.RoleID, impl.CreatedAt, impl.UpdatedAt, | ||
} | ||
} | ||
|
||
func (ur UserRole) ReadItem(row pgx.Row) (UserRole, error) { | ||
var userRole UserRole | ||
err := row.Scan(&userRole.ID, &userRole.UserID, &userRole.RoleID, &userRole.CreatedAt, &userRole.UpdatedAt) | ||
if err != nil { | ||
return UserRole{}, err | ||
} | ||
return userRole, nil | ||
} | ||
|
||
func (ur UserRole) ReadList(rows pgx.Rows) ([]UserRole, error) { | ||
var userRoles []UserRole | ||
for rows.Next() { | ||
userRole, err := ur.ReadItem(rows) | ||
if err != nil { | ||
return nil, err | ||
} | ||
userRoles = append(userRoles, userRole) | ||
} | ||
return userRoles, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package entity | ||
|
||
import ( | ||
"github.com/jackc/pgx/v5" | ||
"time" | ||
) | ||
|
||
type UserToken struct { | ||
ID string | ||
UserID string | ||
Token string | ||
Context string | ||
SentTo string | ||
InsertedAt time.Time | ||
} | ||
|
||
func (ut UserToken) TableName() string { | ||
return "user_tokens" | ||
} | ||
|
||
func (ut UserToken) AllFields() []string { | ||
return []string{"id", "user_id", "token", "context", "sent_to", "inserted_at"} | ||
} | ||
|
||
func (ut UserToken) InsertOrUpdateFields() []string { | ||
return []string{"user_id", "token", "context", "sent_to", "inserted_at"} | ||
} | ||
|
||
func (ut UserToken) EntityToInsertValues(impl *UserToken) []interface{} { | ||
return []interface{}{ | ||
impl.UserID, impl.Token, impl.Context, impl.SentTo, impl.InsertedAt, | ||
} | ||
} | ||
|
||
func (ut UserToken) ReadItem(row pgx.Row) (UserToken, error) { | ||
var userToken UserToken | ||
err := row.Scan(&userToken.ID, &userToken.UserID, &userToken.Token, &userToken.Context, &userToken.SentTo, &userToken.InsertedAt) | ||
if err != nil { | ||
return UserToken{}, err | ||
} | ||
return userToken, nil | ||
} | ||
|
||
func (ut UserToken) ReadList(rows pgx.Rows) ([]UserToken, error) { | ||
var userTokens []UserToken | ||
for rows.Next() { | ||
userToken, err := ut.ReadItem(rows) | ||
if err != nil { | ||
return nil, err | ||
} | ||
userTokens = append(userTokens, userToken) | ||
} | ||
return userTokens, nil | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
auth/internal/infrastructure/repository/pgrepo/role_repo.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package pgrepo | ||
|
||
import ( | ||
"github.com/SShlykov/zeitment/auth/internal/domain/entity" | ||
"github.com/SShlykov/zeitment/postgres" | ||
) | ||
|
||
type RolesRepo interface { | ||
Repository[entity.Role] | ||
} | ||
|
||
type rolesRepo struct { | ||
repository[entity.Role] | ||
} | ||
|
||
func NewRolesRepository(db postgres.Client) RolesRepo { | ||
return &rolesRepo{ | ||
repository: repository[entity.Role]{ | ||
Name: "RolesRepository", | ||
entity: entity.Role{}, | ||
db: db, | ||
}, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
auth/internal/infrastructure/repository/pgrepo/user_profile_repo.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package pgrepo | ||
|
||
import ( | ||
"github.com/SShlykov/zeitment/auth/internal/domain/entity" | ||
"github.com/SShlykov/zeitment/postgres" | ||
) | ||
|
||
type UserProfileRepo interface { | ||
Repository[entity.UserProfile] | ||
} | ||
|
||
type userProfilesRepo struct { | ||
repository[entity.UserProfile] | ||
} | ||
|
||
func NewUserProfilesRepository(db postgres.Client) UserProfileRepo { | ||
return &userProfilesRepo{ | ||
repository: repository[entity.UserProfile]{ | ||
Name: "UserProfileRepository", | ||
entity: entity.UserProfile{}, | ||
db: db, | ||
}, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
auth/internal/infrastructure/repository/pgrepo/user_repo.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package pgrepo | ||
|
||
import ( | ||
"github.com/SShlykov/zeitment/auth/internal/domain/entity" | ||
"github.com/SShlykov/zeitment/postgres" | ||
) | ||
|
||
type UsersRepo interface { | ||
Repository[entity.User] | ||
} | ||
|
||
type usersRepo struct { | ||
repository[entity.User] | ||
} | ||
|
||
func NewUsersRepository(db postgres.Client) UsersRepo { | ||
return &usersRepo{ | ||
repository: repository[entity.User]{ | ||
Name: "UsersRepository", | ||
entity: entity.User{}, | ||
db: db, | ||
}, | ||
} | ||
} |
Oops, something went wrong.