You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.0 KiB
174 lines
5.0 KiB
<%@ CodeTemplate Language="C#" ClassName="Go_APICrtl" TargetLanguage="C#" Debug="False" Description="" %>
|
|
<%@ Property Name="databaseName" Type="System.String" Default="TqAd" Optional="True" Category="Context" Description="" %>
|
|
|
|
<%@ Property Name="databaseProjectName" Type="System.String" Default="SpSampleDb" Optional="True" Category="Context" Description="" %>
|
|
<%@ Property Name="nameSpace" Type="System.String" Default="Ctrl" Optional="True" Category="Context" Description="" %>
|
|
<%
|
|
DbEntity db = Template.GetDataBase(databaseProjectName);
|
|
foreach(Table tb in db.Tables)
|
|
{
|
|
OpenResponse(databaseProjectName+"\\GoApiCtrl\\"+tb.ModuleName+"\\"+tb.PropertyName.ToLower()+"ctrl.go");
|
|
string pkParmList = "";
|
|
foreach(Field fd in tb.Fields)
|
|
{
|
|
if(fd.IsPK == true)
|
|
pkParmList += fd.DataType.DotNetType+" "+fd.MemberName+",";
|
|
}
|
|
pkParmList = pkParmList.Trim(',');
|
|
%>
|
|
|
|
/*******************************************************/
|
|
/*Project:
|
|
Module :
|
|
Description :
|
|
Date : <%=DateTime.Now.ToString()%>
|
|
Create : Lxc
|
|
Update :
|
|
TODO : */
|
|
/*******************************************************/
|
|
package controllers
|
|
|
|
import (
|
|
|
|
//"encoding/json"
|
|
|
|
//"hm/eclibs/formatcom"
|
|
"hm/carapi/apiservice/dtos"
|
|
"hm/carapi/apiservice/pubdata"
|
|
//"hm/carapi/models"
|
|
"hm/carapi/models/<%=tb.ModuleName.ToLower()%>"
|
|
"hm/eclibs/logger"
|
|
"net/http"
|
|
)
|
|
|
|
|
|
|
|
// Operations about <%=tb.PropertyName%>
|
|
type <%=tb.PropertyName%>Ctrl struct {
|
|
BaseController
|
|
}
|
|
|
|
|
|
// @Title Query
|
|
// @Description get all <%=tb.MemberName%>
|
|
// @Success 200 {object} models.<%=tb.MemberName%>
|
|
// @router / [get]
|
|
func (c *<%=tb.PropertyName%>Ctrl) Query(w http.ResponseWriter, r *http.Request) {
|
|
|
|
resultDto := new(dtos.ResultDto)
|
|
method := c.RequestString(r, "method")
|
|
logger.Debug("method=" + method)
|
|
|
|
<%=tb.MemberName.ToLower()%>Model := new(<%=tb.MemberName.ToLower()%>.<%=tb.PropertyName%>)
|
|
where := ""
|
|
|
|
if method == "all" {
|
|
<%=tb.MemberName%>List, _ := <%=tb.MemberName.ToLower()%>Model.WashSiteArr(where)
|
|
resultDto.Rows = <%=tb.MemberName%>List
|
|
} else if method == "<%=tb.MemberName%>" {
|
|
where = ""
|
|
<%=tb.MemberName%>List, _ := <%=tb.MemberName.ToLower()%>Model.WashSiteArr(where)
|
|
resultDto.Rows = <%=tb.MemberName%>List
|
|
} else {
|
|
resultDto.Result = "error"
|
|
resultDto.Message = "??"
|
|
resultDto.Resutcode = "err:<%=tb.MemberName%>_Q_002"
|
|
|
|
}
|
|
|
|
c.WriteJson(w, r, resultDto)
|
|
}
|
|
|
|
// @Title create<%=tb.PropertyName%>
|
|
// @Description create <%=tb.PropertyName%>
|
|
// @Param body body models.<%=tb.PropertyName%> true "body for <%=tb.PropertyName%> content"
|
|
// @Success 200 {int} models.<%=tb.PropertyName%>.Id
|
|
// @Failure 403 body is empty
|
|
// @router / [post]
|
|
func (c *<%=tb.PropertyName%>Ctrl) Post(w http.ResponseWriter, r *http.Request) {
|
|
|
|
resultDto := new(dtos.ResultDto)
|
|
<%=tb.MemberName.ToLower()%>Model := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
|
|
|
|
ok := <%=tb.MemberName.ToLower()%>Model.Add()
|
|
|
|
|
|
if ok {
|
|
resultDto.Result = pubdata.Success
|
|
} else {
|
|
resultDto.Result = pubdata.Error
|
|
}
|
|
c.WriteJson(w, r, resultDto)
|
|
}
|
|
|
|
|
|
// @Title Get
|
|
// @Description get <%=tb.PropertyName%> by uid
|
|
// @Param uid path string true "The key for staticblock"
|
|
// @Success 200 {object} models.<%=tb.MemberName%>
|
|
// @Failure 403 :uid is empty
|
|
// @router /:uid [get]
|
|
func (c *<%=tb.PropertyName%>Ctrl) Get(w http.ResponseWriter, r *http.Request) {
|
|
resultDto := new(dtos.ResultDto)
|
|
uid := c.RequestString(r, ":uid")
|
|
logger.Debug(uid)
|
|
|
|
if uid != "" {
|
|
<%=tb.MemberName.ToLower()%>Dal:= new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
|
|
|
|
|
|
<%=tb.MemberName.ToLower()%> := <%=tb.MemberName.ToLower()%>Dal.GetModel(uid)
|
|
if washsite != nil {
|
|
resultDto.Obj = <%=tb.MemberName.ToLower()%>
|
|
} else {
|
|
|
|
logger.Error("<%=tb.MemberName.ToLower()%>")
|
|
}
|
|
}
|
|
c.WriteJson(w, r, resultDto)
|
|
}
|
|
|
|
// @Title update
|
|
// @Description update the user
|
|
// @Param uid path string true "The uid you want to update"
|
|
// @Param body body models.User true "body for user content"
|
|
// @Success 200 {object} models.User
|
|
// @Failure 403 :uid is not int
|
|
// @router /:uid [put]
|
|
func (c *<%=tb.PropertyName%>Ctrl) Put(w http.ResponseWriter, r *http.Request) {
|
|
resultDto := new(dtos.ResultDto)
|
|
<%=tb.MemberName.ToLower()%>Model := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
|
|
|
|
|
|
ok := <%=tb.MemberName.ToLower()%>Model.Update()
|
|
if ok {
|
|
resultDto.Result = pubdata.Success
|
|
} else {
|
|
resultDto.Result = pubdata.Error
|
|
}
|
|
c.WriteJson(w, r, resultDto)
|
|
}
|
|
|
|
// @Title delete
|
|
// @Description delete the <%=tb.MemberName%>
|
|
// @Param uid path string true "The uid you want to delete"
|
|
// @Success 200 {string} delete success!
|
|
// @Failure 403 uid is empty
|
|
// @router /:uid [delete]
|
|
func (c *<%=tb.PropertyName%>Ctrl) Delete(w http.ResponseWriter, r *http.Request) {
|
|
resultDto := new(dtos.ResultDto)
|
|
uid := c.RequestInt(r,":uid")
|
|
logger.Debug(uid)
|
|
<%=tb.PropertyName.ToLower()%>Model := new(<%=tb.ModuleName.ToLower()%>.<%=tb.PropertyName%>)
|
|
<%=tb.PropertyName.ToLower()%>Model.Id=uid;
|
|
<%=tb.PropertyName.ToLower()%>Model.Delete()
|
|
|
|
c.WriteJson(w, r, resultDto)
|
|
}
|
|
|
|
|
|
|
|
<%
|
|
CloseResponse();
|
|
}
|
|
%>
|
|
|