# IWS5.AdminApi
The IWS5.AdminApi project is a work-in-progress RESTful API which provides endpoints and methods for client applications to consume to facilitate the management of configurations by administrator users of the Process Director system. This API is consumed by the work-in-progress [React iAdmin (react-iAdmin)](https://github.com/Greenfield-Investments/react-iAdmin) application.

The IWS5.AdminApi project exists only in the FEMA branch of the iWS5 solution. The below documentation is for the FEMA branch only.

## Controllers & Linked Projects
The primary code found in this project are the [Controllers](Controllers/), which have names ending in `Controller.cs` (auto-detected by ASP.NET) and expose API endpoints for consumption by client applications. These controllers call service methods in the [IWS5.Services](../IWS5.Services/) project.

Additionally, IWS5.AdminApi links the [IWS5.Api](../IWS5.Api/) project in such a way that the admin API also provides all of the endpoints and methods of the standard API. This is primarily done so that the same authentication methods can be used, however it also provides the ability for client applications consuming the admin API to use existing IWS5.Api methods when necessary.

All IWS5.AdminApi endpoints begin with `/admin`, as opposed to IWS5.Api endpoints which begin with `/api`.

## Code Inconsistencies
As with the IWS5.Api project, there are some inconsistencies to do with HTTP response codes, JSON data formatting, and error handling across the methods provided by the admin API. Since the IWS5.Api project is linked to the admin API, all inconsistencies in that project carry over. However, the admin API has fewer inconsistencies and is generally more in line with RESTful development standards.

## Development & Configuration
The IWS5.AdminApi project has a single `appsettings.json` file which contains configuration variables that must be set/updated for the admin API to run:

1. LDAP variables (used for Active Directory authentication):
    1. `server` - The hostname of an Active Directory controller, accessible over the network. Can be either an IP address, hostname, or FQDN.
    2. `port` - The port used for LDAP connection. The default `389` will suffice for most deployments, but `636` can be used for secure connections.
    3. `subDomain` - The subdomain of the Active Directory domain to connect to. If your domain is `gfi.com`, this value would be `gfi`.
    4. `domain` - The extension of the Active Directory domain to connect to. If your domain is `gfi.com`, this value would be `com`.
2. Connection strings (used for database connection):
    1. `GreenfieldPD` - The full connection string to authenticate with a local or production copy of the Process Director database. For example: `Data Source=MY-DATABASE-SERVER;User ID=PDAdmin;Password=MY_SECURE_PASSWORD;Initial Catalog=ProcessDirector;Encrypt=True;Trust Server Certificate=True`. In general, this string is dependent on the SQL Server configuration, but the PDAdmin user (with the `sysadmin` role on the server) should be used.
3. Serilog (logging) - The important variable(s) here are `path`, which control where API log files are written to. The default location is recommended, but can be changed at will.

The [IWS5.AdminApi setup package script](https://github.com/Greenfield-Investments/setup-packages/tree/main/IWS5.AdminApi) modifies the `appsettings.json` file with the values for the LDAP and database connections provided by the user during installation.

## Additional Notes
The IWS5.AdminApi project is essentially just an extension of the IWS5.Api project, meaning all the same notes for the IWS5.Api project (such as additional/missing methods vs the LPNU branch) apply.

The `appsettings.json` file for the admin API takes priority over its IWS5.Api equivalents, meaning that the database connection and etc. set for the admin API will always be used during development and upon publishing.

One other important note is to do with scheduling: the scheduling API methods use the `ATScheduledItem` database table, *not* `ATScheduledItem-old`. A scheduler is not implemented in the admin API, only the methods to read, create, update, and delete schedules.