lhs %!s(int64=4) %!d(string=hai) anos
pai
achega
db417291fd
Modificáronse 6 ficheiros con 201 adicións e 3 borrados
  1. 28 0
      controller/test.go
  2. 40 0
      docs/docs.go
  3. 40 0
      docs/swagger.json
  4. 26 0
      docs/swagger.yaml
  5. 62 3
      repository/postgres/test.go
  6. 5 0
      service/test.go

+ 28 - 0
controller/test.go

@@ -30,3 +30,31 @@ func (t *Test) UserAdd() (err error) {
 	t.Ctx().JSON(http.StatusOK, newResponseBase())
 	return
 }
+
+type UserList struct {
+	ResponseBase
+	Rs []interface{}
+	//Rs []*gorm.ShopUserSimpleInfo
+}
+
+// UserListQuery godoc
+// @Summary 会员用户查询
+// @tags Test
+// @Description 会员用户查询
+// @Accept  x-www-form-urlencoded
+// @Produce  json
+// @Success 200 {object} controller.UserList
+// @Router /Test/UserListQuery [post]
+func (t *Test) UserListQuery() (err error) {
+
+	rs, err := service.Test{}.UserListQuery()
+	if err != nil {
+		return
+	}
+	rp := UserList{
+		newResponseBase(),
+		rs,
+	}
+	t.Ctx().JSON(http.StatusOK, rp)
+	return
+}

+ 40 - 0
docs/docs.go

@@ -227,6 +227,29 @@ var doc = `{
                 }
             }
         },
+        "/Test/UserListQuery": {
+            "post": {
+                "description": "会员用户查询",
+                "consumes": [
+                    "application/x-www-form-urlencoded"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Test"
+                ],
+                "summary": "会员用户查询",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/controller.UserList"
+                        }
+                    }
+                }
+            }
+        },
         "/User/ShopCoachAdd": {
             "post": {
                 "description": "商家教练添加",
@@ -907,6 +930,23 @@ var doc = `{
                     "type": "string"
                 }
             }
+        },
+        "controller.UserList": {
+            "type": "object",
+            "properties": {
+                "code": {
+                    "type": "integer"
+                },
+                "memo": {
+                    "type": "string"
+                },
+                "rs": {
+                    "type": "array",
+                    "items": {
+                        "type": "object"
+                    }
+                }
+            }
         }
     },
     "securityDefinitions": {

+ 40 - 0
docs/swagger.json

@@ -211,6 +211,29 @@
                 }
             }
         },
+        "/Test/UserListQuery": {
+            "post": {
+                "description": "会员用户查询",
+                "consumes": [
+                    "application/x-www-form-urlencoded"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Test"
+                ],
+                "summary": "会员用户查询",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/controller.UserList"
+                        }
+                    }
+                }
+            }
+        },
         "/User/ShopCoachAdd": {
             "post": {
                 "description": "商家教练添加",
@@ -891,6 +914,23 @@
                     "type": "string"
                 }
             }
+        },
+        "controller.UserList": {
+            "type": "object",
+            "properties": {
+                "code": {
+                    "type": "integer"
+                },
+                "memo": {
+                    "type": "string"
+                },
+                "rs": {
+                    "type": "array",
+                    "items": {
+                        "type": "object"
+                    }
+                }
+            }
         }
     },
     "securityDefinitions": {

+ 26 - 0
docs/swagger.yaml

@@ -36,6 +36,17 @@ definitions:
       rs:
         type: string
     type: object
+  controller.UserList:
+    properties:
+      code:
+        type: integer
+      memo:
+        type: string
+      rs:
+        items:
+          type: object
+        type: array
+    type: object
 info:
   contact:
     email: support@swagger.io
@@ -179,6 +190,21 @@ paths:
       summary: 会员用户添加
       tags:
       - Test
+  /Test/UserListQuery:
+    post:
+      consumes:
+      - application/x-www-form-urlencoded
+      description: 会员用户查询
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/controller.UserList'
+      summary: 会员用户查询
+      tags:
+      - Test
   /User/ShopCoachAdd:
     post:
       consumes:

+ 62 - 3
repository/postgres/test.go

@@ -1,13 +1,72 @@
 package postgres
 
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/jackc/pgx/v4"
+)
+
 type Test struct {
 	base
 }
 
 func (t Test) UserAdd(name string) {
+	stCode := -999
+	sql := `select fn_user_add2($1,$2);`
+	_, err := t.writeDB().QueryFunc(t.ctx(), sql, []interface{}{name, stCode}, []interface{}{&stCode}, func(pgx.QueryFuncRow) error {
+		fmt.Printf("%v", stCode)
+		return nil
+	})
+	if err != nil {
+		fmt.Printf("QueryFunc error: %v", err)
+	}
+
+}
+
+type UserListInfo struct {
+	Id   int
+	Name string
+}
+
+func (t Test) UserList1() (rs []interface{}, err error) {
+	//var id int32
+	//var name string
+	//var ct time.Time
+	var one interface{}
+	var rs_ struct {
+		Rs []interface{}
+	}
+	//var a interface{}
+
+	sql := `select id,name from func_userlist_query();`
+	_, err = t.writeDB().QueryFunc(t.ctx(), sql, []interface{}{}, []interface{}{&one}, func(rows pgx.QueryFuncRow) error {
+
+		rs_.Rs = append(rs_.Rs, one)
+		return nil
+	})
+	if err != nil {
+		fmt.Printf("QueryFunc error: %v", err)
+	}
+
+	data, err := json.Marshal(rs_)
+	println(string(data))
+	return
+}
+func (t Test) UserList() (rs []interface{}, err error) {
+	//var id int32
+	//var name string
+	//var ct time.Time
+	usone := UserListInfo{}
+	sql := `select id,name from func_userlist_query();`
+	_, err = t.writeDB().QueryFunc(t.ctx(), sql, []interface{}{}, []interface{}{&usone.Id, &usone.Name}, func(pgx.QueryFuncRow) error {
 
-	sql := `insert into t_user ( name,create_at) VALUES ($1,now())`
+		fmt.Printf("%v\n", usone)
+		rs = append(rs, usone)
 
-	panicExec(t.writeDB().Exec(t.ctx(), sql,
-		name))
+		return nil
+	})
+	if err != nil {
+		fmt.Printf("QueryFunc error: %v", err)
+	}
+	return
 }

+ 5 - 0
service/test.go

@@ -13,3 +13,8 @@ func (t Test) UserAdd(name string) (err error) {
 	db.Test{}.UserAdd(name)
 	return
 }
+func (t Test) UserListQuery() (rs []interface{}, err error) {
+
+	rs, err = db.Test{}.UserList()
+	return
+}