├── .gitignore ├── filas-aula-2 ├── a │ ├── .env │ ├── a.go │ └── templates │ │ ├── home.html │ │ └── process.html ├── b │ ├── .env │ └── b.go ├── c │ └── c.go ├── docker-compose.yaml ├── go.mod └── go.sum ├── integracao-continua-react-3 ├── .github │ └── workflows │ │ └── ci.yaml ├── .gitignore ├── .vscode │ └── settings.json ├── README.md ├── debug.log ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── components │ │ ├── App │ │ │ ├── index.css │ │ │ └── index.tsx │ │ ├── Chart │ │ │ ├── index.css │ │ │ └── index.tsx │ │ ├── Coin │ │ │ ├── index.css │ │ │ ├── index.test.tsx │ │ │ └── index.tsx │ │ ├── Header │ │ │ ├── index.css │ │ │ └── index.tsx │ │ └── Legend │ │ │ ├── index.css │ │ │ └── index.tsx │ ├── http │ │ └── index.ts │ ├── index.tsx │ ├── react-app-env.d.ts │ ├── reportWebVitals.ts │ └── setupTests.ts └── tsconfig.json └── microsservicos-aula-1 ├── a ├── a.go └── templates │ └── home.html ├── b └── b.go ├── c └── c.go ├── go.mod └── go.sum /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /filas-aula-2/a/.env: -------------------------------------------------------------------------------- 1 | RABBITMQ_DEFAULT_USER=rabbitmq 2 | RABBITMQ_DEFAULT_PASS=rabbitmq 3 | RABBITMQ_DEFAULT_HOST=localhost 4 | RABBITMQ_DEFAULT_PORT=5672 5 | RABBITMQ_DEFAULT_VHOST=/ 6 | RABBITMQ_CONSUMER_NAME=app-name 7 | RABBITMQ_CONSUMER_QUEUE_NAME=exemplo 8 | RABBITMQ_NOTIFICATION_EX=amq.direct 9 | RABBITMQ_NOTIFICATION_ROUTING_KEY=jobs 10 | RABBITMQ_DLX=dlx -------------------------------------------------------------------------------- /filas-aula-2/a/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/joho/godotenv" 6 | "github.com/wesleywillians/go-rabbitmq/queue" 7 | "html/template" 8 | "log" 9 | "net/http" 10 | ) 11 | 12 | type Order struct { 13 | Coupon string 14 | CcNumber string 15 | } 16 | 17 | type Result struct { 18 | Status string 19 | } 20 | 21 | func init() { 22 | err := godotenv.Load() 23 | if err != nil { 24 | log.Fatal("Error loading .env") 25 | } 26 | } 27 | 28 | func main() { 29 | http.HandleFunc("/", home) 30 | http.HandleFunc("/process", process) 31 | http.ListenAndServe(":9090", nil) 32 | } 33 | 34 | func home(w http.ResponseWriter, r *http.Request) { 35 | t := template.Must(template.ParseFiles("templates/home.html")) 36 | t.Execute(w, Result{}) 37 | } 38 | 39 | func process(w http.ResponseWriter, r *http.Request) { 40 | 41 | coupon := r.PostFormValue("coupon") 42 | ccNumber := r.PostFormValue("cc-number") 43 | 44 | order := Order{ 45 | Coupon: coupon, 46 | CcNumber: ccNumber, 47 | } 48 | 49 | jsonOrder, err := json.Marshal(order) 50 | if err != nil { 51 | log.Fatal("Error parsing to json") 52 | } 53 | 54 | rabbitMQ := queue.NewRabbitMQ() 55 | ch := rabbitMQ.Connect() 56 | defer ch.Close() 57 | 58 | err = rabbitMQ.Notify(string(jsonOrder), "application/json", "orders_ex", "") 59 | if err != nil { 60 | log.Fatal("Error sending message to the queue") 61 | } 62 | 63 | t := template.Must(template.ParseFiles("templates/process.html")) 64 | t.Execute(w, "") 65 | } 66 | -------------------------------------------------------------------------------- /filas-aula-2/a/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Checkout example · Bootstrap 8 | 10 | 11 | 12 | 13 |
14 |
15 |

