hhroc / yellr-server

Server for yellr project
GNU Affero General Public License v3.0
6 stars 5 forks source link

Migrate to relationships rather than join-sloppiness #268

Closed thequbit closed 8 years ago

thequbit commented 9 years ago

It's so bad. Responses will change. Here are the details.

Note: all client end points need cuid, language_code, lat, lng, and platform (new!) in the URL parms. An example would look like:

/get_assignments.json?cuid=828870ec-5568-4d44-ab15-404f38504b29&language_code=en&lat=43.1&lng=-77.5&platform=web

_Unchanged end points_

register_vote.json

POST post_id and is_up_vote and get back:

{
    "post_id": 1,
    "vote_id": 1,
    "is_up_vote": true,
    "success": true
}

flag_post.json

POST post_id and get back:

{
    "post_id": 1,
    "success": true
}

get_stories.json

{
    "stories": [
        {
            "author_first_name": "SYSTEM",
            "tags": "things, other things",
            "story_unique_id": "1234",
            "top_left_lng": -77.9,
            "edited_datetime": "None",
            "bottom_right_lng": -77.3,
            "bottom_right_lat": 43,
            "author_organization": "Yellr",
            "title": "Mah Story.",
            "author_email": "",
            "top_left_lat": 43.4,
            "publish_datetime_ago": "1m",
            "publish_datetime": "2015-08-19 16:49:00",
            "author_last_name": "USER",
            "contents_rendered": "<p>zomg, you should have seen it!  It was awesome!</p>"
        }
    ],
    "success": true
}

get_profile.json

no POST parms are needed

{
    "first_name": null,
    "last_name": null,
    "verified": false,
    "success": true,
    "post_count": 2,
    "post_view_count": 0,
    "post_used_count": 0,
    "client_id": 1,
    "organization": "",
    "email": null
}

* Changed end points *

publish_post.json

_Note: you create the post first, then use the ID with your uploadmedia contents.

POST contents and get:

{
    "post_id": 3,
    "vote_id": 1,
    "success": true
}

upload_media.json

Note: you upload media objects against a post. You must create the post first

POST media_type and post_id (new!) and get:

{
    "preview": "065ccbc8-9d0d-4f6a-9f5b-42542cca7342p.jpg",
    "media_id": "a26394c7-d722-4b53-93a8-3fe41d14fe93",
    "success": true,
    "filename": "065ccbc8-9d0d-4f6a-9f5b-42542cca7342.jpg"
}

get_assignments.json

{
    "assignments": [
        {
            "bottom_right_lat": 43,
            "response_count": 0,
            "name": "New Years",
            "author": {
                "first_name": "SYSTEM",
                "last_name": "USER",
                "user_id": 1,
                "user_geo_fence": {
                    "bottom_right_lat": -90,
                    "user_geo_fence_id": 1,
                    "top_left_lng": -180,
                    "top_left_lat": 90,
                    "bottom_right_lng": -180
                },
                "organization": {
                    "organization_id": 1,
                    "creation_datetime": "2015-08-19 11:02:56.511430",
                    "description": "",
                    "contact_email": "",
                    "contact_name": "",
                    "name": "Yellr"
                },
                "user_name": "system",
                "email": ""
            },
            "expire_datetime": "2015-08-26 11:09:32.249082",
            "top_left_lng": -77.9,
            "assignment_id": 1,
            "bottom_right_lng": -77.3,
            "questions": [
                {
                    "question_text": "How will you be spending New Years Eve?",
                    "user_id": 1,
                    "description": "Will you be doing anything special for New Years?!?",
                    "language": {
                        "language_code": "en",
                        "language_id": 1,
                        "name": "English"
                    },
                    "question_type": {
                        "question_type_description": "Free form text response.",
                        "question_type": "free_text"
                    },
                    "question_id": 1
                }
            ],
            "collection_id": 1,
            "publish_datetime": "2015-08-19 11:09:32.249077",
            "use_fence": true,
            "top_left_lat": 43.4
        }
    ],
    "success": true
}

get_local_posts.json

{
    "posts": [
        {
            "deleted": false,
            "assignment": null,
            "post_id": 2,
            "client_id": 1,
            "language_code": "en",
            "lat": 43.1,
            "lng": -77.5,
            "post_datetime": "2015-08-19 16:20:21",
            "approved": true,
            "contents": "Hi There.",
            "up_count": 0,
            "media_objects": [
                {
                    "file_name": "my_file.jpg",
                    "media_type": {
                        "media_type_id": 2,
                        "description": "An Audio Clip.",
                        "name": "audio"
                    },
                    "media_object_id": 1,
                    "client_id": 1,
                    "post_id": 2
                }
            ],
            "is_up_vote": false,
            "down_count": 0,
            "has_voted": false,
            "flagged": true
        },
        {
            "deleted": false,
            "assignment": {
                "bottom_right_lat": 43,
                "response_count": 1,
                "name": "Best Friend",
                "author": {
                    "first_name": "SYSTEM",
                    "last_name": "USER",
                    "user_id": 1,
                    "user_geo_fence": {
                        "bottom_right_lat": -90,
                        "user_geo_fence_id": 1,
                        "top_left_lng": -180,
                        "top_left_lat": 90,
                        "bottom_right_lng": -180
                    },
                    "organization": {
                        "organization_id": 1,
                        "creation_datetime": "2015-08-19 12:18:38.601528",
                        "description": "",
                        "contact_email": "",
                        "contact_name": "",
                        "name": "Yellr"
                    },
                    "user_name": "system",
                    "email": ""
                },
                "expire_datetime": "2015-09-01 16:18:47",
                "top_left_lng": -77.9,
                "assignment_id": 1,
                "top_left_lat": 43.4,
                "questions": [],
                "collection_id": 0,
                "publish_datetime": "2015-08-19 16:18:47",
                "bottom_right_lng": -77.3
            },
            "post_id": 1,
            "client_id": 1,
            "language_code": "en",
            "lat": 43.1,
            "lng": -77.5,
            "post_datetime": "2015-08-19 16:19:49",
            "approved": true,
            "contents": "ZOMG SO COOL",
            "up_count": 1,
            "media_objects": [],
            "is_up_vote": true,
            "down_count": 0,
            "has_voted": true,
            "flagged": true
        }
    ],
    "success": true
}
thequbit commented 8 years ago

Implemented. Implemented some sub-queries rather than all relationships as well.