Skip to content

Commit

Permalink
#45 update query for get detail and update request parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
setiadijoe committed Jun 2, 2021
1 parent ce582af commit b9c96dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions model/usecase_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ type GetListRequest struct {
}

type CreateNewPostRequest struct {
Title string
ImagePathURL string
Images string
Tags *string
Status int64
Title string `json:"title"`
ImagePathURL string `json:"image_path_url"`
Images string `json:"images"`
Tags *string `json:"tags,omitempty"`
Status int64 `json:"status"`
}

type UpdatePostRequest struct {
ID int64
Status *int64
Title *string
ID int64 `json:"id"`
Status *int64 `json:"status,omitempty"`
Title *string `json:"title,omitempty"`
}

type CreateCommentRequest struct {
UserPostID int64
Text string
UserPostID int64 `json:"user_post_id"`
Text string `json:"comment"`
}

type ActorFromContext struct {
Expand Down
6 changes: 3 additions & 3 deletions repository/mysql/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func (r *Comment) GetCommentsByPostID(ctx context.Context, id int64) ([]*model.C
var result = make([]*model.CommentResponse, 0)
var err error

query.WriteString("SELECT id, user_post_id, `text` as comment, status, created_by, updated_by, FROM_UNIXTIME(created_at) as created_at, FROM_UNIXTIME(updated_at) as updated_at FROM user_post_comments")
query.WriteString("SELECT id, user_post_id, `text` as comment, status, created_by, updated_by, FROM_UNIXTIME(created_at) as created_at, FROM_UNIXTIME(updated_at) as updated_at FROM user_post_comments ")
query.WriteString("WHERE user_post_id = ?")

if ctx != nil {
err = r.conn.SelectContext(ctx, result, query.String(), id)
err = r.conn.SelectContext(ctx, &result, query.String(), id)
} else {
err = r.conn.Select(result, query.String(), id)
err = r.conn.Select(&result, query.String(), id)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion repository/mysql/userpost.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *UserPost) GetListPost(ctx context.Context, request *model.UserPostReque
query.WriteString("SELECT id, text, tags, image_path, images, last_user_post_comment_id, likes_count, comments_count, status, created_by, updated_by, FROM_UNIXTIME(created_at) as created_at, FROM_UNIXTIME(updated_at) as updated_at FROM user_posts")
query, params := querySelectParams(ctx, query, request)
if request.Limit != nil && request.Offset != nil {
query.WriteString("LIMIT ?, ?")
query.WriteString(" LIMIT ?, ?")
params = append(params, request.Offset, request.Limit)
}
if request.OrderBy != nil && request.SortBy != nil {
Expand Down

0 comments on commit b9c96dd

Please sign in to comment.