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.
139 lines
3.3 KiB
139 lines
3.3 KiB
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"laic-backend/common"
|
|
"laic-backend/service"
|
|
"laic-backend/vo"
|
|
"strconv"
|
|
)
|
|
|
|
func ChangePassword(c *gin.Context) {
|
|
var req vo.ChangePasswordReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
if e := service.DefaultUserService.ChangePassword(common.GetUserId(c), &req); e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
func ListSessions(c *gin.Context) {
|
|
data, e := service.DefaultUserService.ListSessions(common.GetUserId(c), c.GetInt64("session_id"))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, data)
|
|
}
|
|
func RevokeSession(c *gin.Context) {
|
|
id, e := parseID(c)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
if be := service.DefaultUserService.RevokeSession(common.GetUserId(c), id); be != nil {
|
|
common.FailWithBusiError(c, be)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
func RevokeOtherSessions(c *gin.Context) {
|
|
if e := service.DefaultUserService.RevokeOtherSessions(common.GetUserId(c), c.GetInt64("session_id")); e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
|
|
func ListInvoiceProfiles(c *gin.Context) {
|
|
d, e := service.DefaultInvoiceService.ListProfiles(common.GetUserId(c))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, d)
|
|
}
|
|
func SaveInvoiceProfile(c *gin.Context) {
|
|
var req vo.InvoiceProfileReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
id := int64(0)
|
|
if raw := c.Param("id"); raw != "" {
|
|
parsed, err := strconv.ParseInt(raw, 10, 64)
|
|
if err != nil || parsed <= 0 {
|
|
common.FailWithBusiError(c, common.ErrParam)
|
|
return
|
|
}
|
|
id = parsed
|
|
}
|
|
d, e := service.DefaultInvoiceService.SaveProfile(common.GetUserId(c), id, &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, d)
|
|
}
|
|
func DeleteInvoiceProfile(c *gin.Context) {
|
|
id, e := parseID(c)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
if e = service.DefaultInvoiceService.DeleteProfile(common.GetUserId(c), id); e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
func ListInvoiceOrders(c *gin.Context) {
|
|
d, e := service.DefaultInvoiceService.ListEligibleOrders(common.GetUserId(c))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, d)
|
|
}
|
|
func CreateInvoiceRequest(c *gin.Context) {
|
|
var req vo.InvoiceRequestCreateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
d, e := service.DefaultInvoiceService.CreateRequest(common.GetUserId(c), &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, d)
|
|
}
|
|
func ListInvoiceRequests(c *gin.Context) {
|
|
d, e := service.DefaultInvoiceService.ListRequests(common.GetUserId(c))
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, d)
|
|
}
|
|
func ReviewInvoiceRequest(c *gin.Context) {
|
|
id, e := parseID(c)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
var req vo.InvoiceReviewReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
d, e := service.DefaultInvoiceService.ReviewRequest(id, &req)
|
|
if e != nil {
|
|
common.FailWithBusiError(c, e)
|
|
return
|
|
}
|
|
common.OKWithData(c, d)
|
|
}
|
|
|