07-19-2023 9:24 AM - edited 08-02-2023 2:14 PM
Please note that this challenge is closed. The deadline for receiving a badge upon successful completion has passed. Check out this new challenge for the month of August.
Welcome to the third week of this month's SAP Developer Challenge. This week we are going to learn how to use event handlers with the SAP Cloud Application Programming Model.
After moving to the SAP Business Application Studio and adding some sample data to our application last week, it's now time to explore some more features and capabilities of the SAP Cloud Application Programming Model. One of those is event handling, which will be our focus for this week.
Let's say we would like to enhance our application by automatically populating a new data field for the entity Holes. We would like to know what score a player scored on a hole, but not as a number, rather as one of the following strings: "birdie", "par", "bogey" (and a few more, see table below). These terms are frequently used in golf to describe the score a player scored on a hole in relation to the hole's par (par = expected score from a professional player). Let's say it took the player 4 shots to get the ball into the hole on a par 4 - that is a par. If it took the player only 3 shots on that same hole - that would be a birdie. See the table below for all mappings.
The described requirement is a perfect use case for event handling in CAP. As described in the documentation, calculated fields should be pre-calculated whenever a new entry is written into the database (instead of calculating on every read operation). This means we need a custom event handler for the CREATE operation on the Holes entity.
This is what you have to do to successfully complete this week's challenge:
1. Create a new property result: String; in the schema definition of the Holes entity. This is where we will store "par", "birdie", "bogey" etc..
Score in relation to par | String |
score - par = -3 | albatross |
score - par = -2 | eagle |
score - par = -1 | birdie |
score - par = 0 | par |
score - par = +1 | bogey |
score - par = +2 | double bogey |
score - par = +3 | triple bogey |
score = 1 | hole in one |
POST http://localhost:4004/browse/Holes
Content-Type: application/json
{
"score": 3,
"par": 4
}
We have gathered a few helpful resources for this week's challenge. Feel free to use the comments sections if you have question or need help.
Good luck and happy learning!
07-19-2023 4:34 PM
07-20-2023 8:41 AM
Well done ✅
Interestingly, these terms never get translated and are pretty universal - good to know how it would be done though!
07-19-2023 4:40 PM
07-20-2023 8:39 AM
07-19-2023 9:10 PM
07-20-2023 8:39 AM
07-19-2023 9:22 PM
07-20-2023 8:39 AM
07-19-2023 11:01 PM
I have used POSTMAN here. I will deploy this in BAS and test it with .http file later->
Here is my submission for Week 3. Please check ->
1. Create Round
2. Create Hole Entry ->
07-20-2023 8:39 AM
07-20-2023 2:44 AM
07-20-2023 8:38 AM
07-20-2023 5:29 AM
07-20-2023 8:38 AM
07-20-2023 5:40 AM
I am receiving this error when posting the json:
, "message": "Deserialization Error: Unexpected token in JSON at position 33."
Here's link to gitrepo- https://github.com/abapalways/cap-developer-challenge1/blob/main/srv/cat-service.js
Can anyone help?
07-20-2023 5:48 AM - edited 07-20-2023 5:49 AM
Check your http file.
I also faced this similar issue, due to additional space after the curly {} brackets
07-20-2023 7:18 AM
07-20-2023 8:37 AM
07-20-2023 7:19 AM
07-20-2023 8:38 AM
07-23-2023 1:04 PM
07-20-2023 8:37 AM
07-20-2023 3:08 PM
07-20-2023 11:42 AM
07-20-2023 3:08 PM
07-20-2023 3:37 PM
07-24-2023 8:57 AM
07-20-2023 3:57 PM
07-24-2023 8:57 AM
07-20-2023 8:33 PM
07-24-2023 8:56 AM
07-21-2023 8:22 AM
07-24-2023 8:56 AM
07-21-2023 9:14 AM
07-24-2023 8:56 AM
07-21-2023 9:25 AM
07-24-2023 8:56 AM
07-21-2023 10:35 AM
07-24-2023 8:56 AM