Checkout

16 |
17 | 18 |
19 |
20 |
21 |

22 | Carrinho 23 | 1 24 |

25 |
    26 |
  • 27 |
    28 |
    Tênis Adidas
    29 |
    30 | R$ 100,00 31 |
  • 32 | 33 |
  • 34 | Total 35 | R$ 100,00 36 |
  • 37 |
38 | 39 |
40 | 41 |
42 |
43 |
44 |

Dados pessoais

45 |
46 |
47 | 48 | 49 |
50 |
51 | 52 | 53 |
54 |
55 | 56 |
57 | 58 |

Pagamento

59 | 60 | 61 |
62 |
63 | 64 | 65 |
66 |
67 | 68 | 69 |
70 |
71 |
72 |
73 | 74 | 75 | 76 |
77 |
78 | 79 | 80 |
81 |
82 |
83 | 84 |
85 |
86 |
87 | 88 | 91 | 92 |
93 | 94 | 95 | -------------------------------------------------------------------------------- /filas-aula-2/a/templates/process.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Checkout example · Bootstrap 8 | 10 | 11 | 12 | 13 |
14 |
15 |

Checkout

16 |
17 | 18 |

Seu pedido foi recebido com sucesso! Aguarde um email de confirmação.

19 | 20 | 23 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /filas-aula-2/b/.env: -------------------------------------------------------------------------------- 1 | RABBITMQ_DEFAULT_USER=rabbitmq 2 | RABBITMQ_DEFAULT_PASS=rabbitmq 3 | RABBITMQ_DEFAULT_HOST=localhost 4 | RABBITMQ_DEFAULT_PORT=5672 5 | RABBITMQ_DEFAULT_VHOST=/ 6 | RABBITMQ_CONSUMER_NAME=payment-ms 7 | RABBITMQ_CONSUMER_QUEUE_NAME=orders 8 | RABBITMQ_NOTIFICATION_EX=amq.direct 9 | RABBITMQ_NOTIFICATION_ROUTING_KEY= 10 | RABBITMQ_DLX=dlx -------------------------------------------------------------------------------- /filas-aula-2/b/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/joho/godotenv" 6 | uuid "github.com/satori/go.uuid" 7 | "github.com/streadway/amqp" 8 | "github.com/wesleywillians/go-rabbitmq/queue" 9 | "io/ioutil" 10 | "log" 11 | "net/http" 12 | "net/url" 13 | ) 14 | 15 | type Result struct { 16 | Status string 17 | } 18 | 19 | type Order struct { 20 | ID uuid.UUID 21 | Coupon string 22 | CcNumber string 23 | } 24 | 25 | func NewOrder() Order { 26 | return Order{ID: uuid.NewV4()} 27 | } 28 | 29 | const ( 30 | InvalidCoupon = "invalid" 31 | ValidCoupon = "valid" 32 | ConnectionError = "connection error" 33 | ) 34 | 35 | func init() { 36 | err := godotenv.Load() 37 | if err != nil { 38 | log.Fatalf("Error loading .env file") 39 | } 40 | } 41 | 42 | func main() { 43 | messageChannel := make(chan amqp.Delivery) 44 | 45 | rabbitMQ := queue.NewRabbitMQ() 46 | ch := rabbitMQ.Connect() 47 | defer ch.Close() 48 | 49 | rabbitMQ.Consume(messageChannel) 50 | 51 | for msg := range messageChannel { 52 | process(msg) 53 | } 54 | } 55 | 56 | func process(msg amqp.Delivery) { 57 | 58 | order := NewOrder() 59 | json.Unmarshal(msg.Body, &order) 60 | 61 | resultCoupon := makeHttpCall("http://localhost:9092", order.Coupon) 62 | 63 | switch resultCoupon.Status { 64 | case InvalidCoupon: 65 | log.Println("Order: ", order.ID, ": invalid coupon!") 66 | 67 | case ConnectionError: 68 | msg.Reject(false) 69 | log.Println("Order: ", order.ID, ": could not process!") 70 | 71 | case ValidCoupon: 72 | log.Println("Order: ", order.ID, ": Processed") 73 | } 74 | } 75 | 76 | func makeHttpCall(urlMicroservice string, coupon string) Result { 77 | 78 | values := url.Values{} 79 | values.Add("coupon", coupon) 80 | 81 | res, err := http.PostForm(urlMicroservice, values) 82 | if err != nil { 83 | result := Result{Status: ConnectionError} 84 | return result 85 | } 86 | 87 | defer res.Body.Close() 88 | 89 | data, err := ioutil.ReadAll(res.Body) 90 | if err != nil { 91 | log.Fatal("Error processing result") 92 | } 93 | 94 | result := Result{} 95 | 96 | json.Unmarshal(data, &result) 97 | 98 | return result 99 | 100 | } 101 | -------------------------------------------------------------------------------- /filas-aula-2/c/c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | "net/http" 8 | ) 9 | 10 | type Coupon struct { 11 | Code string 12 | } 13 | 14 | type Coupons struct { 15 | Coupon []Coupon 16 | } 17 | 18 | func (c Coupons) Check(code string) string { 19 | for _, item := range c.Coupon { 20 | if code == item.Code { 21 | return "valid" 22 | } 23 | } 24 | return "invalid" 25 | } 26 | 27 | type Result struct { 28 | Status string 29 | } 30 | 31 | var coupons Coupons 32 | 33 | func main() { 34 | coupon := Coupon{ 35 | Code: "abc", 36 | } 37 | 38 | coupons.Coupon = append(coupons.Coupon, coupon) 39 | 40 | http.HandleFunc("/", home) 41 | http.ListenAndServe(":9092", nil) 42 | } 43 | 44 | func home(w http.ResponseWriter, r *http.Request) { 45 | coupon := r.PostFormValue("coupon") 46 | valid := coupons.Check(coupon) 47 | 48 | result := Result{Status: valid} 49 | 50 | jsonResult, err := json.Marshal(result) 51 | if err != nil { 52 | log.Fatal("Error converting json") 53 | } 54 | 55 | fmt.Fprintf(w, string(jsonResult)) 56 | 57 | } -------------------------------------------------------------------------------- /filas-aula-2/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | rabbit: 6 | image: "rabbitmq:3-management" 7 | environment: 8 | RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG" 9 | RABBITMQ_DEFAULT_USER: "rabbitmq" 10 | RABBITMQ_DEFAULT_PASS: "rabbitmq" 11 | RABBITMQ_DEFAULT_VHOST: "/" 12 | ports: 13 | - "15672:15672" 14 | - "5672:5672" -------------------------------------------------------------------------------- /filas-aula-2/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/codeedu/avancadev-micrservice-1dia 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/joho/godotenv v1.3.0 7 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect 8 | github.com/satori/go.uuid v1.2.0 9 | github.com/wesleywillians/go-rabbitmq v0.0.0-20201027193450-55e6a80937af 10 | gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /filas-aula-2/go.sum: -------------------------------------------------------------------------------- 1 | github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= 2 | github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= 3 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 4 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 5 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 6 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= 7 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 8 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= 9 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= 10 | github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo= 11 | github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= 12 | github.com/wesleywillians/go-rabbitmq v0.0.0-20201027193450-55e6a80937af h1:pE+leqmw6k0BXMHeFwoMQY/6N8rGR6NWYfrYpVTdHY8= 13 | github.com/wesleywillians/go-rabbitmq v0.0.0-20201027193450-55e6a80937af/go.mod h1:a8g6tNV76FrnJSlQDpAeuJ4EA8JvRGSejc8PAkKfro4= 14 | gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= 15 | gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 16 | -------------------------------------------------------------------------------- /integracao-continua-react-3/.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | deploy: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v1 13 | - name: Get Node.js 14 | uses: actions/setup-node@v1 15 | with: 16 | node-version: 12 17 | - name: Install dependencies 18 | run: npm install 19 | - name: Testing 20 | run: CI=true npm test 21 | - name: Build 22 | run: npm run build 23 | -------------------------------------------------------------------------------- /integracao-continua-react-3/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | 25 | .history/ -------------------------------------------------------------------------------- /integracao-continua-react-3/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "workbench.colorCustomizations": { 3 | "activityBar.activeBackground": "#93e6fc", 4 | "activityBar.activeBorder": "#fa45d4", 5 | "activityBar.background": "#93e6fc", 6 | "activityBar.foreground": "#15202b", 7 | "activityBar.inactiveForeground": "#15202b99", 8 | "activityBarBadge.background": "#fa45d4", 9 | "activityBarBadge.foreground": "#15202b", 10 | "statusBar.background": "#93e6fc", 11 | "statusBar.foreground": "#15202b", 12 | "statusBarItem.hoverBackground": "#61dbfb" 13 | }, 14 | "peacock.remoteColor": "#61dbfb", 15 | "peacock.color": "#61dbfb" 16 | } -------------------------------------------------------------------------------- /integracao-continua-react-3/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /integracao-continua-react-3/debug.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeedu/avancadev/HEAD/integracao-continua-react-3/debug.log -------------------------------------------------------------------------------- /integracao-continua-react-3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crypto-view", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.5", 7 | "@testing-library/react": "^11.1.1", 8 | "@testing-library/user-event": "^12.2.0", 9 | "@types/jest": "^26.0.15", 10 | "@types/node": "^12.19.3", 11 | "@types/react": "^16.9.55", 12 | "@types/react-dom": "^16.9.9", 13 | "axios": "^0.21.0", 14 | "lightweight-charts": "^3.1.5", 15 | "react": "^17.0.1", 16 | "react-dom": "^17.0.1", 17 | "react-scripts": "4.0.0", 18 | "typescript": "^4.0.5", 19 | "web-vitals": "^0.2.4" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /integracao-continua-react-3/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeedu/avancadev/HEAD/integracao-continua-react-3/public/favicon.ico -------------------------------------------------------------------------------- /integracao-continua-react-3/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | 33 | React App 34 | 35 | 36 | 37 |
38 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /integracao-continua-react-3/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeedu/avancadev/HEAD/integracao-continua-react-3/public/logo192.png -------------------------------------------------------------------------------- /integracao-continua-react-3/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeedu/avancadev/HEAD/integracao-continua-react-3/public/logo512.png -------------------------------------------------------------------------------- /integracao-continua-react-3/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /integracao-continua-react-3/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/App/index.css: -------------------------------------------------------------------------------- 1 | .App { 2 | height: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/App/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { Chart } from '../Chart'; 3 | import { Header } from '../Header'; 4 | import './index.css'; 5 | 6 | function App() { 7 | const [coinSelected, setCoinSelected] = useState("BTC"); 8 | return ( 9 |
10 |
setCoinSelected(coin)}/> 11 | 12 |
13 | ); 14 | } 15 | 16 | export default App; 17 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Chart/index.css: -------------------------------------------------------------------------------- 1 | .Chart{ 2 | flex: 1 1 auto; 3 | position: relative; 4 | } -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Chart/index.tsx: -------------------------------------------------------------------------------- 1 | // @flow 2 | import { createChart, CrosshairMode, ISeriesApi } from "lightweight-charts"; 3 | import * as React from "react"; 4 | import { cryptoHttp } from "../../http"; 5 | import { Legend } from "../Legend"; 6 | import "./index.css"; 7 | 8 | interface ChartProps { 9 | coin: string; 10 | } 11 | export const Chart: React.FC = (props) => { 12 | const { coin } = props; 13 | const containerRef = React.useRef() as React.MutableRefObject; 14 | const candleSeriesRef = React.useRef() as React.MutableRefObject< 15 | ISeriesApi<"Candlestick"> 16 | >; 17 | const [prices, setPrices] = React.useState([]); 18 | const [chartLoaded, setChartLoaded] = React.useState(false); 19 | 20 | React.useEffect(() => { 21 | const interval = setInterval(() => { 22 | cryptoHttp 23 | .get(`histominute?fsym=${coin}&tsym=BRL&limit=1`) 24 | .then((response) => { 25 | setPrices((prevState) => { 26 | const price = response.data.Data[1]; 27 | const newPrice = { 28 | time: price.time, 29 | low: price.low, 30 | high: price.high, 31 | open: price.open, 32 | close: price.close, 33 | volume: price.volumefrom, 34 | }; 35 | candleSeriesRef.current.update(newPrice); 36 | return [...prevState, newPrice] 37 | }); 38 | }); 39 | }, 60000); 40 | return () => clearInterval(interval) 41 | }, [coin]); 42 | 43 | React.useEffect(() => { 44 | if (!chartLoaded) { 45 | return; 46 | } 47 | cryptoHttp 48 | .get(`histoday?fsym=${coin}&tsym=BRL&limit=300`) 49 | .then((response) => { 50 | const prices = response.data.Data.map((row: any) => ({ 51 | time: row.time, 52 | low: row.low, 53 | high: row.high, 54 | open: row.open, 55 | close: row.close, 56 | volume: row.volumefrom, 57 | })); 58 | setPrices(prices); 59 | }); 60 | }, [coin, chartLoaded]); 61 | 62 | React.useEffect(() => { 63 | if (candleSeriesRef.current) { 64 | candleSeriesRef.current.setData(prices); 65 | } 66 | }, [prices]); 67 | 68 | React.useEffect(() => { 69 | setPrices([]); 70 | }, [coin]); 71 | 72 | React.useEffect(() => { 73 | const chart = createChart(containerRef.current, { 74 | width: containerRef.current.clientWidth, 75 | height: containerRef.current.clientHeight, 76 | layout: { 77 | backgroundColor: "#253248", 78 | textColor: "rgba(255,255,255,0.9)", 79 | }, 80 | grid: { 81 | vertLines: { 82 | color: "#334158", 83 | }, 84 | horzLines: { 85 | color: "#334158", 86 | }, 87 | }, 88 | crosshair: { 89 | mode: CrosshairMode.Normal, 90 | }, 91 | //@ts-ignore 92 | priceScale: { 93 | borderColor: "#485c7b", 94 | }, 95 | timeScale: { 96 | borderColor: "#485c7b", 97 | }, 98 | }); 99 | 100 | candleSeriesRef.current = chart.addCandlestickSeries({ 101 | upColor: "#4bffb5", 102 | downColor: "#ff4976", 103 | borderDownColor: "#ff4976", 104 | borderUpColor: "#4bffb5", 105 | wickDownColor: "#838ca1", 106 | wickUpColor: "#838ca1", 107 | }); 108 | setChartLoaded(true); 109 | }, []); 110 | 111 | return ( 112 |
113 | 114 |
115 | ); 116 | }; 117 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Coin/index.css: -------------------------------------------------------------------------------- 1 | .Coin{ 2 | width: 100%; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | .Coin.down{ 8 | color: #ff4976 9 | } 10 | 11 | .Coin.up{ 12 | color: #4bffb5 13 | } -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Coin/index.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {render, screen} from '@testing-library/react'; 3 | import {Coin} from './index'; 4 | 5 | it('Check coin label', () => { 6 | render() 7 | expect(screen.getByText('BTC')); 8 | }) -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Coin/index.tsx: -------------------------------------------------------------------------------- 1 | // @flow 2 | import * as React from "react"; 3 | import "./index.css"; 4 | 5 | interface CoinProps { 6 | coin: string; 7 | oldPrice: number; 8 | currentPrice: number; 9 | } 10 | export const Coin: React.FC = (props) => { 11 | const { coin, oldPrice, currentPrice } = props; 12 | const classes = ['Coin']; 13 | if(oldPrice < currentPrice){ 14 | classes.push('up'); 15 | } 16 | if(oldPrice > currentPrice){ 17 | classes.push('down'); 18 | } 19 | return ( 20 |
21 | {coin} 22 | R$ {currentPrice.toLocaleString()} 23 |
24 | ); 25 | }; 26 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Header/index.css: -------------------------------------------------------------------------------- 1 | .Header{ 2 | border-bottom: 1px solid rgba(255, 255, 255, 0.9); 3 | border-top: 1px solid rgba(255, 255, 255, 0.9); 4 | display: flex; 5 | flex-direction: row; 6 | background-color: #334158; 7 | color: rgba(255, 255, 255, 0.9) 8 | } 9 | 10 | .Header > div{ 11 | margin-left: 16px; 12 | } -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Header/index.tsx: -------------------------------------------------------------------------------- 1 | // @flow 2 | import * as React from "react"; 3 | import { cryptoHttp } from "../../http"; 4 | import { Coin } from "../Coin"; 5 | import "./index.css"; 6 | interface HeaderProps { 7 | onSelected: (coin: string) => void; 8 | } 9 | 10 | interface Price { 11 | [key: string]: { oldPrice: number; currentPrice: number }; 12 | } 13 | 14 | const ALL_PRICES: Price = { 15 | BTC: { oldPrice: 0, currentPrice: 0 }, 16 | LTC: { oldPrice: 0, currentPrice: 0 }, 17 | }; 18 | 19 | export const Header: React.FC = (props) => { 20 | const {onSelected} = props; 21 | const [prices, setPrices] = React.useState(ALL_PRICES); 22 | React.useEffect(() => { 23 | const intervals = Object.keys(ALL_PRICES).map((coin) => { 24 | return setInterval(() => { 25 | cryptoHttp.get(`price?fsym=${coin}&tsyms=BRL`).then((response) => { 26 | setPrices((prevState) => { 27 | if(prevState[coin].currentPrice === response.data.BRL){ 28 | return prevState; 29 | } 30 | return { 31 | ...prevState, 32 | [coin]: { 33 | oldPrice: prevState[coin].currentPrice, 34 | currentPrice: response.data.BRL 35 | } 36 | } 37 | }) 38 | }); 39 | }, 5000); 40 | }); 41 | return () => { 42 | intervals.forEach(interval => clearInterval(interval)) 43 | } 44 | 45 | }, []); 46 | return ( 47 |
48 | {Object.keys(prices).map((coin) => ( 49 |
onSelected(coin)}> 50 | 55 |
56 | ))} 57 |
58 | ); 59 | }; 60 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Legend/index.css: -------------------------------------------------------------------------------- 1 | .Legend{ 2 | position: absolute; 3 | left: 16px; 4 | top: 16px; 5 | z-index: 9999; 6 | font-size: 16px; 7 | font-weight: 300; 8 | color: rgba(255, 255, 255, 0.9) 9 | } -------------------------------------------------------------------------------- /integracao-continua-react-3/src/components/Legend/index.tsx: -------------------------------------------------------------------------------- 1 | // @flow 2 | import * as React from 'react'; 3 | import './index.css'; 4 | interface LegendProps { 5 | legend: string 6 | }; 7 | export const Legend: React.FC = (props) => { 8 | const {legend} = props; 9 | return ( 10 |
11 | {legend} 12 |
13 | ); 14 | }; -------------------------------------------------------------------------------- /integracao-continua-react-3/src/http/index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const apiKey = '56682a154c70b16b43bf33455d0b0c09f23e178ca82c3ad3c105ebbbf19bf21a'; 4 | 5 | export const cryptoHttp = axios.create({ 6 | baseURL: 'https://min-api.cryptocompare.com/data', 7 | headers: { 8 | authorization: `Apikey ${apiKey}` 9 | } 10 | }); -------------------------------------------------------------------------------- /integracao-continua-react-3/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './components/App'; 4 | import reportWebVitals from './reportWebVitals'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | 13 | // If you want to start measuring performance in your app, pass a function 14 | // to log results (for example: reportWebVitals(console.log)) 15 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 16 | reportWebVitals(); 17 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | } 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /integracao-continua-react-3/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /integracao-continua-react-3/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /microsservicos-aula-1/a/a.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/hashicorp/go-retryablehttp" 6 | "html/template" 7 | "io/ioutil" 8 | "log" 9 | "net/http" 10 | "net/url" 11 | ) 12 | 13 | type Result struct { 14 | Status string 15 | } 16 | 17 | func main() { 18 | http.HandleFunc("/", home) 19 | http.HandleFunc("/process", process) 20 | http.ListenAndServe(":9090", nil) 21 | } 22 | 23 | func home(w http.ResponseWriter, r *http.Request) { 24 | t := template.Must(template.ParseFiles("templates/home.html")) 25 | t.Execute(w, Result{}) 26 | } 27 | 28 | func process(w http.ResponseWriter, r *http.Request) { 29 | 30 | result := makeHttpCall("http://localhost:9091", r.FormValue("coupon"), r.FormValue("cc-number")) 31 | 32 | t := template.Must(template.ParseFiles("templates/home.html")) 33 | t.Execute(w, result) 34 | } 35 | 36 | func makeHttpCall(urlMicroservice string, coupon string, ccNumber string) Result { 37 | 38 | values := url.Values{} 39 | values.Add("coupon", coupon) 40 | values.Add("ccNumber", ccNumber) 41 | 42 | retryClient := retryablehttp.NewClient() 43 | retryClient.RetryMax = 5 44 | 45 | res, err := retryClient.PostForm(urlMicroservice, values) 46 | if err != nil { 47 | result := Result{Status: "Servidor fora do ar!"} 48 | return result 49 | } 50 | 51 | defer res.Body.Close() 52 | 53 | data, err := ioutil.ReadAll(res.Body) 54 | if err != nil { 55 | log.Fatal("Error processing result") 56 | } 57 | 58 | result := Result{} 59 | 60 | json.Unmarshal(data, &result) 61 | 62 | return result 63 | 64 | } 65 | -------------------------------------------------------------------------------- /microsservicos-aula-1/a/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Checkout example · Bootstrap 8 | 10 | 11 | 12 | 13 |
14 |
15 |

