-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac286ae
commit f8670bd
Showing
415 changed files
with
4,438 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
*.swp | ||
.idea | ||
coverage.out | ||
finance-wallet-api | ||
purchases.sh | ||
sales.sh |
This file contains 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,27 @@ | ||
Copyright (c) 2020, Marcelo Jorge Vieira. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains 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,12 @@ | ||
setup: | ||
@go get github.com/codegangsta/gin | ||
@go get | ||
|
||
setup-prod: | ||
@go get | ||
|
||
run: | ||
@FINANCE_WALLETAPI_DEBUG=True gin -b finance-wallet-api -a 8889 -p 3001 -i | ||
|
||
clean: | ||
@find . -name "*.swp" -delete |
This file contains 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,68 @@ | ||
# Finance Wallet | ||
|
||
## Dependencies | ||
|
||
* golang | ||
* mongodb | ||
|
||
### Installing dependencies | ||
|
||
```bash | ||
make setup | ||
``` | ||
|
||
## Run it | ||
|
||
```bash | ||
make run | ||
``` | ||
|
||
## Examples: | ||
|
||
* Adding portfolio: | ||
```curlrc | ||
curl \ | ||
http://localhost:8889/api/v1/portfolios \ | ||
-X POST \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"id": "default", "name": "Default"}' | ||
``` | ||
|
||
* Adding brokers: | ||
```curlrc | ||
curl \ | ||
http://localhost:8889/api/v1/brokers \ | ||
-X POST \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"id": "clear", "name": "CLEAR"}' | ||
``` | ||
|
||
* Adding stocks purchases: | ||
```curlrc | ||
curl \ | ||
http://localhost:8889/api/v1/stocks/purchases \ | ||
-X POST \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"portfolioId": "default", "symbol": "PETR4", "brokerId": "clear", | ||
"shares": 500, "price": 10, "date": "2020-04-24T00:00:00Z"}' | ||
``` | ||
|
||
* Adding stocks sales: | ||
```curlrc | ||
curl \ | ||
http://localhost:8889/api/v1/stocks/sales \ | ||
-X POST \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"portfolioId": "default", "symbol": "PETR4", "brokerId": "clear", | ||
"shares": 100, "price": 15, "date": "2020-06-30T00:00:00Z"}' | ||
``` | ||
|
||
## Third Party | ||
|
||
Favicon uses a picture from [icon-library.com][icon-library] | ||
licensed under [CC0 Public Domain Licence][cco]. | ||
|
||
[icon-library]: http://icon-library.com/icon/icon-finance-15.html | ||
[cco]: https://creativecommons.org/share-your-work/public-domain/cc0/ |
This file contains 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,97 @@ | ||
// Copyright (c) 2020, Marcelo Jorge Vieira | ||
// Licensed under the BSD 3-Clause License | ||
|
||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gosimple/slug" | ||
"github.com/labstack/echo/v4" | ||
"github.com/mfinancecombr/finance-wallet-api/wallet" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *server) broker(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("[API] Retrieving broker id: %s", id) | ||
result, err := s.db.GetBrokerByID(id) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
if result == nil { | ||
return c.JSON(http.StatusNotFound, "Broker data not found") | ||
} | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) brokers(c echo.Context) error { | ||
log.Debug("Retrieving all brokers") | ||
|
||
result, err := s.db.GetAllBrokers() | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) brokersAdd(c echo.Context) error { | ||
log.Debug("Insert brokers data") | ||
|
||
broker := &wallet.Broker{} | ||
if err := c.Bind(broker); err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
broker.ID = slug.Make(broker.Name) | ||
|
||
if err := c.Validate(broker); err != nil { | ||
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error()) | ||
} | ||
|
||
result, err := s.db.InsertBroker(broker) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) brokersDelete(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("Deleting %s data", id) | ||
result, err := s.db.DeleteBrokerByID(id) | ||
if err != nil { | ||
return err | ||
} | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) brokersUpdate(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("Updating %s data", id) | ||
|
||
broker := &wallet.Broker{} | ||
if err := c.Bind(broker); err != nil { | ||
log.Errorf("Error on bind: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if err := c.Validate(broker); err != nil { | ||
log.Errorf("Error on validate: %v", err) | ||
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error()) | ||
} | ||
|
||
result, err := s.db.UpdateBroker(id, broker) | ||
if err != nil { | ||
log.Errorf("Error on update broker: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if result.MatchedCount != 0 { | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
return c.JSON(http.StatusNotFound, "Broker not found") | ||
} |
This file contains 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 @@ | ||
// Copyright (c) 2020, Marcelo Jorge Vieira (https://github.com/mfinancecombr) | ||
// Licensed under the BSD 3-Clause License | ||
|
||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/mfinancecombr/finance-wallet-api/wallet" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *server) getAllCertificatesOfDepositPurchases(c echo.Context) error { | ||
log.Debug("[API] Retrieving all certificates of deposit purchases") | ||
result, err := s.db.GetAllCertificatesOfDepositsPurchases() | ||
if err != nil { | ||
log.Errorf("[API] Error on retrieve data: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) getCertificateOfDepositPurchaseByID(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("[API] Retrieving certificate of deposit purchase with id: %s", id) | ||
result, err := s.db.GetCertificateOfDepositPurchaseByID(id) | ||
if err != nil { | ||
log.Errorf("[API] Error on retrieve data: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
if result == nil { | ||
return c.JSON(http.StatusNotFound, "Certificate of deposit purchase data not found") | ||
} | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) insertCertificateOfDepositPurchase(c echo.Context) error { | ||
log.Debugf("[API] Inserting certificate of deposit purchase") | ||
|
||
data := wallet.NewCertificateOfDeposit() | ||
|
||
if err := c.Bind(data); err != nil { | ||
log.Errorf("[API] Error on bind: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if err := c.Validate(data); err != nil { | ||
log.Errorf("[API] Error on validate: %v", err) | ||
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error()) | ||
} | ||
|
||
result, err := s.db.InsertCertificateOfDepositPurchase(data) | ||
if err != nil { | ||
log.Errorf("[API] Error on insert: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) updateCertificateOfDepositPurchaseByID(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("[API] Updating certificate of deposit purchase with id %s", id) | ||
|
||
data := wallet.NewCertificateOfDeposit() | ||
|
||
if err := c.Bind(data); err != nil { | ||
log.Errorf("[API] Error on bind: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if err := c.Validate(data); err != nil { | ||
log.Errorf("[API] Error on validate: %v", err) | ||
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error()) | ||
} | ||
|
||
result, err := s.db.UpdateCertificateOfDepositPurchaseByID(id, data) | ||
if err != nil { | ||
log.Errorf("[API] Error on update: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if result.MatchedCount != 0 { | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
return c.JSON(http.StatusNotFound, "Certificate of deposit purchase not found") | ||
} |
This file contains 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 @@ | ||
// Copyright (c) 2020, Marcelo Jorge Vieira (https://github.com/mfinancecombr) | ||
// Licensed under the BSD 3-Clause License | ||
|
||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"github.com/mfinancecombr/finance-wallet-api/wallet" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *server) getAllCertificatesOfDepositSales(c echo.Context) error { | ||
log.Debug("[API] Retrieving all certificates of deposit sales") | ||
result, err := s.db.GetAllCertificatesOfDepositsSales() | ||
if err != nil { | ||
log.Errorf("[API] Error on retrieve data: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) getCertificateOfDepositSaleByID(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("[API] Retrieving certificate of deposit sale with id: %s", id) | ||
result, err := s.db.GetCertificateOfDepositSaleByID(id) | ||
if err != nil { | ||
log.Errorf("[API] Error on retrieve data: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
if result == nil { | ||
return c.JSON(http.StatusNotFound, "Certificate of deposit sale data not found") | ||
} | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) insertCertificateOfDepositSale(c echo.Context) error { | ||
log.Debugf("[API] Inserting certificate of deposit sale") | ||
|
||
data := wallet.NewCertificateOfDeposit() | ||
|
||
if err := c.Bind(data); err != nil { | ||
log.Errorf("[API] Error on bind: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if err := c.Validate(data); err != nil { | ||
log.Errorf("[API] Error on validate: %v", err) | ||
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error()) | ||
} | ||
|
||
result, err := s.db.InsertCertificateOfDepositSale(data) | ||
if err != nil { | ||
log.Errorf("[API] Error on insert: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func (s *server) updateCertificateOfDepositSaleByID(c echo.Context) error { | ||
id := c.Param("id") | ||
log.Debugf("[API] Updating certificate of deposit sale with id %s", id) | ||
|
||
data := wallet.NewCertificateOfDeposit() | ||
|
||
if err := c.Bind(data); err != nil { | ||
log.Errorf("[API] Error on bind: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if err := c.Validate(data); err != nil { | ||
log.Errorf("[API] Error on validate: %v", err) | ||
return echo.NewHTTPError(http.StatusUnprocessableEntity, err.Error()) | ||
} | ||
|
||
result, err := s.db.UpdateCertificateOfDepositSaleByID(id, data) | ||
if err != nil { | ||
log.Errorf("[API] Error on update: %v", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
if result.MatchedCount != 0 { | ||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
return c.JSON(http.StatusNotFound, "Certificate of deposit sale not found") | ||
} |
Oops, something went wrong.