Skip to content

Commit

Permalink
Complete function Todo
Browse files Browse the repository at this point in the history
  • Loading branch information
letienlocvn committed Nov 14, 2024
1 parent c512a82 commit 3c85e1d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
30 changes: 23 additions & 7 deletions starter/backend/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ provider:
environment:
TODOS_TABLE: todos-${self:provider.stage}
TODOS_CREATED_AT_INDEX: CreateAtIndex
ATTACHMENT_S3_BUCKET: todo-images-${self:provider.stage}
TODOS_S3_BUCKET: todo-s3-${self:provider.stage}
PROJECT_NAME: todo-app
SIGNED_URL_EXPIRATION: 300
Expand All @@ -33,12 +32,16 @@ functions:
events:
- http:
method: get
authorizer: Auth
path: todos
cors: true
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.TODOS_TABLE}
- dynamodb:Query
Resource:
- arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.TODOS_TABLE}
- arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.TODOS_TABLE}/index/${self:provider.environment.TODOS_CREATED_AT_INDEX}
- Effect: Allow
Action:
- 'xray:PutTraceSegments'
Expand Down Expand Up @@ -71,12 +74,17 @@ functions:
handler: src/lambda/http/updateTodo.handler
events:
- http:
authorizer: Auth
method: patch
cors: true
path: todos/{todoId}
request:
schemas:
application/json: ${file(models/update-todo-request.json)}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.TODOS_TABLE}
- Effect: Allow
Action:
Expand All @@ -88,13 +96,19 @@ functions:
handler: src/lambda/http/deleteTodo.handler
events:
- http:
authorizer: Auth
method: delete
cors: true
path: todos/{todoId}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:DeleteItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.TODOS_TABLE}
- Effect: Allow
Action:
- s3:DeleteObject
Resource: arn:aws:s3:::${self:provider.environment.TODOS_S3_BUCKET}/*
- Effect: Allow
Action:
- 'xray:PutTraceSegments'
Expand All @@ -105,13 +119,15 @@ functions:
handler: src/lambda/http/generateUploadUrl.handler
events:
- http:
authorizer: Auth
method: post
cors: true
path: todos/{todoId}/attachment
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.TODOS_TABLE}
- s3:PutObject
Resource: arn:aws:s3:::${self:provider.environment.TODOS_S3_BUCKET}/*
- Effect: Allow
Action:
- 'xray:PutTraceSegments'
Expand Down
1 change: 1 addition & 0 deletions starter/backend/src/dataLayer/todoAccess.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class TodosAccess {
':userId': userId
}
})
console.log("Called getListOfTodo: ", tableTodos.Items);
return tableTodos.Items
}
}
2 changes: 1 addition & 1 deletion starter/client/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REACT_APP_AUTH0_DOMAIN=dev-letienlocvn.us.auth0.com
REACT_APP_AUTH0_CLIENT_ID=1H7JKQ6xREdMhjL4MFYMmPagdV8ncFIg
REACT_APP_API_ENDPOINT=https://urax6i4r99.execute-api.us-east-1.amazonaws.com/dev/todos
REACT_APP_API_ENDPOINT=https://urax6i4r99.execute-api.us-east-1.amazonaws.com/dev
3 changes: 2 additions & 1 deletion starter/client/src/api/todos-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Axios from 'axios'

export async function getTodos(idToken) {
console.log('Fetching todos')

console.log('getTodos token', idToken);

const response = await Axios.get(
`${process.env.REACT_APP_API_ENDPOINT}/todos`,
{
Expand Down
4 changes: 2 additions & 2 deletions starter/client/src/components/Todos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function Todos() {
async function onTodoDelete(todoId) {
try {
const accessToken = await getAccessTokenSilently({
audience: `https://test-endpoint.auth0.com/api/v2/`,
audience: `https://${domain}/api/v2/`,
scope: 'delete:todo'
})
await deleteTodo(accessToken, todoId)
Expand All @@ -92,7 +92,7 @@ export function Todos() {
try {
const todo = todos[pos]
const accessToken = await getAccessTokenSilently({
audience: `https://test-endpoint.auth0.com/api/v2/`,
audience: `https://${domain}/api/v2/`,
scope: 'write:todo'
})
await patchTodo(accessToken, todo.todoId, {
Expand Down

0 comments on commit 3c85e1d

Please sign in to comment.