-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
228 lines (215 loc) · 9.42 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
APIs created using Django.
Database - SQLITE
Models:
1. Movie:
Fields:
a. 'name' - Name of the movie(character field)
b. 'director' - Name of the director(character field)
c. 'imdb_score' - Imdb score of the movie(Decimal field - 2 decimal places)
d. 'popularity' - Popularity of the movie(Decimal field - 1 decimal place)
e. 'genres' - Different genres of the movie(Many-to-many fields)
2. Genres:
Fields:
a. 'name' - Name of the genre(character field)
Views:
MovieViewSet:
- ModelViewSet that uses Generic API view and different mixins to provide default CRUD operations
- To serialize the data we have used Movie Serializer.
- To filter data to be used in search, we have overridden SearchFilter to provide default and dynamic
fields
- We have overridden the default get_permission to allow only authenticated users to perform GET
method on the API
- And allow only Admin users to execute POST, PUT and PATCH methods, to create or update the movie data
Serializer:
MovieSerializer:
- The Movie serializer that returns the movie data and also adds the genre data with all its fields.
- Implemented custom create function since we have many-to-many relation in our data set
- New moive is created whilst checking if the genre already exists.
- Implemented custom update where the id of the genre that is passed in the API is loaded and available
here as instance.
- We update the instance on the with the data provided in the body.
- Same is used to make partial updates(PATCH)
Access level:
There are 2 levels of access:
1. Authenticated user - Has access only to movies list
2. Admin user - Has access to movies list, and can perform CRUD operations
on movies database
USERS:
Admin user:
username: admin
password: admin
Authenticated user:
username: alex
password: imdb1234
API:
LOGIN: To get the auth token for successive requests.
REQUEST:
URL - POST https://ahmedimdbapp.herokuapp.com/api/auth/token/login
Header - 'Content-Type: application/json'
body - {
"username": "alex",
"password": "imdb1234"
}
RESPONSE:
{
"auth_token": "a6e857632c4f751b9e65db5920ec1bb8db3ddc47"
}
MOVIE List: To get the list of all the movies. Default page limit for movies is 10.
REQUEST:
URL - GET https://ahmedimdbapp.herokuapp.com/imdb/movies/
GET https://ahmedimdbapp.herokuapp.com/imdb/movies/?page=2
HEADER - 'Content-Type: application/json'
- 'Authorization: Token a6e857632c4f751b9e65db5920ec1bb8db3ddc47'
RESPONSE:
{
"count": 248,
"next": "http://127.0.0.1:8000/imdb/movies/?page=3",
"previous": "http://127.0.0.1:8000/imdb/movies/",
"results": [
{
"id": 11,
"genres": [
{
"id": 7,
"name": "Drama"
},
{
"id": 14,
"name": "Crime"
}
],
"name": "The Godfather",
"director": "Francis Ford Coppola",
"imdb_score": "9.2",
"popularity": "92.0"
},
]
}
SEARCH Movies:
REQUEST:
URL - GET https://ahmedimdbapp.herokuapp.com/imdb/movies?search=wiz
GET https://ahmedimdbapp.herokuapp.com/imdb/movies?search=Victor&search_fields=director
HEADER - 'Content-Type: application/json'
- 'Authorization: Token a6e857632c4f751b9e65db5920ec1bb8db3ddc47'
RESPONSE:
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"genres": [
{
"id": 1,
"name": "Adventure"
},
{
"id": 2,
"name": "Family"
},
{
"id": 3,
"name": "Fantasy"
},
{
"id": 4,
"name": "Musical"
}
],
"name": "The Wizard of Oz",
"director": "Victor Fleming",
"imdb_score": "8.3",
"popularity": "83.0"
},
{
"id": 37,
"genres": [
{
"id": 1,
"name": "Adventure"
},
{
"id": 2,
"name": "Family"
},
{
"id": 3,
"name": "Fantasy"
},
{
"id": 18,
"name": "Comedy"
}
],
"name": "The Wizard of Oz",
"director": "Larry Semon",
"imdb_score": "5.3",
"popularity": "53.0"
}
]
}
CREATE Movie: Create movie, use admin token.
REQUEST:
URL - POST https://ahmedimdbapp.herokuapp.com/imdb/movies/
HEADER - 'Content-Type: application/json'
- 'Authorization: Token 52223333b674f40303f2cbb46e5cdce4cd801092'
BODY - {
"genres": [
{
"name": "Action"
}
],
"name": "Mars rover",
"director": "J K",
"imdb_score": "8.3",
"popularity": "8.2"
}
RESPONSE:
{
"id" : 250
"genres": [
{
"id" : 7
"name": "Action"
}
],
"name": "Mars rover",
"director": "J K",
"imdb_score": "8.3",
"popularity": "8.2"
}
Update Movie: Update movie(mention movie 'id' in the URL), use admin token.
REQUEST:
URL - PUT https://ahmedimdbapp.herokuapp.com/imdb/movies/25
HEADER - 'Content-Type: application/json'
- 'Authorization: Token 52223333b674f40303f2cbb46e5cdce4cd801092'
BODY - {
"genres": [
{
"name": "Action"
}
],
"name": "Mars rover 2",
"director": "J K",
"imdb_score": "8.7",
"popularity": "84.2"
}
RESPONSE:
{
"genres": [
{
"name": "Action"
}
],
"name": "Mars 2",
"director": "JK",
"imdb_score": "8.3",
"popularity": "8.2"
}
Delete Movie: Delete movie(mention movie 'id' in the URL), user admin token
REQUEST:
URL - Delete https://ahmedimdbapp.herokuapp.com/imdb/movies/25
HEADER - 'Content-Type: application/json'
- 'Authorization: Token 52223333b674f40303f2cbb46e5cdce4cd801092'
RESPONSE: