Merge pull request 'history-order-list' (#3) from history-order-list into main
Reviewed-on: https://git.altru.id/Furtuna/furtuna-backend/pulls/3
This commit is contained in:
commit
6a987f78b9
@ -18,6 +18,22 @@ type Order struct {
|
|||||||
OrderItems []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE;"`
|
OrderItems []OrderItem `gorm:"foreignKey:OrderID;constraint:OnDelete:CASCADE;"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OrderDB struct {
|
||||||
|
Order
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Order) ToOrderDB() *OrderDB {
|
||||||
|
return &OrderDB{
|
||||||
|
Order: *b,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *OrderDB) ToSumAmount() *Order {
|
||||||
|
return &Order{
|
||||||
|
Amount: e.Amount,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type OrderResponse struct {
|
type OrderResponse struct {
|
||||||
Order *Order
|
Order *Order
|
||||||
Token string
|
Token string
|
||||||
@ -99,11 +115,12 @@ type HistoryOrderDB struct {
|
|||||||
HistoryOrder
|
HistoryOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryOrderSearch struct {
|
type OrderSearch struct {
|
||||||
PartnerID *int64
|
PartnerID *int64
|
||||||
IsAdmin bool
|
IsAdmin bool
|
||||||
Limit int
|
PaymentType string
|
||||||
Offset int
|
Limit int
|
||||||
|
Offset int
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryOrderList []*HistoryOrderDB
|
type HistoryOrderList []*HistoryOrderDB
|
||||||
@ -136,3 +153,23 @@ func (b *HistoryOrderList) ToHistoryOrderList() []*HistoryOrder {
|
|||||||
}
|
}
|
||||||
return HistoryOrders
|
return HistoryOrders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TicketSold struct {
|
||||||
|
Count int64 `gorm:"type:int;column:count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TicketSoldDB struct {
|
||||||
|
TicketSold
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *TicketSold) ToTicketSoldDB() *TicketSoldDB {
|
||||||
|
return &TicketSoldDB{
|
||||||
|
TicketSold: *b,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *TicketSoldDB) ToTicketSold() *TicketSold {
|
||||||
|
return &TicketSold{
|
||||||
|
Count: e.Count,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -28,10 +28,12 @@ type Site struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SiteSearch struct {
|
type SiteSearch struct {
|
||||||
Search string
|
PartnerID *int64
|
||||||
Name string
|
IsAdmin bool
|
||||||
Limit int
|
Search string
|
||||||
Offset int
|
Name string
|
||||||
|
Limit int
|
||||||
|
Offset int
|
||||||
}
|
}
|
||||||
|
|
||||||
type SiteList []*SiteDB
|
type SiteList []*SiteDB
|
||||||
@ -143,3 +145,23 @@ func (o *SiteDB) SetDeleted(updatedBy int64) {
|
|||||||
o.DeletedAt = ¤tTime
|
o.DeletedAt = ¤tTime
|
||||||
o.UpdatedBy = updatedBy
|
o.UpdatedBy = updatedBy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SiteCount struct {
|
||||||
|
Count int `gorm:"type:int;column:count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SiteCountDB struct {
|
||||||
|
SiteCount
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *SiteCount) ToSiteCountDB() *SiteCountDB {
|
||||||
|
return &SiteCountDB{
|
||||||
|
SiteCount: *b,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SiteCountDB) ToSiteCount() *SiteCount {
|
||||||
|
return &SiteCount{
|
||||||
|
Count: e.Count,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -23,6 +23,8 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
|||||||
route.POST("/inquiry", jwt, h.Inquiry)
|
route.POST("/inquiry", jwt, h.Inquiry)
|
||||||
route.POST("/execute", jwt, h.Execute)
|
route.POST("/execute", jwt, h.Execute)
|
||||||
route.GET("/history", jwt, h.GetAllHistoryOrders)
|
route.GET("/history", jwt, h.GetAllHistoryOrders)
|
||||||
|
route.GET("/ticket-sold", jwt, h.CountSoldOfTicket)
|
||||||
|
route.GET("/sum-amount", jwt, h.SumAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(service services.Order) *Handler {
|
func NewHandler(service services.Order) *Handler {
|
||||||
@ -169,15 +171,38 @@ func (h *Handler) toHistoryOrderResponse(resp *entity.HistoryOrder) response.His
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
|
func (h *Handler) SumAmount(c *gin.Context) {
|
||||||
var req request.HistoryOrderParam
|
var req request.OrderParam
|
||||||
if err := c.ShouldBindQuery(&req); err != nil {
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := request.GetMyContext(c)
|
ctx := request.GetMyContext(c)
|
||||||
orders, total, err := h.service.GetAllHistoryOrders(ctx, req.ToEntity(ctx))
|
order, err := h.service.SumAmount(ctx, req.ToOrderEntity(ctx))
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorWrapper(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, response.BaseResponse{
|
||||||
|
Success: true,
|
||||||
|
Status: http.StatusOK,
|
||||||
|
Data: response.OrderAmount{
|
||||||
|
Amount: order.Amount,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
|
||||||
|
var req request.OrderParam
|
||||||
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
|
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := request.GetMyContext(c)
|
||||||
|
orders, total, err := h.service.GetAllHistoryOrders(ctx, req.ToOrderEntity(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorWrapper(c, err)
|
response.ErrorWrapper(c, err)
|
||||||
return
|
return
|
||||||
@ -190,7 +215,32 @@ func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.HistoryOrderParam) response.HistoryOrderList {
|
func (h *Handler) CountSoldOfTicket(c *gin.Context) {
|
||||||
|
var req request.OrderParam
|
||||||
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
|
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := request.GetMyContext(c)
|
||||||
|
|
||||||
|
res, err := h.service.CountSoldOfTicket(ctx, req.ToOrderEntity(ctx))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorWrapper(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, response.BaseResponse{
|
||||||
|
Success: true,
|
||||||
|
Status: http.StatusOK,
|
||||||
|
Data: response.TicketSold{
|
||||||
|
Count: res.Count,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.OrderParam) response.HistoryOrderList {
|
||||||
var orders []response.HistoryOrder
|
var orders []response.HistoryOrder
|
||||||
for _, b := range resp {
|
for _, b := range resp {
|
||||||
orders = append(orders, h.toHistoryOrderResponse(b))
|
orders = append(orders, h.toHistoryOrderResponse(b))
|
||||||
|
|||||||
@ -26,6 +26,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
|||||||
route.PUT("/:id", jwt, h.Update)
|
route.PUT("/:id", jwt, h.Update)
|
||||||
route.GET("/:id", jwt, h.GetByID)
|
route.GET("/:id", jwt, h.GetByID)
|
||||||
route.DELETE("/:id", jwt, h.Delete)
|
route.DELETE("/:id", jwt, h.Delete)
|
||||||
|
route.GET("/count", jwt, h.Count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(service services.Site) *Handler {
|
func NewHandler(service services.Site) *Handler {
|
||||||
@ -148,7 +149,8 @@ func (h *Handler) GetAll(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Sites, total, err := h.service.GetAll(c.Request.Context(), req.ToEntity())
|
ctx := request.GetMyContext(c)
|
||||||
|
Sites, total, err := h.service.GetAll(c.Request.Context(), req.ToEntity(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrorWrapper(c, err)
|
response.ErrorWrapper(c, err)
|
||||||
return
|
return
|
||||||
@ -242,6 +244,30 @@ func (h *Handler) GetByID(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) Count(c *gin.Context) {
|
||||||
|
var req request.SiteParam
|
||||||
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
|
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := request.GetMyContext(c)
|
||||||
|
res, err := h.service.Count(ctx, req.ToEntity(ctx))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorWrapper(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, response.BaseResponse{
|
||||||
|
Success: true,
|
||||||
|
Status: http.StatusOK,
|
||||||
|
Data: response.SiteCount{
|
||||||
|
Count: res.Count,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
|
func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
|
||||||
return response.Site{
|
return response.Site{
|
||||||
ID: &resp.ID,
|
ID: &resp.ID,
|
||||||
|
|||||||
@ -12,15 +12,17 @@ type Order struct {
|
|||||||
OrderItems []OrderItem `json:"order_items" validate:"required"`
|
OrderItems []OrderItem `json:"order_items" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryOrderParam struct {
|
type OrderParam struct {
|
||||||
Limit int `form:"limit" json:"limit" example:"10"`
|
PaymentType string `form:"payment_type" json:"payment_type" example:"CASH"`
|
||||||
Offset int `form:"offset" json:"offset" example:"0"`
|
Limit int `form:"limit" json:"limit" example:"10"`
|
||||||
|
Offset int `form:"offset" json:"offset" example:"0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *HistoryOrderParam) ToEntity(ctx mycontext.Context) entity.HistoryOrderSearch {
|
func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
|
||||||
return entity.HistoryOrderSearch{
|
return entity.OrderSearch{
|
||||||
PartnerID: ctx.GetPartnerID(),
|
PartnerID: ctx.GetPartnerID(),
|
||||||
IsAdmin: ctx.IsAdmin(),
|
IsAdmin: ctx.IsAdmin(),
|
||||||
|
PaymentType: o.PaymentType,
|
||||||
Limit: o.Limit,
|
Limit: o.Limit,
|
||||||
Offset: o.Offset,
|
Offset: o.Offset,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package request
|
package request
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"furtuna-be/internal/common/mycontext"
|
||||||
"furtuna-be/internal/entity"
|
"furtuna-be/internal/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,8 +66,10 @@ type SiteParam struct {
|
|||||||
Offset int `form:"offset,default=0"`
|
Offset int `form:"offset,default=0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SiteParam) ToEntity() entity.SiteSearch {
|
func (r *SiteParam) ToEntity(ctx mycontext.Context) entity.SiteSearch {
|
||||||
return entity.SiteSearch{
|
return entity.SiteSearch{
|
||||||
|
PartnerID: ctx.GetPartnerID(),
|
||||||
|
IsAdmin: ctx.IsAdmin(),
|
||||||
Search: r.Search,
|
Search: r.Search,
|
||||||
Name: r.Name,
|
Name: r.Name,
|
||||||
Limit: r.Limit,
|
Limit: r.Limit,
|
||||||
|
|||||||
@ -21,6 +21,10 @@ type Order struct {
|
|||||||
UpdatedAt string `json:"updated_at"`
|
UpdatedAt string `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OrderAmount struct {
|
||||||
|
Amount float64 `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
type HistoryOrder struct {
|
type HistoryOrder struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Employee string `json:"employee"`
|
Employee string `json:"employee"`
|
||||||
@ -58,6 +62,10 @@ type HistoryOrderList struct {
|
|||||||
Offset int `json:"offset"`
|
Offset int `json:"offset"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TicketSold struct {
|
||||||
|
Count int64 `json:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
type OrderMonthlyRevenue struct {
|
type OrderMonthlyRevenue struct {
|
||||||
TotalRevenue float64 `json:"total_revenue"`
|
TotalRevenue float64 `json:"total_revenue"`
|
||||||
TotalTransaction int64 `json:"total_transaction"`
|
TotalTransaction int64 `json:"total_transaction"`
|
||||||
|
|||||||
@ -24,6 +24,10 @@ type SiteName struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SiteCount struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
type SiteList struct {
|
type SiteList struct {
|
||||||
Sites []Site `json:"sites"`
|
Sites []Site `json:"sites"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
|
|||||||
@ -3,8 +3,10 @@ package orders
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"furtuna-be/internal/common/logger"
|
"furtuna-be/internal/common/logger"
|
||||||
|
"furtuna-be/internal/common/mycontext"
|
||||||
"furtuna-be/internal/entity"
|
"furtuna-be/internal/entity"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -83,7 +85,7 @@ func (r *OrderRepository) Update(ctx context.Context, order *entity.Order) (*ent
|
|||||||
return order, nil
|
return order, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.HistoryOrderSearch) (entity.HistoryOrderList, int, error) {
|
func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.OrderSearch) (entity.HistoryOrderList, int, error) {
|
||||||
var orders []*entity.HistoryOrderDB
|
var orders []*entity.HistoryOrderDB
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
@ -128,3 +130,47 @@ func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.Hi
|
|||||||
|
|
||||||
return orders, int(total), nil
|
return orders, int(total), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *OrderRepository) CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSoldDB, error) {
|
||||||
|
today := time.Now().Format("2006-01-02")
|
||||||
|
ticketCount := new(entity.TicketSoldDB)
|
||||||
|
|
||||||
|
query := r.db.Table("orders").
|
||||||
|
Select("sum(items.qty) as count").
|
||||||
|
Joins("left join order_items items on orders.id = items.order_id").
|
||||||
|
Where("orders.status = ?", "PAID").
|
||||||
|
Where("orders.created_at = ?", today)
|
||||||
|
|
||||||
|
if !req.IsAdmin {
|
||||||
|
query = query.Where("orders.partner_id = ?", req.PartnerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Scan(&ticketCount).Error; err != nil {
|
||||||
|
logger.ContextLogger(ctx).Error("error when get count ticket", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ticketCount, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *OrderRepository) SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.OrderDB, error) {
|
||||||
|
amount := new(entity.OrderDB)
|
||||||
|
today := time.Now().Format("2006-01-02")
|
||||||
|
|
||||||
|
query := r.db.Table("orders").
|
||||||
|
Select("sum(amount) as amount").
|
||||||
|
Where("payment_type = ?", req.PaymentType).
|
||||||
|
Where("date(created_at) = ?", today).
|
||||||
|
Where("status = ?", "PAID")
|
||||||
|
|
||||||
|
if !req.IsAdmin {
|
||||||
|
query = query.Where("orders.partner_id = ?", req.PartnerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Scan(&amount).Error; err != nil {
|
||||||
|
logger.ContextLogger(ctx).Error("error when get cash amount", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"furtuna-be/internal/common/mycontext"
|
||||||
"furtuna-be/internal/repository/branches"
|
"furtuna-be/internal/repository/branches"
|
||||||
"furtuna-be/internal/repository/brevo"
|
"furtuna-be/internal/repository/brevo"
|
||||||
"furtuna-be/internal/repository/license"
|
"furtuna-be/internal/repository/license"
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
"furtuna-be/internal/repository/trx"
|
"furtuna-be/internal/repository/trx"
|
||||||
"furtuna-be/internal/repository/users"
|
"furtuna-be/internal/repository/users"
|
||||||
repository "furtuna-be/internal/repository/wallet"
|
repository "furtuna-be/internal/repository/wallet"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
@ -133,7 +135,9 @@ type Order interface {
|
|||||||
FindByID(ctx context.Context, id int64) (*entity.Order, error)
|
FindByID(ctx context.Context, id int64) (*entity.Order, error)
|
||||||
Update(ctx context.Context, order *entity.Order) (*entity.Order, error)
|
Update(ctx context.Context, order *entity.Order) (*entity.Order, error)
|
||||||
SetOrderStatus(ctx context.Context, db *gorm.DB, orderID int64, status string) error
|
SetOrderStatus(ctx context.Context, db *gorm.DB, orderID int64, status string) error
|
||||||
GetAllHystoryOrders(ctx context.Context, req entity.HistoryOrderSearch) (entity.HistoryOrderList, int, error)
|
GetAllHystoryOrders(ctx context.Context, req entity.OrderSearch) (entity.HistoryOrderList, int, error)
|
||||||
|
SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.OrderDB, error)
|
||||||
|
CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSoldDB, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OSSRepository interface {
|
type OSSRepository interface {
|
||||||
@ -157,6 +161,7 @@ type SiteRepository interface {
|
|||||||
GetByID(ctx context.Context, id int64) (*entity.SiteDB, error)
|
GetByID(ctx context.Context, id int64) (*entity.SiteDB, error)
|
||||||
GetAll(ctx context.Context, req entity.SiteSearch) (entity.SiteList, int, error)
|
GetAll(ctx context.Context, req entity.SiteSearch) (entity.SiteList, int, error)
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
|
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransactionManager interface {
|
type TransactionManager interface {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package sites
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"furtuna-be/internal/common/logger"
|
"furtuna-be/internal/common/logger"
|
||||||
|
"furtuna-be/internal/common/mycontext"
|
||||||
"furtuna-be/internal/entity"
|
"furtuna-be/internal/entity"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -129,3 +130,21 @@ func (r *SiteRepository) Delete(ctx context.Context, id int64) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *SiteRepository) Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error) {
|
||||||
|
count := new(entity.SiteCountDB)
|
||||||
|
|
||||||
|
query := r.db.Table("sites").
|
||||||
|
Select("count(*) as count")
|
||||||
|
|
||||||
|
if !req.IsAdmin {
|
||||||
|
query = query.Where("partner_id = ?", req.PartnerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := query.Scan(&count).Error; err != nil {
|
||||||
|
logger.ContextLogger(ctx).Error("error when get count sites", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -298,7 +298,7 @@ func (s *OrderService) updateWalletBalance(ctx context.Context, tx *gorm.DB, par
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OrderService) GetAllHistoryOrders(ctx mycontext.Context, req entity.HistoryOrderSearch) ([]*entity.HistoryOrder, int, error) {
|
func (s *OrderService) GetAllHistoryOrders(ctx mycontext.Context, req entity.OrderSearch) ([]*entity.HistoryOrder, int, error) {
|
||||||
historyOrders, total, err := s.repo.GetAllHystoryOrders(ctx, req)
|
historyOrders, total, err := s.repo.GetAllHystoryOrders(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ContextLogger(ctx).Error("error when get all history orders", zap.Error(err))
|
logger.ContextLogger(ctx).Error("error when get all history orders", zap.Error(err))
|
||||||
@ -309,3 +309,29 @@ func (s *OrderService) GetAllHistoryOrders(ctx mycontext.Context, req entity.His
|
|||||||
|
|
||||||
return data, total, nil
|
return data, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s OrderService) CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSold, error) {
|
||||||
|
ticket, err := s.repo.CountSoldOfTicket(ctx, req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.ContextLogger(ctx).Error("error when get all history orders", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := ticket.ToTicketSold()
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s OrderService) SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.Order, error) {
|
||||||
|
amount, err := s.repo.SumAmount(ctx, req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.ContextLogger(ctx).Error("error when get amount cash orders", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := amount.ToSumAmount()
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
@ -104,7 +104,9 @@ type Order interface {
|
|||||||
CreateOrder(ctx context.Context, req *entity.OrderRequest) (*entity.OrderResponse, error)
|
CreateOrder(ctx context.Context, req *entity.OrderRequest) (*entity.OrderResponse, error)
|
||||||
Execute(ctx context.Context, req *entity.OrderExecuteRequest) (*entity.ExecuteOrderResponse, error)
|
Execute(ctx context.Context, req *entity.OrderExecuteRequest) (*entity.ExecuteOrderResponse, error)
|
||||||
ProcessCallback(ctx context.Context, req *entity.CallbackRequest) error
|
ProcessCallback(ctx context.Context, req *entity.CallbackRequest) error
|
||||||
GetAllHistoryOrders(ctx mycontext.Context, req entity.HistoryOrderSearch) ([]*entity.HistoryOrder, int, error)
|
GetAllHistoryOrders(ctx mycontext.Context, req entity.OrderSearch) ([]*entity.HistoryOrder, int, error)
|
||||||
|
CountSoldOfTicket(ctx mycontext.Context, req entity.OrderSearch) (*entity.TicketSold, error)
|
||||||
|
SumAmount(ctx mycontext.Context, req entity.OrderSearch) (*entity.Order, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OSSService interface {
|
type OSSService interface {
|
||||||
@ -125,6 +127,7 @@ type Site interface {
|
|||||||
GetByID(ctx context.Context, id int64) (*entity.Site, error)
|
GetByID(ctx context.Context, id int64) (*entity.Site, error)
|
||||||
GetAll(ctx context.Context, search entity.SiteSearch) ([]*entity.Site, int, error)
|
GetAll(ctx context.Context, search entity.SiteSearch) ([]*entity.Site, int, error)
|
||||||
Delete(ctx mycontext.Context, id int64) error
|
Delete(ctx mycontext.Context, id int64) error
|
||||||
|
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCount, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type License interface {
|
type License interface {
|
||||||
|
|||||||
@ -87,3 +87,13 @@ func (s *SiteService) Delete(ctx mycontext.Context, id int64) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SiteService) Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCount, error) {
|
||||||
|
count, err := s.repo.Count(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
logger.ContextLogger(ctx).Error("error when getting all sites", zap.Error(err))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return count.ToSiteCount(), nil
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user