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

Folders API (for caseworker UI project) #115

Merged
merged 6 commits into from
Jun 22, 2024
Merged

Folders API (for caseworker UI project) #115

merged 6 commits into from
Jun 22, 2024

Conversation

katerina-kossler
Copy link
Contributor

@katerina-kossler katerina-kossler commented Jun 13, 2024

note - draft PR

includes:

  • SQL queries
  • types
  • folders manager
  • routing

completed:

  • get folders for user
  • new folder for user
  • get folder by folderId
  • delete folder by Id
  • update folder by Id

notes:

  • having trouble testing locally

- SQL queries
- types
- folders manager
- routing
func (m *Manager) Get(w http.ResponseWriter, r *http.Request) {
userId, err := strconv.Atoi(chi.URLParam(r, "user_id"))
if err != nil {
fmt.Println("error:", err)
Copy link
Member

Choose a reason for hiding this comment

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

I know that this is just a placeholder for now, but what's our general strategy for returning useful error messages to the API client? I guess we might want two separate error messages for the following scenarios related to part of the function:

  1. user_id should probably be mandatory, at least for now, so if it's missing, we should let the client know it's mandatory
  2. if it's an invalid number, then we should also report that

Thinking a little bit ahead, with the user auth stuff that I worked on, we'll also want to report an error message if there's an authentication failure (JWT failed to validate) or an authorization failure (the logged in user doesn't match the user_id query parameter here).

Copy link
Member

Choose a reason for hiding this comment

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

Let me see if I can add an example of such on one of the existing endpoints

@katerina-kossler
Copy link
Contributor Author

having issues testing my endpoints locally... maybe due to auth or no folders being in the db

Copy link
Member

@richardxia richardxia left a comment

Choose a reason for hiding this comment

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

Overall, this looks good, thanks for working on this, @katerina-kossler! In the interest of time, I'm going to go make the changes for the things I suggested on the PR and push back to this branch, just so that we can get things merged and ready for frontend integration in time.

I'm going to leave off the auth part for now, so that's something that can happen in a separate ticket.

internal/db/sql.go Outdated Show resolved Hide resolved
internal/db/manager.go Outdated Show resolved Hide resolved
cmd/sheltertech-go/main.go Outdated Show resolved Hide resolved
internal/db/sql.go Outdated Show resolved Hide resolved
internal/folders/manager.go Show resolved Hide resolved
internal/folders/manager.go Show resolved Hide resolved
err = m.DbClient.UpdateFolder(dBFolder)
if err != nil {
log.Print(err)
writeStatus(w, http.StatusInternalServerError)
Copy link
Member

Choose a reason for hiding this comment

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

We probably need some more specific error handling here, since one of the possible failure modes is trying to PUT to an ID that doesn't exist, and this line will cause it to return a 500 error, even though the issue is on the caller's side for attempting to modify a non-existent object.

Ideally, we'd want to distinguish between server-side errors (5xx errors) and client-side errors (4xx errors), but I'm not sure what the best way of doing that in Go is.

It looks like newerish Go has an errors.Is function for checking an error of a known type, but I'm not exactly sure how to use it, so I may punt on this.

- Changed the get by users route from `/api/folders/user/{user_id}` to
  `/api/folders` with a `user_id` query parameter
- Fixed `createFolder` query to have correct number of parameters
- Fixed SQL syntax errors due to `order` being a keyword by ensuring
  that every occurrence is quoted
- Do error handling for `GetByID` on nonexistent ID
- Change `Post` to also return the newly created folder
- Various error handling improvements
- go fmt
@richardxia
Copy link
Member

I'm going to merge this in now, but if @lgarofalo has any post-merge comments, definitely let us know, since the rest of us are all still learning Go.

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