ubeac / ubeac-api

Source of uBeac .NET Core packages
3 stars 2 forks source link

Implement Exposing Enums #89

Closed ilhesam closed 2 years ago

ilhesam commented 2 years ago

GET: /API/Enums/GetAll Returns enums that have EnumAttribute or exists in EnumConfiguration.AllowedToExpose. πŸ˜€ Also, enums exists in EnumConfiguration.NotAllowedToExpose will not be returned!

Scenario 1 - I want expose test enum with EnumAttrbute: ❕ Due to the existence of enum attribute, this enum is exposed

[Enum(DisplayName = "This is enum name", Description = "This is enum description")]
public enum TestEnum
{
    [EnumValue(DisplayName = "This is A name", Description = "This is A description")] A,
    [EnumValue(DisplayName = "This is B name", Description = "This is B description")] B,
    [EnumValue(DisplayName = "This is C name", Description = "This is C description")] C
}

Scenario 2 - I want expose test enum with adding to EnumConfiguration.AllowedToExpose: ❕ This code can located inside Startup.cs ❕ This method can be used when we want to expose the enum outside the assembly or project

EnumConfiguration.AllowExposing(typeof(TestEnum));

Scenario 3 - I do not want expose test enum: ❕ This code can located inside Startup.cs ❕ This method can be used when we do not want an enum to be exposed

EnumConfiguration.BlockExposing(typeof(TestEnum));

Sample Output:

{
  "pageSize": 1,
  "totalPages": 1,
  "pageNumber": 1,
  "totalCount": 1,
  "hasPrevious": false,
  "hasNext": false,
  "data": [
    {
      "displayName": "This is enum name",
      "name": "TestEnum",
      "description": "This is enum description",
      "values": [
        {
          "value": 0,
          "displayName": "This is A name",
          "name": "A",
          "description": "This is A description"
        },
        {
          "value": 1,
          "displayName": "This is B name",
          "name": "B",
          "description": "This is B description"
        },
        {
          "value": 2,
          "displayName": "This is C name",
          "name": "C",
          "description": "This is C description"
        }
      ]
    }
  ],
  "errors": [],
  "debug": [],
  "traceId": "4000014d-0005-fc00-b63f-84710c7967bb",
  "sessionId": "4000014d-0005-fc00-b63f-84710c7967bb",
  "duration": 183.7795,
  "code": 200
}