Skip to content

feat(api): add donor profile, API and temporary screen - #91

Open
MarcAntoineGmd wants to merge 1 commit into
developfrom
feature/63-donor-profile
Open

MarcAntoineGmd wants to merge 1 commit into
developfrom
feature/63-donor-profile

Conversation

@MarcAntoineGmd

Copy link
Copy Markdown
Collaborator

Closes #63

Overview

The goal of this ticket is to complete the donor profile so a donor can be created, viewed and edited, with what is needed to identify them now and to issue their tax receipt later (#83, #84). It adds the profile columns, an API to create, read and update a donor, server-side validation, and a temporary profile screen in the desktop app.

To confirm with Nafissa before merging: the acceptance criterion "The address is sufficient to appear on a receipt" depends on her. The profile now stores the street address, the city, the province and the postal code. There is no country column, since donors are in Canada.

donors: the table already existed (#15). It keeps name, address (now the street address), postal_code, contact_person and created_at, and gets:

  • type (varchar(20), not null): individual or organization, checked by ck_donors_type. An individual and an organization are named differently on a receipt.
  • city (varchar(100)) and province (varchar(50))
  • email (varchar(254)), phone (varchar(30)) and notes (text)
  • business_central_code (varchar(50)): unique through ix_donors_business_central_code, and not empty when set (ck_donors_business_central_code_not_empty). Many donors can have no code. The comparison is exact, like the catalog code, so C-100 and c-100 are two codes.
  • updated_at (timestamptz, stored in UTC): empty until the donor is edited

Required fields: the API requires name, type, street address, city, province and postal code. In the database only name and type are not null, so the donors that already exist and the donors brought in by the Business Central import (#78) are not blocked by a missing address.

Existing donors: the migration gives them the type organization, then removes the default, so a new donor must state its type. This step is written by hand in the migration, with an XML note to keep it if the migration is regenerated. Their city, province and other new columns stay empty, to complete by hand. In code, a Donor created without a type is an organization, which keeps the existing tests that create donors unchanged. The API always requires the type.

API (api/donors):

Action Request Who
View GET api/donors/{id} Any signed-in employee
Create POST api/donors ManageDonors: Supply, Supply Director, Admin
Edit PUT api/donors/{id} ManageDonors: Supply, Supply Director, Admin
  • An unknown donor id returns 404, and so does an id that is not a GUID.
  • A missing or invalid field returns 400 with exactly one message per field, keyed by the field name. Every field is trimmed and has a maximum length, an email must be a valid email address, and an empty optional field is stored as null.
  • A Business Central code that another donor already uses returns 409.
  • The list of donors and the search by name are a separate feature of the PRD, so there is no list endpoint here.

Temporary screen: the Donors page of the desktop app opens a donor by its id, creates a donor and edits it. Each message from the API is shown under its field, and 404, 409, 401 and 403 each show their own message. The desktop app does not sign in yet (#9 is not merged), so every call shows "You must be signed in to manage donors" until it is.

Changes:

  • Donor entity: new properties and maximum lengths, and DonorTypes (individual, organization) in src/MoissonMontreal.Core/Entities/
  • DonorRequest and DonorDto in src/MoissonMontreal.Core/Dtos/
  • DonorConfiguration: new columns, checks and the unique Business Central code
  • DonorValidator in src/MoissonMontreal.Api/Donors/ and DonorsController
  • Migration 20261118185010_AddDonorProfile and the snapshot
  • Desktop: IApiClient, ApiClient, FakeApiClient, DonorResult, DonorsViewModel, DonorsView, DesignData, and MainViewModel now passes the API client to the donors page
  • Docs:
    • docs/database/donors.md, donors.dbml and images/donors.png
    • docs/database/sql/0007_add_donor_profile.sql, generated from the migration, without BOM
    • the donors table updated in schema.dbml, receipts.dbml, prices.dbml and quality-classes.dbml, with their images re-exported
    • schema.md: donors section, rules and migration table
  • SchemaDriftTests: the "missing default" case now includes the new updated_at line of donors, since it searches the exact text around created_at

Testing:

  • dotnet test: 435 tests pass, 80 of them new
  • DonorValidatorTests (43):
    • a full profile is trimmed and accepted, and both types are accepted
    • each required field missing, empty or blank gives exactly one message for that field
    • a type other than individual or organization is refused, including Organization and INDIVIDUAL
    • every field accepts its longest value and refuses one more character
    • invalid emails are refused, including a display name and two addresses
    • blank optional fields become null
    • several problems at once give one message per field
  • DonorEndpointTests (25):
    • 401 without a token
    • create returns 201 with the location and every field, and dates in UTC
    • view and edit, including changing the type, emptying optional fields and removing the code
    • 404 on GET and PUT for an unknown id, and on GET for an id that is not a GUID
    • 400 with exactly one message per missing field, and an invalid edit leaves the donor unchanged
    • 409 on a duplicate code on create and on edit, including a code that only differs by spaces
    • two donors without a code are accepted
    • Supply, Supply Director and Admin can create and edit, Finance gets 403 on create and edit but can view
  • DonorProfileMigrationTests (12):
    • existing donors are kept and become organizations
    • the type default is removed after the migration
    • every new column is stored, and updated_at is saved in UTC
    • exact constraint names: ck_donors_type, ck_donors_business_central_code_not_empty, ix_donors_business_central_code
    • many donors without a code are accepted
    • rolling back removes the new columns and keeps the donors
  • Manual, on PostgreSQL 17:
    • scripts 0001 to 0007 run in order on a database that already had a donor, which became an organization
    • a donor without a type, with the type company, with an empty code, or with a code already used was refused by the expected rule
    • two donors without a code, and the codes C-1 and c-1, were accepted
    • the rollback script removed the new columns and kept the 5 donors
  • The desktop app builds without warnings. The screen was not tested against the API, since the desktop does not sign in yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant