Skip to content
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

fix: comment not showing on Featured Projects #773

Closed
wants to merge 1 commit into from

Conversation

aqsaaqeel
Copy link
Contributor

@aqsaaqeel aqsaaqeel commented Oct 4, 2023

Summary

The Projects under Featured Projects list are showing comments count now.
Closes #85, Closes #22

Solution

The response from staff-picks API did not have a comments_count field. I have added it under the serializers.py / ProjectSerializer

Screenshots

Screenshot from 2023-10-04 05-41-07

Requests / Responses

Request

GET /api/projects/staff-picks/

Response

[
    {
        "id": "226bd96d-8f3d-4d85-85df-b07469a4bdc5",
        "title": "Featured Projects",
        "description": "Curated by Unstructured Studio team",
        "projects": {
            "results": [
                {
                    "id": "86a0456d-f86b-4b12-ace8-28d2ed9557fc",
                    "creator": {
                        "id": "b7c4ede2-b2e9-475d-a517-63e3ef407d2f",
                        "username": "aqsacodes",
                        "avatar": "https://robohash.org/aqsacodes",
                        "comments": [
                            {
                                "id": 2,
                                "project": null,
                                "creator": {
                                    "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                    "username": "dummy",
                                    "avatar": "https://robohash.org/dummy"
                                },
                                "text": "hello",
                                "created_on": "2023-10-03T23:31:49.614297Z",
                                "replies": []
                            }
                        ],
                        "bio": "",
                        "followers": [],
                        "following_count": 0,
                        "projects_count": 2,
                        "members_count": null,
                        "tags": [
                            "creator"
                        ],
                        "badges": [
                            "Hatchling"
                        ]
                    },
                    "title": "fvz",
                    "description": "<p>sds</p>",
                    "images": [
                        {
                            "image_url": "http://localhost:8001/project_images/95uDEPJ9_kJP4VJ5m1Tx2",
                            "public_id": "project_images/95uDEPJ9_kJP4VJ5m1Tx2"
                        }
                    ],
                    "video": "",
                    "materials_used": "Paint",
                    "tags": [],
                    "category": [
                        "Toys"
                    ],
                    "likes": [],
                    "saved_by": [],
                    "views_count": 2,
                    "comments": [
                        {
                            "id": 6,
                            "project": "86a0456d-f86b-4b12-ace8-28d2ed9557fc",
                            "creator": {
                                "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                "username": "dummy",
                                "avatar": "https://robohash.org/dummy"
                            },
                            "text": "hello again",
                            "created_on": "2023-10-03T23:36:55.329495Z",
                            "replies": []
                        }
                    ],
                    "created_on": "2023-09-30T16:24:14.918966Z",
                    "publish": {
                        "type": 4,
                        "visible_to": []
                    },
                    "comments_count": 0
                },
                {
                    "id": "9fac8df9-fe5c-46b0-ad50-d077e7f1f388",
                    "creator": {
                        "id": "b7c4ede2-b2e9-475d-a517-63e3ef407d2f",
                        "username": "aqsacodes",
                        "avatar": "https://robohash.org/aqsacodes",
                        "comments": [
                            {
                                "id": 2,
                                "project": null,
                                "creator": {
                                    "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                    "username": "dummy",
                                    "avatar": "https://robohash.org/dummy"
                                },
                                "text": "hello",
                                "created_on": "2023-10-03T23:31:49.614297Z",
                                "replies": []
                            }
                        ],
                        "bio": "",
                        "followers": [],
                        "following_count": 0,
                        "projects_count": 2,
                        "members_count": null,
                        "tags": [
                            "creator"
                        ],
                        "badges": [
                            "Hatchling"
                        ]
                    },
                    "title": "New proj",
                    "description": "<p>jkjbk</p>",
                    "images": [
                        {
                            "image_url": "http://localhost:8001/project_images/dNhIE21WW8XRtnIo61W0f",
                            "public_id": "project_images/dNhIE21WW8XRtnIo61W0f"
                        }
                    ],
                    "video": "",
                    "materials_used": "Glue",
                    "tags": [
                        {
                            "name": "General"
                        }
                    ],
                    "category": [],
                    "likes": [],
                    "saved_by": [
                        "537c5432-daed-412a-8616-b140563ed8a7"
                    ],
                    "views_count": 2,
                    "comments": [
                        {
                            "id": 5,
                            "project": "9fac8df9-fe5c-46b0-ad50-d077e7f1f388",
                            "creator": {
                                "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                "username": "dummy",
                                "avatar": "https://robohash.org/dummy"
                            },
                            "text": "hey",
                            "created_on": "2023-10-03T23:36:25.975529Z",
                            "replies": []
                        },
                        {
                            "id": 4,
                            "project": "9fac8df9-fe5c-46b0-ad50-d077e7f1f388",
                            "creator": {
                                "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                "username": "dummy",
                                "avatar": "https://robohash.org/dummy"
                            },
                            "text": "hello again",
                            "created_on": "2023-10-03T23:33:50.130544Z",
                            "replies": []
                        },
                        {
                            "id": 3,
                            "project": "9fac8df9-fe5c-46b0-ad50-d077e7f1f388",
                            "creator": {
                                "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                "username": "dummy",
                                "avatar": "https://robohash.org/dummy"
                            },
                            "text": "hello",
                            "created_on": "2023-10-03T23:32:44.291663Z",
                            "replies": []
                        },
                        {
                            "id": 1,
                            "project": "9fac8df9-fe5c-46b0-ad50-d077e7f1f388",
                            "creator": {
                                "id": "537c5432-daed-412a-8616-b140563ed8a7",
                                "username": "dummy",
                                "avatar": "https://robohash.org/dummy"
                            },
                            "text": "hello  world",
                            "created_on": "2023-10-03T23:26:15.827164Z",
                            "replies": []
                        }
                    ],
                    "created_on": "2023-09-30T16:18:57.224607Z",
                    "publish": {
                        "type": 4,
                        "visible_to": []
                    },
                    "comments_count": 3
                }
            ],
            "prev": null,
            "next": null,
            "count": 2
        },
        "created_on": "2023-09-30T16:24:14.918966Z"
    }
]

