Skip to content

Commit

Permalink
fix: add current time as created date and remove date in get post fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
saiaunghlyanhtet committed Aug 28, 2024
1 parent 57a5592 commit 2ee37c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions pkg/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func GetAllPostsOverview(req events.APIGatewayProxyRequest, tableName string, dy

func GetPostById(req events.APIGatewayProxyRequest, tableName string, dynamoDBClient dynamodbiface.DynamoDBAPI) (*events.APIGatewayProxyResponse, error) {
id := req.PathParameters["id"]
createdDate := req.QueryStringParameters["createdDate"]
result, err := post.GetPostById(dynamoDBClient, tableName, id, createdDate)
result, err := post.GetPostById(dynamoDBClient, tableName, id)

if err != nil {
return apiResponse(http.StatusBadRequest, ErrorBody{
Expand Down
18 changes: 9 additions & 9 deletions pkg/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func CreatePost(dynamodbClient dynamodbiface.DynamoDBAPI, tableName string, req

// Generate a new UUID for the post ID
id := uuid.New().String()
createdDate := time.Now().Format("2006-01-02")
post.CreatedDate = createdDate
post.ID = id

// Marshal the post into a DynamoDB map
Expand Down Expand Up @@ -68,11 +70,12 @@ func GetAllPostsOverview(dynamodbClient dynamodbiface.DynamoDBAPI, tableName str
TableName: aws.String(tableName),
ProjectionExpression: aws.String("#id, #title, #author, #summary, #tags"),
ExpressionAttributeNames: map[string]*string{
"#id": aws.String("id"),
"#title": aws.String("title"),
"#author": aws.String("author"),
"#summary": aws.String("summary"),
"#tags": aws.String("tags"),
"#id": aws.String("id"),
"#title": aws.String("title"),
"#author": aws.String("author"),
"#summary": aws.String("summary"),
"#tags": aws.String("tags"),
"#createdDate": aws.String("createdDate"),
},
}

Expand Down Expand Up @@ -106,16 +109,13 @@ func InitializeS3SessionAndBucket(session *session.Session, name string) {
bucketName = name
}

func GetPostById(dynamodbClient dynamodbiface.DynamoDBAPI, tableName, id string, createdDate string) (*Post, error) {
func GetPostById(dynamodbClient dynamodbiface.DynamoDBAPI, tableName, id string) (*Post, error) {
input := &dynamodb.GetItemInput{
TableName: aws.String(tableName),
Key: map[string]*dynamodb.AttributeValue{
"id": {
S: aws.String(id),
},
"createdDate": {
S: aws.String(createdDate),
},
},
}

Expand Down

0 comments on commit 2ee37c5

Please sign in to comment.