2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  api  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2021-11-03 18:31:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"context" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-19 20:34:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"strconv" 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-19 20:34:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/dtos" 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/api/response" 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-24 06:35:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/metrics" 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									contextmodel  "github.com/grafana/grafana/pkg/services/contexthandler/model" 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-24 01:26:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/services/org" 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-30 16:12:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/setting" 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-22 14:13:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/util" 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-11 20:30:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/web" 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /org org getCurrentOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
									
										
										
										
											2022-09-12 15:40:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Get current Organization.
  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getCurrentOrgResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetCurrentOrg ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . getOrgHelper ( c . Req . Context ( ) ,  c . OrgID ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /orgs/{org_id} orgs getOrgByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get Organization by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getOrgByIDResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetOrgByID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgId ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":orgId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "orgId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-23 18:12:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . getOrgHelper ( c . Req . Context ( ) ,  orgId ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /orgs/name/{org_name} orgs getOrgByName
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Get Organization by ID.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: getOrgByNameResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  GetOrgByName ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orga ,  err  :=  hs . orgService . GetByName ( c . Req . Context ( ) ,  & org . GetOrgByNameQuery { Name :  web . Params ( c . Req ) [ ":name" ] } ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-07 18:36:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  org . ErrOrgNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusNotFound ,  "Organization not found" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-13 05:50:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to get organization" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-13 05:50:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  org . OrgDetailsDTO { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ID :    orga . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Name :  orga . Name , 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Address :  org . Address { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Address1 :  orga . Address1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Address2 :  orga . Address2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											City :      orga . City , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ZipCode :   orga . ZipCode , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											State :     orga . State , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Country :   orga . Country , 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-13 05:50:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  & result ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-13 05:50:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-23 18:12:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  getOrgHelper ( ctx  context . Context ,  orgID  int64 )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  org . GetOrgByIDQuery { ID :  orgID } 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									res ,  err  :=  hs . orgService . GetByID ( ctx ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  org . ErrOrgNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusNotFound ,  "Organization not found" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to get organization" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orga  :=  res 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result  :=  org . OrgDetailsDTO { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ID :    orga . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Name :  orga . Name , 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Address :  org . Address { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 02:48:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Address1 :  orga . Address1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Address2 :  orga . Address2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											City :      orga . City , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ZipCode :   orga . ZipCode , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											State :     orga . State , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Country :   orga . Country , 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  & result ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route POST /orgs orgs createOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Create Organization.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Only works if [users.allow_org_create](https://grafana.com/docs/grafana/latest/administration/configuration/#allow_org_create) is set.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: createOrgResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 409: conflictError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  CreateOrg ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-10-05 21:47:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  org . CreateOrgCommand { } 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-04-25 16:42:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									acEnabled  :=  ! hs . AccessControl . IsDisabled ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-27 19:13:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ! acEnabled  &&  ! ( setting . AllowUserOrgCreate  ||  c . IsGrafanaAdmin )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusForbidden ,  "Access denied" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-30 16:12:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 21:47:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd . UserID  =  c . UserID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									result ,  err  :=  hs . orgService . CreateWithMember ( c . Req . Context ( ) ,  & cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  org . ErrOrgNameTaken )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusConflict ,  "Organization name taken" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 19:06:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to create organization" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 22:58:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									metrics . MApiOrgCreate . Inc ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-23 03:14:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-04-15 20:01:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  & util . DynMap { 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-05 21:47:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										"orgId" :    result . ID , 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-22 14:13:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										"message" :  "Organization created" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /org org updateCurrentOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Update current Organization.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  UpdateCurrentOrg ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									form  :=  dtos . UpdateOrgForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . updateOrgHelper ( c . Req . Context ( ) ,  form ,  c . OrgID ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /orgs/{org_id} orgs updateOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Update Organization.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  UpdateOrg ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									form  :=  dtos . UpdateOrgForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgId ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":orgId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "orgId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-26 03:30:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . updateOrgHelper ( c . Req . Context ( ) ,  form ,  orgId ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 16:16:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-26 03:30:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  updateOrgHelper ( ctx  context . Context ,  form  dtos . UpdateOrgForm ,  orgID  int64 )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-08-24 01:26:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  org . UpdateOrgCommand { Name :  form . Name ,  OrgId :  orgID } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  hs . orgService . UpdateOrg ( ctx ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  org . ErrOrgNameTaken )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusBadRequest ,  "Organization name taken" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 19:06:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to update organization" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "Organization updated" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /org/address org updateCurrentOrgAddress
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Update current Organization's address.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  UpdateCurrentOrgAddress ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									form  :=  dtos . UpdateOrgAddressForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . updateOrgAddressHelper ( c . Req . Context ( ) ,  form ,  c . OrgID ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route PUT /orgs/{org_id}/address orgs updateOrgAddress
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Update Organization's address.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  UpdateOrgAddress ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2021-11-29 17:18:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									form  :=  dtos . UpdateOrgAddressForm { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  :=  web . Bind ( c . Req ,  & form ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "bad request data" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgId ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":orgId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "orgId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2022-01-26 03:30:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  hs . updateOrgAddressHelper ( c . Req . Context ( ) ,  form ,  orgId ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-26 03:30:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  updateOrgAddressHelper ( ctx  context . Context ,  form  dtos . UpdateOrgAddressForm ,  orgID  int64 )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-09-27 18:30:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cmd  :=  org . UpdateOrgAddressCommand { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OrgID :  orgID , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Address :  org . Address { 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Address1 :  form . Address1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Address2 :  form . Address2 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											City :      form . City , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											State :     form . State , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ZipCode :   form . ZipCode , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Country :   form . Country , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 18:30:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . orgService . UpdateAddress ( ctx ,  & cmd ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to update org address" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "Address updated" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-08 20:22:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route DELETE /orgs/{org_id} orgs deleteOrgByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Delete Organization.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: okResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 400: badRequestError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 404: notFoundError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  DeleteOrgByID ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2022-01-15 00:55:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									orgID ,  err  :=  strconv . ParseInt ( web . Params ( c . Req ) [ ":orgId" ] ,  10 ,  64 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "orgId is invalid" ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-23 14:58:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// before deleting an org, check if user does not belong to the current org
 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-11 19:28:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  c . OrgID  ==  orgID  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusBadRequest ,  "Can not delete org for current user" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-23 14:58:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-27 18:30:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  hs . orgService . Delete ( c . Req . Context ( ) ,  & org . DeleteOrgCommand { ID :  orgID } ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  errors . Is ( err ,  org . ErrOrgNotFound )  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  response . Error ( http . StatusNotFound ,  "Failed to delete organization. ID not found" ,  nil ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-28 06:09:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to update organization" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 14:59:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2021-01-15 21:43:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . Success ( "Organization deleted" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-12 14:59:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// swagger:route GET /orgs orgs searchOrgs
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
									
										
										
										
											2022-09-12 15:40:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Search all Organizations.
  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Security:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// - basic:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								//
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Responses:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 200: searchOrgsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 401: unauthorisedError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 403: forbiddenError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 409: conflictError
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// 500: internalServerError
  
						 
					
						
							
								
									
										
										
										
											2023-01-27 15:50:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( hs  * HTTPServer )  SearchOrgs ( c  * contextmodel . ReqContext )  response . Response  {  
						 
					
						
							
								
									
										
										
										
											2020-08-12 15:59:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									perPage  :=  c . QueryInt ( "perpage" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  perPage  <=  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										perPage  =  1000 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									page  :=  c . QueryInt ( "page" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 15:55:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									query  :=  org . SearchOrgsQuery { 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Query :  c . Query ( "query" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Name :   c . Query ( "name" ) , 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-12 15:59:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Page :   page , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Limit :  perPage , 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 15:55:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									result ,  err  :=  hs . orgService . Search ( c . Req . Context ( ) ,  & query ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 20:50:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  response . Error ( http . StatusInternalServerError ,  "Failed to search orgs" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-20 15:55:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  response . JSON ( http . StatusOK ,  result ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-19 17:47:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateCurrentOrgAddress
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateCurrentOrgAddressParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . UpdateOrgAddressForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateCurrentOrgUser
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateCurrentOrgUserParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-09 21:39:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  org . UpdateOrgUserCommand  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									UserID  int64  ` json:"user_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateCurrentOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateCurrentOrgParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . UpdateOrgForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateOrgAddress
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateOrgAddressParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . UpdateOrgAddressForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OrgID  int64  ` json:"org_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getOrgByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetOrgByIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OrgID  int64  ` json:"org_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters deleteOrgByID
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  DeleteOrgByIDParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OrgID  int64  ` json:"org_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters updateOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  UpdateOrgParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  dtos . UpdateOrgForm  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OrgID  int64  ` json:"org_id" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters getOrgByName
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetOrgByNameParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OrgName  string  ` json:"org_name" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters createOrg
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  CreateOrgParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:true
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  org . CreateOrgCommand  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:parameters searchOrgs
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  SearchOrgParams  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// default: 1
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Page  int  ` json:"page" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Number of items per page
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The totalCount field in the response can be used for pagination list E.g. if totalCount is equal to 100 teams and the perpage parameter is set to 10 then there are 10 pages of teams.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in:query
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// default: 1000
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PerPage  int     ` json:"perpage" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Name     string  ` json:"name" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// If set it will return results where the query value is contained in the name field. Query values with spaces need to be URL encoded.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// required:false
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Query  string  ` json:"query" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response createOrgResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  CreateOrgResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Body  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// ID Identifier of the created org.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// example: 65
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										OrgID  int64  ` json:"orgId" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Message Message of the created org.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// required: true
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// example: Data source added
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Message  string  ` json:"message" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  ` json:"body" ` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response searchOrgsResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  SearchOrgsResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  [ ] * org . OrgDTO  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getCurrentOrgResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetCurrentOrgResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  org . OrgDetailsDTO  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getOrgByIDResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetOrgByIDResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  org . OrgDetailsDTO  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// swagger:response getOrgByNameResponse
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  GetOrgByNameResponse  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// The response message
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// in: body
 
							 
						 
					
						
							
								
									
										
										
										
											2023-01-04 23:20:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Body  org . OrgDetailsDTO  ` json:"body" ` 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-27 21:54:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}