Skip to content

Commit

Permalink
Merge pull request #4 from swbengs/final_touches_for_handin
Browse files Browse the repository at this point in the history
Final touches for handin
  • Loading branch information
swbengs authored Mar 8, 2019
2 parents 237ef0c + c01c7c4 commit 5587e78
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
35 changes: 27 additions & 8 deletions api_design.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
# api design file

## URL(names are not final)
all api have a prefix of /api/ which I will not keep re-typing. An example: /api/pokemon?page=1 would get the pagination result
## API calls
- All calls are designed to work with HTTP GET. A few need the URL line querys such as page or email. You can type in the fields just like shown below in a browser to test the API
- Making a program or app to do this for you is even better but more time consuming
- Tested in Laravel Homestead version 8.02

## URL
all api have a prefix of /api/ which I will not keep re-typing. An example: /api/pokemon?page=1 would get the pagination result. I will only show the pokemon?page=1 part the api is assumed to have been added

### Required
1. page(get page JSON of pokemon page number and or setting for # per page)
2. pokemon(single pokemon pokemon id to display info for)
3. register(new trainer requires email and password) return api token used for trainer api calls like mark, marked
4. caught(api token id of pokemon to mark caught)
5. all_caught(api token. Returns all pokemon caught. Probably just pokemon id and name)
1. pokemon?page=pagenumber&per_page=perpage //views all pokemon available. per_page is not required. The default if not there is 15. page starts at 1 and goes until the last pokemon is shown. In our case it's number 553. Extra data from laravel is sent back such as previous and next page number
2. pokemon/number //replace number with an actua number. pokemon/7 shows squirtle, who has an id of 7
3. register?name=name&email=email&password=password&password_confirmation=password //all these GET fields are required. Replace the part after = with the actual name/email and so on
4. trainer?api_token=token //View the given user who has the sent API token's caught pokemon
5. trainer/mark?api_token=token&pokemon_id=id //Marks the pokemon with said id as caught for the trainer who matches the api token given. pokemon_id=7 would set squirtle as caught since it has an id of 7. These are all aquired from viewing them individually or by pagination

### Trainer/User related
* A trainers user name is their email they give
* After registering and after all logins, a new API token is generated. This is required to access the caught pokemon list and to add more pokemon to the list
1. login?email=email&password=password //login with user. All fields required. Creates new api token. Previous one is invalid
2. logout?email=email&password=password //logout with user. All fields required. Clears the users api token so it is invalid

### Admin
1. setup(allows all tables to be wiped and started clean. Should probably have authentication and or password but first version will just be available to anyone who knows of it)
1. admin/setup //fills in the pokemon related tables. Tables must be manually cleared between runs of this command. Only needs to be done once. If you wipe the DB for any reason just run it again

### Debug/dev
1. test(simple test route)

### Example of how to use
1. View single pokemon or view the pagination form to get an idea of what pokemon are out there. Note pokemon id numbers for later use
2. Create a trainer with register. Keep the api_token that is passed back to you. Username is your email. Don't forget your password.
3. Login and logout as needed to make new api tokens or clear old ones. You can stay logged in as long as you want. The system will not auto log you out.
4. Use this to start marking pokemon you have caught with trainer?apitoken&pokemon_id GET fields. If you caught a blastoise send it with pokemon_id=9 for example.
5. View pokemon you have caught. Some basic information about the trainer is sent back and a JSON array with the id and name of all pokemon you listed as caught.
6. Enjoy!

### Sample routes for homestead
* Single pokemon get
* http://192.168.10.10:8000/api/pokemon/1 gets pokemon with id of 1. in this case Bulbasaur
Expand Down
4 changes: 4 additions & 0 deletions branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
2. Can be merged once Pokemon is fully ready with a way to automatically load the CSV file properly
3. Way to list single pokemon
4. Way to list pokemon in pages aka pagination
3. Phase 2
1. Adding in support for trainer aka user
2. Authentication for trainer related pages
3. Way to view and mark pokemon as caught for a specific trainer
2 changes: 0 additions & 2 deletions design.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ The models themselves will control the tables but this will guide the models to
Method to take pokemon information and place it all correctly in the required tables. Again simply an abstraction so we don't have to worry about how the pokemon is actually stored. Many controllers can use it so it should be shared.
Controllers calling other controllers is bad design from what I've read

## Important notes

2 changes: 2 additions & 0 deletions design_file_descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
- List all public api URL
- List admin URL
- List debug/dev URL
- Sample URLs for Homestead to show how it works

0 comments on commit 5587e78

Please sign in to comment.