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

Create an endpoint to get next choice option #16

Closed
tiagostutz opened this issue Jul 17, 2020 · 23 comments
Closed

Create an endpoint to get next choice option #16

tiagostutz opened this issue Jul 17, 2020 · 23 comments
Assignees
Labels

Comments

@tiagostutz
Copy link
Contributor

tiagostutz commented Jul 17, 2020

Implement only the Route, you don't have to implement yet the algorithm of sorting items and actually retrieve them, just the endpoint retrieving a fixed array of items. We will create another issue for that algorithm.

Spec:

Wedding dress Stop Analyzing Database

Using th API

...

Get Choice Option

To get the next choices to be presented to the user, the client will invoke an endpoint passing and array with the previous choices and how many items it wants to be retrieved and the algorithm will compute an ordered list of items based on the features (tags) of those previously chosen items returning the n items requested and the completion ratio of the choice session (we will discuss this in another issue).
This approach will have scale issues on large databases, but we won't address this issues now as we don't have any large database scenario on sight.

GET /choice

query params:

?previous=ccbd7e00301aaa903a2dd30093&previous=...
  • previous: an array of previously selected choices used to filter the next choices. Default: empty
?count=2
  • count: a number of how many items to return. Default: 2

Examples:

$ curl -X GET http://localhost:8008/api/v1/choice?previous=16913&previous=17901

$ curl -X GET http://localhost:8008/api/v1/choice?previous=ccbd7e00301a60703aedbadba&previous=ccbh7e00301aaa903a2dd3dba&count=3

Return:

{
   "id": "5bdae898eaba99",
  "completionRate": 0.3,
  "choices": [{
    "title": "stringt1",
    "subtitle": "strings1",
    "contentURL": "stringc1",
    "tags": ["tag11", "tag12", "tag13"]
  },
  {
   "id": "5bdae89eeae8a99",
    "title": "stringt2",
    "subtitle": "strings2",
    "contentURL": "stringc2",
    "tags": ["tag21", "tag12", "tag13"]
  },
  {
   "id": "5bdae890aa0a0993e",
    "title": "stringt3",
    "subtitle": "strings3",
    "contentURL": "stringc3",
    "tags": ["tag21", "tag12", "tag31"]
  }]
}
@marciojunior88
Copy link

@tiagostutz
Copy link
Contributor Author

POST http://stop-analyzing/api/list-option?count=qtde

Hi @marciojunior88 !
Are you asking whether the API call will be like this?

@marciojunior88
Copy link

no, I understood that it was to set up an endpoint that would be used to call the function of returning a list. Is not it?

@tiagostutz
Copy link
Contributor Author

tiagostutz commented Jul 20, 2020

Yes, that's it. Check this line docs in description:

curl -X POST http://localhost:8008/api/v1/choice/next?count=3 --header 'Content-Type: application/json' -d '{  "previousChoices": ["ckbh7gi0h01t60703woheadgh","ckbnvn0g143g20708xgpr101i"] }'

This is a request example. So, you will receive this data in query param and in the body. Currently, we don't have the function that will calculate what is the next option but that's not a problem now and you don't have to implement that. So, what you will do is to create the endpoint, parse the query params and the body into a struct and Println this returning 200 with an empty array.

@marciojunior88
Copy link

am I supposed to write an endpoint in this complete format above?

I was thinking it was to write only the url of the endpoint as I did above

@tiagostutz
Copy link
Contributor Author

am I supposed to write an endpoint in this complete format above?

I was thinking it was to write only the url of the endpoint as I did above

Ah, now I understood your doubt....! 🤓

Yes, you should write in this complete format to preserve the semantic in the URL because this endpoint will not only list average options, it will return the next n choices the user will have to device between based on the previsou one. That's why it is "choice" and "next".
Sounds ok?

@marciojunior88
Copy link

$ curl -X POST http://stop-analyzing/api/list-option?count=3 --header 'Content-Type: application/json' -d '{ "previousChoices": ["1","2","3"] }'

it is?

@tiagostutz
Copy link
Contributor Author

$ curl -X POST http://stop-analyzing/api/list-option?count=3 --header 'Content-Type: application/json' -d '{ "previousChoices": ["1","2","3"] }'

it is?

Actually, not. Please, check my comment above: #16 (comment)

@marciojunior88
Copy link

$ curl -X POST http: // análise de parada / api / list-option? count = 3 --header 'Tipo de conteúdo: application / json' -d '{"previousChoices": ["1", "2" , "3"]} '
isto é?

