Skip to content

Commit 34e7f70

Browse files
Kandeel4411Aaron Suarez
and
Aaron Suarez
authored
Renamed all references of paid to true (#379)
Co-authored-by: Aaron Suarez <[email protected]>
1 parent 94f7d0a commit 34e7f70

19 files changed

+360
-331
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ run: build
6060
run_windows: build
6161
@cmd /c (IF NOT "$(shell ${DOCKER} ps -q -f name=resources-api)" == "" ${DOCKER_COMPOSE} down)
6262
${DOCKER_COMPOSE} run -p 5000:5000 ${RESOURCES_CONTAINER} ${FLASK} run -h 0.0.0.0
63-
63+
6464

6565
.PHONY: bg
6666
bg:

app/api/routes/resource_creation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def create_resources(json, db):
4444
# Create each Resource in the database one by one
4545
for resource in json:
4646
langs, categ = get_attributes(resource)
47-
paid_bool = ensure_bool(resource.get('paid'))
47+
free_bool = ensure_bool(resource.get('free'))
4848
new_resource = Resource(
4949
name=resource.get('name'),
5050
url=resource.get('url'),
5151
category=categ,
5252
languages=langs,
53-
paid=paid_bool,
53+
free=free_bool,
5454
notes=resource.get('notes'))
5555

5656
try:

app/api/routes/resource_modification.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def update_resource(id, json, db):
5757
if json.get('url'):
5858
resource.url = json.get('url')
5959
index_object['url'] = json.get('url')
60-
if 'paid' in json:
61-
paid = ensure_bool(json.get('paid'))
62-
resource.paid = paid
63-
index_object['paid'] = paid
60+
if 'free' in json:
61+
free = ensure_bool(json.get('free'))
62+
resource.free = free
63+
index_object['free'] = free
6464
if 'notes' in json:
6565
resource.notes = json.get('notes')
6666
index_object['notes'] = json.get('notes')

app/api/routes/resource_retrieval.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_resources():
4040
languages = request.args.getlist('languages')
4141
category = request.args.get('category')
4242
updated_after = request.args.get('updated_after')
43-
paid = request.args.get('paid')
43+
free = request.args.get('free')
4444

4545
q = Resource.query
4646

@@ -81,13 +81,13 @@ def get_resources():
8181
)
8282
)
8383

84-
# Filter on paid
85-
if isinstance(paid, str) and paid.lower() in ['true', 'false']:
86-
paidAsBool = paid.lower() == 'true'
87-
q = q.filter(Resource.paid == paidAsBool)
84+
# Filter on free
85+
if isinstance(free, str) and free.lower() in ['true', 'false']:
86+
freeAsBool = free.lower() == 'true'
87+
q = q.filter(Resource.free == freeAsBool)
8888

