Skip to content

Commit 186286a

Browse files
committed
fix: remove required binding from bio field in UserCreateRequest
1 parent ae1a4d6 commit 186286a

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

dto/user_dto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type (
3535
UserCreateRequest struct {
3636
Name string `json:"name" form:"name" binding:"required"`
3737
UserName string `json:"username" form:"username" binding:"required"`
38-
Bio string `json:"bio" form:"bio" binding:"required"`
38+
Bio string `json:"bio" form:"bio"`
3939
Image *multipart.FileHeader `json:"image" form:"image"`
4040
Password string `json:"password" form:"password" binding:"required"`
4141
}
@@ -44,7 +44,7 @@ type (
4444
ID string `json:"id"`
4545
Name string `json:"name"`
4646
UserName string `json:"username"`
47-
Bio string `json:"bio"`
47+
Bio *string `json:"bio"`
4848
ImageUrl *string `json:"image_url"`
4949
}
5050

entity/user_entity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type User struct {
1010
ID uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"`
1111
Name string `gorm:"not null" json:"name"`
1212
Username string `gorm:"not null" gorm:"unique" json:"username"`
13-
Bio string `gorm:"not null" json:"bio"`
13+
Bio *string `json:"bio"`
1414
Password string `gorm:"not null" json:"password"`
1515
ImageUrl *string `json:"image_url"`
1616

service/user_service.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ func (s *userService) Register(ctx context.Context, req dto.UserCreateRequest) (
5252
filenamePtr = &filename
5353
}
5454

55+
var bioPtr *string
56+
if req.Bio != "" {
57+
bio := req.Bio
58+
bioPtr = &bio
59+
}
60+
5561
user := entity.User{
5662
Name: req.Name,
5763
Username: req.UserName,
5864
ImageUrl: filenamePtr,
59-
Bio: req.Bio,
65+
Bio: bioPtr,
6066
Password: req.Password,
6167
}
6268

0 commit comments

Comments
 (0)