Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions app/go/e2e/E2E_postman_tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"info": {
"name": "Fender development Exercise",
"description": "E2E test Postman",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create subscription",
"request": {
"method": "POST",
"header": [
{
"key": "x-api-key",
"value": "{{apiKey}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"url": {
"raw": "{{base}}/api/v1/webhooks/subscriptions",
"host": [
"{{base}}"
],
"path": [
"api",
"v1",
"webhooks",
"subscriptions"
]
},
"body": {
"mode": "raw",
"raw": "{\"eventId\": \"evt_123456789\", \"eventType\": \"subscription.created\", \"timestamp\": \"2024-03-20T10:00:00Z\", \"provider\": \"STRIPE\", \"subscriptionId\": \"sub_456789\", \"paymentId\": \"pm_123456\", \"userId\": \"123\", \"customerId\": \"cus_789012\", \"expiresAt\": \"2024-04-20T10:00:00Z\", \"metadata\": {\"planSku\": \"PREMIUM_MONTHLY\", \"autoRenew\": true, \"paymentMethod\": \"CREDIT_CARD\"}}"
}
}
},
{
"name": "Get subscription (after create)",
"request": {
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{apiKey}}"
}
],
"url": {
"raw": "{{base}}/api/v1/subscriptions/123",
"host": [
"{{base}}"
],
"path": [
"api",
"v1",
"subscriptions",
"123"
]
}
}
},
{
"name": "Renew subscription",
"request": {
"method": "POST",
"header": [
{
"key": "x-api-key",
"value": "{{apiKey}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"url": {
"raw": "{{base}}/api/v1/webhooks/subscriptions",
"host": [
"{{base}}"
],
"path": [
"api",
"v1",
"webhooks",
"subscriptions"
]
},
"body": {
"mode": "raw",
"raw": "{\"eventId\": \"evt_123456789\", \"eventType\": \"subscription.renewed\", \"timestamp\": \"2024-04-20T10:00:00Z\", \"provider\": \"STRIPE\", \"subscriptionId\": \"sub_456789\", \"paymentId\": \"pm_122334\", \"userId\": \"123\", \"customerId\": \"cus_789012\", \"expiresAt\": \"2024-05-20T10:00:00Z\", \"metadata\": {\"planSku\": \"PREMIUM_MONTHLY\", \"autoRenew\": true, \"paymentMethod\": \"CREDIT_CARD\"}}"
}
}
},
{
"name": "Get subscription (after renew)",
"request": {
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{apiKey}}"
}
],
"url": {
"raw": "{{base}}/api/v1/subscriptions/123",
"host": [
"{{base}}"
],
"path": [
"api",
"v1",
"subscriptions",
"123"
]
}
}
},
{
"name": "Cancel subscription",
"request": {
"method": "POST",
"header": [
{
"key": "x-api-key",
"value": "{{apiKey}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"url": {
"raw": "{{base}}/api/v1/webhooks/subscriptions",
"host": [
"{{base}}"
],
"path": [
"api",
"v1",
"webhooks",
"subscriptions"
]
},
"body": {
"mode": "raw",
"raw": "{\"eventId\": \"evt_456789123\", \"eventType\": \"subscription.cancelled\", \"timestamp\": \"2024-05-20T10:00:00Z\", \"provider\": \"STRIPE\", \"subscriptionId\": \"sub_456789\", \"paymentId\": null, \"userId\": \"123\", \"customerId\": \"cus_789012\", \"expiresAt\": \"2024-05-20T10:00:00Z\", \"cancelledAt\": \"2024-05-20T10:00:00Z\", \"metadata\": {\"planSku\": \"PREMIUM_MONTHLY\", \"autoRenew\": false, \"paymentMethod\": \"CREDIT_CARD\", \"cancelReason\": \"USER_REQUESTED\"}}"
}
}
},
{
"name": "Get subscription (after cancel)",
"request": {
"method": "GET",
"header": [
{
"key": "x-api-key",
"value": "{{apiKey}}"
}
],
"url": {
"raw": "{{base}}/api/v1/subscriptions/123",
"host": [
"{{base}}"
],
"path": [
"api",
"v1",
"subscriptions",
"123"
]
}
}
}
]
}
24 changes: 23 additions & 1 deletion app/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,26 @@ module github.com/fenderdigital/fds-aws-coding-exercise

