This repository was archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/gh-111/badge_threshold #121
Open
edreinoso
wants to merge
43
commits into
development
Choose a base branch
from
feat/gh-111/badge_threshold
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
ae8e84d
🚀 crowdaction hex refactoring init
edreinoso ac8387f
🚧 dynamodb manager repository, pt1: init
edreinoso 7ae52c7
⚡️ launching own sam config
edreinoso f0656c4
Merge branch 'development' into feat/gh-73/crowdactions
edreinoso 1eae809
Merge branch 'development' into feat/gh-73/crowdactions
edreinoso 9963992
🚧 [crowdaction] deployed first function on to aws
edreinoso 605e564
🚧 [crowdaction] removing extra copy of dynamo repository
edreinoso 0423b32
🚧 [crowdaction] init model and validation on request
edreinoso d7daae2
🚧 [crowdaction] changed the model function names
edreinoso e684acf
🚧 [crowdaction] working on internal and handler
edreinoso 32666f8
🚧 [crowdaction] simple version of GET request by ID
edreinoso c25eec9
🚧 [crowdaction] testing GET request by ID
edreinoso bae64a5
🚧 [crowdaction] creating external function to GET crowdaction by ID
edreinoso 3d5c1a5
🚧 [crowdaction] including query function in ddb repository
edreinoso 33a7ab1
🚧 [crowdaction] initial code base for GET crowdactions by status
edreinoso b555b09
🚧 [crowdaction] cleaning up, commitment options
edreinoso 841b968
🚧 [crowdaction] including the mock repository for dynamo and crowdaction
edreinoso 483e006
🚧 [crowdaction] modifying the mock repository to include GetCrowdacti…
edreinoso 9ce295a
🚧 [crowdaction] removed unnecessary comments, per the feedback on pul…
edreinoso 8c5c280
[pull request] removing samconfig file from history
edreinoso 99f52ef
[pull request] ignoring samconfig file as per the pull request
edreinoso 4dc7789
[pull request] modified naming for the internal interface
edreinoso 18aa963
[pull request] getting rid of useless else statement
edreinoso 8fb01c0
[pull request] removing dynamodb dependencies in logic
edreinoso a47a23b
[pull request] including mock repository and crowdaction test
edreinoso 39c7417
[pull request] cleaning up some unnecessary lines
edreinoso 525b2b4
[pull request] separating repository concerns
edreinoso 595b737
[pull request] modifying test cases with new repository structure
edreinoso 98f45af
[pull request] changing dynamo repository call from crowdaction main …
edreinoso 45cb593
[pull request] changing parameters to pass unit test case
edreinoso 93138e2
[pull request] changing crowdactionID from test case
edreinoso f03c63a
[pull request] changing method call for crowdaction test
edreinoso 8449139
[pull request] fixing parameter issue in crowdaction_test
edreinoso 14f671a
[pull request] testing issue with the args.get(x) call in mock/dynamo…
edreinoso 09ed55a
[pull request] including Mock in each of the function calls from the …
edreinoso 589a25c
[pull request] modifying test cases for crowdaction
edreinoso 72c469f
[pull request] changes done based on feedback
edreinoso 11d5e7f
Merge branch 'feat/gh-73/crowdactions' of github.com:CollActionteam/c…
edreinoso 4c3e35e
[pull request] removing unnecessary hello world
edreinoso 4c44370
[pull request] removing some unnecessary comments
edreinoso 77bed7e
pointing system for the commitments in crowdactions
edreinoso 9858c8b
Merge branch 'development' of github.com:CollActionteam/collaction_ba…
edreinoso 4459c00
Merge branch 'feat/gh-73/crowdactions' of github.com:CollActionteam/c…
edreinoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package crowdaction | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| m "github.com/CollActionteam/collaction_backend/internal/models" | ||
| "github.com/CollActionteam/collaction_backend/utils" | ||
| ) | ||
|
|
||
| type Service interface { | ||
| GetCrowdactionById(ctx context.Context, crowdactionId string) (*m.CrowdactionData, error) | ||
| GetCrowdactionsByStatus(ctx context.Context, status string, startFrom *utils.PrimaryKey) ([]m.CrowdactionData, error) | ||
| } | ||
| type CrowdactionManager interface { | ||
| GetById(pk string, crowdactionId string) (*m.CrowdactionData, error) | ||
| GetByStatus(filterCond string, startFrom *utils.PrimaryKey) ([]m.CrowdactionData, error) | ||
| } | ||
|
|
||
| const ( | ||
| KeyDateStart = "date_start" | ||
| KeyDateEnd = "date_end" | ||
| KeyDateJoinBefore = "date_limit_join" | ||
| ) | ||
|
|
||
| type crowdactionService struct { | ||
| crowdactionRepository CrowdactionManager | ||
| } | ||
|
|
||
| func NewCrowdactionService(crowdactionRepository CrowdactionManager) Service { | ||
| return &crowdactionService{crowdactionRepository: crowdactionRepository} | ||
| } | ||
|
|
||
| func (e *crowdactionService) GetCrowdactionById(ctx context.Context, crowdactionID string) (*m.CrowdactionData, error) { | ||
| fmt.Println("GetCrowdactionById", crowdactionID) | ||
| return e.crowdactionRepository.GetById(utils.PKCrowdaction, crowdactionID) | ||
| } | ||
|
|
||
| func (e *crowdactionService) GetCrowdactionsByStatus(ctx context.Context, status string, startFrom *utils.PrimaryKey) ([]m.CrowdactionData, error) { | ||
| fmt.Println("GetCrowdactionsByStatus", status, startFrom) | ||
| return e.crowdactionRepository.GetByStatus(status, startFrom) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package crowdaction_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| cwd "github.com/CollActionteam/collaction_backend/internal/crowdactions" | ||
| m "github.com/CollActionteam/collaction_backend/internal/models" | ||
| "github.com/CollActionteam/collaction_backend/pkg/mocks/repository" | ||
|
|
||
| "github.com/CollActionteam/collaction_backend/utils" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestCrowdaction_GetCrowdactionById(t *testing.T) { | ||
| as := assert.New(t) | ||
| dynamoRepository := &repository.Dynamo{} | ||
| var ctx context.Context | ||
| var crowdactions *m.CrowdactionData | ||
| crowdactionID := "sustainability#food#185f66fd" | ||
|
|
||
| t.Run("dev stage", func(t *testing.T) { | ||
| dynamoRepository.On("GetById", utils.PKCrowdaction, crowdactionID).Return(crowdactions, nil).Once() | ||
|
|
||
| service := cwd.NewCrowdactionService(dynamoRepository) | ||
|
|
||
| crowdaction, err := service.GetCrowdactionById(ctx, crowdactionID) | ||
|
|
||
| fmt.Println("Hello world", crowdaction) | ||
|
|
||
| as.NoError(err) | ||
|
|
||
| dynamoRepository.AssertExpectations(t) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package models | ||
|
|
||
| type CommitmentOption struct { | ||
| Id string `json:"id"` | ||
| Label string `json:"label"` | ||
| Description string `json:"description"` | ||
| Requires []CommitmentOption `json:"requires,omitempty"` | ||
| Points int `json:"points"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package models | ||
|
|
||
| type CrowdactionRequest struct { | ||
| Data CrowdactionData `json:"data" validate:"required"` | ||
| } | ||
|
|
||
| type CrowdactionParticipant struct { | ||
| Name string `json:"name,omitempty"` | ||
| UserID string `json:"userID,omitempty"` | ||
| } | ||
|
|
||
| type CrowdactionImages struct { | ||
| Card string `json:"card,omitempty"` | ||
| Banner string `json:"banner,omitempty"` | ||
| } | ||
|
|
||
| type CrowdactionData struct { | ||
| CrowdactionID string `json:"crowdactionID"` | ||
| Title string `json:"title"` | ||
| Description string `json:"description"` | ||
| Category string `json:"category"` | ||
| Subcategory string `json:"subcategory"` | ||
| Location string `json:"location"` | ||
| DateStart string `json:"date_start"` | ||
| DateEnd string `json:"date_end"` | ||
| DateLimitJoin string `json:"date_limit_join"` | ||
| PasswordJoin string `json:"password_join"` | ||
| ParticipationCount int `json:"participant_count"` | ||
| TopParticipants []CrowdactionParticipant `json:"top_participants"` | ||
| Images CrowdactionImages `json:"images"` | ||
| CommitmentOptions []CommitmentOption `json:"commitment_options"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "net/http" | ||
|
|
||
| cwd "github.com/CollActionteam/collaction_backend/internal/crowdactions" | ||
| "github.com/CollActionteam/collaction_backend/internal/models" | ||
| hnd "github.com/CollActionteam/collaction_backend/pkg/handler" | ||
| awsRepository "github.com/CollActionteam/collaction_backend/pkg/repository/aws" | ||
| "github.com/CollActionteam/collaction_backend/utils" | ||
| "github.com/aws/aws-lambda-go/events" | ||
| "github.com/aws/aws-lambda-go/lambda" | ||
| "github.com/go-playground/validator/v10" | ||
| ) | ||
|
|
||
| func getCrowdactionByID(ctx context.Context, crowdactionID string) (events.APIGatewayV2HTTPResponse, error) { | ||
| dynamoRepository := awsRepository.NewCrowdaction(awsRepository.NewDynamo()) | ||
| getCrowdaction, err := cwd.NewCrowdactionService(dynamoRepository).GetCrowdactionById(ctx, crowdactionID) | ||
|
|
||
| if err != nil { | ||
| return utils.CreateMessageHttpResponse(http.StatusInternalServerError, err.Error()), nil | ||
| } | ||
| if getCrowdaction == nil { | ||
| return utils.CreateMessageHttpResponse(http.StatusNotFound, "not participating"), nil | ||
| } | ||
|
|
||
| jsonPayload, _ := json.Marshal(getCrowdaction) | ||
| return events.APIGatewayV2HTTPResponse{ | ||
| Body: string(jsonPayload), | ||
| StatusCode: http.StatusOK, | ||
| }, nil | ||
| } | ||
|
|
||
| func getCrowdactionsByStatus(ctx context.Context, status string) (events.APIGatewayV2HTTPResponse, error) { | ||
| dynamoRepository := awsRepository.NewCrowdaction(awsRepository.NewDynamo()) | ||
| getCrowdactions, err := cwd.NewCrowdactionService(dynamoRepository).GetCrowdactionsByStatus(ctx, status, nil) | ||
|
|
||
| if err != nil { | ||
| return utils.CreateMessageHttpResponse(http.StatusInternalServerError, err.Error()), nil | ||
| } | ||
| jsonPayload, _ := json.Marshal(getCrowdactions) | ||
|
|
||
| return events.APIGatewayV2HTTPResponse{ | ||
| Body: string(jsonPayload), | ||
| StatusCode: http.StatusOK, | ||
| }, nil | ||
| } | ||
|
|
||
| func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) { | ||
| crowdactionID := req.PathParameters["crowdactionID"] | ||
| var request models.CrowdactionRequest | ||
|
|
||
| validate := validator.New() | ||
| if err := validate.StructCtx(ctx, request); err != nil { | ||
| body, _ := json.Marshal(hnd.Response{Status: hnd.StatusFail, Data: map[string]interface{}{"error": utils.ValidationResponse(err, validate)}}) | ||
| return events.APIGatewayV2HTTPResponse{Body: string(body), StatusCode: http.StatusBadRequest}, nil | ||
| } | ||
|
|
||
| if crowdactionID == "" { | ||
| status := req.QueryStringParameters["status"] | ||
| return getCrowdactionsByStatus(ctx, status) | ||
| } | ||
|
|
||
| return getCrowdactionByID(ctx, crowdactionID) | ||
| } | ||
|
|
||
| func main() { | ||
| lambda.Start(handler) | ||
| } | ||
|
|
||
| func errToResponse(err error, code int) events.APIGatewayV2HTTPResponse { | ||
| msg, _ := json.Marshal(map[string]string{"message": err.Error()}) | ||
| return events.APIGatewayV2HTTPResponse{Body: string(msg), StatusCode: code} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package repository | ||
|
|
||
| import ( | ||
| m "github.com/CollActionteam/collaction_backend/internal/models" | ||
| "github.com/CollActionteam/collaction_backend/utils" | ||
| "github.com/stretchr/testify/mock" | ||
| ) | ||
|
|
||
| type Dynamo struct { | ||
| mock.Mock | ||
| } | ||
|
|
||
| func (d *Dynamo) GetById(pk string, sk string) (*m.CrowdactionData, error) { | ||
| args := d.Mock.Called(pk, sk) | ||
| return args.Get(0).(*m.CrowdactionData), args.Error(1) | ||
| } | ||
|
|
||
| func (d *Dynamo) GetByStatus(filterCond string, startFrom *utils.PrimaryKey) ([]m.CrowdactionData, error) { | ||
| args := d.Mock.Called(filterCond, startFrom) | ||
| return args.Get(0).([]m.CrowdactionData), args.Error(1) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/CollActionteam/collaction_backend/internal/constants" | ||
| m "github.com/CollActionteam/collaction_backend/internal/models" | ||
| "github.com/CollActionteam/collaction_backend/utils" | ||
| "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" | ||
| "github.com/aws/aws-sdk-go/service/dynamodb/expression" | ||
| ) | ||
|
|
||
| type Crowdaction interface { | ||
| GetById(pk string, sk string) (*m.CrowdactionData, error) | ||
| GetByStatus(status string, startFrom *utils.PrimaryKey) ([]m.CrowdactionData, error) | ||
| } | ||
|
|
||
| const ( | ||
| KeyDateStart = "date_start" | ||
| KeyDateEnd = "date_end" | ||
| KeyDateJoinBefore = "date_limit_join" | ||
| ) | ||
|
|
||
| type crowdaction struct { | ||
| dbClient *Dynamo | ||
| } | ||
|
|
||
| func NewCrowdaction(dynamo *Dynamo) Crowdaction { | ||
| return &crowdaction{dbClient: dynamo} | ||
| } | ||
|
|
||
| /** | ||
| GET Crowdaction by Id | ||
| **/ | ||
| func (s *crowdaction) GetById(pk string, sk string) (*m.CrowdactionData, error) { | ||
| item, err := s.dbClient.GetDBItem(constants.TableName, pk, sk) | ||
|
|
||
| if item == nil || err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var c m.CrowdactionData | ||
| err = dynamodbattribute.UnmarshalMap(item, &c) | ||
|
|
||
| return &c, err | ||
| } | ||
|
|
||
| /** | ||
| GET Crowdaction by Status | ||
| **/ | ||
| func (s *crowdaction) GetByStatus(status string, startFrom *utils.PrimaryKey) ([]m.CrowdactionData, error) { | ||
| crowdactions := []m.CrowdactionData{} | ||
| var filterCond expression.ConditionBuilder | ||
|
|
||
| switch status { | ||
| case "joinable": | ||
| filterCond = expression.Name(KeyDateJoinBefore).GreaterThan(expression.Value(utils.GetDateStringNow())) | ||
| fmt.Println("GetByStatus: joinable", filterCond) | ||
| case "active": | ||
| filterCond = expression.Name(KeyDateStart).LessThanEqual(expression.Value(utils.GetDateStringNow())) | ||
| fmt.Println("GetByStatus: active", filterCond) | ||
| case "ended": | ||
| filterCond = expression.Name(KeyDateEnd).LessThanEqual(expression.Value(utils.GetDateStringNow())) | ||
| fmt.Println("GetByStatus: ended", filterCond) | ||
| default: | ||
| fmt.Println("None of the edge cases matched") | ||
| } | ||
|
|
||
| items, err := s.dbClient.Query(constants.TableName, filterCond, startFrom) | ||
|
|
||
| if items == nil || err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, foo := range items { | ||
| var crowdaction m.CrowdactionData | ||
| err := dynamodbattribute.UnmarshalMap(foo, &crowdaction) | ||
|
|
||
| if err == nil { | ||
| crowdactions = append(crowdactions, crowdaction) | ||
| } | ||
| } | ||
|
|
||
| if len(items) != len(crowdactions) { | ||
| err = fmt.Errorf("error unmarshelling %d items", len(items)-len(crowdactions)) | ||
| } | ||
|
|
||
| return crowdactions, err | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CrowdactionDatastructure should have a fieldbadge_thresholdsof type[]int.