Skip to content

Conversation

@mashazyu
Copy link
Contributor

@mashazyu mashazyu commented Sep 29, 2025

This PR adds POST functionality for creating new boxes (devices) via the API and updates the data format returned by the /users/me/boxes endpoint to match the openSenseMap API specification.

Changes

  • Implement POST /api/boxes endpoint for creating new devices with sensors.
  • Ensure that returned device data is backwards compatible for both POST /boxes and GET /users/me/boxes
  • Convert last measurement data to string format (this format is expected by the app)
  • I hope I fixed ts and lint issues for current pr, but I didn't address anything prior

Testing

I have been testing current PR with senseBox:bike app.

  1. After login, I get boxes data in the format supported by current version of senseBox:bike app.
  2. I can create new box via app.

Open questions

  • What attributes should be returned after box is created and at /users/me/boxes? Is it ok not to return attributes with null values (like it was done before)?
  • Is it ok to return last measurement as string, not as double?
  • What should be returned as device.acces_token?

scheidtdav and others added 30 commits May 14, 2025 16:26
* feat(api): add api routes for /users/me

* fix(tests): api me PUT

* feat(api): add delete me endpoint
@mashazyu mashazyu self-assigned this Sep 30, 2025
@mashazyu mashazyu marked this pull request as ready for review September 30, 2025 12:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements POST functionality for creating new devices (boxes) via the API and updates the data format for the /users/me/boxes endpoint to match the openSenseMap API specification.

  • Adds a new POST /api/boxes endpoint for creating devices with sensors
  • Updates the /users/me/boxes endpoint to return data in openSenseMap-compatible format
  • Ensures measurement values are returned as strings instead of numbers for app compatibility

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/routes/api.boxes.ts New POST endpoint implementation with comprehensive OpenAPI documentation
app/routes/api.users.me.boxes.ts Updated to use device transformation and include JWT token in response
app/models/device.server.ts Enhanced createDevice function to return sensors and support additional fields
app/models/sensor.server.ts Modified to cast measurement values to text format
app/lib/device-transform.ts New utility for transforming device data to openSenseMap API format
app/lib/devices-service.server.ts Added Zod schema for validating box creation requests
app/schema/sensor.ts Added TypeScript type for lastMeasurement JSON field
tests/ Added comprehensive test coverage for new functionality
app/routes/api.ts Updated route configuration to enable POST /boxes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@scheidtdav scheidtdav left a comment

Choose a reason for hiding this comment

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

Regarding your open questions:

  • What attributes should be returned after box is created and at /users/me/boxes? Is it ok not to return attributes with null values (like it was done before)?

Yes thats ok. Whatever was done before is currently our goal.

  • Is it ok to return last measurement as string, not as double?

It was probably string before, so again: Yes thats ok.

  • What should be returned as device.acces_token?

I am frankly somewhat confused by this. Where does this field even come from?
Why would a device respond with an access token if the client just did a request for which a token is required. That implies the client already having a token. Do we even need this?

Base automatically changed from feat/api-boxes to feat/api-boxes-sensors October 1, 2025 14:46
Base automatically changed from feat/api-boxes-sensors to dev October 2, 2025 13:14
@mashazyu mashazyu requested a review from scheidtdav October 8, 2025 10:46
@mashazyu
Copy link
Contributor Author

mashazyu commented Oct 8, 2025

@scheidtdav, thank you very much for the review and feedback!

Per our conversation I removed access_token mentions and addressed your comments.

Last question - because current PR was based on some other PR, which was based on another PR, now i contains commits from one/all of those prs. How would you like me to proceed? I could create a new pr and cherry-pick only my changes? Or there is a better way?

@scheidtdav
Copy link
Collaborator

@mashazyu Don't worry about those. Its a bit of a leftover from how we approached the migration previously.
Those commits are all already on dev, but because we squash and merge GitHub cannot figure out which ones to ignore for this PR. There are only your changes though :-)

@scheidtdav scheidtdav merged commit 3c51c55 into dev Oct 8, 2025
6 checks passed
@scheidtdav scheidtdav deleted the feat/post-api-boxes branch October 8, 2025 13:35
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.

5 participants