go 1.24.5

require github.com/aws/aws-lambda-go v1.49.0
require (
github.com/aws/aws-lambda-go v1.49.0
github.com/aws/aws-sdk-go-v2 v1.39.3
github.com/aws/aws-sdk-go-v2/config v1.31.14
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.17
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.52.1
)

require (
github.com/aws/aws-sdk-go-v2/credentials v1.18.18 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.31.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.10 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.29.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.38.8 // indirect
github.com/aws/smithy-go v1.23.1 // indirect
)
34 changes: 34 additions & 0 deletions app/go/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
github.com/aws/aws-lambda-go v1.49.0 h1:z4VhTqkFZPM3xpEtTqWqRqsRH4TZBMJqTkRiBPYLqIQ=
github.com/aws/aws-lambda-go v1.49.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
github.com/aws/aws-sdk-go-v2 v1.39.3 h1:h7xSsanJ4EQJXG5iuW4UqgP7qBopLpj84mpkNx3wPjM=
github.com/aws/aws-sdk-go-v2 v1.39.3/go.mod h1:yWSxrnioGUZ4WVv9TgMrNUeLV3PFESn/v+6T/Su8gnM=
github.com/aws/aws-sdk-go-v2/config v1.31.14 h1:kj/KpDqvt0UqcEL3WOvCykE9QUpBb6b23hQdnXe+elo=
github.com/aws/aws-sdk-go-v2/config v1.31.14/go.mod h1:X5PaY6QCzViihn/ru7VxnIamcJQrG9NSeTxuSKm2YtU=
github.com/aws/aws-sdk-go-v2/credentials v1.18.18 h1:5AfxTvDN0AJoA7rg/yEc0sHhl6/B9fZ+NtiQuOjWGQM=
github.com/aws/aws-sdk-go-v2/credentials v1.18.18/go.mod h1:m9mE1mJ1s7zI6rrt7V3RQU2SCgUbNaphlfqEksLp+Fs=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.17 h1:IPznA4MUKCdHL28SZeuMhFxBSMTYZjm+lqLdQRKd6gM=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.20.17/go.mod h1:OFWH4SmyLk8MzTWhk3XaveS3cNyY7SU6UQDPviMIEbM=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10 h1:UuGVOX48oP4vgQ36oiKmW9RuSeT8jlgQgBFQD+HUiHY=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10/go.mod h1:vM/Ini41PzvudT4YkQyE/+WiQJiQ6jzeDyU8pQKwCac=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10 h1:mj/bdWleWEh81DtpdHKkw41IrS+r3uw1J/VQtbwYYp8=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10/go.mod h1:7+oEMxAZWP8gZCyjcm9VicI0M61Sx4DJtcGfKYv2yKQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10 h1:wh+/mn57yhUrFtLIxyFPh2RgxgQz/u+Yrf7hiHGHqKY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10/go.mod h1:7zirD+ryp5gitJJ2m1BBux56ai8RIRDykXZrJSp540w=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.52.1 h1:HWdbTAAa51HIg4jXyTtkHRU5ZF0n3+rNChldmveicDw=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.52.1/go.mod h1:GyNGZUbiqJH5lMAVNlYlYXCNoJcCmyPAeLxlDKsmi1g=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.31.2 h1:AVmNRz6Sjfwug8mA314XbCOETbotDO1PtwZGk5bTy3I=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.31.2/go.mod h1:IakOzjzwZN+7RAC1Hja1n0A466zBL9lx/I4KIDvJjUY=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 h1:xtuxji5CS0JknaXoACOunXOYOQzgfTvGAc9s2QdCJA4=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2/go.mod h1:zxwi0DIR0rcRcgdbl7E2MSOvxDyyXGBlScvBkARFaLQ=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.10 h1:T0QsDQNCVealR4CrVt+spgWJgjl8oIDje/5TH8YnCmE=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.11.10/go.mod h1:SGBJMtnGk4y9Yvrr3iNPos9WUqexJHxq2OI6Z1ch634=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10 h1:DRND0dkCKtJzCj4Xl4OpVbXZgfttY5q712H9Zj7qc/0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10/go.mod h1:tGGNmJKOTernmR2+VJ0fCzQRurcPZj9ut60Zu5Fi6us=
github.com/aws/aws-sdk-go-v2/service/sso v1.29.7 h1:fspVFg6qMx0svs40YgRmE7LZXh9VRZvTT35PfdQR6FM=
github.com/aws/aws-sdk-go-v2/service/sso v1.29.7/go.mod h1:BQTKL3uMECaLaUV3Zc2L4Qybv8C6BIXjuu1dOPyxTQs=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2 h1:scVnW+NLXasGOhy7HhkdT9AGb6kjgW7fJ5xYkUaqHs0=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2/go.mod h1:FRNCY3zTEWZXBKm2h5UBUPvCVDOecTad9KhynDyGBc0=
github.com/aws/aws-sdk-go-v2/service/sts v1.38.8 h1:xSL4IV19pKDASL2fjWXRfTGmZddPiPPZNPpbv6uZQZY=
github.com/aws/aws-sdk-go-v2/service/sts v1.38.8/go.mod h1:L1xxV3zAdB+qVrVW/pBIrIAnHFWHo6FBbFe4xOGsG/o=
github.com/aws/smithy-go v1.23.1 h1:sLvcH6dfAFwGkHLZ7dGiYF7aK6mg4CgKA/iDKjLDt9M=
github.com/aws/smithy-go v1.23.1/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
35 changes: 35 additions & 0 deletions app/go/src/dtos/dtos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package dtos

