2023 Jul 19 9:24 AM - edited 2023 Aug 02 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!
2023 Jul 19 4:34 PM
2023 Jul 20 8:41 AM
Well done ✅
Interestingly, these terms never get translated and are pretty universal - good to know how it would be done though!
2023 Jul 19 4:40 PM
2023 Jul 20 8:39 AM
2023 Jul 19 9:10 PM
2023 Jul 20 8:39 AM
2023 Jul 19 9:22 PM
2023 Jul 20 8:39 AM
2023 Jul 19 11:01 PM
2023 Jul 20 8:39 AM
2023 Jul 20 2:44 AM
2023 Jul 20 8:38 AM
2023 Jul 20 5:29 AM
2023 Jul 20 8:38 AM
2023 Jul 20 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?
2023 Jul 20 5:48 AM - edited 2023 Jul 20 5:49 AM
Check your http file.
I also faced this similar issue, due to additional space after the curly {} brackets
2023 Jul 20 7:18 AM
2023 Jul 20 8:37 AM
2023 Jul 20 7:19 AM
2023 Jul 20 8:38 AM
2023 Jul 23 1:04 PM
2023 Jul 20 8:37 AM
2023 Jul 20 3:08 PM
2023 Jul 20 11:42 AM
2023 Jul 20 3:08 PM
2023 Jul 20 3:37 PM
2023 Jul 24 8:57 AM
2023 Jul 20 3:57 PM
2023 Jul 24 8:57 AM
2023 Jul 20 8:33 PM
2023 Jul 24 8:56 AM
2023 Jul 21 8:22 AM
2023 Jul 24 8:56 AM
2023 Jul 21 9:14 AM
2023 Jul 24 8:56 AM
2023 Jul 21 9:25 AM
Hi, here's my submission for the week, I hope that it's OK. thanks for organising this!
2023 Jul 24 8:56 AM
2023 Jul 21 10:35 AM
2023 Jul 24 8:56 AM