diff --git a/authorizationapp/app.go b/authorizationapp/app.go index aed312ff..08208eec 100644 --- a/authorizationapp/app.go +++ b/authorizationapp/app.go @@ -18,7 +18,7 @@ type Config struct { MySQLDB mySql.Config `koanf:"mariadb"` } type Application struct { - RoleRepo *repository.DB + RoleRepo *repository.RoleRepo AuthorizationService service.Authorization RoleHandler http.RoleHandler RoleServer http.RoleServer @@ -40,6 +40,10 @@ func (a Application) Setup() Application { } } +func (a Application) Start() { + // todo implement role service start +} + func (a Application) getYamlConfigPath() Config { var appConfig Config diff --git a/authorizationapp/delivery/http/handler.go b/authorizationapp/delivery/http/handler.go index d4cdc2a1..7a6c7ceb 100644 --- a/authorizationapp/delivery/http/handler.go +++ b/authorizationapp/delivery/http/handler.go @@ -17,8 +17,8 @@ func NewRoleHandler(service service.Authorization) RoleHandler { func (r RoleHandler) Store(c *gin.Context) { var request service.StoreRoleRequest - err := c.ShouldBindJSON(&request) + err := c.ShouldBindJSON(&request) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return diff --git a/domain/authorization/repository/mysql_repo.go b/domain/authorization/repository/mysql_repo.go index 4c97e821..ef446e0b 100644 --- a/domain/authorization/repository/mysql_repo.go +++ b/domain/authorization/repository/mysql_repo.go @@ -9,15 +9,15 @@ import ( "git.gocasts.ir/ebhomengo/niki/types" ) -type DB struct { +type RoleRepo struct { conn *mysql.DB } -func New(conn *mysql.DB) *DB { - return &DB{conn: conn} +func New(conn *mysql.DB) *RoleRepo { + return &RoleRepo{conn: conn} } -func (m DB) Store(ctx context.Context, req service.StoreRoleRequest) (types.ID, error) { +func (m RoleRepo) Store(ctx context.Context, req service.StoreRoleRequest) (types.ID, error) { const op = "domain.authorization.repository.role.store" result, err := m.conn.Conn().ExecContext(ctx, "INSERT INTO roles VALUES (`?,?`)", req.Title, req.TitleFa) diff --git a/domain/authorization/service/authorization.go b/domain/authorization/service/authorization.go index 8a877713..90bff27d 100644 --- a/domain/authorization/service/authorization.go +++ b/domain/authorization/service/authorization.go @@ -19,7 +19,7 @@ func NewAuthorization(roleRepo RoleRepo) Authorization { func (a Authorization) Store(ctx context.Context, req StoreRoleRequest) (entity.Role, error) { const op = "authorizationservice.Store" - if err := a.validateRole(req); err != nil { + if err := a.validateStoreRole(req); err != nil { return entity.Role{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } @@ -27,10 +27,14 @@ func (a Authorization) Store(ctx context.Context, req StoreRoleRequest) (entity. if err != nil { return entity.Role{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) } - return role, nil + return entity.Role{ + ID: role, + Title_fa: req.TitleFa, + Title: req.Title, + }, nil } -func (s Authorization) validateRole(req StoreRoleRequest) error { +func (s Authorization) validateStoreRole(req StoreRoleRequest) error { return validation.ValidateStruct(&req, validation.Field(&req.Title, validation.Required, diff --git a/domain/authorization/service/param.go b/domain/authorization/service/param.go index 179c4ea4..afdde9bb 100644 --- a/domain/authorization/service/param.go +++ b/domain/authorization/service/param.go @@ -1,6 +1,6 @@ package service -type StoreRoleRequest struct { +type RoleRequest struct { Title string `json:"title"` TitleFa string `json:"title_fa"` }