initial commit
This commit is contained in:
148
services/customerService.go
Normal file
148
services/customerService.go
Normal file
@@ -0,0 +1,148 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CustomerService interface {
|
||||
GetCustomer(cid int, cno string) (*models.CustomerInfo, error)
|
||||
UpdateCustomer(input models.Customers) models.Result
|
||||
GetCustomerLocations(cid int) models.CustomerLocationResult
|
||||
CreateCustomerLocation(input models.Customerlocations) (int, error)
|
||||
CreateCustomerRequest(req models.CustomerRequest) (models.CustomerRequest, error)
|
||||
GetCustomerRequests(customerIDStr string, pageNo, pageSize int) ([]models.CustomerRequest, int64, error)
|
||||
GetTenantCustomers(tid, lid, pageno, pagesize int, keyword string) []models.CustomerInfo
|
||||
SearchCustomer(keyword string, tid int) []models.CustomerInfo
|
||||
CreateCustomer(input models.Customers) (models.CustomerInfo, error)
|
||||
LoginCustomer(contactNo string) (*models.Customers, error)
|
||||
}
|
||||
|
||||
type customerService struct {
|
||||
repo repositories.CustomerRepository
|
||||
}
|
||||
|
||||
func NewCustomerService(repo repositories.CustomerRepository) CustomerService {
|
||||
return &customerService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *customerService) GetCustomer(cid int, cno string) (*models.CustomerInfo, error) {
|
||||
return s.repo.GetCustomer(cid, cno)
|
||||
}
|
||||
|
||||
func (s *customerService) UpdateCustomer(input models.Customers) models.Result {
|
||||
err := s.repo.UpdateCustomer(input)
|
||||
if err != nil {
|
||||
return models.Result{
|
||||
Code: http.StatusConflict,
|
||||
Status: false,
|
||||
Message: "Update Customer Failed",
|
||||
}
|
||||
}
|
||||
|
||||
return models.Result{
|
||||
Code: http.StatusAccepted,
|
||||
Status: true,
|
||||
Message: "Customer update successful",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *customerService) CreateCustomerLocation(input models.Customerlocations) (int, error) {
|
||||
return s.repo.CreateCustomerLocation(input)
|
||||
}
|
||||
|
||||
func (s *customerService) GetCustomerLocations(cid int) models.CustomerLocationResult {
|
||||
data, err := s.repo.GetCustomerLocations(cid)
|
||||
if err != nil {
|
||||
return models.CustomerLocationResult{
|
||||
Code: http.StatusInternalServerError,
|
||||
Status: false,
|
||||
Message: "Failed to fetch customer locations",
|
||||
Details: []models.Customerlocations{},
|
||||
}
|
||||
}
|
||||
|
||||
return models.CustomerLocationResult{
|
||||
Code: http.StatusOK,
|
||||
Status: true,
|
||||
Message: "Successful",
|
||||
Details: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *customerService) CreateCustomerRequest(req models.CustomerRequest) (models.CustomerRequest, error) {
|
||||
err := s.repo.CreateCustomerRequest(&req)
|
||||
if err != nil {
|
||||
return models.CustomerRequest{}, err
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (s *customerService) GetCustomerRequests(customerIDStr string, pageNo, pageSize int) ([]models.CustomerRequest, int64, error) {
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
var customerID int
|
||||
var err error
|
||||
if customerIDStr != "" {
|
||||
customerID, err = strconv.Atoi(customerIDStr)
|
||||
if err != nil {
|
||||
return nil, 0, errors.New("invalid customerid")
|
||||
}
|
||||
}
|
||||
|
||||
return s.repo.GetCustomerRequests(customerID, pageNo, pageSize)
|
||||
}
|
||||
|
||||
func (s *customerService) GetTenantCustomers(tid, lid, pageno, pagesize int, keyword string) []models.CustomerInfo {
|
||||
return s.repo.GetTenantCustomers(tid, lid, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *customerService) SearchCustomer(keyword string, tid int) []models.CustomerInfo {
|
||||
return s.repo.SearchCustomer(keyword, tid)
|
||||
}
|
||||
|
||||
func (s *customerService) CreateCustomer(input models.Customers) (models.CustomerInfo, error) {
|
||||
|
||||
cid := s.repo.CheckCustomer(input.Contactno)
|
||||
if cid != 0 {
|
||||
input.Customerid = cid
|
||||
|
||||
tcid := s.repo.CheckTenantCustomer(input.Customerid, input.Tenantid)
|
||||
if tcid != 0 {
|
||||
return models.CustomerInfo{}, errors.New("Customer Already available")
|
||||
}
|
||||
|
||||
s.repo.CreateTenantCustomer(input)
|
||||
} else {
|
||||
|
||||
cid = s.repo.CreateCustomer(input)
|
||||
}
|
||||
|
||||
result, err := s.repo.GetCustomer(cid, "")
|
||||
if err != nil {
|
||||
return models.CustomerInfo{}, err
|
||||
}
|
||||
return *result, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *customerService) LoginCustomer(contactNo string) (*models.Customers, error) {
|
||||
customer, err := s.repo.GetCustomerByContactNo(contactNo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if customer.Customerid == 0 {
|
||||
return nil, nil // handle "not found" in controller
|
||||
}
|
||||
|
||||
return customer, nil
|
||||
}
|
||||
87
services/deliveriesService.go
Normal file
87
services/deliveriesService.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
)
|
||||
|
||||
type DeliveriesService interface {
|
||||
CreateDeliveriesService(data []models.Deliveries) error
|
||||
UpdateDeliveryService(data models.UpdateDeliveryStatus) error
|
||||
GetDeliverySummary(tid, pid, uid, aid, lid int, fdate, tdate string) (models.DeliverySummary, error)
|
||||
GetDeliveryInsightService(tid int) ([]models.OrderInsightv1, error)
|
||||
GetLocationDeliverySummary(tenantID int) ([]models.Ordersummarylocation, error)
|
||||
GetReportSummary(tid, pid, uid, aid int, fdate, tdate string) ([]models.ReportSummary, error)
|
||||
GetRiderSummary(aid, pid, tid int, fdate, tdate string) ([]models.Ridersummary, error)
|
||||
GetDeliveries(input models.DeliveryQuery) []models.Deliveryinfo
|
||||
GetDeliveryQueues(uid int, fdate, tdate string) ([]models.Deliveryinfo, error)
|
||||
}
|
||||
|
||||
type deliveriesService struct {
|
||||
repo repositories.DeliveriesRepository
|
||||
}
|
||||
|
||||
func NewDeliveriesService(repo repositories.DeliveriesRepository) DeliveriesService {
|
||||
return &deliveriesService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *deliveriesService) CreateDeliveriesService(data []models.Deliveries) error {
|
||||
return s.repo.CreateDeliveries(data)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) UpdateDeliveryService(data models.UpdateDeliveryStatus) error {
|
||||
return s.repo.UpdateDelivery(data)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) GetDeliverySummary(tid, pid, uid, aid, lid int, fdate, tdate string) (models.DeliverySummary, error) {
|
||||
return s.repo.GetDeliverySummary(tid, pid, uid, aid, lid, fdate, tdate)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) GetDeliveryInsightService(tid int) ([]models.OrderInsightv1, error) {
|
||||
return s.repo.GetDeliveryInsight(tid)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) GetLocationDeliverySummary(tenantID int) ([]models.Ordersummarylocation, error) {
|
||||
return s.repo.GetLocationDeliverySummary(tenantID)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) GetReportSummary(tid, pid, uid, aid int, fdate, tdate string) ([]models.ReportSummary, error) {
|
||||
return s.repo.GetReportSummary(tid, pid, uid, aid, fdate, tdate)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) GetRiderSummary(aid, pid, tid int, fdate, tdate string) ([]models.Ridersummary, error) {
|
||||
return s.repo.GetRiderSummary(aid, pid, tid, fdate, tdate)
|
||||
}
|
||||
|
||||
func (s *deliveriesService) GetDeliveries(input models.DeliveryQuery) []models.Deliveryinfo {
|
||||
switch {
|
||||
case input.Tenantid != 0 && input.Locationid != 0:
|
||||
return s.repo.GetTenantLocationDeliveries(input) // 👈 NEW
|
||||
|
||||
case input.Tenantid != 0:
|
||||
return s.repo.GetTenantDeliveries(input)
|
||||
|
||||
case input.Partnerid != 0:
|
||||
return s.repo.GetPartnerDeliveries(input)
|
||||
|
||||
case input.Customerid != 0:
|
||||
return s.repo.GetCustomerDeliveries(input)
|
||||
|
||||
case input.Applocationid != 0:
|
||||
return s.repo.GetAdminDeliveries(input)
|
||||
|
||||
case input.UserID != 0:
|
||||
return s.repo.GetUserDeliveries(input)
|
||||
|
||||
case input.Appuserid != 0:
|
||||
return s.repo.GetAppUserDeliveries(input)
|
||||
|
||||
default:
|
||||
return s.repo.GetDeliveries(input)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (s *deliveriesService) GetDeliveryQueues(uid int, fdate, tdate string) ([]models.Deliveryinfo, error) {
|
||||
return s.repo.GetDeliveryQueues(uid, fdate, tdate)
|
||||
}
|
||||
88
services/orderService.go
Normal file
88
services/orderService.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
)
|
||||
|
||||
type OrderService interface {
|
||||
GetTenantOrders(input models.DeliveryQuery) ([]models.OrderInfo, error)
|
||||
GetPartnerOrders(stat, fdate, tdate string, pid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
|
||||
GetCustomerOrders(stat, fdate, tdate string, cid, mid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
|
||||
GetAdminOrders(stat, fdate, tdate string, aid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
|
||||
GetUserOrders(stat, fdate, tdate string, uid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
|
||||
GetAllOrders(stat, fdate, tdate string, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
|
||||
GetOrderSummary(tid, pid, cid, lid int, fdate, tdate string) ([]models.Ordersummarydaily, error)
|
||||
GetLocationOrderSummary(tenantID int) ([]models.Ordersummarylocation, error)
|
||||
GetOrderInsights(tenantID int) ([]models.OrderInsightv1, error)
|
||||
GetOrderDetails(orderHeaderID int) ([]models.OrderDetails, error)
|
||||
UpdateOrder(order *models.Orders) error
|
||||
CreateOrder(order models.Orders) (models.Orders, error)
|
||||
GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword string, pageSize, offset int) ([]models.CustomerOrder, error)
|
||||
GetTenantLocationOrders(input models.DeliveryQuery) ([]models.OrderInfo, error)
|
||||
|
||||
}
|
||||
|
||||
type orderService struct {
|
||||
repo repositories.OrderRepository
|
||||
}
|
||||
|
||||
func NewOrderService(repo repositories.OrderRepository) OrderService {
|
||||
return &orderService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *orderService) GetTenantOrders(input models.DeliveryQuery) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetTenantOrders(input)
|
||||
}
|
||||
|
||||
func (s *orderService) GetPartnerOrders(stat, fdate, tdate string, pid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetPartnerOrders(stat, fdate, tdate, pid, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *orderService) GetCustomerOrders(stat, fdate, tdate string, cid, mid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetCustomerOrders(stat, fdate, tdate, cid, mid, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *orderService) GetAdminOrders(stat, fdate, tdate string, aid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetAdminOrders(stat, fdate, tdate, aid, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *orderService) GetUserOrders(stat, fdate, tdate string, uid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetUserOrders(stat, fdate, tdate, uid, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *orderService) GetAllOrders(stat, fdate, tdate string, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetAllOrders(stat, fdate, tdate, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *orderService) GetOrderSummary(tid, pid, cid, lid int, fdate, tdate string) ([]models.Ordersummarydaily, error) {
|
||||
return s.repo.GetOrderSummary(tid, pid, cid, lid, fdate, tdate)
|
||||
}
|
||||
|
||||
func (s *orderService) GetLocationOrderSummary(tenantID int) ([]models.Ordersummarylocation, error) {
|
||||
return s.repo.GetLocationOrderSummary(tenantID)
|
||||
}
|
||||
|
||||
func (s *orderService) GetOrderInsights(tenantID int) ([]models.OrderInsightv1, error) {
|
||||
return s.repo.GetOrderInsights(tenantID)
|
||||
}
|
||||
|
||||
func (s *orderService) GetOrderDetails(orderHeaderID int) ([]models.OrderDetails, error) {
|
||||
return s.repo.GetOrderDetails(orderHeaderID)
|
||||
}
|
||||
|
||||
func (s *orderService) UpdateOrder(order *models.Orders) error {
|
||||
return s.repo.UpdateOrder(order)
|
||||
}
|
||||
|
||||
func (s *orderService) CreateOrder(order models.Orders) (models.Orders, error) {
|
||||
return s.repo.CreateOrder(order)
|
||||
}
|
||||
|
||||
func (s *orderService) GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword string, pageSize, offset int) ([]models.CustomerOrder, error) {
|
||||
return s.repo.GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword, pageSize, offset)
|
||||
}
|
||||
|
||||
func (s *orderService) GetTenantLocationOrders(input models.DeliveryQuery) ([]models.OrderInfo, error) {
|
||||
return s.repo.GetTenantLocationOrders(input)
|
||||
}
|
||||
55
services/partnerService.go
Normal file
55
services/partnerService.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
)
|
||||
|
||||
type PartnerService interface {
|
||||
GetActiveRiders(partnerid, aid, uid, tid int) ([]models.RiderInfo, error)
|
||||
GetPartners(aid, pid, uid int) ([]models.Partnerinfo, error)
|
||||
GetRiderShifts(aid int) ([]models.Ridershifts, error)
|
||||
GetLocationConfig(uid, cid int) ([]models.Locationconfigs, error)
|
||||
GetRiderLogs(pid, aid int, fdate, tdate string) ([]models.RiderlogDetails, error)
|
||||
GetRiderInfo(userid int) (models.RiderInfo, error)
|
||||
}
|
||||
|
||||
type partnerService struct {
|
||||
repo repositories.PartnerRepository
|
||||
}
|
||||
|
||||
func NewPartnerService(repo repositories.PartnerRepository) PartnerService {
|
||||
return &partnerService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *partnerService) GetActiveRiders(partnerid, aid, uid, tid int) ([]models.RiderInfo, error) {
|
||||
return s.repo.GetActiveRiders(partnerid, aid, uid, tid)
|
||||
}
|
||||
|
||||
func (s *partnerService) GetPartners(aid, pid, uid int) ([]models.Partnerinfo, error) {
|
||||
result, err := s.repo.GetPartners(aid, pid, uid)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *partnerService) GetRiderShifts(aid int) ([]models.Ridershifts, error) {
|
||||
|
||||
return s.repo.GetRiderShifts(aid)
|
||||
}
|
||||
|
||||
func (s *partnerService) GetLocationConfig(uid, cid int) ([]models.Locationconfigs, error) {
|
||||
|
||||
return s.repo.GetLocationConfig(uid, cid)
|
||||
}
|
||||
|
||||
func (s *partnerService) GetRiderLogs(pid, aid int, fdate, tdate string) ([]models.RiderlogDetails, error) {
|
||||
return s.repo.GetRiderLogs(pid, aid, fdate, tdate)
|
||||
}
|
||||
|
||||
func (s *partnerService) GetRiderInfo(userid int) (models.RiderInfo, error) {
|
||||
return s.repo.GetRiderInfo(userid)
|
||||
}
|
||||
208
services/productService.go
Normal file
208
services/productService.go
Normal file
@@ -0,0 +1,208 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ProductService interface {
|
||||
GetProductSubCategory(categoryID, tenantID int) ([]models.ProductSubCategory, error)
|
||||
GetProductCount(tenantID, categoryID, subcategoryID int, approve string) ([]models.Productcount, error)
|
||||
GetProductCategory() ([]models.ProductCategory, error)
|
||||
GetProductVariants(tenantID, subcategoryID int) ([]models.Productvariant, error)
|
||||
GetCatalougeProducts(tenantID, locationID, subcategoryID, pageno, pagesize int, keyword string) ([]models.Products, error)
|
||||
GetProductStocks(tenantID, locationID string) ([]models.Productstocks, error)
|
||||
UpdateProductStatus(productIDs []int, status string) error
|
||||
CreateProductStock(stocks []models.Productstock) error
|
||||
CreateProduct(product models.Products) error
|
||||
UpdateProduct(product models.Products) error
|
||||
DeleteProduct(productID int) error
|
||||
GetStockStatement(tenantID, locationID, subcategoryID, pageno, pagesize int, keyword string) ([]models.Productstockstatement, error)
|
||||
GetLocationProducts(tenantID, locationID, subcategoryID, pageno, pagesize int, keyword string) ([]models.Locationproducts, error)
|
||||
GetLocationProductSummary(tenantID, locationID int) ([]models.ProductSummary, error)
|
||||
FetchFilteredProducts(categoryID, subcategoryID, productID, applocationID, tenantID, locationID int, keyword, productStatus, approve string, pageno, pagesize int) ([]models.Tenantproducts, error)
|
||||
GetProductByVariant(tenantid, variantid int) ([]models.Products, error)
|
||||
GetProductsBySubcategory(params models.ProductFilter) (map[string]interface{}, error)
|
||||
UpdateProductLocation(input models.Productlocations) error
|
||||
CreateProductLocation(input []models.Productlocations) error
|
||||
CreateProductVariant(input models.Productvariant) error
|
||||
}
|
||||
type productService struct {
|
||||
repo repositories.ProductRepository
|
||||
}
|
||||
|
||||
func NewProductService(repo repositories.ProductRepository) ProductService {
|
||||
return &productService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *productService) GetProductSubCategory(categoryID, tenantID int) ([]models.ProductSubCategory, error) {
|
||||
return s.repo.GetProductSubCategory(categoryID, tenantID)
|
||||
}
|
||||
|
||||
func (s *productService) GetProductCount(tenantID, categoryID, subcategoryID int, approve string) ([]models.Productcount, error) {
|
||||
return s.repo.GetProductCount(tenantID, categoryID, subcategoryID, approve)
|
||||
}
|
||||
|
||||
func (s *productService) GetProductCategory() ([]models.ProductCategory, error) {
|
||||
return s.repo.GetProductCategory()
|
||||
}
|
||||
|
||||
func (s *productService) GetProductVariants(tenantID, subcategoryID int) ([]models.Productvariant, error) {
|
||||
return s.repo.GetProductVariants(tenantID, subcategoryID)
|
||||
}
|
||||
|
||||
func (s *productService) GetCatalougeProducts(tenantID, locationID, subcategoryID, pageno, pagesize int, keyword string) ([]models.Products, error) {
|
||||
return s.repo.GetCatalougeProducts(tenantID, locationID, subcategoryID, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *productService) GetProductStocks(tenantID, locationID string) ([]models.Productstocks, error) {
|
||||
return s.repo.GetProductStocks(tenantID, locationID)
|
||||
}
|
||||
|
||||
func (s *productService) CreateProductStock(stocks []models.Productstock) error {
|
||||
|
||||
for i := range stocks {
|
||||
stocks[i].Stockdate = time.Now()
|
||||
}
|
||||
|
||||
if err := s.repo.CreateProductStock(stocks); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
idMap := make(map[int]struct{})
|
||||
var productIDs []int
|
||||
for _, s := range stocks {
|
||||
if s.Productid > 0 {
|
||||
if _, exists := idMap[s.Productid]; !exists {
|
||||
idMap[s.Productid] = struct{}{}
|
||||
productIDs = append(productIDs, s.Productid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(productIDs) > 0 {
|
||||
if err := s.repo.UpdateProductStatus(productIDs, "available"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *productService) UpdateProductStatus(productIDs []int, status string) error {
|
||||
return s.repo.UpdateProductStatus(productIDs, status)
|
||||
}
|
||||
|
||||
func (s *productService) CreateProduct(product models.Products) error {
|
||||
return s.repo.CreateProduct(product)
|
||||
}
|
||||
|
||||
func (s *productService) UpdateProduct(product models.Products) error {
|
||||
return s.repo.UpdateProduct(product)
|
||||
}
|
||||
|
||||
func (s *productService) DeleteProduct(productID int) error {
|
||||
return s.repo.DeleteProduct(productID)
|
||||
}
|
||||
|
||||
func (s *productService) GetStockStatement(tenantID, locationID, subcategoryID, pageno, pagesize int, keyword string) ([]models.Productstockstatement, error) {
|
||||
return s.repo.GetStockStatement(tenantID, locationID, subcategoryID, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *productService) GetLocationProducts(tenantID, locationID, subcategoryID, pageno, pagesize int, keyword string) ([]models.Locationproducts, error) {
|
||||
return s.repo.GetLocationProducts(tenantID, locationID, subcategoryID, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *productService) GetLocationProductSummary(tenantID, locationID int) ([]models.ProductSummary, error) {
|
||||
return s.repo.GetLocationProductSummary(tenantID, locationID)
|
||||
}
|
||||
|
||||
func (s *productService) FetchFilteredProducts(categoryID, subcategoryID, productID, applocationID, tenantID, locationID int, keyword, productStatus,
|
||||
approve string, pageno, pagesize int) ([]models.Tenantproducts, error) {
|
||||
return s.repo.FetchFilteredProducts(categoryID, subcategoryID, productID, applocationID, tenantID, locationID, keyword, productStatus, approve, pageno, pagesize)
|
||||
}
|
||||
|
||||
func (s *productService) GetProductByVariant(tenantid, variantid int) ([]models.Products, error) {
|
||||
|
||||
var data []models.Products
|
||||
|
||||
result, err := s.repo.GetProductByVariant(tenantid, variantid)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data = result
|
||||
|
||||
return data, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *productService) GetProductsBySubcategory(params models.ProductFilter) (map[string]interface{}, error) {
|
||||
|
||||
subcategories, err := s.repo.GetSubcategories(params.CategoryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
products, err := s.repo.GetProducts(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var details []models.SubcategoryProductResponse
|
||||
var uncategorized []models.Products
|
||||
|
||||
for _, sub := range subcategories {
|
||||
var subProducts []models.Products
|
||||
for _, p := range products {
|
||||
if p.Subcategoryid == sub.Subcategoryid {
|
||||
subProducts = append(subProducts, p)
|
||||
}
|
||||
}
|
||||
if len(subProducts) > 0 {
|
||||
details = append(details, models.SubcategoryProductResponse{
|
||||
SubcategoryID: sub.Subcategoryid,
|
||||
SubcategoryName: sub.Subcategoryname,
|
||||
Image: sub.Image,
|
||||
Products: subProducts,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range products {
|
||||
if p.Subcategoryid == 0 {
|
||||
uncategorized = append(uncategorized, p)
|
||||
}
|
||||
}
|
||||
if len(uncategorized) > 0 {
|
||||
details = append(details, models.SubcategoryProductResponse{
|
||||
SubcategoryID: 0,
|
||||
SubcategoryName: "Uncategorized",
|
||||
Products: uncategorized,
|
||||
})
|
||||
}
|
||||
|
||||
if params.TenantID > 0 {
|
||||
tenantInfo, err := s.repo.GetTenantInfo(params.TenantID, params.AppLocationID)
|
||||
if err == nil && tenantInfo != nil {
|
||||
tenantInfo["details"] = details
|
||||
return tenantInfo, nil
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{"details": details}, nil
|
||||
}
|
||||
|
||||
func (s *productService) UpdateProductLocation(input models.Productlocations) error {
|
||||
return s.repo.UpdateProductLocation(input)
|
||||
}
|
||||
|
||||
func (s *productService) CreateProductLocation(input []models.Productlocations) error {
|
||||
return s.repo.CreateProductLocation(input)
|
||||
}
|
||||
|
||||
func (s *productService) CreateProductVariant(input models.Productvariant) error {
|
||||
return s.repo.CreateProductVariant(input)
|
||||
}
|
||||
162
services/tenantService.go
Normal file
162
services/tenantService.go
Normal file
@@ -0,0 +1,162 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type TenantService interface {
|
||||
SearchTenant(status, keyword string) ([]models.Tenantinfo, error)
|
||||
GetAllTenants(pageno, pagesize, aid int, status, tenanttype, keyword string) ([]models.Tenantinfo, error)
|
||||
GetTenantLocations(tid int) ([]models.Tenantlocations, error)
|
||||
GetTenantSlot() (models.Tenantslot, error)
|
||||
CreateTenantCustomer(req models.CreateTenantCustomerRequest) (*models.Tenantcustomer, error)
|
||||
GetCustomerTenants(customerID int, categoryID int, tenantFlag int) (*models.CustomerTenantResponse, error)
|
||||
GetTenantPricing(tid, aid int) (models.Tenantpricing, error)
|
||||
UpdateLocation(input models.Tenantlocations) error
|
||||
CreateLocation(data models.Tenantlocations) error
|
||||
GetStaffs(tid int) ([]models.StaffInfo, error)
|
||||
CreateStaff(user models.User) error
|
||||
UpdateStaff(user models.User) error
|
||||
CreateTenantLocation(data models.Tenantlocations) map[string]interface{}
|
||||
UpdateTenantLocation(data models.Tenantlocations) map[string]interface{}
|
||||
CreateTenantUser(data models.Tenants) (models.UserInfo, error)
|
||||
GetTenantByID(tid int, locationid int) (models.Tenantinfo, error)
|
||||
GetTenantByKeyword(keyword string) ([]models.TenantSearch, error)
|
||||
}
|
||||
|
||||
type tenantService struct {
|
||||
repo repositories.TenantRepository
|
||||
}
|
||||
|
||||
func NewTenantService(repo repositories.TenantRepository) TenantService {
|
||||
return &tenantService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *tenantService) SearchTenant(status, keyword string) ([]models.Tenantinfo, error) {
|
||||
return s.repo.SearchTenant(status, keyword)
|
||||
}
|
||||
|
||||
func (s *tenantService) GetAllTenants(pageno, pagesize, aid int, status, tenanttype, keyword string) ([]models.Tenantinfo, error) {
|
||||
return s.repo.GetAllTenants(pageno, pagesize, aid, status, tenanttype, keyword)
|
||||
}
|
||||
|
||||
func (s *tenantService) GetTenantLocations(tid int) ([]models.Tenantlocations, error) {
|
||||
return s.repo.GetTenantLocations(tid)
|
||||
}
|
||||
|
||||
func (s *tenantService) GetTenantSlot() (models.Tenantslot, error) {
|
||||
return s.repo.GetTenantSlot()
|
||||
}
|
||||
|
||||
func (s *tenantService) CreateTenantCustomer(req models.CreateTenantCustomerRequest) (*models.Tenantcustomer, error) {
|
||||
tenantCustomer := models.Tenantcustomer{
|
||||
TenantID: req.TenantID,
|
||||
LocationID: req.LocationID,
|
||||
CustomerID: req.CustomerID,
|
||||
CustomerLocationID: req.CustomerLocationID,
|
||||
Status: req.Status,
|
||||
}
|
||||
return s.repo.CreateTenantCustomer(tenantCustomer)
|
||||
}
|
||||
|
||||
func (s *tenantService) GetCustomerTenants(customerID int, categoryID int, tenantFlag int) (*models.CustomerTenantResponse, error) {
|
||||
details, err := s.repo.GetCustomerTenants(customerID, categoryID, tenantFlag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &models.CustomerTenantResponse{
|
||||
Details: details,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *tenantService) GetTenantPricing(tid, aid int) (models.Tenantpricing, error) {
|
||||
result, err := s.repo.GetTenantPricing(tid, aid)
|
||||
if err != nil {
|
||||
return models.Tenantpricing{}, err
|
||||
}
|
||||
return *result, nil
|
||||
}
|
||||
|
||||
func (s *tenantService) UpdateLocation(input models.Tenantlocations) error {
|
||||
return s.repo.UpdateLocation(input)
|
||||
}
|
||||
|
||||
func (s *tenantService) CreateLocation(data models.Tenantlocations) error {
|
||||
return s.repo.CreateLocation(data)
|
||||
}
|
||||
|
||||
func (s *tenantService) GetStaffs(tid int) ([]models.StaffInfo, error) {
|
||||
return s.repo.GetStaffs(tid)
|
||||
}
|
||||
|
||||
func (s *tenantService) CreateStaff(user models.User) error {
|
||||
return s.repo.CreateStaff(user)
|
||||
}
|
||||
|
||||
func (s *tenantService) UpdateStaff(user models.User) error {
|
||||
return s.repo.UpdateStaff(user)
|
||||
}
|
||||
|
||||
func (s *tenantService) CreateTenantLocation(data models.Tenantlocations) map[string]interface{} {
|
||||
err := s.repo.CreateTenantLocation(data)
|
||||
if err != nil {
|
||||
return map[string]interface{}{
|
||||
"code": http.StatusConflict,
|
||||
"message": err.Error(),
|
||||
"status": false,
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"code": http.StatusCreated,
|
||||
"message": "Tenant Location Successfully Created",
|
||||
"status": true,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *tenantService) UpdateTenantLocation(data models.Tenantlocations) map[string]interface{} {
|
||||
err := s.repo.UpdateTenantLocation(data)
|
||||
if err != nil {
|
||||
return map[string]interface{}{
|
||||
"status": false,
|
||||
"code": http.StatusConflict,
|
||||
"message": err.Error(),
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"status": true,
|
||||
"code": http.StatusAccepted,
|
||||
"message": "Tenant Location update successful",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *tenantService) CreateTenantUser(data models.Tenants) (models.UserInfo, error) {
|
||||
// ✅ Check if tenant already exists
|
||||
exists := s.repo.CheckTenantByNo(data.Primarycontact)
|
||||
if exists != 0 {
|
||||
return models.UserInfo{}, errors.New("Tenant Already Exists")
|
||||
}
|
||||
|
||||
// ✅ Create Tenant User
|
||||
status, err := s.repo.CreateTenantUser(data)
|
||||
if err != nil || !status {
|
||||
return models.UserInfo{}, err
|
||||
}
|
||||
|
||||
// ✅ Get user details by contact number
|
||||
result := s.repo.GetUserByNo(data.Primarycontact)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *tenantService) GetTenantByID(tid int, locationid int) (models.Tenantinfo, error) {
|
||||
return s.repo.GetTenantByID(tid, locationid)
|
||||
}
|
||||
|
||||
func (s *tenantService) GetTenantByKeyword(keyword string) ([]models.TenantSearch, error) {
|
||||
return s.repo.GetTenantByKeyword(keyword)
|
||||
}
|
||||
267
services/userService.go
Normal file
267
services/userService.go
Normal file
@@ -0,0 +1,267 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber"
|
||||
)
|
||||
|
||||
type UserService interface {
|
||||
GetAllUsers(roleID, tenantID, pageno, pagesize int, keyword string) ([]models.UserInfo, error)
|
||||
GetUserByID(uid int) (models.UserInfo, error)
|
||||
Login(user models.User) (models.UserInfo, error)
|
||||
TenantLogin(user models.User) (models.TenantUserInfo, error)
|
||||
UpdateStaff(user models.User) error
|
||||
AppLogin(user models.User) (models.TenantUserInfo, fiber.Map, error)
|
||||
CreateUser(user models.User) (models.UserInfo, error)
|
||||
TenantWebLogin(user models.User) (models.TenantUserInfo, map[string]interface{})
|
||||
}
|
||||
|
||||
type userService struct {
|
||||
repo repositories.UserRepository
|
||||
}
|
||||
|
||||
func NewUserService(repo repositories.UserRepository) UserService {
|
||||
return &userService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *userService) GetAllUsers(roleID, tenantID, pageno, pagesize int, keyword string) ([]models.UserInfo, error) {
|
||||
return s.repo.GetAllUsers(roleID, tenantID, pageno, pagesize, keyword)
|
||||
}
|
||||
|
||||
func (s *userService) GetUserByID(uid int) (models.UserInfo, error) {
|
||||
return s.repo.GetUserByID(uid)
|
||||
}
|
||||
|
||||
func (s *userService) Login(user models.User) (models.UserInfo, error) {
|
||||
return s.repo.Login(user)
|
||||
}
|
||||
|
||||
func (s *userService) TenantLogin(user models.User) (models.TenantUserInfo, error) {
|
||||
uid, err := s.repo.FindUserID(user.Authname, user.Contactno, user.Configid)
|
||||
if err != nil {
|
||||
return models.TenantUserInfo{}, err
|
||||
}
|
||||
|
||||
if uid == 0 {
|
||||
return models.TenantUserInfo{}, errors.New("user not found")
|
||||
}
|
||||
|
||||
return s.repo.GetTenantUserByID(uid)
|
||||
}
|
||||
|
||||
func (s *userService) UpdateStaff(user models.User) error {
|
||||
return s.repo.UpdateStaff(user)
|
||||
}
|
||||
|
||||
func (s *userService) AppLogin(user models.User) (models.TenantUserInfo, fiber.Map, error) {
|
||||
var uid int
|
||||
var status, dbPassword string
|
||||
|
||||
// Get user by authname or contactno
|
||||
if user.Authname != "" {
|
||||
uid, dbPassword, status = s.repo.GetUserByAuthname(user.Authname, user.Configid)
|
||||
} else if user.Contactno != "" {
|
||||
uid, dbPassword, status = s.repo.GetUserByContactNo(user.Contactno, user.Configid)
|
||||
} else {
|
||||
resp := fiber.Map{
|
||||
"code": 400,
|
||||
"status": false,
|
||||
"message": "authname or contactno required",
|
||||
}
|
||||
return models.TenantUserInfo{}, resp, errors.New("missing authname or contactno")
|
||||
}
|
||||
|
||||
// Invalid user
|
||||
if uid == 0 {
|
||||
resp := fiber.Map{
|
||||
"status": false,
|
||||
"code": 409,
|
||||
"message": "Invalid Email",
|
||||
"tenantform": true,
|
||||
}
|
||||
return models.TenantUserInfo{}, resp, errors.New("invalid user")
|
||||
}
|
||||
|
||||
// Inactive account
|
||||
if status == "InActive" {
|
||||
resp := fiber.Map{
|
||||
"status": false,
|
||||
"code": 403,
|
||||
"message": "Inactive Account. Contact admin.",
|
||||
}
|
||||
return models.TenantUserInfo{}, resp, errors.New("inactive account")
|
||||
}
|
||||
|
||||
// No password set
|
||||
if strings.TrimSpace(dbPassword) == "" {
|
||||
resp := fiber.Map{
|
||||
"status": true,
|
||||
"code": 409,
|
||||
"message": "Please setup a password.",
|
||||
"tenantform": true,
|
||||
"details": fiber.Map{
|
||||
"userid": uid,
|
||||
"setup": true,
|
||||
},
|
||||
}
|
||||
return models.TenantUserInfo{}, resp, nil
|
||||
}
|
||||
|
||||
// Empty request password
|
||||
if strings.TrimSpace(user.Password) == "" {
|
||||
resp := fiber.Map{
|
||||
"status": true,
|
||||
"code": 401,
|
||||
"message": "Password is required",
|
||||
"tenantform": true,
|
||||
}
|
||||
return models.TenantUserInfo{}, resp, nil
|
||||
}
|
||||
|
||||
// Incorrect password
|
||||
if user.Password != dbPassword {
|
||||
resp := fiber.Map{
|
||||
"status": false,
|
||||
"code": 401,
|
||||
"message": "Incorrect password",
|
||||
"tenantform": true,
|
||||
}
|
||||
return models.TenantUserInfo{}, resp, errors.New("incorrect password")
|
||||
}
|
||||
|
||||
// Update FCM token
|
||||
if user.Userfcmtoken != "" {
|
||||
_ = s.repo.UpdateFCMToken(uid, user.Userfcmtoken)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ✅ Fetch tenant user info
|
||||
info := s.repo.GetTenantUserById(uid)
|
||||
|
||||
// ✅ Return success response
|
||||
resp := fiber.Map{
|
||||
"status": true,
|
||||
"code": 200,
|
||||
"message": "Login successful",
|
||||
"details": info,
|
||||
}
|
||||
|
||||
return info, resp, nil
|
||||
}
|
||||
|
||||
func (s *userService) CreateUser(user models.User) (models.UserInfo, error) {
|
||||
// Call repository to create user
|
||||
userid, err := s.repo.CreateUser(user)
|
||||
if err != nil {
|
||||
return models.UserInfo{}, err
|
||||
}
|
||||
|
||||
// Get user info by id
|
||||
info, err := s.repo.GetUserById(userid)
|
||||
if err != nil {
|
||||
return models.UserInfo{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
|
||||
func (s *userService) TenantWebLogin(user models.User) (models.TenantUserInfo, map[string]interface{}) {
|
||||
tenantFormExists := true
|
||||
|
||||
uid, dbPassword, status, roleid := 0, "", "", 0
|
||||
|
||||
// Step 1: Login by authname or contactno
|
||||
if user.Authname != "" {
|
||||
uid, dbPassword, status, roleid = s.repo.GetUserLogin("authname", user.Authname, user.Configid)
|
||||
} else if user.Contactno != "" {
|
||||
uid, dbPassword, status, roleid = s.repo.GetUserLogin("contactno", user.Contactno, user.Configid)
|
||||
} else {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": true,
|
||||
"code": 400,
|
||||
"message": "authname or contactno required",
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Validate user
|
||||
if uid == 0 {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": false,
|
||||
"code": 409,
|
||||
"message": "Invalid Email",
|
||||
"tenantform": tenantFormExists,
|
||||
}
|
||||
}
|
||||
|
||||
if status == "InActive" {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": false,
|
||||
"code": 403,
|
||||
"message": "Inactive Account. Contact admin.",
|
||||
}
|
||||
}
|
||||
|
||||
if user.Roleid != roleid {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": false,
|
||||
"code": 403,
|
||||
"message": "Unauthorized email.",
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Password checks
|
||||
if strings.TrimSpace(dbPassword) == "" {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": true,
|
||||
"code": 409,
|
||||
"message": "Please setup a password.",
|
||||
"tenantform": tenantFormExists,
|
||||
"details": map[string]interface{}{
|
||||
"userid": uid,
|
||||
"setup": true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if strings.TrimSpace(user.Password) == "" {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": true,
|
||||
"code": 401,
|
||||
"message": "Password is required",
|
||||
"tenantform": tenantFormExists,
|
||||
}
|
||||
}
|
||||
|
||||
if user.Password != dbPassword {
|
||||
return models.TenantUserInfo{}, map[string]interface{}{
|
||||
"status": false,
|
||||
"code": 401,
|
||||
"message": "Incorrect password",
|
||||
"tenantform": tenantFormExists,
|
||||
}
|
||||
}
|
||||
|
||||
user.Userid = uid
|
||||
|
||||
// Step 4: Update FCM if provided
|
||||
if user.Userfcmtoken != "" {
|
||||
_ = s.repo.UpdateUserFcmToken(uid, user.Userfcmtoken)
|
||||
}
|
||||
|
||||
// Step 5: Get full tenant info
|
||||
info := s.repo.GetTenantUserById(uid)
|
||||
|
||||
return info, map[string]interface{}{
|
||||
"status": true,
|
||||
"code": 200,
|
||||
"message": "Login successful",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
52
services/utilsService.go
Normal file
52
services/utilsService.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"nearle/models"
|
||||
"nearle/repositories"
|
||||
)
|
||||
|
||||
type UtilsService interface {
|
||||
GetApptypes(tag string) ([]models.Apptypes, error)
|
||||
SendNotification(token string, notification models.FcmNotification, data map[string]string) error
|
||||
GetSubcategories(moduleid int, categoryid int) ([]models.Appsubcategories, error)
|
||||
GetApplocations(aid int) ([]models.Applocations, error)
|
||||
GetApplocationConfig(aid int) ([]models.Applocations, error)
|
||||
GetAppConfig(configID int) (models.Appconfig, error)
|
||||
GetAppCategory() ([]models.AppCategory, error)
|
||||
}
|
||||
|
||||
type utilsService struct {
|
||||
repo repositories.UtilsRepository
|
||||
}
|
||||
|
||||
func NewUtilsService(repo repositories.UtilsRepository) UtilsService {
|
||||
return &utilsService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *utilsService) GetApptypes(tag string) ([]models.Apptypes, error) {
|
||||
return s.repo.GetApptypes(tag)
|
||||
}
|
||||
|
||||
func (s *utilsService) SendNotification(token string, notification models.FcmNotification, data map[string]string) error {
|
||||
return s.repo.SendNotification(token, notification, data)
|
||||
}
|
||||
|
||||
func (s *utilsService) GetSubcategories(moduleid int, categoryid int) ([]models.Appsubcategories, error) {
|
||||
return s.repo.GetSubcategories(moduleid, categoryid)
|
||||
}
|
||||
|
||||
func (s *utilsService) GetApplocations(aid int) ([]models.Applocations, error) {
|
||||
return s.repo.GetApplocations(aid)
|
||||
}
|
||||
|
||||
func (s *utilsService) GetApplocationConfig(aid int) ([]models.Applocations, error) {
|
||||
return s.repo.GetApplocationConfig(aid)
|
||||
}
|
||||
|
||||
func (s *utilsService) GetAppConfig(configID int) (models.Appconfig, error) {
|
||||
return s.repo.GetAppConfig(configID)
|
||||
}
|
||||
|
||||
func (s *utilsService) GetAppCategory() ([]models.AppCategory, error) {
|
||||
return s.repo.GetAppCategory()
|
||||
}
|
||||
Reference in New Issue
Block a user