Na verdade não. Por favor, verifique meu comentário acima: # 16 (comentário)

sorry, what's wrong?

@tiagostutz
Copy link
Contributor Author

The URL path will be /api/v1/choice/next?count=3. In your example it is /api/list-option?count=3

@marciojunior88
Copy link

anything else you can contribute?

@tiagostutz
Copy link
Contributor Author

Nope, I think the only thing I had to point was the URL path.

If you have any doubt about the requirements or the code, please feel free to ask! =)

@marciojunior88
Copy link

Entendido !

@GreenStage
Copy link
Collaborator

GreenStage commented Jul 27, 2020

just passing to say that this is not restful, although it ain't a problem if you don't want it to be 😄

@tiagostutz
Copy link
Contributor Author

Yes, It would be good to have it RESTful, but that's not a problem not to have.

For example, changing this from POST to GET (as we are retrieving the next option) would make sense, but technically it would be a problem because we need to pass an array as request param and doing that is really weird. Another thing to point here is that this is not a fully transactional endpoint to the client's perspective, as he will almost have just this one endpoint to invoke. The transactional part will live in another endpoints that makes a lot of sense being RESTful (create product, retrieve product, filter product by attribute...), but they will be used in another client context, in an administration perspective.

But if you have a suggestion on how to make this endpoint RESTful it would be nice to hear you. As this issue is not done yet, there's space to change here.

@GreenStage
Copy link
Collaborator

GET /choice?previous=x&previous=y

This is how I would do it

But it boils down to personal preferences :P

@tiagostutz
Copy link
Contributor Author

tiagostutz commented Aug 1, 2020

@GreenStage I was thinking about your RESTful suggestion and I think it is better than the POST approach I suggested. Let's go for it and change the Spec to use it.

@marciojunior88, I just updated the spec in the first comment of this thread #16 (comment). please follow the new Spec for this endpoint. Quick tip:

GET /choice?previous=<previous_choice_0_id>&previous=<previous_choice_1_id>&count=<how_many_returning_choices>

  • returns an array of choices based on the previous choices

Example:

$ curl -X GET http://localhost:8008/api/v1/choice?previous=ccbd7e00301a60703a3310a9&previous=ccbd7e00301a60703aedbadba&count=3

Thanks @GreenStage !

@tiagostutz
Copy link
Contributor Author

tiagostutz commented Aug 14, 2020

Hi @marciojunior88 !
Are you still working on this issue? If not, can we assign it to another contributor that is looking for an issue?

Thanks!

@dianalin2
Copy link
Collaborator

I could tackle this issue!

@tiagostutz
Copy link
Contributor Author

tiagostutz commented Aug 18, 2020

Awesome, @dianalin2 ! 🚀
Just assigned the issue to you. Go ahead.

If you need some help, just ask and we will come to you.


Pingback: bancodobrasil/stop-analyzing-embed#70

@dianalin2
Copy link
Collaborator

Hi, @tiagostutz, just for clarification, I am just writing the routing path, correct? I'm not returning anything?

@tiagostutz
Copy link
Contributor Author

Hi @dianalin2 ! Yep.!

You could return this fixed payload, just to have something returned:

{
    "completeness": "0.3",
    "choices": [
        {
            "id": "5f355a24ccb4180025ee98ab",
            "title": "Fashion Shirt",
            "subtitle": "Colored nice Shirt",
            "contentURL": "https://lorempixel.com/640/480/",
            "attributes": [
                {
                    "size": "S",
                    "color": "multiple"
                }
            ]
        },
        {
            "id": "5f358359ccb4180025ee98ad",
            "title": "Corporate Shirt",
            "subtitle": "Corporate long sleeve Shirt",
            "contentURL": "https://lorempixel.com/640/480/",
            "attributes": [
                {
                    "size": "S",
                    "color": "black"
                }
            ]
        }
    ]
}

Then, in another issue we will tackle the selecting items logic.

dianalin2 added a commit to dianalin2/stop-analyzing-api that referenced this issue Aug 19, 2020
dianalin2 added a commit to dianalin2/stop-analyzing-api that referenced this issue Aug 24, 2020
tiagostutz added a commit that referenced this issue Aug 24, 2020
feat: add next choice. refs #16
@tiagostutz
Copy link
Contributor Author

Hi @dianalin2
Congrats on your awesome PR!! Thanks for your contribution. I have just sent you and invite to be part of the team. I hope you can accept this and we can work on the evolution of this project. =)

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

No branches or pull requests

4 participants