Skip to content

Commit 31d3b66

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

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

dto/user_dto.go

Lines changed: 1 addition & 1 deletion
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
}

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/post_service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (s *postService) CreatePost(ctx context.Context, userId string, req dto.Pos
6464
User: dto.UserResponse{
6565
ID: user.ID.String(),
6666
Name: user.Name,
67-
Bio: user.Bio,
67+
Bio: *user.Bio,
6868
UserName: user.Username,
6969
ImageUrl: user.ImageUrl,
7070
},
@@ -91,7 +91,7 @@ func (s *postService) GetPostById(ctx context.Context, postId uint64) (dto.PostR
9191
User: dto.UserResponse{
9292
ID: reply.UserID.String(),
9393
Name: reply.User.Name,
94-
Bio: reply.User.Bio,
94+
Bio: *reply.User.Bio,
9595
UserName: reply.User.Username,
9696
ImageUrl: reply.User.ImageUrl,
9797
},
@@ -108,7 +108,7 @@ func (s *postService) GetPostById(ctx context.Context, postId uint64) (dto.PostR
108108
User: dto.UserResponse{
109109
ID: post.UserID.String(),
110110
Name: post.User.Name,
111-
Bio: post.User.Bio,
111+
Bio: *post.User.Bio,
112112
UserName: post.User.Username,
113113
ImageUrl: post.User.ImageUrl,
114114
},
@@ -160,7 +160,7 @@ func (s *postService) UpdatePostById(ctx context.Context, userId string, postId
160160
User: dto.UserResponse{
161161
ID: result.UserID.String(),
162162
Name: result.User.Name,
163-
Bio: result.User.Bio,
163+
Bio: *result.User.Bio,
164164
UserName: result.User.Username,
165165
ImageUrl: result.User.ImageUrl,
166166
},
@@ -182,7 +182,7 @@ func (s *postService) GetAllPosts(ctx context.Context, req dto.PaginationRequest
182182
User: dto.UserResponse{
183183
ID: post.UserID.String(),
184184
Name: post.User.Name,
185-
Bio: post.User.Bio,
185+
Bio: *post.User.Bio,
186186
UserName: post.User.Username,
187187
ImageUrl: post.User.ImageUrl,
188188
},

service/user_service.go

Lines changed: 10 additions & 4 deletions
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

@@ -69,7 +75,7 @@ func (s *userService) Register(ctx context.Context, req dto.UserCreateRequest) (
6975
ID: userReg.ID.String(),
7076
Name: userReg.Name,
7177
UserName: userReg.Username,
72-
Bio: userReg.Bio,
78+
Bio: *userReg.Bio,
7379
ImageUrl: userReg.ImageUrl,
7480
}, nil
7581
}
@@ -84,7 +90,7 @@ func (s *userService) GetUserById(ctx context.Context, userId string) (dto.UserR
8490
ID: user.ID.String(),
8591
Name: user.Name,
8692
UserName: user.Username,
87-
Bio: user.Bio,
93+
Bio: *user.Bio,
8894
ImageUrl: user.ImageUrl,
8995
}, nil
9096
}
@@ -117,7 +123,7 @@ func (s *userService) GetUserByUsername(ctx context.Context, username string) (d
117123
ID: user.ID.String(),
118124
Name: user.Name,
119125
UserName: user.Username,
120-
Bio: user.Bio,
126+
Bio: *user.Bio,
121127
ImageUrl: user.ImageUrl,
122128
}, nil
123129
}

0 commit comments

Comments
 (0)