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>
73 lines
1.8 KiB
Elixir
73 lines
1.8 KiB
Elixir
defmodule MyFirstElixirVibeCode.Reviews.Review do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
schema "reviews" do
|
|
field :rating, :integer
|
|
field :title, :string
|
|
field :content, :string
|
|
field :project_type, :string
|
|
field :client_first_name, :string
|
|
field :client_last_name, :string
|
|
field :client_street_address, :string
|
|
field :client_city, :string
|
|
field :client_state, :string
|
|
field :client_zip, :string
|
|
field :client_country, :string
|
|
field :municipal_registration_proof, :string
|
|
field :work_permit_proof, :string
|
|
field :contractor_id, :id
|
|
field :client_id, :id
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
@doc false
|
|
def changeset(review, attrs) do
|
|
review
|
|
|> cast(attrs, [
|
|
:rating,
|
|
:title,
|
|
:content,
|
|
:project_type,
|
|
:client_first_name,
|
|
:client_last_name,
|
|
:client_street_address,
|
|
:client_city,
|
|
:client_state,
|
|
:client_zip,
|
|
:client_country,
|
|
:municipal_registration_proof,
|
|
:work_permit_proof
|
|
])
|
|
|> validate_required([
|
|
:rating,
|
|
:title,
|
|
:content,
|
|
:project_type,
|
|
:client_first_name,
|
|
:client_last_name,
|
|
:client_street_address,
|
|
:client_city,
|
|
:client_state,
|
|
:client_zip
|
|
])
|
|
|> validate_number(:rating, greater_than_or_equal_to: 1, less_than_or_equal_to: 5)
|
|
|> validate_at_least_one_document()
|
|
end
|
|
|
|
defp validate_at_least_one_document(changeset) do
|
|
municipal_proof = get_field(changeset, :municipal_registration_proof)
|
|
work_permit = get_field(changeset, :work_permit_proof)
|
|
|
|
if is_nil(municipal_proof) && is_nil(work_permit) do
|
|
add_error(
|
|
changeset,
|
|
:municipal_registration_proof,
|
|
"You must provide either municipal registration or work permit proof"
|
|
)
|
|
else
|
|
changeset
|
|
end
|
|
end
|
|
end
|