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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,6 @@ expo-env.d.ts


ios/
android/
android/

*.env
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
4 changes: 4 additions & 0 deletions .trunk/configs/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Following source doesn't work in most setups
ignored:
- SC1090
- SC1091
2 changes: 2 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prettier friendly markdownlint config (all formatting rules disabled)
extends: markdownlint/style/prettier
7 changes: 7 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
14 changes: 14 additions & 0 deletions .trunk/configs/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false, // https://github.com/svg/svgo/issues/1128
sortAttrs: true,
removeOffCanvasPaths: true,
},
},
},
],
};
41 changes: 41 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.2
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.0
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
actions:
disabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
enabled:
- trunk-upgrade-available
4 changes: 3 additions & 1 deletion Backend/delivery_api/app/handlers/solicitations.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func CreateSolicitation(msg string, sendMessageToClient func(clientID int64, mes
}

collection := models.MongoDabase.Collection("solicitations")
log.Println(orderDTO)

filter := bson.M{"orderid": orderDTO.OrderId}

Expand Down Expand Up @@ -152,8 +153,8 @@ func GetApprovedSolicitations(c *fiber.Ctx) error {
if err != nil {
return err
}
defer cur.Close(context.Background())

defer cur.Close(context.Background())
for cur.Next(context.Background()) {
var orderDTO dto.OrderDTO
err := cur.Decode(&orderDTO)
Expand All @@ -165,6 +166,7 @@ func GetApprovedSolicitations(c *fiber.Ctx) error {
distance := calculateDistance(latitude, longitude, orderDTO.Establishment.Lat, orderDTO.Establishment.Long)

// Se a distância for menor ou igual ao limite de distância, adiciona a solicitação à lista

if distance <= limitDist {
approvedSolicitations = append(approvedSolicitations, orderDTO)
}
Expand Down
1 change: 1 addition & 0 deletions Backend/delivery_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func startQueueListener() {
// Processar mensagens recebidas
for msg := range msgs {
bodyStr := string(msg.Body)
log.Printf("\n MENSAGEM ", bodyStr)
handlers.CreateSolicitation(bodyStr, sendMessageToClient)
}
}
Expand Down
1 change: 1 addition & 0 deletions Backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ services:
- RABBIT_DELIVERY_QUEUE=MS_DELIVERY_QUEUE
- RABBIT_ORDER_QUEUE=RABBIT_ORDER_QUEUE
- URL_GET_ESTABLISHMENT_ID=http://api-gateway/api/auth/establishments/%d
- GOOGLE_MAPS_API_KEY=
networks:
- gateway-network
ports:
Expand Down
68 changes: 68 additions & 0 deletions Backend/docs/delivery.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,40 @@
},
"response": []
},
{
"name": "Create Delivery - Avulso",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{AUTH_TOKEN}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"cart\": [\n {\n \"item\": {\n \"ID\": 0,\n \"Name\": \"Pizza Margherita\",\n \"Description\": \"Uma deliciosa pizza com molho de tomate, queijo mozzarella e folhas de manjericão fresco.\",\n \"Price\": 0,\n \"Image\": \"\",\n \"EstablishmentID\": 0,\n \"Categories\": null,\n \"Additional\": []\n },\n \"additionals\": [],\n \"quantity\": 1,\n \"id\": \"UTG5ksjsMUNBcqZ\"\n }\n ],\n \"distance\": 1.1365938003231386,\n \"location\": {\n \"cep\": \"01001-000\",\n \"logradouro\": \"Praça da Sé\",\n \"complemento\": null,\n \"bairro\": \"Sé\",\n \"localidade\": \"São Paulo\",\n \"uf\": \"SP\",\n \"ibge\": \"3550308\",\n \"gia\": \"1004\",\n \"ddd\": \"11\",\n \"siafi\": \"7107\",\n \"numero\": \"6\",\n \"coords\": {\n \"latitude\": -21.7725387727999,\n \"longitude\": -43.35824173879191\n }\n },\n \"paymentMethod\": {\n \"type\": \"credit\",\n \"icon\": \"credit-score\"\n },\n \"deliveryValue\": 3.12,\n \"user\": {\n \"phone\": \"(11) 98844-9999\",\n \"nome\": \"Ronan Silva\"\n },\n \"establishmentId\": 0,\n \"establishment\": {\n \"HorarioFuncionamento\": \"\",\n \"Id\": 1,\n \"Image\": \"https://cdn.pixabay.com/photo/2020/05/25/08/40/food-delivery-5217579_1280.png\",\n \"lat\": -21.7725387727999,\n \"long\": -43.35824173879191,\n \"max_distance_delivery\": 99999,\n \"name\": \"Luana Carla da Silva\",\n \"owner_id\": 1,\n \"primary_color\": \"#8B0000\",\n \"secondary_color\": \"#F0F8FF\",\n \"location_string\": \"Av. Atlântica, 1642 - Cavaleiros, Macaé - RJ, 27920-390, Brazil\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{API_GATEWAY}}/api/order/orders-single",
"host": [
"{{API_GATEWAY}}"
],
"path": [
"api",
"order",
"orders-single"
]
}
},
"response": []
},
{
"name": "Update Status Order",
"request": {
Expand Down Expand Up @@ -1471,6 +1505,40 @@
}
},
"response": []
},
{
"name": "Orders Single - Avulsa sem restaurante",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{AUTH_TOKEN}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"cart\": [\n {\n \"item\": {\n \"ID\": 0,\n \"Name\": \"Pizza Margherita\",\n \"Description\": \"Uma deliciosa pizza com molho de tomate, queijo mozzarella e folhas de manjericão fresco.\",\n \"Price\": 0,\n \"Image\": \"\",\n \"EstablishmentID\": 0,\n \"Categories\": null,\n \"Additional\": []\n },\n \"additionals\": [],\n \"quantity\": 1,\n \"id\": \"UTG5ksjsMUNBcqZ\"\n }\n ],\n \"distance\": 1.1365938003231386,\n \"location\": {\n \"cep\": \"01001-000\",\n \"logradouro\": \"Praça da Sé\",\n \"complemento\": null,\n \"bairro\": \"Sé\",\n \"localidade\": \"São Paulo\",\n \"uf\": \"SP\",\n \"ibge\": \"3550308\",\n \"gia\": \"1004\",\n \"ddd\": \"11\",\n \"siafi\": \"7107\",\n \"numero\": \"6\",\n \"coords\": {\n \"latitude\": -21.7725387727999,\n \"longitude\": -43.35824173879191\n }\n },\n \"paymentMethod\": {\n \"type\": \"credit\",\n \"icon\": \"credit-score\"\n },\n \"deliveryValue\": 20.00,\n \"user\": {\n \"phone\": \"(11) 98844-9999\",\n \"nome\": \"Ronan Silva\"\n },\n \"establishment\": {\n \"horarioFuncionamento\": \"\",\n \"image\": \"https://cdn.pixabay.com/photo/2020/05/25/08/40/food-delivery-5217579_1280.png\",\n \"lat\": -21.7725387727991,\n \"long\": -43.35824173879191,\n \"max_distance_delivery\": 1000,\n \"name\": \"Luana Carla da Silva\",\n \"owner_id\": 0,\n \"primary_color\": \"#8B0000\",\n \"secondary_color\": \"#F0F8FF\",\n \"location_string\": \"Av. Atlântica, 1642 - Cavaleiros, Macaé - RJ, 27920-390, Brazil\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{API_GATEWAY}}/api/order/orders-single",
"host": [
"{{API_GATEWAY}}"
],
"path": [
"api",
"order",
"orders-single"
]
}
},
"response": []
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion Backend/orders_api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ MONGO_DATABASE=orders_mongo_db
RABBIT_CONNECTION=amqp://guest:guest@localhost:5672/
RABBIT_DELIVERY_QUEUE=MS_DELIVERY_QUEUE
URL_GET_ESTABLISHMENT_ID=http://localhost/api/auth/establishments/%d
RABBIT_ORDER_QUEUE=RABBIT_ORDER_QUEUE
RABBIT_ORDER_QUEUE=RABBIT_ORDER_QUEUE
GOOGLE_MAPS_API_KEY=
99 changes: 99 additions & 0 deletions Backend/orders_api/app/handlers/localization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package handlers

