107 lines
3.7 KiB
Go
107 lines
3.7 KiB
Go
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)
|
|
CreateRiderShift(shift models.Ridershifts) (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)
|
|
GetFleetSummary(aid, tid int, fdate, tdate string) (models.FleetSummary, error)
|
|
CreateRider(rider models.NewRider) (int, error)
|
|
UpdateRider(rider models.NewRider) error
|
|
GetRiderRoster(tid, aid, pid int) ([]models.RiderRosterRow, error)
|
|
CreatePartner(input models.NewPartner) (int, error)
|
|
UpdatePartner(input models.NewPartner) error
|
|
GetPartnerLocations(partnerid int) ([]models.PartnerLocation, 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)
|
|
}
|
|
|
|
// CreateRiderShift opens a working window in a region.
|
|
//
|
|
// The counterpart the table never had. `CreateRider` refuses a rider with no
|
|
// shift, so a region shipped without shift rows could not be given a rider from
|
|
// the product at all — the dropdown said "No shifts set up for this region" and
|
|
// that was the end of it.
|
|
func (s *partnerService) CreateRiderShift(shift models.Ridershifts) (models.Ridershifts, error) {
|
|
|
|
return s.repo.CreateRiderShift(shift)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func (s *partnerService) GetFleetSummary(aid, tid int, fdate, tdate string) (models.FleetSummary, error) {
|
|
return s.repo.GetFleetSummary(aid, tid, fdate, tdate)
|
|
}
|
|
|
|
func (s *partnerService) CreateRider(rider models.NewRider) (int, error) {
|
|
return s.repo.CreateRider(rider)
|
|
}
|
|
|
|
func (s *partnerService) UpdateRider(rider models.NewRider) error {
|
|
return s.repo.UpdateRider(rider)
|
|
}
|
|
|
|
func (s *partnerService) GetRiderRoster(tid, aid, pid int) ([]models.RiderRosterRow, error) {
|
|
return s.repo.GetRiderRoster(tid, aid, pid)
|
|
}
|
|
|
|
/* ── Partners ─────────────────────────────────────────────────────────────── */
|
|
|
|
// CreatePartner onboards a delivery partner. Platform-side only — a merchant is
|
|
// ASSIGNED a partner, never allowed to invent one.
|
|
func (s *partnerService) CreatePartner(input models.NewPartner) (int, error) {
|
|
return s.repo.CreatePartner(input)
|
|
}
|
|
|
|
func (s *partnerService) UpdatePartner(input models.NewPartner) error {
|
|
return s.repo.UpdatePartner(input)
|
|
}
|
|
|
|
func (s *partnerService) GetPartnerLocations(partnerid int) ([]models.PartnerLocation, error) {
|
|
return s.repo.GetPartnerLocations(partnerid)
|
|
}
|