Skip to content
Merged
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# onibus-io-backend


##API
## API

* **/versao** : Versão da API;
* **/api/linhas** : Lista de linhas (sem tabela e sem pontos);
* **/api/linhas/{codigoLinha}** : Retorna a linha de acordo com o código.
* **/api/linhas/{codigoLinha}** : Retorna a linha de acordo com o código;
* **/api/veiculos** : Retorna uma lista de todos os veículos em circulação;
* **/api/veiculos/{codigoVeiculo}** : Retorna uma lista das últimas posições de um veículo;
* **/api/veiculos/linha/{codigoLinha}** : Retorna uma lista das últimas posições dos veículos de uma linha;

## FAQ

### Por que são retornados as últimas posições de um veículo e não apenas a última?

Isso é feito para que possamos calcular a direção para onde o veículo está indo.
22 changes: 4 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ package config
import "os"

const (
prefix = "CWBUS_"
serviceURL = "URBS_SERVICE_URL"
urbsCode = "URBS_CODE"
dbStrConn = "DB_URL"
dbName = "DB_HIST"
port = "PORT"
prefix = "ONIBUSIO_"
dbStrConn = "DB_URL"
dbName = "DB_HIST"
port = "PORT"
)

// Configurer é a interface que define um configurador no sistema.
type Configurer interface {
ServiceURL() string
UrbsCode() string
DBName() string
DBStrConn() string
Port() string
Expand All @@ -32,16 +28,6 @@ func (ec EnvConfigurer) getValue(name string) string {
return os.Getenv(ec.key(name))
}

// ServiceURL retorna a URL dos serviços da urbs.
func (ec EnvConfigurer) ServiceURL() string {
return ec.getValue(serviceURL)
}

// UrbsCode retorna o código urbs de acesso aos serviços.
func (ec EnvConfigurer) UrbsCode() string {
return ec.getValue(urbsCode)
}

// DBStrConn retorna a string de conexão do banco de dados.
func (ec EnvConfigurer) DBStrConn() string {
return ec.getValue(dbStrConn)
Expand Down
21 changes: 2 additions & 19 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,17 @@ import (

func TestConfig(t *testing.T) {
ec := EnvConfigurer{}
t.Run("Obtendo url de serviços da urbs", func(t *testing.T) {
want := os.Getenv("CWBUS_URBS_SERVICE_URL")
got := ec.ServiceURL()
test.AssertStringsEqual(t, want, got)
})

t.Run("Obtendo codigo urbs", func(t *testing.T) {
want := os.Getenv("CWBUS_URBS_CODE")
got := ec.UrbsCode()
test.AssertStringsEqual(t, want, got)
})

t.Run("Obtendo conexão com o banco", func(t *testing.T) {
want := os.Getenv("CWBUS_DB_URL")
want := os.Getenv("ONIBUSIO_DB_URL")
got := ec.DBStrConn()
test.AssertStringsEqual(t, want, got)
})

t.Run("Obtendo nome do banco", func(t *testing.T) {
want := os.Getenv("CWBUS_DB_HIST")
want := os.Getenv("ONIBUSIO_DB_HIST")
got := ec.DBName()
test.AssertStringsEqual(t, want, got)
})

t.Run("Obtendo url para acordar dyno", func(t *testing.T) {
want := os.Getenv("CWBUS_WAKEUP_URL")
got := ec.WakeUpURL()
test.AssertStringsEqual(t, want, got)
})

}