-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add profile option in local server #369
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,12 +142,52 @@ open class LocalServerRepositoryImpl( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get("/api/profiles") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val profiles = deeprQueries.getAllProfiles().executeAsList() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val response = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| profiles.map { profile -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ProfileResponse( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id = profile.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name = profile.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createdAt = profile.createdAt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| call.respond(HttpStatusCode.OK, response) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+145
to
+156
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e: Exception) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Log.e("LocalServer", "Error getting profiles", e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| call.respond( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatusCode.InternalServerError, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrorResponse("Error getting profiles: ${e.message}"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| post("/api/profiles") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val request = call.receive<AddProfileRequest>() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deeprQueries.insertProfile(request.name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| call.respond( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HttpStatusCode.Created, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SuccessResponse("Profile created successfully"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+169
to
+173
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deeprQueries.insertProfile(request.name) | |
| call.respond( | |
| HttpStatusCode.Created, | |
| SuccessResponse("Profile created successfully"), | |
| ) | |
| // Check if a profile with the same name already exists | |
| val existingProfiles = deeprQueries.getAllProfiles().executeAsList() | |
| val existingProfile = existingProfiles.find { it.name == request.name } | |
| if (existingProfile != null) { | |
| val response = | |
| ProfileResponse( | |
| id = existingProfile.id, | |
| name = existingProfile.name, | |
| createdAt = existingProfile.createdAt, | |
| ) | |
| call.respond(HttpStatusCode.OK, response) | |
| } else { | |
| // Use AccountViewModel to ensure side effects (backup, analytics, etc.) are applied | |
| accountViewModel.insertProfile(request.name) | |
| // Fetch the newly created profile | |
| val updatedProfiles = deeprQueries.getAllProfiles().executeAsList() | |
| val createdProfile = updatedProfiles.find { it.name == request.name } | |
| if (createdProfile != null) { | |
| val response = | |
| ProfileResponse( | |
| id = createdProfile.id, | |
| name = createdProfile.name, | |
| createdAt = createdProfile.createdAt, | |
| ) | |
| call.respond(HttpStatusCode.Created, response) | |
| } else { | |
| call.respond( | |
| HttpStatusCode.InternalServerError, | |
| ErrorResponse("Profile was not found after creation"), | |
| ) | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
populateProfileSelect()fully replaces the<select>options withprofiles. If the backend returns an empty list (or the default profile’s id isn’t1), the selector becomes empty andselectedProfileIdmay no longer match any option. Consider keeping a fallback option whenprofiles.length === 0, and/or updatingselectedProfileIdto the first returned profile id before rendering so subsequent/api/links?profileId=...requests stay consistent.