Add branch_user table and branch-user assignment endpoints

Introduces a branch_user join table linking branches to users, plus
create/delete API endpoints under the auth module for managing branch
assignments. The create response includes the branch's localized name
via a join. Regenerated swagger docs to include the new endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-08 15:02:05 +05:00
parent 1337175e5d
commit 77bc4025d3
9 changed files with 462 additions and 3 deletions

View File

@@ -15,6 +15,109 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/branch-users": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Creates a branch-user assignment",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Assign user to branch",
"parameters": [
{
"description": "Branch-user payload",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.CreateBranchUserDTO"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/appresult.AppSuccess"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/branch-users/{id}": {
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "Deletes a branch-user assignment",
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Remove user from branch",
"parameters": [
{
"type": "integer",
"description": "Branch-user ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/appresult.AppSuccess"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/branches": {
"get": {
"security": [
@@ -2765,6 +2868,21 @@ const docTemplate = `{
}
}
},
"auth.CreateBranchUserDTO": {
"type": "object",
"required": [
"branchId",
"userId"
],
"properties": {
"branchId": {
"type": "integer"
},
"userId": {
"type": "integer"
}
}
},
"auth.LoginDTO": {
"type": "object",
"required": [

View File

@@ -9,6 +9,109 @@
"host": "localhost:5050",
"basePath": "/api/admin",
"paths": {
"/branch-users": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Creates a branch-user assignment",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Assign user to branch",
"parameters": [
{
"description": "Branch-user payload",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/auth.CreateBranchUserDTO"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/appresult.AppSuccess"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/branch-users/{id}": {
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "Deletes a branch-user assignment",
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Remove user from branch",
"parameters": [
{
"type": "integer",
"description": "Branch-user ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/appresult.AppSuccess"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/appresult.AppError"
}
}
}
}
},
"/branches": {
"get": {
"security": [
@@ -2759,6 +2862,21 @@
}
}
},
"auth.CreateBranchUserDTO": {
"type": "object",
"required": [
"branchId",
"userId"
],
"properties": {
"branchId": {
"type": "integer"
},
"userId": {
"type": "integer"
}
}
},
"auth.LoginDTO": {
"type": "object",
"required": [

View File

@@ -19,6 +19,16 @@ definitions:
status:
type: boolean
type: object
auth.CreateBranchUserDTO:
properties:
branchId:
type: integer
userId:
type: integer
required:
- branchId
- userId
type: object
auth.LoginDTO:
properties:
email:
@@ -430,6 +440,71 @@ info:
title: Service APIs
version: "1.0"
paths:
/branch-users:
post:
consumes:
- application/json
description: Creates a branch-user assignment
parameters:
- description: Branch-user payload
in: body
name: body
required: true
schema:
$ref: '#/definitions/auth.CreateBranchUserDTO'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/appresult.AppSuccess'
"400":
description: Bad Request
schema:
$ref: '#/definitions/appresult.AppError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/appresult.AppError'
security:
- BearerAuth: []
summary: Assign user to branch
tags:
- auth
/branch-users/{id}:
delete:
description: Deletes a branch-user assignment
parameters:
- description: Branch-user ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/appresult.AppSuccess'
"400":
description: Bad Request
schema:
$ref: '#/definitions/appresult.AppError'
"404":
description: Not Found
schema:
$ref: '#/definitions/appresult.AppError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/appresult.AppError'
security:
- BearerAuth: []
summary: Remove user from branch
tags:
- auth
/branches:
get:
description: Returns paginated branches with optional filters