Aaron has been working on this API for a while but it has not worked. He has run into a lot of errors. I am going to try a new attempt, but by modifying the existing jokes code. This should help me find all the problems as I find them one by one.
The problems
Null data error: This error happened because I made significant changes to the API without deleting the sqlite.db file. What would happen is the data in the same table would be formatted in two different ways, leading to too many types of data and resulting and empty or 'null' data. This is not permitted with security standards
CORs error: This was the error that I got stuck on for the longest. After researching it, CORs is a browser security protocol to protect users from malicious attacks. I eventually figured out I had to configure CORs inside the security file in spring.
New understanding of Spring
After making this API and the phrases API, I think I understand Spring a lot better than before. This section will go over what I learned.
I found that Spring is very similar to the python API from CSP, but with much more abstraction, making it a little harder to understand but also easier to use once you understand it. This graph outlines my understanding of how it works:
Final API
Once I fixed the errors and had a better understanding of Spring, it was easy to create the players API. All I did was modify jokes to make the jokes into names, and added a position value.
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(unique=true)
private String joke;
private int pos;
//private int pos;
// starting jokes
public static String[] init() {
final String[] playerNames2 = {
"P1",
"P2",
"P3",
"P4"
};
return playerNames2;
Optional<PTest> optional = repository.findById(id);
if (optional.isPresent()) { // Good ID
PTest joke = optional.get(); // value from findByID
joke.setPos(newPos); // increment value
repository.save(joke); // save entity
return new ResponseEntity<>(joke, HttpStatus.OK); // OK HTTP response: status code, headers, and body
}
New Approach
Aaron has been working on this API for a while but it has not worked. He has run into a lot of errors. I am going to try a new attempt, but by modifying the existing jokes code. This should help me find all the problems as I find them one by one.
The problems
New understanding of Spring
After making this API and the phrases API, I think I understand Spring a lot better than before. This section will go over what I learned.
I found that Spring is very similar to the python API from CSP, but with much more abstraction, making it a little harder to understand but also easier to use once you understand it. This graph outlines my understanding of how it works:
Final API
Once I fixed the errors and had a better understanding of Spring, it was easy to create the players API. All I did was modify jokes to make the jokes into names, and added a position value.