Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add initial user API #26

wants to merge 3 commits into from

Conversation

darshanasbg
Copy link
Member

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

  • Added a new USER table to both PostgreSQL (postgress.sql) and SQLite (sqlite.sql) schemas to store user details such as USER_ID, ORG_ID, TYPE, and ATTRIBUTES. The table includes timestamps for CREATED_AT and UPDATED_AT. [1] [2]
  • Inserted a sample user record into the USER table in both PostgreSQL and SQLite scripts. [1] [2]

Service Layer Implementation

  • Introduced a new UserService in userservice.go to handle user-related operations, including creating, retrieving, updating, and deleting users. The service is registered in the ServiceManager. [1] [2]

REST API for User Management

  • Added a UserHandler in userhandler.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

  • Created a User model in user.go to represent user data, including Id, OrgId, Type, and Attributes.
  • Added a UserProvider in userprovider.go to abstract the creation and retrieval of the UserService instance.

Data Storage Layer

  • Defined SQL queries for user operations (create, retrieve, update, delete) in constants.go under the store package. These queries are used by the UserService to interact with the database.

userService := userProvider.GetUserService()
user, err := userService.GetUser(id)
if err != nil {
http.Error(w, "Failed get user", http.StatusInternalServerError)
Copy link
Contributor

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)
Copy link
Contributor

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) {

Copy link
Contributor

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?

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.

2 participants