8989
# Order by "getting started" category
90-
if not languages and not category and paid is None:
90+
if not languages and not category and free is None:
9191
show_first = Category.query.filter(Category.name == "Getting Started").first()
9292
clause = (
9393
f" CASE resource.category_id"

app/api/routes/search.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ def search_results():
2020
page_size = request.args.get('page_size', Config.RESOURCE_PAGINATOR.per_page, int)
2121

2222
# Fetch the filter params from the url, if they were provided.
23-
paid = request.args.get('paid')
23+
free = request.args.get('free')
2424
category = request.args.get('category')
2525
languages = request.args.getlist('languages')
2626
filters = []
2727

28-
# Filter on paid
29-
if paid:
30-
paid = paid.lower()
28+
# Filter on free
29+
if free:
30+
free = free.lower()
3131
# algolia filters boolean attributes with either 0 or 1
32-
if paid == 'true':
33-
filters.append('paid=1')
34-
elif paid == 'false':
35-
filters.append('paid=0')
32+
if free == 'true':
33+
filters.append('free=1')
34+
elif free == 'false':
35+
filters.append('free=0')
3636

3737
# Filter on category
3838
if category:

app/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def create_resource(resource, db): # pragma: no cover
110110
url=resource['url'],
111111
category=resource['category'],
112112
languages=resource['languages'],
113-
paid=resource.get('paid'),
113+
free=resource.get('free'),
114114
notes=resource.get('notes', ''),
115115
upvotes=resource.get('upvotes', 0),
116116
downvotes=resource.get('downvotes', 0),
@@ -126,7 +126,7 @@ def update_resource(resource, existing_resource): # pragma: no cover
126126
existing_resource.name = resource['name']
127127
existing_resource.url = resource['url']
128128
existing_resource.category = resource['category']
129-
existing_resource.paid = resource.get('paid')
129+
existing_resource.free = resource.get('free')
130130
existing_resource.notes = resource.get('notes', '')
131131
existing_resource.languages = resource['languages']
132132

app/models.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Resource(TimestampMixin, db.Model):
2929
nullable=False)
3030
category = db.relationship('Category')
3131
languages = db.relationship('Language', secondary=language_identifier)
32-
paid = db.Column(db.Boolean, nullable=False, default=False)
32+
free = db.Column(db.Boolean, nullable=False, default=True)
3333
notes = db.Column(db.String)
3434
upvotes = db.Column(db.INTEGER, default=0)
3535
downvotes = db.Column(db.INTEGER, default=0)
@@ -54,7 +54,7 @@ def serialize(self):
5454
'url': self.url,
5555
'category': self.category.name,
5656
'languages': self.serialize_languages,
57-
'paid': self.paid,
57+
'free': self.free,
5858
'notes': self.notes,
5959
'upvotes': self.upvotes,
6060
'downvotes': self.downvotes,
@@ -84,7 +84,7 @@ def __eq__(self, other):
8484
for attribute in [
8585
"name",
8686
"url",
87-
"paid",
87+
"free",
8888
"notes",
8989
"category",
9090
"languages",

app/static/openapi.yaml

+23-23
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ paths:
116116
type: string
117117
required: true
118118
- in: query
119-
name: paid
119+
name: free
120120
required: false
121-
description: Whether the resource is paid or not. To search for *free* resources, make a `GET` request to `/search?paid=false`.
121+
description: Whether the resource is free or not. To search for *free* resources, make a `GET` request to `/search?free=true`.
122122
schema:
123123
type: boolean
124124
- in: query
@@ -152,7 +152,7 @@ paths:
152152
last_updated: '2019-05-25 18:52:15'
153153
name: 'C Tutorial'
154154
notes: 'Learn C with our popular C tutorial, which will take you from the very basics of C all the way through sophisticated topics like binary trees and data structures.'
155-
paid: false
155+
free: true
156156
times_clicked: 0
157157
upvotes: 0
158158
url: 'https://www.cprogramming.com/tutorial/c-tutorial.html'
@@ -394,7 +394,7 @@ paths:
394394
last_updated: '2019-06-15 17:55:32'
395395
name: 'Free Tech Books'
396396
notes: 'Focuses on general computer science concepts rather than a specific language'
397-
paid: false
397+
free: true
398398
times_clicked: 0
399399
upvotes: 0
400400
url: 'http://www.freetechbooks.com/'
@@ -443,7 +443,7 @@ paths:
443443
last_updated: '2019-07-22 16:05:53'
444444
name: 'Updated Book Title'
445445
notes: null
446-
paid: false
446+
free: true
447447
times_clicked: 3
448448
upvotes: 1
449449
url: 'http://www.test.com'
@@ -506,7 +506,7 @@ paths:
506506
last_updated: '2019-07-26 13:47:52'
507507
name: 'Thinking Forth'
508508
notes: null
509-
paid: false
509+
free: true
510510
times_clicked: 2
511511
upvotes: 0
512512
url: 'http://thinking-forth.sourceforge.net/'
@@ -550,7 +550,7 @@ paths:
550550
last_updated: '2020-03-12 23:17:52'
551551
name: 'Teach Your Kids to Code'
552552
notes: null
553-
paid: true
553+
free: false
554554
times_clicked: 0
555555
upvotes: 1
556556
url: 'http://teachyourkidstocode.com/'
@@ -594,7 +594,7 @@ paths:
594594
last_updated: '2020-03-12 23:17:52'
595595
name: 'Teach Your Kids to Code'
596596
notes: null
597-
paid: true
597+
free: false
598598
times_clicked: 0
599599
upvotes: 0
600600
url: 'http://teachyourkidstocode.com/'
@@ -611,9 +611,9 @@ paths:
611611
- List Resources
612612
parameters:
613613
- in: query
614-
name: paid
614+
name: free
615615
required: false
616-
description: Whether the resource is paid or not. To search for *free* resources, make a `GET` request to `/resources?paid=false`.
616+
description: Whether the resource is free or not. To search for *free* resources, make a `GET` request to `/resources?free=true`.
617617
schema:
618618
type: boolean
619619
- in: query
@@ -654,7 +654,7 @@ paths:
654654
last_updated: '2019-07-22 17:39:50'
655655
name: 'Some, but not ALL of the knowledge'
656656
notes: null
657-
paid: false
657+
free: true
658658
times_clicked: 3
659659
upvotes: 1
660660
url: 'http://www.test.com'
@@ -685,7 +685,7 @@ paths:
685685

686686
post:
687687
summary: Create Resources
688-
description: Creates new learning resources. The structure of the request is a list of resource objects. The required properties for each new resource are `category`, `name`, `paid`, and `url`.
688+
description: Creates new learning resources. The structure of the request is a list of resource objects. The required properties for each new resource are `category`, `name`, `free`, and `url`.
689689
tags:
690690
- Create Resources
691691
requestBody:
@@ -696,7 +696,7 @@ paths:
696696
example:
697697
- category: 'Tutorial'
698698
name: 'CSS Tutorial'
699-
paid: false
699+
free: true
700700
url: 'https://www.w3schools.com/css/'
701701
required: true
702702
responses:
@@ -718,7 +718,7 @@ paths:
718718
last_updated: '2019-07-22 16:05:53'
719719
name: 'CSS Tutorial'
720720
notes: null
721-
paid: false
721+
free: true
722722
times_clicked: 3
723723
upvotes: 1
724724
url: 'https://www.w3schools.com/css/'
@@ -744,11 +744,11 @@ paths:
744744
- url
745745
resource: 'https://resources.operationcode.org/api/v1/2137'
746746
missing-params:
747-
message: 'The following params were missing: name, category, paid.'
747+
message: 'The following params were missing: name, category, free.'
748748
params:
749749
- name
750750
- category
751-
- paid
751+
- free
752752
status: 'Unprocessable Entity'
753753
status_code: 422
754754
security:
@@ -984,7 +984,7 @@ components:
984984
CreateResourcesRequest:
985985
allOf:
986986
- $ref: '#/components/schemas/ResourcesRequest'
987-
# - required: [category, name, paid, url]
987+
# - required: [category, name, free, url]
988988

989989
ResourcesRequest:
990990
type: array
@@ -1005,9 +1005,9 @@ components:
10051005
notes:
10061006
type: string
10071007
description: Resource notes
1008-
paid:
1008+
free:
10091009
type: boolean
1010-
description: True or false for whether resource is paid
1010+
description: True or false for whether resource is free
10111011
url:
10121012
type: string
10131013
description: Resource url
@@ -1028,9 +1028,9 @@ components:
10281028
notes:
10291029
type: string
10301030
description: Resource notes
1031-
paid:
1031+
free:
10321032
type: boolean
1033-
description: True or false for whether resource is paid
1033+
description: True or false for whether resource is free
10341034
url:
10351035
type: string
10361036
description: Resource url
@@ -1066,9 +1066,9 @@ components:
10661066
notes:
10671067
type: string
10681068
description: Resource notes
1069-
paid:
1069+
free:
10701070
type: boolean
1071-
description: True or false for whether resource is paid
1071+
description: True or false for whether resource is free
10721072
upvotes:
10731073
type: integer
10741074
description: Positive ratings

app/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def format_resource_search(hit):
6767
'url': hit['url'],
6868
'category': hit['category'],
6969
'languages': hit['languages'],
70-
'paid': hit['paid'],
70+
'free': hit['free'],
7171
'notes': hit['notes'],
7272
'upvotes': hit['upvotes'],
7373
'downvotes': hit['downvotes'],

migrations/versions/fc34137ad3ba_.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Rename paid column to free
2+
3+
Revision ID: fc34137ad3ba
4+
Revises: 205742d3b3f5
5+
Create Date: 2020-09-30 22:35:20.007768
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlalchemy_utils
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = 'fc34137ad3ba'
15+
down_revision = '205742d3b3f5'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.alter_column('resource', 'paid', new_column_name='free', existing_type=sa.Boolean, nullable=False)
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade():
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.alter_column('resource', 'free', new_column_name='paid', existing_type=sa.Boolean, nullable=True)
29+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)