Features: - User registration and authentication with email/password - Admin login with username-based authentication (separate from regular users) - Review system for contractors to rate clients - Star rating system with review forms - Client identification with private data protection - Contractor registration with document verification - Admin dashboard for review management - Contact form (demo, non-functional) - Responsive navigation with DaisyUI components - Docker Compose setup for production deployment - PostgreSQL database with Ecto migrations - High Vis color scheme (dark background with safety orange/green) Admin credentials: username: admin, password: admin123 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
133 lines
2.4 KiB
Elixir
133 lines
2.4 KiB
Elixir
defmodule MyFirstElixirVibeCode.Reviews do
|
|
@moduledoc """
|
|
The Reviews context.
|
|
"""
|
|
|
|
import Ecto.Query, warn: false
|
|
alias MyFirstElixirVibeCode.Repo
|
|
|
|
alias MyFirstElixirVibeCode.Reviews.Review
|
|
|
|
@doc """
|
|
Returns the list of reviews.
|
|
|
|
## Examples
|
|
|
|
iex> list_reviews()
|
|
[%Review{}, ...]
|
|
|
|
"""
|
|
def list_reviews do
|
|
Repo.all(Review)
|
|
end
|
|
|
|
@doc """
|
|
Searches reviews by client name or address.
|
|
|
|
## Examples
|
|
|
|
iex> search_reviews("john")
|
|
[%Review{}, ...]
|
|
|
|
iex> search_reviews("")
|
|
[%Review{}, ...]
|
|
|
|
"""
|
|
def search_reviews(""), do: list_reviews()
|
|
|
|
def search_reviews(query) when is_binary(query) do
|
|
search_term = "%#{query}%"
|
|
|
|
from(r in Review,
|
|
where:
|
|
ilike(r.client_first_name, ^search_term) or
|
|
ilike(r.client_last_name, ^search_term) or
|
|
ilike(r.client_street_address, ^search_term) or
|
|
ilike(r.client_city, ^search_term) or
|
|
ilike(r.client_state, ^search_term) or
|
|
ilike(r.client_zip, ^search_term)
|
|
)
|
|
|> Repo.all()
|
|
end
|
|
|
|
@doc """
|
|
Gets a single review.
|
|
|
|
Raises `Ecto.NoResultsError` if the Review does not exist.
|
|
|
|
## Examples
|
|
|
|
iex> get_review!(123)
|
|
%Review{}
|
|
|
|
iex> get_review!(456)
|
|
** (Ecto.NoResultsError)
|
|
|
|
"""
|
|
def get_review!(id), do: Repo.get!(Review, id)
|
|
|
|
@doc """
|
|
Creates a review.
|
|
|
|
## Examples
|
|
|
|
iex> create_review(%{field: value})
|
|
{:ok, %Review{}}
|
|
|
|
iex> create_review(%{field: bad_value})
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
"""
|
|
def create_review(attrs) do
|
|
%Review{}
|
|
|> Review.changeset(attrs)
|
|
|> Repo.insert()
|
|
end
|
|
|
|
@doc """
|
|
Updates a review.
|
|
|
|
## Examples
|
|
|
|
iex> update_review(review, %{field: new_value})
|
|
{:ok, %Review{}}
|
|
|
|
iex> update_review(review, %{field: bad_value})
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
"""
|
|
def update_review(%Review{} = review, attrs) do
|
|
review
|
|
|> Review.changeset(attrs)
|
|
|> Repo.update()
|
|
end
|
|
|
|
@doc """
|
|
Deletes a review.
|
|
|
|
## Examples
|
|
|
|
iex> delete_review(review)
|
|
{:ok, %Review{}}
|
|
|
|
iex> delete_review(review)
|
|
{:error, %Ecto.Changeset{}}
|
|
|
|
"""
|
|
def delete_review(%Review{} = review) do
|
|
Repo.delete(review)
|
|
end
|
|
|
|
@doc """
|
|
Returns an `%Ecto.Changeset{}` for tracking review changes.
|
|
|
|
## Examples
|
|
|
|
iex> change_review(review)
|
|
%Ecto.Changeset{data: %Review{}}
|
|
|
|
"""
|
|
def change_review(%Review{} = review, attrs \\ %{}) do
|
|
Review.changeset(review, attrs)
|
|
end
|
|
end
|