type SubscriptionResponse struct {
UserID string `json:"userId"`
SubscriptionID string `json:"subscriptionId"`
Plan *SubscriptionResponsePlan `json:"plan"`
StartDate string `json:"startDate"`
ExpiresAt string `json:"expiresAt"`
CancelledAt *string `json:"cancelledAt"`
Status SubStatus `json:"status"`
Attributes map[string]any `json:"attributes"`
}

type SubscriptionResponsePlan struct {
SKU string `json:"sku"`
Name string `json:"name"`
Price float64 `json:"price"`
Currency string `json:"currency"`
BillingCycle string `json:"billingCycle"`
Features []string `json:"features"`
}

type SubscriptionRequest struct {
EventID string `json:"eventId"`
EventType string `json:"eventType"`
Timestamp string `json:"timestamp"`
Provider string `json:"provider"`
SubscriptionID string `json:"subscriptionId"`
PaymentID *string `json:"paymentId"`
UserID string `json:"userId"`
CustomerID string `json:"customerId"`
ExpiresAt string `json:"expiresAt"`
CanceledAt *string `json:"cancelledAt"`
Metadata map[string]any `json:"metadata"`
}
9 changes: 9 additions & 0 deletions app/go/src/dtos/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dtos

type SubStatus string

const (
SubStatusActive SubStatus = "active"
SubStatusPending SubStatus = "pending"
SubStatusCancelled SubStatus = "cancelled"
)
27 changes: 27 additions & 0 deletions app/go/src/entities/subscription.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package entities

type SubscriptionItem struct {
PK string `dynamodbav:"pk"`
SK string `dynamodbav:"sk"`
Type string `dynamodbav:"type"`
PlanSKU string `dynamodbav:"planSku"`
StartDate string `dynamodbav:"startDate"`
ExpiresAt string `dynamodbav:"expiresAt"`
CancelledAt *string `dynamodbav:"cancelledAt"`
LastModifiedAt string `dynamodbav:"lastModifiedAt"`
Attributes map[string]any `dynamodbav:"attributes"`
}

type Plan struct {
PK string `dynamodbav:"pk"`
SK string `dynamodbav:"sk"`
Type string `dynamodbav:"type"`
SKU string `dynamodbav:"-"`
Name string `dynamodbav:"name"`
Price float64 `dynamodbav:"price"`
Currency string `dynamodbav:"currency"`
BillingCycle string `dynamodbav:"billingCycle"`
Features []string `dynamodbav:"features"`
Status string `dynamodbav:"status"`
LastModifiedAt string `dynamodbav:"lastModifiedAt"`
}
Loading