Browse Source

[dev]login

Zhangzhenhua 2 weeks ago
parent
commit
f5904146b8

+ 0 - 15
api/hello/hello.go

@@ -1,15 +0,0 @@
-// =================================================================================
-// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
-// =================================================================================
-
-package hello
-
-import (
-	"context"
-
-	"cris/api/hello/v1"
-)
-
-type IHelloV1 interface {
-	Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error)
-}

+ 0 - 12
api/hello/v1/hello.go

@@ -1,12 +0,0 @@
-package v1
-
-import (
-	"github.com/gogf/gf/v2/frame/g"
-)
-
-type HelloReq struct {
-	g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"You first hello api"`
-}
-type HelloRes struct {
-	g.Meta `mime:"text/html" example:"string"`
-}

+ 14 - 0
api/v1/common/login.go

@@ -0,0 +1,14 @@
+package common
+
+import "github.com/gogf/gf/v2/frame/g"
+
+type LoginReq struct {
+	g.Meta   `path:"/login" tags:"Login" method:"get" summary:"Demo"`
+	Email    string `v:"required" json:"email" dc:"email"`
+	Password string `v:"required" json:"password"  dc:"password"`
+}
+
+type LoginRes struct {
+	Message string      `json:"message" dc:"消息"`
+	Data    interface{} `json:"data"    dc:"结果"`
+}

+ 2 - 4
internal/cmd/cmd.go

@@ -7,7 +7,7 @@ import (
 	"github.com/gogf/gf/v2/net/ghttp"
 	"github.com/gogf/gf/v2/os/gcmd"
 
-	"cris/internal/controller/hello"
+	"cris/internal/controller"
 )
 
 var (
@@ -19,9 +19,7 @@ var (
 			s := g.Server()
 			s.Group("/", func(group *ghttp.RouterGroup) {
 				group.Middleware(ghttp.MiddlewareHandlerResponse)
-				group.Bind(
-					hello.NewV1(),
-				)
+				group.Bind(new(controller.LoginController))
 			})
 			s.Run()
 			return nil

+ 29 - 0
internal/controller/auth_controller.go

@@ -0,0 +1,29 @@
+package controller
+
+import (
+	"context"
+
+	"cris/api/v1/common"
+	"cris/internal/service"
+
+	"github.com/gogf/gf/v2/frame/g"
+)
+
+type LoginController struct {
+	LoginService *service.LoginService
+}
+
+// 登录处理方法
+func (c *LoginController) Login(ctx context.Context, req *common.LoginReq) (res *common.LoginRes, err error) {
+
+	r := g.RequestFromCtx(ctx) // 获取 *ghttp.Request
+	if err := r.Parse(req); err != nil {
+		r.Response.WriteJsonExit(map[string]interface{}{"error": err.Error()})
+	}
+
+	// 调用服务层进行业务逻辑处理
+	res = c.LoginService.Login(req)
+
+	r.Response.WriteJson(res)
+	return
+}

+ 0 - 5
internal/controller/hello/hello.go

@@ -1,5 +0,0 @@
-// =================================================================================
-// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
-// =================================================================================
-
-package hello

+ 0 - 16
internal/controller/hello/hello_new.go

@@ -1,16 +0,0 @@
-// =================================================================================
-// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. 
-// =================================================================================
-
-package hello
-
-import (
-	"cris/api/hello"
-)
-
-type ControllerV1 struct{}
-
-func NewV1() hello.IHelloV1 {
-	return &ControllerV1{}
-}
-

+ 0 - 13
internal/controller/hello/hello_v1_hello.go

@@ -1,13 +0,0 @@
-package hello
-
-import (
-	"context"
-	"github.com/gogf/gf/v2/frame/g"
-
-	"cris/api/hello/v1"
-)
-
-func (c *ControllerV1) Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) {
-	g.RequestFromCtx(ctx).Response.Writeln("Hello World!")
-	return
-}

+ 19 - 0
internal/service/auth_service.go

@@ -0,0 +1,19 @@
+package service
+
+import (
+	"cris/api/v1/common"
+)
+
+type LoginService struct{}
+
+func (s *LoginService) Login(req *common.LoginReq) *common.LoginRes {
+	// 在这里进行具体的登录逻辑处理
+
+	return &common.LoginRes{
+		Message: "Login successful",
+		Data: map[string]interface{}{
+			"email":    req.Email,
+			"password": req.Password,
+		},
+	}
+}