|
|
@@ -1,130 +0,0 @@
|
|
|
-package main
|
|
|
-
|
|
|
-import (
|
|
|
- "git.sxidc.com/go-framework/baize"
|
|
|
- "git.sxidc.com/go-framework/baize/application"
|
|
|
- "git.sxidc.com/go-framework/baize/binding/request"
|
|
|
- "git.sxidc.com/go-framework/baize/convenient/entity"
|
|
|
- "git.sxidc.com/go-framework/baize/domain"
|
|
|
- "git.sxidc.com/go-framework/baize/infrastructure"
|
|
|
- "git.sxidc.com/go-framework/baize/infrastructure/database/data_service"
|
|
|
- DEATH "github.com/vrecan/death"
|
|
|
- "syscall"
|
|
|
- "time"
|
|
|
-)
|
|
|
-
|
|
|
-// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:10100/test/v1/class/create"
|
|
|
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"92cede40e5464ff79541418a7fc738ec", "name":"test-new"}' "http://localhost:10100/test/v1/class/update"
|
|
|
-// curl -X GET "http://localhost:10100/test/v1/class/query?name=test-new&pageNo=1&pageSize=1"
|
|
|
-// curl -X GET "http://localhost:10100/test/v1/class/get?id=92cede40e5464ff79541418a7fc738ec"
|
|
|
-// curl -X DELETE "http://localhost:10100/test/v1/class/92cede40e5464ff79541418a7fc738ec/delete"
|
|
|
-
|
|
|
-type CreateClassJsonBody struct {
|
|
|
- Name string `json:"name" binding:"required" assign:"toField:Name"`
|
|
|
- StudentNum int `json:"studentNum" binding:"required" assign:"toField:StudentNum"`
|
|
|
-}
|
|
|
-
|
|
|
-type DeleteClassPathParams struct {
|
|
|
- request.IDPath
|
|
|
-}
|
|
|
-
|
|
|
-type UpdateClassJsonBody struct {
|
|
|
- request.IDJsonBody
|
|
|
- Name string `json:"name" assign:"toField:Name"`
|
|
|
- StudentNum int `json:"studentNum" assign:"toField:StudentNum"`
|
|
|
-}
|
|
|
-
|
|
|
-type QueryClassesQueryParams struct {
|
|
|
- Name string `form:"name" assign:"toField:Name"`
|
|
|
- StudentNum int `form:"studentNum" assign:"toField:StudentNum"`
|
|
|
- request.BaseQuery
|
|
|
-}
|
|
|
-
|
|
|
-type GetClassQueryParams struct {
|
|
|
- request.IDQuery
|
|
|
-}
|
|
|
-
|
|
|
-type Class struct {
|
|
|
- domain.BaseEntity
|
|
|
- Name string `sqlmapping:"column:name"`
|
|
|
- StudentNum int `sqlmapping:"column:student_num"`
|
|
|
- CreatedTime time.Time
|
|
|
- LastUpdatedTime *time.Time
|
|
|
-}
|
|
|
-
|
|
|
-func (class *Class) DomainCNName() string {
|
|
|
- return "班级"
|
|
|
-}
|
|
|
-
|
|
|
-type InfoIDField struct {
|
|
|
- ID string `json:"id" sqlresult:"column:id"`
|
|
|
-}
|
|
|
-
|
|
|
-type ClassInfo struct {
|
|
|
- *InfoIDField
|
|
|
- Name string `json:"name" sqlresult:"column:name"`
|
|
|
- StudentNum int `json:"studentNum" sqlresult:"column:student_num"`
|
|
|
- CreatedTime string `sqlresult:"parseTime:'2006-01-02 15:04:05'"`
|
|
|
- LastUpdatedTime string `sqlresult:"parseTime:'2006-01-02 15:04:05'"`
|
|
|
-}
|
|
|
-
|
|
|
-const (
|
|
|
- tableName = "test.classes"
|
|
|
-)
|
|
|
-
|
|
|
-func main() {
|
|
|
- app := baize.NewApplication(application.Config{
|
|
|
- ApiConfig: application.ApiConfig{
|
|
|
- UrlPrefix: "test",
|
|
|
- Port: "10100",
|
|
|
- },
|
|
|
- InfrastructureConfig: application.InfrastructureConfig{
|
|
|
- Database: infrastructure.DatabaseConfig{
|
|
|
- DataService: &data_service.Config{
|
|
|
- Token: "8qe+uPgpQ2JWxu3lSyOx5NjX+INp5WsnoD1ZWb7PBm4=",
|
|
|
- BaseUrl: "http://localhost:10000",
|
|
|
- GrpcAddress: "localhost:10001",
|
|
|
- Namespace: "baize",
|
|
|
- DataSource: "baize-binding",
|
|
|
- TimeoutSec: 30,
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- })
|
|
|
-
|
|
|
- defer func() {
|
|
|
- baize.DestroyApplication(app)
|
|
|
- }()
|
|
|
-
|
|
|
- app.Api().
|
|
|
- PrefixRouter().
|
|
|
- RegisterVersionedRouter("v1")
|
|
|
-
|
|
|
- entity.BindSimple[ClassInfo](app.Binder("v1"), &entity.Simple[ClassInfo]{
|
|
|
- Entity: &Class{},
|
|
|
- TableName: tableName,
|
|
|
- DomainPath: "/class",
|
|
|
- CreateJsonBody: &CreateClassJsonBody{},
|
|
|
- DeleteQueryParams: &DeleteClassPathParams{},
|
|
|
- UpdateJsonBody: &UpdateClassJsonBody{},
|
|
|
- QueryParams: &QueryClassesQueryParams{},
|
|
|
- GetByIDQueryParams: &GetClassQueryParams{},
|
|
|
- }, entity.WithUpdateTx[ClassInfo](), entity.WithDeleteTx[ClassInfo]())
|
|
|
-
|
|
|
- go func() {
|
|
|
- err := app.Start()
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
- defer func() {
|
|
|
- err := app.Finish()
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
- death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
|
|
|
- _ = death.WaitForDeath()
|
|
|
-}
|