import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
)

type Coords struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}

type Location struct {
Cep string `json:"cep"`
Logradouro string `json:"logradouro"`
Complemento string `json:"complemento"`
Bairro string `json:"bairro"`
Localidade string `json:"localidade"`
Uf string `json:"uf"`
Ibge string `json:"ibge"`
Gia string `json:"gia"`
Ddd string `json:"ddd"`
Siafi string `json:"siafi"`
Numero string `json:"numero"`
Coords Coords `json:"coords"`
}

func GetLocationDetails(address string) (*Location, error) {
apiKey := os.Getenv("GOOGLE_MAPS_API_KEY")

apiURL := "https://maps.googleapis.com/maps/api/geocode/json"
reqURL := fmt.Sprintf("%s?address=%s&key=%s", apiURL, url.QueryEscape(address), apiKey)

resp, err := http.Get(reqURL)
if err != nil {
return nil, fmt.Errorf("failed to make request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("received non-200 response code: %d", resp.StatusCode)
}

var geocodeResponse struct {
Results []struct {
AddressComponents []struct {
LongName string `json:"long_name"`
ShortName string `json:"short_name"`
Types []string `json:"types"`
} `json:"address_components"`
Geometry struct {
Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
} `json:"location"`
} `json:"geometry"`
FormattedAddress string `json:"formatted_address"`
} `json:"results"`
Status string `json:"status"`
}

if err := json.NewDecoder(resp.Body).Decode(&geocodeResponse); err != nil {
return nil, fmt.Errorf("failed to decode response: %v", err)
}

if geocodeResponse.Status != "OK" {
return nil, fmt.Errorf("geocoding API error: %s", geocodeResponse.Status)
}

// Extrair as informações do primeiro resultado
result := geocodeResponse.Results[0]
location := &Location{}

for _, component := range result.AddressComponents {
for _, t := range component.Types {
switch t {
case "postal_code":
location.Cep = component.LongName
case "route":
location.Logradouro = component.LongName
case "sublocality", "sublocality_level_1", "political":
location.Bairro = component.LongName
case "administrative_area_level_2":
location.Localidade = component.LongName
case "administrative_area_level_1":
location.Uf = component.ShortName
}
}
}

// Coordenadas geográficas
location.Coords.Latitude = result.Geometry.Location.Lat
location.Coords.Longitude = result.Geometry.Location.Lng

return location, nil
}
Loading