Checkout

16 |
17 | 18 | {{ if eq .Status ""}} 19 |
20 |
21 |
22 |

23 | Carrinho 24 | 1 25 |

26 |
    27 |
  • 28 |
    29 |
    Tênis Adidas
    30 |
    31 | R$ 100,00 32 |
  • 33 | 34 |
  • 35 | Total 36 | R$ 100,00 37 |
  • 38 |
39 | 40 |
41 | 42 |
43 |
44 |
45 |

Dados pessoais

46 |
47 |
48 | 49 | 50 |
51 |
52 | 53 | 54 |
55 |
56 | 57 |
58 | 59 |

Pagamento

60 | 61 | 62 |
63 |
64 | 65 | 66 |
67 |
68 | 69 | 70 |
71 |
72 |
73 |
74 | 75 | 76 | 77 |
78 |
79 | 80 | 81 |
82 |
83 |
84 | 85 |
86 |
87 |
88 | {{ else}} 89 |

Resultado da operação: {{ .Status }}

90 | {{end}} 91 | 92 | 95 | 96 |
97 | 98 | 99 | -------------------------------------------------------------------------------- /microsservicos-aula-1/b/b.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "net/http" 9 | "net/url" 10 | ) 11 | 12 | type Result struct { 13 | Status string 14 | } 15 | 16 | func main() { 17 | http.HandleFunc("/", home) 18 | http.ListenAndServe(":9091", nil) 19 | } 20 | 21 | func home(w http.ResponseWriter, r *http.Request) { 22 | coupon := r.PostFormValue("coupon") 23 | ccNumber := r.PostFormValue("ccNumber") 24 | 25 | resultCoupon := makeHttpCall("http://localhost:9092", coupon) 26 | 27 | result := Result{Status: "declined"} 28 | 29 | if ccNumber == "1" { 30 | result.Status = "approved" 31 | } 32 | 33 | if resultCoupon.Status == "invalid" { 34 | result.Status = "invalid coupon" 35 | } 36 | 37 | jsonData, err := json.Marshal(result) 38 | if err != nil { 39 | log.Fatal("Error processing json") 40 | } 41 | 42 | fmt.Fprintf(w, string(jsonData)) 43 | } 44 | 45 | 46 | func makeHttpCall(urlMicroservice string, coupon string) Result { 47 | 48 | values := url.Values{} 49 | values.Add("coupon", coupon) 50 | 51 | res, err := http.PostForm(urlMicroservice, values) 52 | if err != nil { 53 | result := Result{Status: "Servidor fora do ar!"} 54 | return result 55 | } 56 | 57 | defer res.Body.Close() 58 | 59 | data, err := ioutil.ReadAll(res.Body) 60 | if err != nil { 61 | log.Fatal("Error processing result") 62 | } 63 | 64 | result := Result{} 65 | 66 | json.Unmarshal(data, &result) 67 | 68 | return result 69 | 70 | } 71 | -------------------------------------------------------------------------------- /microsservicos-aula-1/c/c.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | "net/http" 8 | ) 9 | 10 | type Coupon struct { 11 | Code string 12 | } 13 | 14 | type Coupons struct { 15 | Coupon []Coupon 16 | } 17 | 18 | func (c Coupons) Check(code string) string { 19 | for _, item := range c.Coupon { 20 | if code == item.Code { 21 | return "valid" 22 | } 23 | } 24 | return "invalid" 25 | } 26 | 27 | type Result struct { 28 | Status string 29 | } 30 | 31 | var coupons Coupons 32 | 33 | func main() { 34 | coupon := Coupon{ 35 | Code: "abc", 36 | } 37 | 38 | coupons.Coupon = append(coupons.Coupon, coupon) 39 | 40 | http.HandleFunc("/", home) 41 | http.ListenAndServe(":9092", nil) 42 | } 43 | 44 | func home(w http.ResponseWriter, r *http.Request) { 45 | coupon := r.PostFormValue("coupon") 46 | valid := coupons.Check(coupon) 47 | 48 | result := Result{Status: valid} 49 | 50 | jsonResult, err := json.Marshal(result) 51 | if err != nil { 52 | log.Fatal("Error converting json") 53 | } 54 | 55 | fmt.Fprintf(w, string(jsonResult)) 56 | 57 | } -------------------------------------------------------------------------------- /microsservicos-aula-1/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/codeedu/avancadev-micrservice-1dia 2 | 3 | go 1.15 4 | 5 | require github.com/hashicorp/go-retryablehttp v0.6.7 6 | -------------------------------------------------------------------------------- /microsservicos-aula-1/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= 4 | github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 5 | github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= 6 | github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= 7 | github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo= 8 | github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= 12 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 13 | --------------------------------------------------------------------------------