- This is a REST API microservice which handles companies. Is exposes REST API to create, get, patch and delete a company.
- Postgres database is used for persistance.
- Only authenticated users will be able to access create, patch and delete API
- Get company API in not protected.
.
├── Dockerfile
├── Makefile
├── README.md
├── api
│ ├── constants
│ │ └── constants.go
│ ├── controller
│ │ ├── company.go
│ │ └── login.go
│ ├── database
│ │ └── db.go
│ ├── dto
│ │ └── dto.go
│ ├── errors
│ │ └── errors.go
│ ├── logging
│ │ └── logger.go
│ ├── middleware
│ │ └── auth.go
│ ├── models
│ │ └── models.go
│ ├── repository
│ │ ├── mocks
│ │ │ └── mock_repository.go
│ │ ├── repository.go
│ │ └── repository_test.go
│ ├── router
│ │ └── router.go
│ ├── service
│ │ ├── auth.go
│ │ ├── company.go
│ │ ├── company_test.go
│ │ ├── login.go
│ │ └── mocks
│ │ └── mock_company.go
│ └── utils
│ └── utils.go
├── companies
├── db-migration
│ ├── Dockerfile
│ ├── V1__create_table_companies.sql
│ └── flyway.conf
├── docs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── e2e
│ ├── docker-compose.yml
│ └── e2e_test.go
├── go.mod
├── go.sum
└── main.go
- go 1.20+
- docker
- docker compose
- golangci-lint ref
$ make format
$ make lint
$ make test-unit
$ make test-e2e
$ make start-all-services
$ make stop-all-services
- APIs are listed in swagger endpoint
http://localhost:8080/api/company/v1/swagger/index.html#/
- This microservices currently supports only static authentication which has only one user, the credentials are
{
"email": "admin@company.com",
"password": "password"
}
All URIs are relative to http://127.0.0.1:8080/api/company/v1
create company
creation of new company
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
CreateCompany | body | request body | Yes | models.Company |
authorization | header | string | Yes | string |
Code | Description | Schema |
---|---|---|
201 | Created | models.Company |
400 | Bad Request | errors.ErrorResponse |
403 | Forbidden | errors.ErrorResponse |
500 | Internal Server Error | errors.ErrorResponse |
get company
get company info by ID
Code | Description | Schema |
---|---|---|
200 | OK | models.Company |
400 | Bad Request | errors.ErrorResponse |
403 | Forbidden | errors.ErrorResponse |
500 | Internal Server Error | errors.ErrorResponse |
delete a company
delete company by ID
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
authorization | header | string | Yes | string |
Code | Description | Schema |
---|---|---|
200 | OK | string |
400 | Bad Request | errors.ErrorResponse |
403 | Forbidden | errors.ErrorResponse |
500 | Internal Server Error | errors.ErrorResponse |
update a company
update company by ID
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
updateReq | body | request body | Yes | models.Company |
authorization | header | string | Yes | string |
Code | Description | Schema |
---|---|---|
200 | OK | models.Company |
400 | Bad Request | errors.ErrorResponse |
403 | Forbidden | errors.ErrorResponse |
500 | Internal Server Error | errors.ErrorResponse |
Name | Type | Description | Required |
---|---|---|---|
error_code | string | No | |
error_message | string | No | |
status | integer | No |
Name | Type | Description | Required |
---|---|---|---|
amount_of_employees | integer | No | |
ceated_at | string | No | |
description | string | No | |
id | string | No | |
name | string | No | |
registered | boolean | No | |
type | string | No | |
updated_at | string | No |
- To connect this microservice with external DB, export below env variables.
DB_HOST=<host>
DB_PORT=<port>
DB_USER=<user>
DB_PWD=<password>
DB_NAME=<name>
DB_SSL_MODE=<ssl mode>
-
Clone the repo
-
Navigate to project directory
- $ cd companies
-
Build the application by following command
- $ go build -o companies main.go
-
Make sure you have a postgres database up and running and env variables are set
-
Run the application by the following command
- $ ./companies
Alternatively, using docker,
-
Clone the repo
-
Navigate to project directory
- $ cd companies
-
Build the docker image by following command
- $ docker build -t companies:1.0 .
-
Make sure you have a postgres database up and running and env variables are set
-
Run the application by the following command
- $ docker run -p 8080:8080 companies:1.0