aboutsummaryrefslogtreecommitdiff
path: root/api/internal
AgeCommit message (Collapse)Author
2024-03-18clean up, add better error handlingZach Berwaldt
2024-03-16remove unnessary logs. remove logger and recovery, default has theseZach Berwaldt
2024-03-15cleanupZach Berwaldt
2024-03-15add newline, clean up testZach Berwaldt
2024-03-15add env samples, move filesZach Berwaldt
2024-03-15Add routes for preference, clean up and add typesZach Berwaldt
2024-03-07feat: Update authentication route and add comments to exported membersZach Berwaldt
- The authentication route in the API has been updated to use a new router setup function. - Comments have been added to all exported members of the `auth.go` module in the internal controllers package.
2024-03-07Refactor router and middleware packagesZach Berwaldt
- Move middleware functions from `main.go` to `middleware.go` in the `middleware` package. - Update import statements in `main.go` and use the `router` package instead of the `controllers` package. ``` Refactor router and middleware packages Move middleware functions from `main.go` to `middleware.go` in the `middleware` package. Update import statements in `main.go` and use the `router` package instead of the `controllers` package. ```
2024-03-07chore: Update paths in test and database configurationZach Berwaldt
This commit updates the paths in the test suite and database configuration to reflect the new directory structure. In the `api/cmd/main_test.go` file, the path for the config file is changed from `viper.SetConfigName(".env")` to `viper.SetConfigFile("../.env")` and `viper.AddConfigPath(".")` is added for configuration purposes. Additionally, `viper.AutomaticEnv()` is added to enable automatic environment variable configuration. In the same file, error handling is improved by adding explicit checks and error messages. The `api/internal/database/database.go` file is also modified, updating the path for database initialization from `"../db/water.sqlite3"` to `"../../db/water.sqlite3"`. These changes ensure proper configuration and functioning of the application.
2024-03-07Add CORS middleware and authentication middleware to the API server.Zach Berwaldt
The `setupRouter` function in `main.go` now includes a CORS middleware and a token authentication middleware. The CORS middleware allows cross-origin resource sharing by setting the appropriate response headers. The token authentication middleware checks for the presence of an `Authorization` header with a valid bearer token. If the token is missing or invalid, an unauthorized response is returned. In addition to these changes, a new test file `main_test.go` has been added to test the `/api/v1/auth` route. This test suite includes two test cases: one for successful authentication and one for failed authentication. Update go.mod to include new dependencies. The `go.mod` file has been modified to include two new dependencies: `github.com/spf13/viper` and `github.com/stretchr/testify`. Ignore go.sum changes. Ignore changes in the `go.sum` file, as they only include updates to existing dependencies.