|
|
|
@ -1,6 +1,6 @@ |
|
|
|
This is a web application written using the Phoenix web framework. |
|
|
|
This is a web application written using the Phoenix web framework. |
|
|
|
|
|
|
|
|
|
|
|
## Project guidelines |
|
|
|
## Project Overview |
|
|
|
|
|
|
|
|
|
|
|
- **Always** run unit tests with `mix test.unit` and autoformat with `mix format` after making edits |
|
|
|
- **Always** run unit tests with `mix test.unit` and autoformat with `mix format` after making edits |
|
|
|
- Use `mix precommit` alias when you are done with all changes and fix any pending issues |
|
|
|
- Use `mix precommit` alias when you are done with all changes and fix any pending issues |
|
|
|
@ -46,6 +46,44 @@ This is a Nostr relay built with Phoenix 1.8 / Elixir. It stores and serves Nost |
|
|
|
|
|
|
|
|
|
|
|
REST API at `/api/events` (show, create, delete) with JSON rendering. Uses `FallbackController` for error handling. |
|
|
|
REST API at `/api/events` (show, create, delete) with JSON rendering. Uses `FallbackController` for error handling. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Development Guidelines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Elixir Code Style Rules |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Avoid excessively nested expressions. Prefer named variables to incrementally store results. Example: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```elixir |
|
|
|
|
|
|
|
# BAD: Deeply nested result expression |
|
|
|
|
|
|
|
def query_events(filter_map) do |
|
|
|
|
|
|
|
with {:ok, filter} <- Filter.from_map(filter_map) do |
|
|
|
|
|
|
|
events = |
|
|
|
|
|
|
|
from(e in Event) |
|
|
|
|
|
|
|
|> Filter.apply(filter) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, |
|
|
|
|
|
|
|
Enum.map(events, fn event -> |
|
|
|
|
|
|
|
{:ok, pub_event} = PubEvent.from_db(event) |
|
|
|
|
|
|
|
pub_event |
|
|
|
|
|
|
|
end)} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GOOD: Build the result incrementally with named variables |
|
|
|
|
|
|
|
def query_events(filter_map) when is_map(filter_map) do |
|
|
|
|
|
|
|
with {:ok, filter} <- Filter.from_map(filter_map), |
|
|
|
|
|
|
|
events <- |
|
|
|
|
|
|
|
from(e in Event) |
|
|
|
|
|
|
|
|> Filter.apply(filter), |
|
|
|
|
|
|
|
pub_events <- |
|
|
|
|
|
|
|
Enum.map(events, fn event -> |
|
|
|
|
|
|
|
{:ok, pub_event} = PubEvent.from_db(event) |
|
|
|
|
|
|
|
pub_event |
|
|
|
|
|
|
|
end) do |
|
|
|
|
|
|
|
{:ok, pub_events} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### Test Structure |
|
|
|
### Test Structure |
|
|
|
|
|
|
|
|
|
|
|
- Tests tagged `@moduletag :unit` run with `mix test.unit` (no DB). |
|
|
|
- Tests tagged `@moduletag :unit` run with `mix test.unit` (no DB). |
|
|
|
|