manuelroemer / abap-lab-ss23-csrd

The CSRD Reporting application, written with ABAP and UI5.
GNU Affero General Public License v3.0
7 stars 0 forks source link

User Story: Create the Customer API #28

Open manuelroemer opened 1 year ago

manuelroemer commented 1 year ago

Description

As a user, I want to be able to associate a filled out questionnaire with a customer. For this sake, I need the system to manage customer data for me.

This requires the creation of a new OData entity called Customer with the following attributes:

The OData service should offer the following endpoints:

Acceptance Criteria

Additional Information

None.

manuelroemer commented 1 year ago

Customer API implementation:

  METHOD customerset_get_entityset.
    DATA(filter) = io_tech_request_context->get_osql_where_clause(  ).
    SELECT *
    FROM z00t1_customer
    WHERE (filter)
    ORDER BY name ASCENDING
    INTO CORRESPONDING FIELDS OF TABLE @et_entityset.
  ENDMETHOD.

  METHOD customerset_get_entity.
    DATA(id) = get_key( it_key_tab = it_key_tab key = 'Id' ).

    SELECT SINGLE *
    FROM z00t1_customer
    WHERE id = @id
    INTO @er_entity.
  ENDMETHOD.

  METHOD customerset_create_entity.
    io_data_provider->read_entry_data( IMPORTING es_data = er_entity ).
    GET TIME STAMP FIELD DATA(now).

    er_entity-mandt = sy-mandt.
    er_entity-id = cl_system_uuid=>create_uuid_c36_static( ).
    er_entity-createdat = now.
    er_entity-updatedat = now.

    INSERT z00t1_customer FROM er_entity.
  ENDMETHOD.

  METHOD customerset_update_entity.
    io_data_provider->read_entry_data( IMPORTING es_data = er_entity ).
    DATA(id) = get_key( it_key_tab = it_key_tab key = 'Id' ).
    GET TIME STAMP FIELD DATA(now).

    UPDATE z00t1_customer
    SET name = @er_entity-name,
        customercode = @er_entity-customercode,
        updatedat = @now
    WHERE id = @id.
  ENDMETHOD.

  METHOD customerset_delete_entity.
    DATA(id) = get_key( it_key_tab = it_key_tab  key = 'Id' ).
    DELETE FROM z00t1_customer WHERE id = @id.
    DELETE FROM z00t1_fschemares WHERE customerid = @id.
  ENDMETHOD.

  METHOD verify_customer_exists.
    SELECT COUNT( * )
    FROM z00t1_customer
    WHERE id = @id
    INTO @DATA(count).

    IF count = 0.
      RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
        EXPORTING
          message          = |The customer with the ID { id } does not exist.|
          http_status_code = 404.
    ENDIF.
  ENDMETHOD.

Postman: Image