Copy link
Member

@tuxology tuxology left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 LGTM 🌈

@tuxology
Copy link
Member

tuxology commented Oct 4, 2023

@aqsaaqeel Can you rebase this to current master branch?

@aqsaaqeel
Copy link
Contributor Author

@aqsaaqeel Can you rebase this to current master branch?

I have rebased
Screenshot from 2023-10-05 02-17-03

@tuxology
Copy link
Member

tuxology commented Oct 4, 2023

@aqsaaqeel Can you pull the latest master branch and then rebase? I see conflicts in zubhub_backend/zubhub/projects/serializers.py

@benndip
Copy link
Contributor

benndip commented Oct 5, 2023

Hello @aqsaaqeel nice work, but I really don't think the backend was missing a comment_count field because you see that your comments_count result and your comments are different. Above you have a comment_count of 3, but there are 4 comments. Same with the one above. And in your image.

Now if we go to the backend code of models.py, you will see that, StaffPick is related to Project and Project is related to Comment with a related name of comments. So that is the count already. So this issue is to be solved from the frontend as it's just one line of code to adjust.

@tuxology @srish I will release a PR that reloves this from the front end as it was just a missing key somewhere.

@benndip
Copy link
Contributor

benndip commented Oct 5, 2023

Please this is what I mean @aqsaaqeel and @tuxology . Projects and Staff Picked Projects have different response structures. as seen below these screenshots

  • Staff-Picked has the comments field on that particular project
Staff Picked

so we can pick the length of comments from there

  • Projects have a comments_count field for the number of comments for that project
Projects

Hence the backend had no issue. It was just for the front end to reference both differently according to the fields from the backend, and the issue will be resolved.

@benndip
Copy link
Contributor

benndip commented Oct 5, 2023

@tuxology
Copy link
Member

tuxology commented Oct 5, 2023

@benndip Ok, this is a good observation! I guess I was too quick in approving the PR 😅 @aqsaaqeel Sorry, we will close this since this will be resolved via #799 Thanks for your efforts!

@tuxology tuxology closed this Oct 5, 2023
@rak16
Copy link

rak16 commented Oct 5, 2023

@benndip If comments_count is not returning the correct value then isn't that something we should look into and resolve? Fixing it on the frontend with a conditional is merely a bandage, and not a well-rounded solution.

What do you think @tuxology ?

@benndip
Copy link
Contributor

benndip commented Oct 5, 2023 via email

@rak16
Copy link

rak16 commented Oct 5, 2023

I feel this is a consistency issue and we should fix it on the backend. Nevertheless, even if we are okay with this, why is comments_count not the correct value if comments array is showing the right set of comments. Something is definitely not right on the backed side and should be addressed.

@benndip
Copy link
Contributor

benndip commented Oct 5, 2023 via email

@rak16
Copy link

rak16 commented Oct 5, 2023

Sure, let's connect.

@benndip
Copy link
Contributor

benndip commented Oct 5, 2023

Are you available now @rak16 you can join here https://meet.google.com/uvn-dybq-gwp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants