Public Access
64 lines
1.4 KiB
Smarty
64 lines
1.4 KiB
Smarty
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
// We can assume imports like 'response' are available in the same package
|
|
// or we might need to fix imports if this file is in a subfolder.
|
|
)
|
|
|
|
type {{ .Name }}Request struct {
|
|
// TODO: Add request fields
|
|
// Username string `json:"username" binding:"required"`
|
|
}
|
|
|
|
type {{ .Name }}Response struct {
|
|
// TODO: Add response fields
|
|
}
|
|
|
|
// {{ .Name }} godoc
|
|
// @Summary {{ .Name }}
|
|
// @Description {{ .Name }} handler
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body {{ .Name }}Request true "Request body"
|
|
// @Success 200 {object} response.JSONResponse{data={{ .Name }}Response}
|
|
// @Router /v1/{{ .Name }} [post]
|
|
func (s *Server) create{{ .Name }}(ctx *gin.Context) {
|
|
var req {{ .Name }}Request
|
|
// We assume response.JSONResponse is available or imported
|
|
var resp response.JSONResponse
|
|
|
|
if err := ctx.ShouldBindJSON(&req); err != nil {
|
|
resp = response.JSONResponse{
|
|
Success: false,
|
|
Error: err.Error(),
|
|
}
|
|
ctx.JSON(http.StatusBadRequest, resp)
|
|
return
|
|
}
|
|
|
|
// TODO: Call your service here
|
|
// result, err := s.service.{{ .Name }}(ctx, req)
|
|
|
|
/*
|
|
if err != nil {
|
|
resp = response.JSONResponse{
|
|
Success: false,
|
|
Error: err.Error(),
|
|
}
|
|
ctx.JSON(http.StatusInternalServerError, resp)
|
|
return
|
|
}
|
|
*/
|
|
|
|
resp = response.JSONResponse{
|
|
Success: true,
|
|
Message: "Operation successful",
|
|
Data: nil, // Replace with actual data
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, resp)
|
|
}
|