-
Notifications
You must be signed in to change notification settings - Fork 10
Add initial user API #26
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
base: main
Are you sure you want to change the base?
Conversation
userService := userProvider.GetUserService() | ||
user, err := userService.GetUser(id) | ||
if err != nil { | ||
http.Error(w, "Failed get user", http.StatusInternalServerError) |
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.
We should handle client errors here right? Otherwise there will be a 500 for non existing users as well.
Same with put and delete
userService := userProvider.GetUserService() | ||
err := userService.DeleteUser(id) | ||
if err != nil { | ||
http.Error(w, "Failed delete user", http.StatusInternalServerError) |
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.
Maybe should return 200 for user non existing case
// @Failure 500 {string} "Internal Server Error: An unexpected error occurred while processing the request." | ||
// @Router /users [post] | ||
func (ah *UserHandler) HandleUserPostRequest(w http.ResponseWriter, r *http.Request) { | ||
|
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.
As discussed during last week's review, shall we remove empty line after the func definition?
Purpose
This pull request introduces a new user management feature to the backend system. It includes database schema updates for both PostgreSQL and SQLite, a new
UserService
with REST API endpoints, and supporting models, handlers, and data storage logic. Below are the most important changes grouped by theme:Database Schema Updates
USER
table to both PostgreSQL (postgress.sql
) and SQLite (sqlite.sql
) schemas to store user details such asUSER_ID
,ORG_ID
,TYPE
, andATTRIBUTES
. The table includes timestamps forCREATED_AT
andUPDATED_AT
. [1] [2]USER
table in both PostgreSQL and SQLite scripts. [1] [2]Service Layer Implementation
UserService
inuserservice.go
to handle user-related operations, including creating, retrieving, updating, and deleting users. The service is registered in theServiceManager
. [1] [2]REST API for User Management
UserHandler
inuserhandler.go
to define REST API endpoints (POST
,GET
,PUT
,DELETE
) for user management. Each endpoint is mapped to a corresponding service method.Supporting Models and Providers
User
model inuser.go
to represent user data, includingId
,OrgId
,Type
, andAttributes
.UserProvider
inuserprovider.go
to abstract the creation and retrieval of theUserService
instance.Data Storage Layer
constants.go
under thestore
package. These queries are used by theUserService
to interact with the database.