feat (user): adjust for auth, hide pass

This commit is contained in:
dpurbosakti
2025-08-19 14:26:19 +07:00
parent 0c5aa0becf
commit f80cba1cf5
20 changed files with 305 additions and 35 deletions

No files matched your search

+3 -3
View File
@@ -7,9 +7,9 @@ import (
)
type Base struct {
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamptz"`
UpdatedAt string `json:"updatedAt" gorm:"type:timestamptz"`
DeteledAt gorm.DeletedAt `json:"deletedAt,omitempty"`
CreatedAt time.Time `json:"createdAt" gorm:"column:CreatedAt;type:timestamptz"`
UpdatedAt time.Time `json:"updatedAt" gorm:"column:UpdatedAt;type:timestamptz"`
DeletedAt gorm.DeletedAt `json:"deletedAt,omitempty" gorm:"column:DeletedAt"`
}
type Main struct {
+42 -3
View File
@@ -1,6 +1,10 @@
package user
import erc "simrs-vx/internal/domain/references/common"
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erc "simrs-vx/internal/domain/references/common"
"time"
)
type CreateDto struct {
Name string `json:"name"`
@@ -22,12 +26,12 @@ type ReadDetailDto struct {
Name string `json:"name"`
}
type Updatedto struct {
type UpdateDto struct {
Id uint `json:"id"`
CreateDto
}
type Deletedto struct {
type DeleteDto struct {
Id uint `json:"id"`
}
@@ -36,3 +40,38 @@ type MetaDto struct {
PageSize int `json:"page_size"`
Count int `json:"count"`
}
type LoginDto struct {
Name string `json:"name" validate:"required"`
Password string `json:"password" validate:"required"`
Duration uint32 `json:"duration"` // in minutes
}
type ResponseDto struct {
ecore.Main
Name string `json:"name"`
Status_Code erc.StatusCode `json:"status_code"`
FailedLoginCount uint8 `json:"failedLoginCount"`
LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"`
LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"`
}
func (u User) ToResponse() ResponseDto {
resp := ResponseDto{
Name: u.Name,
Status_Code: u.Status_Code,
FailedLoginCount: u.FailedLoginCount,
LastSuccessLogin: u.LastSuccessLogin,
LastAllowdLogin: u.LastAllowdLogin,
}
resp.Main = u.Main
return resp
}
func ToResponseList(users []User) []ResponseDto {
resp := make([]ResponseDto, len(users))
for i, u := range users {
resp[i] = u.ToResponse()
}
return resp
}
+9 -5
View File
@@ -3,12 +3,16 @@ package user
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erc "simrs-vx/internal/domain/references/common"
"time"
)
type User struct {
ecore.Main // adjust this according to the needs
Name string `json:"name" gorm:"not null;size:25"`
Password string `json:"password" gorm:"not null;size:255"`
Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"`
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
ecore.Main // adjust this according to the needs
Name string `json:"name" gorm:"not null;size:25"`
Password string `json:"password" gorm:"not null;size:255"`
Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"`
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
LoginAttemptCount int `json:"-"`
LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"`
LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"`
}
+4 -2
View File
@@ -35,6 +35,8 @@ const (
)
const (
SCActive StatusCode = "active"
SCInactive StatusCode = "inactive"
SCNew StatusCode = "new"
SCActive StatusCode = "active"
SCBlocked StatusCode = "blocked"
SCSuspended StatusCode = "suspended"
)