-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BE User's Weekly Dashboard #49
Open
stefanjbloom
wants to merge
13
commits into
main
Choose a base branch
from
feat/user-dashboard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+484
β94
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
94d8e65
Feat: controller/testing suite/serializer for dashboard created. updβ¦
stefanjbloom bcbf391
Feat: dashboard serializer built to use relationships to render nesteβ¦
stefanjbloom 2685f9d
Refactor: dashboard route no longer generates a dashboard/:id for /daβ¦
stefanjbloom 2242609
Refactor/Feat: pulled main and now postman is showing serialized respβ¦
stefanjbloom ee16197
Merge branch 'main' of github.com:turingschool/tracker-crm into feat/β¦
stefanjbloom 542c601
Feat/Refactor: factored job and contact policies to allow autho. gettβ¦
stefanjbloom f3f6bd3
Refactor/Test: CompanyPolicy testing green. refactored out pseudo in β¦
stefanjbloom 2ed4961
Test/Refactor: remove pseudo and ContactPolicy testing green
stefanjbloom 4d3db36
Refactor/Test: minor policy refactors to align user id w/ given resouβ¦
stefanjbloom 521d8c4
Refactor/Test: all user request specs green except for #create actionβ¦
stefanjbloom 4dc69eb
Test/Refactor: dashboard controller minor refactor and now testing green
stefanjbloom 282b33f
Docs: readme updated for this dashboard endpoint
stefanjbloom f21995e
Bug: image for rspec failures
stefanjbloom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -716,6 +716,124 @@ Response: 422 Unprocessable Entity | |
"error": "Phone number must be in the format '555-555-5555'" | ||
} | ||
``` | ||
### User Dashboard | ||
|
||
Get login credentials: <br> | ||
`Refer to Companies "Get login credentials" above` | ||
|
||
**Make sure to not only create/login a user, but to have that user also create a Company/Job Application/Contact for your Postman scripts. Refer to above endpoints to do so and make sure that user is the one creating the other resources** | ||
|
||
#### Get Dashboard | ||
Request: | ||
|
||
``` | ||
GET /api/v1/users/:user_id/dashboard | ||
|
||
Authorization: Bearer Token - put in token for user | ||
``` | ||
Successful Response: | ||
|
||
``` | ||
{ | ||
"data": { | ||
"id": "5", | ||
"type": "dashboard", | ||
"attributes": { | ||
"id": 5, | ||
"name": "Danny DeVito", | ||
"email": "[email protected]", | ||
"dashboard": { | ||
"weekly_summary": { | ||
"job_applications": [ | ||
{ | ||
"id": 1, | ||
"position_title": "Jr. CTO", | ||
"date_applied": "2024-10-31", | ||
"status": 1, | ||
"notes": "Fingers crossed!", | ||
"job_description": "Looking for Turing grad/jr dev to be CTO", | ||
"application_url": "www.example.com", | ||
"contact_information": "[email protected]", | ||
"created_at": "2024-12-14T17:20:41.979Z", | ||
"updated_at": "2024-12-14T17:20:41.979Z", | ||
"company_id": 1, | ||
"user_id": 5 | ||
}, | ||
{ | ||
"id": 2, | ||
"position_title": " CTO", | ||
"date_applied": "2024-10-31", | ||
"status": 2, | ||
"notes": "Fingers crossed!", | ||
"job_description": "Looking for Turing grad/jr dev to be CTO", | ||
"application_url": "www.testexample.com", | ||
"contact_information": "[email protected]", | ||
"created_at": "2024-12-14T17:37:28.465Z", | ||
"updated_at": "2024-12-14T17:37:28.465Z", | ||
"company_id": 2, | ||
"user_id": 5 | ||
} | ||
], | ||
"contacts": [ | ||
{ | ||
"id": 1, | ||
"first_name": "Jonny", | ||
"last_name": "Smith", | ||
"email": "[email protected]", | ||
"phone_number": "555-785-5555", | ||
"notes": "Good contact for XYZ", | ||
"created_at": "2024-12-14T17:55:21.875Z", | ||
"updated_at": "2024-12-14T17:55:21.875Z", | ||
"user_id": 5, | ||
"company_id": 1 | ||
}, | ||
{ | ||
"id": 2, | ||
"first_name": "Josnny", | ||
"last_name": "Smsith", | ||
"email": "[email protected]", | ||
"phone_number": "555-785-5555", | ||
"notes": "Good contact for XYZ", | ||
"created_at": "2024-12-15T01:57:14.557Z", | ||
"updated_at": "2024-12-15T01:57:14.557Z", | ||
"user_id": 5, | ||
"company_id": 1 | ||
} | ||
], | ||
"companies": [ | ||
{ | ||
"id": 1, | ||
"user_id": 5, | ||
"name": "New Company", | ||
"website": "www.company.com", | ||
"street_address": "123 Main St", | ||
"city": "New York", | ||
"state": "NY", | ||
"zip_code": "10001", | ||
"notes": "This is a new company.", | ||
"created_at": "2024-12-14T17:20:10.909Z", | ||
"updated_at": "2024-12-14T17:20:10.909Z" | ||
}, | ||
{ | ||
"id": 2, | ||
"user_id": 5, | ||
"name": "New Company1", | ||
"website": "www.company1.com", | ||
"street_address": "1231 Main St", | ||
"city": "New York", | ||
"state": "NY", | ||
"zip_code": "10001", | ||
"notes": "This is a new company1.", | ||
"created_at": "2024-12-14T17:37:24.153Z", | ||
"updated_at": "2024-12-14T17:37:24.153Z" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
# Authentication, User Roles, and Authorization | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Api::V1::DashboardsController < ApplicationController | ||
before_action :authenticate_user | ||
|
||
def show | ||
user = current_user | ||
authorize user | ||
render json: DashboardSerializer.new(user), status: :ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
class ContactPolicy < ApplicationPolicy | ||
# NOTE: Up to Pundit v2.3.1, the inheritance was declared as | ||
# `Scope < Scope` rather than `Scope < ApplicationPolicy::Scope`. | ||
# In most cases the behavior will be identical, but if updating existing | ||
# code, beware of possible changes to the ancestors: | ||
# https://gist.github.com/Burgestrand/4b4bc22f31c8a95c425fc0e30d7ef1f5 | ||
|
||
def index? | ||
admin? || user.present? | ||
end | ||
|
||
def create? | ||
admin? || user.present? | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
# NOTE: Be explicit about which records you allow access to! | ||
# def resolve | ||
# scope.all | ||
# end | ||
|
||
def resolve | ||
if admin? | ||
scope.all | ||
elsif user? | ||
scope.where(user: user) | ||
else | ||
scope.none | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class DashboardPolicy < ApplicationPolicy | ||
|
||
def show? | ||
user == record | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
|
||
# def resolve | ||
# if user? | ||
# scope.all | ||
# else | ||
# scope.none | ||
# end | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class JobApplicationPolicy < ApplicationPolicy | ||
|
||
def index? | ||
user.present? | ||
end | ||
|
||
def create? | ||
record.user_id == user.id | ||
end | ||
|
||
def show? | ||
record.user_id == user.id | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
|
||
def resolve | ||
if user? | ||
scope.where(user_id: user.id) | ||
else | ||
scope.none | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class DashboardSerializer | ||
include JSONAPI::Serializer | ||
attributes :id, :name, :email | ||
|
||
attribute :dashboard do |user| | ||
{ | ||
weekly_summary: { | ||
job_applications: user.job_applications, | ||
contacts: user.contacts, | ||
companies: user.companies | ||
} | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say, "When we add authentication" do you mean the authentication using JWT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, and that pseudo is deleted. I was mocking and stubbing prior to introduction of JWT, and finally got rid of the remnants.