changes...

This commit is contained in:
KamilM1205 2025-09-22 22:12:49 +04:00
parent 41944884b4
commit ab4b53fd40
26 changed files with 600 additions and 51 deletions

View file

@ -0,0 +1,15 @@
package errors
type DBError struct {
msg string
}
func NewDBError(msg string) DBError {
return DBError{
msg: msg,
}
}
func (e *DBError) Error() string {
return e.msg
}

View file

@ -0,0 +1,15 @@
package errors
type NotFoundError struct {
msg string
}
func NewNotFoundError(msg string) *NotFoundError {
return &NotFoundError{
msg: msg,
}
}
func (e *NotFoundError) Error() string {
return e.msg
}

View file

@ -3,6 +3,7 @@ package services
import (
"58team_blog/internal/application/commands"
"58team_blog/internal/application/common"
ie "58team_blog/internal/application/errors"
"58team_blog/internal/application/mapper"
"58team_blog/internal/application/queries"
"58team_blog/internal/domain/entities"
@ -44,6 +45,10 @@ func (s *PostService) FindById(query queries.PostFindByIdQuery) (*queries.PostFi
return nil, err
}
if post == nil {
return nil, ie.NewNotFoundError("Post")
}
if err := post.Validate(); err != nil {
return nil, err
}

View file

@ -15,7 +15,7 @@ type UserService struct {
repo repository.UsersRepository
}
func NewUserService(repo repository.UsersRepository) UserService {
func CreateUserService(repo repository.UsersRepository) UserService {
return UserService{
repo: repo,
}
@ -26,7 +26,7 @@ func (s *UserService) Create(cmd commands.CreateUserCommand) (*common.UserResult
{
user, err := s.repo.FindByName(cmd.Username)
if err != nil {
return nil, err
return nil, fmt.Errorf("User.create findByName error: %s", err)
}
if user != nil {