Code Monkey home page Code Monkey logo

odata-basics-handsonsapdev's Introduction

Back to basics: OData

REUSE status

Description

This repository contains a simple OData service to accompany the "Back to basics: OData" series on the Hands-on SAP Dev live stream show.

Getting started

After cloning this repo and moving into the repo top directory, first set things up by installing the required packages:

npm install

Then, after deploying to a local SQLite database, start the service up:

cds deploy --to sqlite
cds run

Requirements

To use this repository you can make use of a GitHub Codespace - just open this repo up in a new codespace and you're all set.

Download and installation

To enjoy these scripts, you don't have to download or install anything. But you can of course clone this repository to have the content available to you locally.

Support

Support for the content in this repository is available during the Hands-on SAP Dev live stream episodes.

Contributing

Please refer to the CONTRIBUTING.md file.

Code of conduct

SAP adopts the Contributor's Covenant 2.0 across our open source projects to ensure a welcoming and open culture for everyone involved. Please follow the standard Code of Conduct link in this repository to find out more.

License

Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

odata-basics-handsonsapdev's People

Contributors

ospo-bot[bot] avatar qmacro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odata-basics-handsonsapdev's Issues

Filter query : Categories with fewer than 10 products not working

Hi DJ,
First of all Thanks for the amazing content on odata filter.

the filter query Categories?$filter=Products/$count lt 10 does not work and throws an error . I am running it via postman

this is my whole query
https://developer-challenge.cfapps.eu10.hana.ondemand.com/odata/v4/northbreeze/Categories?$filter=Products/$count lt 10

Is there any changes in the filters ??
{
"error": {
"code": "500",
"message": "/An association can't be used as a value in an expression/"
}
}

Authorization with JWT

Hello DJ, I was wondering how would it be possible to integrate mutators (e.g. a bound action) to specific roles inside JWT tokens. is there a way to simplify the access control mapping the functions/actions to specific roles and finally JWT?

Annotations

What they are, how they're defined and consumed

README.md - Getting Started

In the README.md, section Getting started, the user is advised:

After cloning this repo and moving into the repo top directory, first deploy to a local SQLite database and then start the service up:

cds deploy --to sqlite
cds run

May I suggest adding npm install to the bash commands, so the required packages are installed?

Can $filter be applied at multiple levels in an expand?

In today's episode, there was a question at around 58:30 about applying the system query option $filter to multiple levels in an $expand request, and whether it is possible. The context was this OData resource URL:

http://localhost:4004/northwind-model/Categories?$expand=Products($filter=Discontinued eq true)

and the wording of the question was: "can we combine filter on both Categories and Products entity set?".

The answer is: yes.

Here's an example (based on the CAP-based OData service defined in this repository) that uses the Suppliers entity set instead of the Categories entity set simply because there's more data for us with which to find a meaningful filter example.

If we want to retrieve the suppliers in the UK, and, alongside the supplier information itself, want a list of their products, but only products that have low stock (say, 15 units or fewer), we could ask for all of this in a single OData query operation thus:

http://localhost:4004/northwind-model/Suppliers
?$filter=Country eq 'UK'
&$expand=Products($filter=UnitsInStock le 15)

There are two filters at work here, one on the Suppliers entity set, and one on the Products entity set (remember that there's a managed association in the schema linking a supplier to their products).

This results in a JSON representation of that resource, that looks like this:

{
  "@odata.context": "$metadata#Suppliers(Products())",
  "value": [
    {
      "SupplierID": 1,
      "CompanyName": "Exotic Liquids",
      "ContactName": "Charlotte Cooper",
      "ContactTitle": "Purchasing Manager",
      "Address": "49 Gilbert St.",
      "City": "London",
      "Region": "NULL",
      "PostalCode": "EC1 4SD",
      "Country": "UK",
      "Phone": "(171) 555-2222",
      "Fax": "NULL",
      "HomePage": "NULL",
      "Products": [
        {
          "ProductID": 3,
          "ProductName": "Aniseed Syrup",
          "QuantityPerUnit": "12 - 550 ml bottles",
          "UnitPrice": 10,
          "Category_CategoryID": 2,
          "Supplier_SupplierID": 1,
          "UnitsInStock": 13,
          "UnitsOnOrder": 70,
          "ReorderLevel": 25,
          "Discontinued": false
        }
      ]
    },
    {
      "SupplierID": 8,
      "CompanyName": "Specialty Biscuits Ltd.",
      "ContactName": "Peter Wilson",
      "ContactTitle": "Sales Representative",
      "Address": "29 King's Way",
      "City": "Manchester",
      "Region": "NULL",
      "PostalCode": "M14 GSD",
      "Country": "UK",
      "Phone": "(161) 555-4448",
      "Fax": "NULL",
      "HomePage": "NULL",
      "Products": [
        {
          "ProductID": 21,
          "ProductName": "Sir Rodney's Scones",
          "QuantityPerUnit": "24 pkgs. x 4 pieces",
          "UnitPrice": 10,
          "Category_CategoryID": 3,
          "Supplier_SupplierID": 8,
          "UnitsInStock": 3,
          "UnitsOnOrder": 40,
          "ReorderLevel": 5,
          "Discontinued": false
        },
        {
          "ProductID": 68,
          "ProductName": "Scottish Longbreads",
          "QuantityPerUnit": "10 boxes x 8 pieces",
          "UnitPrice": 12.5,
          "Category_CategoryID": 3,
          "Supplier_SupplierID": 8,
          "UnitsInStock": 6,
          "UnitsOnOrder": 10,
          "ReorderLevel": 15,
          "Discontinued": false
        }
      ]
    }
  ]
}

CDS deploy --to sqlite error

I tried to follow your instructions of your youtube video for VS code "cds deploy --to sqlite", but it returns with error: cds : File C:\Users\XXXXX\AppData\Roaming\npm\cds.ps1 cannot be loaded. The file C:\Users\XXXXX\AppData\Roaming\npm\cds.ps1 is not digitally signed. You cannot run this script on the current system.
For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • cds deploy --to sqlite
  • CategoryInfo : SecurityError: (:) [], PSSecurityException
  • FullyQualifiedErrorId : UnauthorizedAccess

I tried to google, but did not found a working solution, will you know why? thanks Sam

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.