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

Upload API Prep Part 3: Add Project and User Insert API #34

Merged
merged 9 commits into from
Dec 9, 2024

Conversation

francisduvivier
Copy link
Collaborator

@francisduvivier francisduvivier commented Nov 27, 2024

This PR implements the first working upload api parts:

  • insertProject
  • updateProject
  • deleteProject
  • publishProject

@francisduvivier francisduvivier linked an issue Nov 27, 2024 that may be closed by this pull request
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from 100db5c to 47029b6 Compare November 27, 2024 20:21
src/controllers/private-rest.ts Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Nov 27, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 34.11% 757 / 2219
🔵 Statements 34.11% 757 / 2219
🔵 Functions 38.93% 44 / 113
🔵 Branches 82.14% 46 / 56
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.ts 0% 0% 0% 0% 1-26
src/controllers/private-rest.ts 36.98% 100% 0% 36.98% 22-23, 30-35, 42-46, 53-54, 61-65, 72-77, 84-88, 95-99, 106-109, 116-120, 127-128
src/db/BadgeHubDataPostgresAdapter.ts 20.91% 100% 14.28% 20.91% 41-51, 61-65, 68-72, 75-88, 91-101, 104-107, 110-137, 140-144, 147-151, 154-159, 162-163, 167-199, 202-203, 206-207, 210-215, 218-222, 244-276, 279-292
src/db/models/DBProjectStatusOnBadge.ts 100% 100% 100% 100%
src/db/models/app/DBUser.ts 100% 100% 100% 100%
src/db/sqlHelpers/objectToSQL.ts 29.41% 100% 0% 29.41% 7-11, 14-20
src/domain/BadgeHubDataPort.ts 100% 100% 100% 100%
src/domain/readModels/app/User.ts 100% 100% 100% 100%
src/generated/routes.ts 51.99% 66.66% 10.52% 51.99% 507-508, 520-549, 558-592, 601-639, 650-687, 698-741, 752-783, 794-831, 842-879, 890-927, 938-969, 980-1017, 1028-1072, 1083-1120, 1131-1168, 1179-1210, 1221-1258, 1269-1300
src/util/objectEntries.ts 9.09% 100% 0% 9.09% 1-5, 14-18
Generated in workflow #89 for commit a57a210 by the Vitest Coverage Report Action

@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch 2 times, most recently from 5dce7f9 to 4dcd6d7 Compare November 27, 2024 23:04
@francisduvivier francisduvivier changed the title Add Project and User Insert API Upload API Prep Part 3: Add Project and User Insert API Nov 27, 2024
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from bbd055c to da8d725 Compare November 27, 2024 23:33
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from dbbb2c2 to 102bf05 Compare November 27, 2024 23:38
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from 102bf05 to 79342cb Compare December 1, 2024 12:27
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from a94a1e4 to 2a470fd Compare December 3, 2024 19:17
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from 79342cb to abd80bd Compare December 3, 2024 19:20
mockup-data.sql Outdated Show resolved Hide resolved
src/controllers/private-rest.ts Show resolved Hide resolved
* Create a new user
*/
@Post("/users/{userId}")
public async insertUser(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should:

  1. Get some validation middleware on all of these so we can return proper status codes instead of waiting for the DB insert to fail and sending back what I assume to be a 500 and a raw DB error
  2. Create a different implementation of the data port interface that doesn"t talk directly to the database. Going straight from post data to a SQL insert is iffy imo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • I agree about the raw DB erros being sent back from the API should change. Maybe we can indeed use some TSOA middleware for that. Could you create a ticket for this?

  • Extra manual validation is not really that necessary I think because TSOA is already checking the input shape of the requests so that they match the typescript types.

  • Now I was also wondering whether I should make an extra layer for the DB, but it felt a bit overengineering for now. Idea currently is that the BadgeHubDataPostgresAdapter translates between Badgehub Domain and DB, the Badgehub domain is used by the API. The abstraction is a bit broken because in some places it made sense to reuse the DB insert typings. But if we want extra validation and shielding, I think we can do that in the BadgeHubDataPostgresAdapter.ts or private-rest.ts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Edit: now that I wanted to start working on the file uploads, I see it does make sense to to make an separate abstraction layer for the DB.
So I"ve created a ticket to follow up on your suggestion (#43), and I"ll do that before starting on draft file management (#36)

src/index.ts Show resolved Hide resolved
@@ -19,7 +22,7 @@ create table badges

create table users
(
id text primary key, -- using text as recommended
id serial primary key,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think at some point we may want to switch to UUIDs instead of sequential, since we"re dealing with a write API and a bunch of hackers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah uuids instead of these increasing numbers would make sense.
Shall we make a ticket for using uuidv6?
But for the users I actually would prefer to use unique readable user ids that users have to choose. Nicer to read API"s that way. So I changed it in #35 to strings, but then I saw it cause extra migration work, so I just changed it back here the scope of these PR while keeping everthing that currently works working.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update: I created #44 for this

@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from 2a470fd to c290e27 Compare December 4, 2024 17:20
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from abd80bd to ef76ebc Compare December 4, 2024 17:22
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from c04df81 to dadfd31 Compare December 4, 2024 18:26
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from 7f679a1 to 15fdef0 Compare December 9, 2024 16:35
Base automatically changed from feature/26-upload-api-part-2 to main December 9, 2024 16:37
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-3 branch from dadfd31 to a57a210 Compare December 9, 2024 16:41
@francisduvivier francisduvivier merged commit ea9f1da into main Dec 9, 2024
3 checks passed
@francisduvivier francisduvivier deleted the feature/26-upload-api-part-3 branch December 9, 2024 16:54
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.

REST Project Creation API
3 participants