BobTheFarmer / VACTQ-Typing-Game

Apache License 2.0
0 stars 1 forks source link

Players API #11

Open BobTheFarmer opened 1 year ago

BobTheFarmer commented 1 year ago

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:

Spring Understanding (2)

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
    }