feat(service): get kind_box_req ready to deliver.

This commit is contained in:
Iman Mirazimi 2024-03-14 17:08:42 +03:30
parent 47649e9952
commit 0d54a3765b
71 changed files with 1082 additions and 1329 deletions

View File

@ -0,0 +1,42 @@
package adminkindboxreqhandler
import (
"net/http"
"strconv"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
echo "github.com/labstack/echo/v4"
)
func (h Handler) Deliver(c echo.Context) error {
var req param.DeliverKindBoxReqRequest
id, cErr := strconv.ParseUint(c.Param("id"), 10, 64)
if cErr != nil {
return c.JSON(http.StatusBadRequest, errmsg.ErrorMsgInvalidInput)
}
req.KindBoxReqID = uint(id)
if fieldErrors, err := h.adminKindBoxReqVld.ValidateDeliver(req); err != nil {
msg, code := httpmsg.Error(err)
return c.JSON(code, echo.Map{
"message": msg,
"errors": fieldErrors,
})
}
resp, sErr := h.adminKindBoxReqSvc.Deliver(c.Request().Context(), req)
if sErr != nil {
msg, code := httpmsg.Error(sErr)
return echo.NewHTTPError(code, msg)
}
return c.JSON(http.StatusOK, resp)
}

View File

@ -11,5 +11,6 @@ func (h Handler) SetRoutes(e *echo.Echo) {
// todo - add acl // todo - add acl
r.PATCH("/accept-kind-box-req/:id", h.Accept) r.PATCH("/accept-kind-box-req/:id", h.Accept)
r.PATCH("/reject-kind-box-req/:id", h.Reject) r.PATCH("/reject-kind-box-req/:id", h.Reject)
r.PATCH("/deliver-kind-box-req/:id", h.Deliver)
r.GET("/", h.GetAll, middleware.Auth(h.authSvc, h.authConfig)) r.GET("/", h.GetAll, middleware.Auth(h.authSvc, h.authConfig))
} }

View File

@ -4,8 +4,9 @@ type Address struct {
ID uint ID uint
PostalCode string PostalCode string
Address string Address string
Lat float32 Lat float64
Lon float32 Lon float64
IsMain bool
CityID uint CityID uint
ProvinceID uint ProvinceID uint
BenefactorID uint BenefactorID uint

View File

@ -4,7 +4,7 @@ type Admin struct {
ID uint ID uint
FirstName string FirstName string
LastName string LastName string
password string Password string
PhoneNumber string PhoneNumber string
Role AdminRole Role AdminRole
Description string Description string
@ -12,11 +12,3 @@ type Admin struct {
Gender Gender Gender Gender
Status AdminStatus Status AdminStatus
} }
func (a *Admin) GetPassword() string {
return a.password
}
func (a *Admin) SetPassword(password string) {
a.password = password
}

View File

@ -0,0 +1,15 @@
package entity
type AdminAccessControl struct {
ID uint
ActorID uint
ActorType AdminActorType
Permission AdminPermission
}
type AdminActorType string
const (
AdminRoleActorType = AdminActorType("role")
AdminAdminActorType = AdminActorType("admin")
)

View File

@ -0,0 +1,10 @@
package entity
type AdminPermission string
const (
AdminAdminRegisterPermission = AdminPermission("admin-register")
AdminKindBoxReqAcceptPermission = AdminPermission("kindboxreq-accept")
AdminKindBoxReqRejectPermission = AdminPermission("kindboxreq-reject")
AdminKindBoxReqGetAllPermission = AdminPermission("kindboxreq-getall")
)

View File

@ -3,13 +3,15 @@ package entity
type AdminRole uint type AdminRole uint
const ( const (
AdminAdminRole AdminRole = iota + 1 AdminSuperAdminRole AdminRole = iota + 1
AdminSuperAdminRole AdminAdminRole
AdminAgentRole
) )
var AdminRoleStrings = map[AdminRole]string{ var AdminRoleStrings = map[AdminRole]string{
AdminAdminRole: "admin",
AdminSuperAdminRole: "super-admin", AdminSuperAdminRole: "super-admin",
AdminAdminRole: "admin",
AdminAgentRole: "agent",
} }
func (s AdminRole) String() string { func (s AdminRole) String() string {

View File

@ -4,12 +4,12 @@ type AdminStatus uint
const ( const (
AdminActiveStatus AdminStatus = iota + 1 AdminActiveStatus AdminStatus = iota + 1
AdminDeactiveStatus AdminInactiveStatus
) )
var AdminStatusStrings = map[AdminStatus]string{ var AdminStatusStrings = map[AdminStatus]string{
AdminActiveStatus: "active", AdminActiveStatus: "active",
AdminDeactiveStatus: "deactive", AdminInactiveStatus: "inactive",
} }
func (s AdminStatus) String() string { func (s AdminStatus) String() string {

View File

@ -7,12 +7,9 @@ type Benefactor struct {
FirstName string FirstName string
LastName string LastName string
PhoneNumber string PhoneNumber string
Address string
Description string Description string
Email string Email string
City string
Gender Gender Gender Gender
Status BenefactorStatus BirthDate time.Time
Birthdate time.Time
Role UserRole Role UserRole
} }

View File

@ -1,38 +0,0 @@
package entity
type BenefactorStatus uint
const (
BenefactorActiveStatus BenefactorStatus = iota + 1
BenefactorDeactiveStatus
)
var BenefactorStatusStrings = map[BenefactorStatus]string{
BenefactorActiveStatus: "active",
BenefactorDeactiveStatus: "deactive",
}
func (s BenefactorStatus) String() string {
return BenefactorStatusStrings[s]
}
// AllBenefactorStatus returns a slice containing all string values of BenefactorStatus.
func AllBenefactorStatus() []string {
statusStrings := make([]string, len(BenefactorStatusStrings))
for status, str := range BenefactorStatusStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToBenefactorStatus converts a string to the corresponding BenefactorStatus value.
func MapToBenefactorStatus(statusStr string) BenefactorStatus {
for status, str := range BenefactorStatusStrings {
if str == statusStr {
return status
}
}
return BenefactorStatus(0)
}

View File

@ -3,14 +3,19 @@ package entity
import "time" import "time"
type KindBox struct { type KindBox struct {
ID uint ID uint
KindBoxReqID uint KindBoxReqID uint
BenefactorID uint BenefactorID uint
Type KindBoxType Type KindBoxType
TotalAmount uint Amount uint
SerialNumber string SerialNumber string
Status KindBoxStatus Status KindBoxStatus
SenderID uint DeliverReferDate time.Time
ReceiverID uint DeliverAddressID uint
StatusChangedAt time.Time SenderAgentID uint
DeliveredAt time.Time
ReturnReferDate time.Time
ReturnAddressID uint
ReceiverAgentID uint
ReturnedAt time.Time
} }

View File

@ -3,14 +3,15 @@ package entity
import "time" import "time"
type KindBoxReq struct { type KindBoxReq struct {
ID uint ID uint
KindBoxType KindBoxType BenefactorID uint
CountRequested uint KindBoxType KindBoxType
CountAccepted uint CountRequested uint
BenefactorID uint CountAccepted uint
Status KindBoxReqStatus Description string
Description string Status KindBoxReqStatus
ReferDate time.Time DeliverReferDate time.Time
AddressID uint DeliverAddressID uint
CreatedAt time.Time SenderAgentID uint
DeliveredAt time.Time
} }

View File

@ -5,13 +5,17 @@ type KindBoxReqStatus uint
const ( const (
KindBoxReqPendingStatus KindBoxReqStatus = iota + 1 KindBoxReqPendingStatus KindBoxReqStatus = iota + 1
KindBoxReqAcceptedStatus KindBoxReqAcceptedStatus
KindBoxReqAssignedSenderAgentStatus
KindBoxReqRejectedStatus KindBoxReqRejectedStatus
KindBoxReqDeliveredStatus
) )
var kindBoxReqStatusStrings = map[KindBoxReqStatus]string{ var kindBoxReqStatusStrings = map[KindBoxReqStatus]string{
KindBoxReqPendingStatus: "pending", KindBoxReqPendingStatus: "pending",
KindBoxReqAcceptedStatus: "accepted", KindBoxReqAcceptedStatus: "accepted",
KindBoxReqRejectedStatus: "rejected", KindBoxReqAssignedSenderAgentStatus: "assigned-sender-agent",
KindBoxReqRejectedStatus: "rejected",
KindBoxReqDeliveredStatus: "delivered",
} }
func (s KindBoxReqStatus) String() string { func (s KindBoxReqStatus) String() string {

View File

@ -3,19 +3,19 @@ package entity
type KindBoxStatus uint type KindBoxStatus uint
const ( const (
KindBoxPendingSendStatus KindBoxStatus = iota + 1 KindBoxDeliveredStatus KindBoxStatus = iota + 1
KindBoxSentStatus KindBoxReadyToReturnStatus
KindBoxPendingReceivedStatus KindBoxAssignedReceiverAgentStatus
KindBoxReceivedStatus KindBoxReturnedStatus
KindBoxEnumeratedStatus KindBoxEnumeratedStatus
) )
var kindBoxStatusStrings = map[KindBoxStatus]string{ var kindBoxStatusStrings = map[KindBoxStatus]string{
KindBoxPendingSendStatus: "pending-send", KindBoxDeliveredStatus: "delivered",
KindBoxSentStatus: "sent", KindBoxReadyToReturnStatus: "ready-to-return",
KindBoxPendingReceivedStatus: "pending-received", KindBoxAssignedReceiverAgentStatus: "assigned-receiver-agent",
KindBoxReceivedStatus: "received", KindBoxReturnedStatus: "returned",
KindBoxEnumeratedStatus: "enumerated", KindBoxEnumeratedStatus: "enumerated",
} }
func (s KindBoxStatus) String() string { func (s KindBoxStatus) String() string {

View File

@ -1,6 +1,5 @@
package entity package entity
// TODO - use config file instead of const.
type KindBoxType uint type KindBoxType uint
const ( const (

View File

@ -1,18 +0,0 @@
package entity
import "time"
type Staff struct {
ID uint
FirstName string
LastName string
PhoneNumber string
Address string
Description string
Email string
City string
Gender Gender
Status StaffStatus
Birthday time.Time
StatusChangedAt time.Time
}

View File

@ -1,38 +0,0 @@
package entity
type StaffStatus uint
const (
StaffActiveStatus StaffStatus = iota + 1
StaffDeactiveStatus
)
var StaffStatusStrings = map[StaffStatus]string{
StaffActiveStatus: "active",
StaffDeactiveStatus: "deactive",
}
func (s StaffStatus) String() string {
return StaffStatusStrings[s]
}
// AllStaffStatus returns a slice containing all string values of StaffStatus.
func AllStaffStatus() []string {
statusStrings := make([]string, len(StaffStatusStrings))
for status, str := range StaffStatusStrings {
statusStrings[int(status)-1] = str
}
return statusStrings
}
// MapToStaffStatus converts a string to the corresponding StaffStatus value.
func MapToStaffStatus(statusStr string) StaffStatus {
for status, str := range StaffStatusStrings {
if str == statusStr {
return status
}
}
return StaffStatus(0)
}

1
go.mod
View File

@ -12,7 +12,6 @@ require (
github.com/knadh/koanf v1.5.0 github.com/knadh/koanf v1.5.0
github.com/labstack/echo-jwt/v4 v4.2.0 github.com/labstack/echo-jwt/v4 v4.2.0
github.com/labstack/echo/v4 v4.11.4 github.com/labstack/echo/v4 v4.11.4
github.com/oklog/ulid/v2 v2.1.0
github.com/redis/go-redis/v9 v9.4.0 github.com/redis/go-redis/v9 v9.4.0
github.com/rubenv/sql-migrate v1.6.0 github.com/rubenv/sql-migrate v1.6.0
github.com/stretchr/testify v1.8.4 github.com/stretchr/testify v1.8.4

View File

@ -1 +1,19 @@
package adminkindboxparam package adminkindboxparam
import (
entity "git.gocasts.ir/ebhomengo/niki/entity"
"time"
)
type AddKindBoxRequest struct {
KindBoxReqID uint
BenefactorID uint
Type entity.KindBoxType
DeliverReferDate time.Time
DeliverAddressID uint
SenderAgentID uint
DeliveredAt time.Time
CountAccepted uint
}
type AddKindBoxResponse struct{}

View File

@ -3,13 +3,13 @@ package adminkindboxparam
import entity "git.gocasts.ir/ebhomengo/niki/entity" import entity "git.gocasts.ir/ebhomengo/niki/entity"
type KindBoxUpdateRequest struct { type KindBoxUpdateRequest struct {
BenefactorID uint BenefactorID uint
KindBoxID uint KindBoxID uint
TotalAmount uint Amount uint
ReceiverID uint ReceiverAgentID uint
SenderID uint SenderAgentID uint
SerialNumber string SerialNumber string
Status entity.KindBoxStatus Status entity.KindBoxStatus
} }
type KindBoxUpdateResponse struct { type KindBoxUpdateResponse struct {

View File

@ -16,6 +16,6 @@ type KindBoxReqAcceptResponse struct {
KindBoxReqStatus entity.KindBoxReqStatus `json:"kind_box_req_status"` KindBoxReqStatus entity.KindBoxReqStatus `json:"kind_box_req_status"`
CountRequested uint `json:"count_requested"` CountRequested uint `json:"count_requested"`
CountAccepted uint `json:"count_accepted"` CountAccepted uint `json:"count_accepted"`
ReferDate time.Time `json:"refer_date"` DeliverReferDate time.Time `json:"deliver_refer_date"`
AddressID uint `json:"address_id"` DeliverAddressID uint `json:"deliver_address_id"`
} }

View File

@ -0,0 +1,7 @@
package adminkindboxreqparam
type DeliverKindBoxReqRequest struct {
KindBoxReqID uint `json:"kind_box_req_id"`
}
type DeliverKindBoxReqResponse struct{}

View File

@ -12,12 +12,12 @@ type KindBoxReqRejectRequest struct {
} }
type KindBoxReqRejectResponse struct { type KindBoxReqRejectResponse struct {
ID uint `json:"id"` ID uint `json:"id"`
KindBoxType entity.KindBoxType `json:"kind_box_type"` KindBoxType entity.KindBoxType `json:"kind_box_type"`
CountRequested uint `json:"count_requested"` CountRequested uint `json:"count_requested"`
BenefactorID uint `json:"benefactor_id"` BenefactorID uint `json:"benefactor_id"`
Status entity.KindBoxReqStatus `json:"status"` Status entity.KindBoxReqStatus `json:"status"`
Description string `json:"description"` Description string `json:"description"`
ReferDate time.Time `json:"refer_date"` DeliverReferDate time.Time `json:"deliver_refer_date"`
AddressID uint `json:"address_id"` DeliverAddressID uint `json:"deliver_address_id"`
} }

View File

@ -5,8 +5,8 @@ import "git.gocasts.ir/ebhomengo/niki/entity"
type BenefactorAddAddressRequest struct { type BenefactorAddAddressRequest struct {
PostalCode string `json:"postal_code"` PostalCode string `json:"postal_code"`
Address string `json:"address"` Address string `json:"address"`
Lat float32 `json:"lat"` Lat float64 `json:"lat"`
Lon float32 `json:"lon"` Lon float64 `json:"lon"`
CityID uint `json:"city_id"` CityID uint `json:"city_id"`
ProvinceID uint `json:"province_id"` ProvinceID uint `json:"province_id"`
BenefactorID uint `json:"benefactor_id"` BenefactorID uint `json:"benefactor_id"`

View File

@ -1,17 +1,15 @@
package benefactorkindboxreqparam package benefactorkindboxreqparam
import ( import (
"time"
entity "git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
) )
type KindBoxReqAddRequest struct { type KindBoxReqAddRequest struct {
BenefactorID uint `json:"benefactor_id"` BenefactorID uint `json:"benefactor_id"`
TypeID entity.KindBoxType `json:"type_id"` TypeID entity.KindBoxType `json:"type_id"`
AddressID uint `json:"address_id"` DeliverAddressID uint `json:"deliver_address_id"`
ReferDate time.Time `json:"refer_date"` DeliverReferDate string `json:"deliver_refer_date"`
CountRequested uint `json:"count_requested"` CountRequested uint `json:"count_requested"`
} }
type KindBoxReqAddResponse struct { type KindBoxReqAddResponse struct {

View File

@ -17,4 +17,5 @@ const (
ErrBadRequest = "Bad request" ErrBadRequest = "Bad request"
ErrorMsgAcceptKindBoxReqStatus = "only pending requests will have the ability to be confirmed" ErrorMsgAcceptKindBoxReqStatus = "only pending requests will have the ability to be confirmed"
ErrorMsgRejectKindBoxReqStatus = "only pending requests will have the ability to be rejected" ErrorMsgRejectKindBoxReqStatus = "only pending requests will have the ability to be rejected"
ErrorMsgDeliverKindBoxReqStatus = "only assigned requests will have the ability to be delivered"
) )

View File

@ -13,7 +13,7 @@ func (d DB) AddAdmin(ctx context.Context, admin entity.Admin) (entity.Admin, err
res, err := d.conn.Conn().ExecContext(ctx, `insert into admins(first_name,last_name,password,phone_number, res, err := d.conn.Conn().ExecContext(ctx, `insert into admins(first_name,last_name,password,phone_number,
role,description,email,gender,status) values (?,?,?,?,?,?,?,?,?)`, role,description,email,gender,status) values (?,?,?,?,?,?,?,?,?)`,
admin.FirstName, admin.LastName, admin.GetPassword(), admin.PhoneNumber, admin.Role.String(), admin.Description, admin.Email, admin.FirstName, admin.LastName, admin.Password, admin.PhoneNumber, admin.Role.String(), admin.Description, admin.Email,
admin.Gender.String(), admin.Status.String()) admin.Gender.String(), admin.Status.String())
if err != nil { if err != nil {
return entity.Admin{}, richerror.New(op).WithErr(err). return entity.Admin{}, richerror.New(op).WithErr(err).

View File

@ -51,7 +51,7 @@ func scanAdmin(scanner mysql.Scanner) (entity.Admin, error) {
admin.Role = entity.MapToAdminRole(roleStr) admin.Role = entity.MapToAdminRole(roleStr)
admin.Status = entity.MapToAdminStatus(statusStr) admin.Status = entity.MapToAdminStatus(statusStr)
admin.SetPassword(password) admin.Password = password
mapNotNullToAdmin(adminNullableFields, &admin) mapNotNullToAdmin(adminNullableFields, &admin)
return admin, err return admin, err

View File

@ -11,8 +11,8 @@ import (
func (d DB) CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error) { func (d DB) CreateBenefactor(ctx context.Context, benefactor entity.Benefactor) (entity.Benefactor, error) {
const op = "mysqlbenefactor.CreateBenefactor" const op = "mysqlbenefactor.CreateBenefactor"
res, err := d.conn.Conn().ExecContext(ctx, `insert into benefactors(phone_number, status, role) values(?, ?, ?)`, res, err := d.conn.Conn().ExecContext(ctx, `insert into benefactors(phone_number) values(?)`,
benefactor.PhoneNumber, benefactor.Status.String(), benefactor.Role.String()) benefactor.PhoneNumber)
if err != nil { if err != nil {
return entity.Benefactor{}, richerror.New(op).WithErr(err). return entity.Benefactor{}, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)

View File

@ -4,8 +4,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"errors" "errors"
"time"
"git.gocasts.ir/ebhomengo/niki/entity" "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg" errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
@ -57,9 +55,8 @@ func (d *DB) IsExistBenefactorByID(ctx context.Context, id uint) (bool, error) {
} }
func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) { func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
var createdAt time.Time
var benefactor entity.Benefactor var benefactor entity.Benefactor
var roleStr, statusStr string
// TODO - use db model and mapper between entity and db model OR use this approach // TODO - use db model and mapper between entity and db model OR use this approach
var benefactorNullableFields nullableFields var benefactorNullableFields nullableFields
@ -68,11 +65,8 @@ func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
&benefactorNullableFields.lastName, &benefactor.PhoneNumber, &benefactorNullableFields.lastName, &benefactor.PhoneNumber,
&benefactorNullableFields.address, &benefactorNullableFields.description, &benefactorNullableFields.address, &benefactorNullableFields.description,
&benefactorNullableFields.email, &benefactorNullableFields.city, &benefactorNullableFields.genderStr, &benefactorNullableFields.email, &benefactorNullableFields.city, &benefactorNullableFields.genderStr,
&statusStr, &benefactorNullableFields.birthdate, &roleStr, &benefactorNullableFields.birthdate)
&createdAt)
benefactor.Role = entity.MapToUserRole(roleStr)
benefactor.Status = entity.MapToBenefactorStatus(statusStr)
mapNotNullToBenefactor(benefactorNullableFields, &benefactor) mapNotNullToBenefactor(benefactorNullableFields, &benefactor)
return benefactor, err return benefactor, err
@ -97,22 +91,22 @@ func mapNotNullToBenefactor(data nullableFields, benefactor *entity.Benefactor)
if data.lastName.Valid { if data.lastName.Valid {
benefactor.LastName = data.lastName.String benefactor.LastName = data.lastName.String
} }
if data.address.Valid { //if data.address.Valid {
benefactor.Address = data.address.String // benefactor.Address = data.address.String
} //}
if data.description.Valid { if data.description.Valid {
benefactor.Description = data.description.String benefactor.Description = data.description.String
} }
if data.email.Valid { if data.email.Valid {
benefactor.Email = data.email.String benefactor.Email = data.email.String
} }
if data.city.Valid { //if data.city.Valid {
benefactor.City = data.city.String // benefactor.City = data.city.String
} //}
if data.genderStr.Valid { if data.genderStr.Valid {
benefactor.Gender = entity.MapToGender(data.genderStr.String) benefactor.Gender = entity.MapToGender(data.genderStr.String)
} }
if data.birthdate.Valid { if data.birthdate.Valid {
benefactor.Birthdate = data.birthdate.Time benefactor.BirthDate = data.birthdate.Time
} }
} }

View File

@ -8,15 +8,28 @@ import (
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
) )
func (d DB) AddKindBox(ctx context.Context, kindBox entity.KindBox) error {
const op = "mysqlkindbox.AddKindBox"
_, err := d.conn.Conn().ExecContext(ctx, `insert into kind_boxes(kind_box_req_id,benefactor_id,type,status,sender_agent_id) values (?,?,?,?,?)`,
kindBox.KindBoxReqID, kindBox.BenefactorID, kindBox.Type, entity.KindBoxDeliveredStatus.String(), kindBox.SenderAgentID)
if err != nil {
return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)
}
return nil
}
func (d DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error { func (d DB) AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error {
const op = "mysqlkindbox.AddBatchKindBoxConcurrentlyRollback" const op = "mysqlkindbox.AddBatchKindBoxConcurrentlyRollback"
queryStr := "INSERT INTO kind_boxes (kind_box_req_id, benefactor_id, type, serial_number, status) VALUES " queryStr := "INSERT INTO kind_boxes (kind_box_req_id, benefactor_id, type, status ,deliver_refer_date,deliver_address_id,sender_agent_id,delivered_at) VALUES "
values := []any{} values := []any{}
for _, kb := range kindBoxes { for _, kb := range kindBoxes {
queryStr += "(?, ?, ?, ?, ?)," queryStr += "(?, ?, ?, ?, ?, ?, ?, ?),"
values = append(values, kb.KindBoxReqID, kb.BenefactorID, kb.Type, kb.SerialNumber, kb.Status.String()) values = append(values, kb.KindBoxReqID, kb.BenefactorID, kb.Type, kb.Status.String(), kb.DeliverReferDate, kb.DeliverAddressID, kb.SenderAgentID, kb.DeliveredAt)
} }
// trim the last , // trim the last ,

View File

@ -0,0 +1,23 @@
package mysqlkindboxreq
import (
"context"
"time"
entity "git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (d DB) DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error {
const op = "mysqlkindboxreq.DeliverKindBoxReq"
_, err := d.conn.Conn().ExecContext(ctx, `update kind_box_reqs set status = ?, delivered_at = ?, updated_at = ?, where id = ?`,
entity.KindBoxReqDeliveredStatus.String(), time.Now(), time.Now(), kindBoxReqID)
if err != nil {
return richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgSomethingWentWrong).WithKind(richerror.KindUnexpected)
}
return nil
}

View File

@ -14,7 +14,7 @@ func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (en
const op = "mysqlkindboxreq.AddKindBoxReq" const op = "mysqlkindboxreq.AddKindBoxReq"
res, err := d.conn.Conn().ExecContext(ctx, `insert into kind_box_reqs(benefactor_id,kind_box_type,address_id,count_requested,refer_date,status) values (?,?,?,?,?,?)`, res, err := d.conn.Conn().ExecContext(ctx, `insert into kind_box_reqs(benefactor_id,kind_box_type,address_id,count_requested,refer_date,status) values (?,?,?,?,?,?)`,
kindBoxReq.BenefactorID, kindBoxReq.KindBoxType.String(), kindBoxReq.AddressID, kindBoxReq.CountRequested, kindBoxReq.ReferDate, kindBoxReq.Status.String()) kindBoxReq.BenefactorID, kindBoxReq.KindBoxType.String(), kindBoxReq.DeliverAddressID, kindBoxReq.CountRequested, kindBoxReq.DeliverReferDate, kindBoxReq.Status.String())
if err != nil { if err != nil {
return entity.KindBoxReq{}, richerror.New(op).WithErr(err). return entity.KindBoxReq{}, richerror.New(op).WithErr(err).
WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected) WithMessage(errmsg.ErrorMsgNotFound).WithKind(richerror.KindUnexpected)

View File

@ -13,9 +13,9 @@ func scanKindBoxReq(scanner mysql.Scanner) (entity.KindBoxReq, error) {
var kindBoxType string var kindBoxType string
var countAccept sql.NullInt64 var countAccept sql.NullInt64
var desc sql.NullString var desc sql.NullString
err := scanner.Scan(&kindBoxReq.ID, &kindBoxReq.BenefactorID, &kindBoxType, &kindBoxReq.AddressID, &kindBoxReq.CountRequested, &countAccept, err := scanner.Scan(&kindBoxReq.ID, &kindBoxReq.BenefactorID, &kindBoxType, &kindBoxReq.DeliverAddressID, &kindBoxReq.CountRequested, &countAccept,
&desc, &desc,
&kindBoxReq.ReferDate, &kindBoxStatus, &kindBoxReq.CreatedAt) &kindBoxReq.DeliverReferDate, &kindBoxStatus)
if countAccept.Valid { if countAccept.Valid {
kindBoxReq.CountAccepted = uint(countAccept.Int64) kindBoxReq.CountAccepted = uint(countAccept.Int64)

View File

@ -1,21 +0,0 @@
-- +migrate Up
-- please read this article to understand why we use VARCHAR(191)
-- https://www.grouparoo.com/blog/varchar-191#why-varchar-and-not-text
CREATE TABLE `benefactors` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`first_name` VARCHAR(191) ,
`last_name` VARCHAR(191) ,
`phone_number` VARCHAR(191) NOT NULL UNIQUE,
`address` TEXT,
`description` TEXT,
`email` VARCHAR(191),
`city` VARCHAR(191),
`gender` VARCHAR(191),
`status` VARCHAR(191),
`birthdate` TIMESTAMP,
`role` ENUM('benefactor') NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- +migrate Down
DROP TABLE `benefactors`;

View File

@ -0,0 +1,20 @@
-- +migrate Up
-- please read this article to understand why we use VARCHAR(191)
-- https://www.grouparoo.com/blog/varchar-191#why-varchar-and-not-text
CREATE TABLE `benefactors` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`first_name` VARCHAR(191),
`last_name` VARCHAR(191),
`phone_number` VARCHAR(191) NOT NULL UNIQUE,
`description` TEXT,
`email` VARCHAR(191),
`gender` ENUM('male','female'),
`birth_date` TIMESTAMP,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP
);
-- +migrate Down
DROP TABLE `benefactors`;

View File

@ -0,0 +1,19 @@
-- +migrate Up
CREATE TABLE `admins` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`first_name` VARCHAR(191),
`last_name` VARCHAR(191),
`password` VARCHAR(191) NOT NULL,
`phone_number` VARCHAR(191) NOT NULL UNIQUE,
`role` ENUM('super-admin','admin','agent') NOT NULL, -- default?
`description` TEXT,
`email` VARCHAR(191) NOT NULL UNIQUE,
`gender` ENUM('male','female'),
`status` ENUM('active','inactive') NOT NULL DEFAULT 'active',
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP
);
-- +migrate Down
DROP TABLE `admins`;

View File

@ -0,0 +1,13 @@
-- +migrate Up
CREATE TABLE `admin_access_controls` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`actor_id` INT NOT NULL,
`actor_type` ENUM('role', 'admin') NOT NULL, -- default?
`permission` ENUM('') NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP
);
-- +migrate Down
DROP TABLE admin_access_controls;

View File

@ -1,9 +0,0 @@
-- +migrate Up
CREATE TABLE `provinces` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL ,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- +migrate Down
DROP TABLE `provinces`;

View File

@ -0,0 +1,11 @@
-- +migrate Up
CREATE TABLE `provinces` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP
);
-- +migrate Down
DROP TABLE `provinces`;

View File

@ -1,11 +0,0 @@
-- +migrate Up
CREATE TABLE `cities` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`province_id` INT NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`province_id`) REFERENCES `provinces`(`id`)
);
-- +migrate Down
DROP TABLE `cities`;

View File

@ -0,0 +1,13 @@
-- +migrate Up
CREATE TABLE `cities` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`province_id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
FOREIGN KEY (`province_id`) REFERENCES `provinces`(`id`)
);
-- +migrate Down
DROP TABLE `cities`;

View File

@ -1,19 +0,0 @@
-- +migrate Up
CREATE TABLE `addresses`
(
`id` INT PRIMARY KEY AUTO_INCREMENT,
`postal_code` VARCHAR(191) NOT NULL,
`address` TEXT NOT NULL,
`lat` FLOAT NOT NULL,
`lon` FLOAT NOT NULL,
`province_id` INT NOT NULL,
`city_id` INT NOT NULL,
`benefactor_id` INT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`)
);
-- +migrate Down
DROP TABLE `addresses`;

View File

@ -0,0 +1,21 @@
-- +migrate Up
CREATE TABLE `addresses` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`postal_code` VARCHAR(191) NOT NULL,
`address` TEXT NOT NULL,
`lat` FLOAT,
`lon` FLOAT,
`is_main` BOOL NOT NULL DEFAULT FALSE,
`city_id` INT NOT NULL,
`province_id` INT NOT NULL,
`benefactor_id` INT NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
FOREIGN KEY (`province_id`) REFERENCES `provinces` (`id`),
FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`)
);
-- +migrate Down
DROP TABLE `addresses`;

View File

@ -1,19 +0,0 @@
-- +migrate Up
CREATE TABLE `kind_box_reqs`
(
`id` INT PRIMARY KEY AUTO_INCREMENT,
`benefactor_id` INT NOT NULL,
`kind_box_type` ENUM('on-table','cylindrical','stand-up') NOT NULL,
`address_id` INT NOT NULL,
`count_requested` INT UNSIGNED NOT NULL,
`count_accepted` INT,
`description` TEXT,
`refer_date` DATETIME NOT NULL,
`status` varchar(191),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`)
);
-- +migrate Down
DROP TABLE `kind_box_reqs`;

View File

@ -0,0 +1,23 @@
-- +migrate Up
CREATE TABLE `kind_box_reqs` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`benefactor_id` INT NOT NULL,
`kind_box_type` ENUM('on-table','cylindrical','stand-up') NOT NULL, -- default?
`count_requested` INT UNSIGNED NOT NULL,
`count_accepted` INT UNSIGNED,
`description` TEXT,
`status` ENUM('pending','accepted','assigned-sender-agent','rejected','delivered') NOT NULL DEFAULT 'pending',
`deliver_refer_date` DATETIME NOT NULL,
`deliver_address_id` INT NOT NULL,
`sender_agent_id` INT,
`delivered_at` DATETIME,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP,
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`sender_agent_id`) REFERENCES `admins` (`id`)
);
-- +migrate Down
DROP TABLE `kind_box_reqs`;

View File

@ -1,35 +0,0 @@
-- +migrate Up
INSERT INTO `provinces` (`id`, `name`) VALUES (1, 'آذربایجان شرقی');
INSERT INTO `provinces` (`id`, `name`) VALUES (2, 'آذربایجان غربی');
INSERT INTO `provinces` (`id`, `name`) VALUES (3, 'اردبیل');
INSERT INTO `provinces` (`id`, `name`) VALUES (4, 'اصفهان');
INSERT INTO `provinces` (`id`, `name`) VALUES (5, 'البرز');
INSERT INTO `provinces` (`id`, `name`) VALUES (6, 'ایلام');
INSERT INTO `provinces` (`id`, `name`) VALUES (7, 'بوشهر');
INSERT INTO `provinces` (`id`, `name`) VALUES (8, 'تهران');
INSERT INTO `provinces` (`id`, `name`) VALUES (9, 'چهارمحال و بختیاری');
INSERT INTO `provinces` (`id`, `name`) VALUES (10, 'خراسان جنوبی');
INSERT INTO `provinces` (`id`, `name`) VALUES (11, 'خراسان رضوی');
INSERT INTO `provinces` (`id`, `name`) VALUES (12, 'خراسان شمالی');
INSERT INTO `provinces` (`id`, `name`) VALUES (13, 'خوزستان');
INSERT INTO `provinces` (`id`, `name`) VALUES (14, 'زنجان');
INSERT INTO `provinces` (`id`, `name`) VALUES (15, 'سمنان');
INSERT INTO `provinces` (`id`, `name`) VALUES (16, 'سیستان و بلوچستان');
INSERT INTO `provinces` (`id`, `name`) VALUES (17, 'فارس');
INSERT INTO `provinces` (`id`, `name`) VALUES (18, 'قزوین');
INSERT INTO `provinces` (`id`, `name`) VALUES (19, 'قم');
INSERT INTO `provinces` (`id`, `name`) VALUES (20, 'كردستان');
INSERT INTO `provinces` (`id`, `name`) VALUES (21, 'كرمان');
INSERT INTO `provinces` (`id`, `name`) VALUES (22, 'كرمانشاه');
INSERT INTO `provinces` (`id`, `name`) VALUES (23, 'کهگیلویه و بویراحمد');
INSERT INTO `provinces` (`id`, `name`) VALUES (24, 'گلستان');
INSERT INTO `provinces` (`id`, `name`) VALUES (25, 'گیلان');
INSERT INTO `provinces` (`id`, `name`) VALUES (26, 'لرستان');
INSERT INTO `provinces` (`id`, `name`) VALUES (27, 'مازندران');
INSERT INTO `provinces` (`id`, `name`) VALUES (28, 'مركزی');
INSERT INTO `provinces` (`id`, `name`) VALUES (29, 'هرمزگان');
INSERT INTO `provinces` (`id`, `name`) VALUES (30, 'همدان');
INSERT INTO `provinces` (`id`, `name`) VALUES (31, 'یزد');
-- +migrate Down
DELETE FROM `provinces` WHERE id BETWEEN '1' AND '31';

View File

@ -1,944 +0,0 @@
-- +migrate Up
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (1, 1, 'آذرشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (2, 1, 'اسکو');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (3, 1, 'اهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (4, 1, 'بستان آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (5, 1, 'بناب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (6, 1, 'تبریز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (7, 1, ' جلفا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (8, 1, ' چار اویماق');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (9, 1, ' سراب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (10, 1, ' شبستر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (11, 1, ' عجبشیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (12, 1, ' کلیبر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (13, 1, ' مراغه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (14, 1, ' مرند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (15, 1, ' ملکان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (16, 1, ' میانه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (17, 1, ' ورزقان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (18, 1, ' هریس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (19, 1, 'هشترود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (20, 2, ' ارومیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (21, 2, ' اشنویه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (22, 2, ' بوکان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (23, 2, ' پیرانشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (24, 2, ' تکاب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (25, 2, ' چالدران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (26, 2, ' خوی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (27, 2, ' سردشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (28, 2, ' سلماس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (29, 2, ' شاهین دژ');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (30, 2, ' ماکو');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (31, 2, ' مهاباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (32, 2, ' میاندوآب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (33, 2, ' نقده');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (34, 3, ' اردبیل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (35, 3, ' بیله سوار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (36, 3, ' پارس آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (37, 3, ' خلخال');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (38, 3, ' کوثر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (39, 3, ' گرمی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (40, 3, ' مشگین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (41, 3, ' نمین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (42, 3, ' نیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (43, 4, ' آران و بیدگل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (44, 4, ' اردستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (45, 4, ' اصفهان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (46, 4, ' برخوار و میمه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (47, 4, ' تیران و کرون');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (48, 4, ' چادگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (49, 4, ' خمینی شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (50, 4, ' خوانسار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (51, 4, ' سمیرم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (52, 4, ' شاهین شهر و میمه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (53, 4, ' شهر رضا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (54, 4, 'دهاقان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (55, 4, ' فریدن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (56, 4, ' فریدون شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (57, 4, ' فلاورجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (58, 4, ' کاشان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (59, 4, ' گلپایگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (60, 4, ' لنجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (61, 4, ' مبارکه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (62, 4, ' نائین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (63, 4, ' نجف آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (64, 4, ' نطنز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (65, 5, ' ساوجبلاق');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (66, 5, ' کرج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (67, 5, ' نظرآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (68, 5, 'طالقان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (69, 6, ' آبدانان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (70, 6, ' ایلام');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (71, 6, ' ایوان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (72, 6, ' دره شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (73, 6, ' دهلران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (74, 6, ' شیران و چرداول');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (75, 6, ' مهران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (76, 7, ' بوشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (77, 7, ' تنگستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (78, 7, ' جم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (79, 7, ' دشتستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (80, 7, ' دشتی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (81, 7, ' دیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (82, 7, ' دیلم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (83, 7, ' کنگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (84, 7, ' گناوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (85, 8, ' اسلام شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (86, 8, ' پاکدشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (87, 8, ' تهران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (88, 8, ' دماوند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (89, 8, ' رباط کریم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (90, 8, ' ری');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (91, 8, ' شمیرانات');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (92, 8, ' شهریار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (93, 8, ' فیروزکوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (94, 8, ' ورامین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (95, 9, ' اردل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (96, 9, ' بروجن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (97, 9, ' شهرکرد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (98, 9, ' فارسان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (99, 9, ' کوهرنگ');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (100, 9, ' لردگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (101, 10, ' بیرجند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (102, 10, ' درمیان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (103, 10, ' سرایان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (104, 10, ' سر بیشه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (105, 10, ' فردوس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (106, 10, ' قائن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (107, 10, ' نهبندان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (108, 11, ' برد سکن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (109, 11, ' بجستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (110, 11, ' تایباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (111, 11, ' تحت جلگه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (112, 11, ' تربت جام');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (113, 11, ' تربت حیدریه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (114, 11, ' چناران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (115, 11, ' جغتای');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (116, 11, ' جوین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (117, 11, ' خلیل آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (118, 11, ' خواف');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (119, 11, ' درگز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (120, 11, ' رشتخوار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (121, 11, ' زاوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (122, 11, ' سبزوار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (123, 11, ' سرخس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (124, 11, ' فریمان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (125, 11, ' قوچان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (126, 11, 'طرقبه شاندیز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (127, 11, ' کاشمر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (128, 11, ' کلات');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (129, 11, ' گناباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (130, 11, ' مشهد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (131, 11, ' مه ولات');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (132, 11, ' نیشابور');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (133, 12, ' اسفراین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (134, 12, ' بجنورد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (135, 12, ' جاجرم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (136, 12, ' شیروان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (137, 12, ' فاروج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (138, 12, ' مانه و سملقان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (139, 13, ' آبادان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (140, 13, ' امیدیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (141, 13, ' اندیمشک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (142, 13, ' اهواز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (143, 13, ' ایذه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (144, 13, ' باغ ملک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (145, 13, ' بندرماهشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (146, 13, ' بهبهان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (147, 13, ' خرمشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (148, 13, ' دزفول');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (149, 13, ' دشت آزادگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (150, 13, ' رامشیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (151, 13, ' رامهرمز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (152, 13, ' شادگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (153, 13, ' شوش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (154, 13, ' شوشتر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (155, 13, ' گتوند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (156, 13, ' لالی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (157, 13, ' مسجد سلیمان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (158, 13, ' هندیجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (159, 14, ' ابهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (160, 14, ' ایجرود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (161, 14, ' خدابنده');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (162, 14, ' خرمدره');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (163, 14, ' زنجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (164, 14, ' طارم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (165, 14, ' ماه نشان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (166, 15, ' دامغان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (167, 15, ' سمنان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (168, 15, ' شاهرود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (169, 15, ' گرمسار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (170, 15, ' مهدی شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (171, 16, ' ایرانشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (172, 16, ' چابهار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (173, 16, ' خاش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (174, 16, ' دلگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (175, 16, ' زابل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (176, 16, ' زاهدان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (177, 16, ' زهک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (178, 16, ' سراوان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (179, 16, ' سرباز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (180, 16, ' کنارک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (181, 16, ' نیکشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (182, 17, ' آباده');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (183, 17, ' ارسنجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (184, 17, ' استهبان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (185, 17, ' اقلید');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (186, 17, ' بوانات');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (187, 17, ' پاسارگاد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (188, 17, ' جهرم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (189, 17, ' خرم بید');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (190, 17, ' خنج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (191, 17, ' داراب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (192, 17, ' زرین دشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (193, 17, ' سپیدان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (194, 17, ' شیراز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (195, 17, ' فراشبند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (196, 17, ' فسا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (197, 17, ' فیروزآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (198, 17, ' قیر و کارزین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (199, 17, ' کازرون');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (200, 17, ' لارستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (201, 17, ' لامرد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (202, 17, ' مرودشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (203, 17, ' ممسنی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (204, 17, ' مهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (205, 17, ' نی ریز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (206, 18, ' آبیک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (207, 18, ' البرز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (208, 18, ' بوئین زهرا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (209, 18, ' تاکستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (210, 18, ' قزوین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (211, 19, ' قم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (212, 20, ' بانه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (213, 20, ' بیجار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (214, 20, ' دیواندره');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (215, 20, ' سروآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (216, 20, ' سقز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (217, 20, ' سنندج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (218, 20, ' قروه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (219, 20, ' کامیاران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (220, 20, ' مریوان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (221, 21, ' بافت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (222, 21, ' بردسیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (223, 21, ' بم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (224, 21, ' جیرفت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (225, 21, ' راور');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (226, 21, ' رفسنجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (227, 21, ' رودبار جنوب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (228, 21, ' زرند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (229, 21, ' سیرجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (230, 21, ' شهر بابک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (231, 21, ' عنبرآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (232, 21, ' قلعه گنج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (233, 21, ' کرمان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (234, 21, ' کوهبنان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (235, 21, ' کهنوج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (236, 21, ' منوجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (237, 22, ' اسلام آباد غرب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (238, 22, ' پاوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (239, 22, ' ثلاث باباجانی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (240, 22, ' جوانرود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (241, 22, ' دالاهو');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (242, 22, ' روانسر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (243, 22, ' سرپل ذهاب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (244, 22, ' سنقر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (245, 22, ' صحنه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (246, 22, ' قصر شیرین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (247, 22, ' کرمانشاه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (248, 22, ' کنگاور');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (249, 22, ' گیلان غرب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (250, 22, ' هرسین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (251, 23, ' بویر احمد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (252, 23, ' بهمئی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (253, 23, ' دنا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (254, 23, ' کهگیلویه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (255, 23, ' گچساران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (256, 24, ' آزادشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (257, 24, ' آق قلا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (258, 24, ' بندر گز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (259, 24, ' بندر ترکمن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (260, 24, ' رامیان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (261, 24, ' علی آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (262, 24, ' کرد کوی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (263, 24, ' کلاله');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (264, 24, ' گرگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (265, 24, ' گنبد کاووس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (266, 24, ' مینو دشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (267, 25, ' آستارا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (268, 25, ' آستانه اشرفیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (269, 25, ' املش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (270, 25, ' بندر انزلی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (271, 25, ' رشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (272, 25, ' رضوانشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (273, 25, ' رودبار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (274, 25, ' رودسر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (275, 25, ' سیاهکل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (276, 25, ' شفت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (277, 25, ' صومعه سرا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (278, 25, ' طوالش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (279, 25, ' فومن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (280, 25, ' لاهیجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (281, 25, ' لنگرود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (282, 25, ' ماسال');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (283, 26, ' ازنا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (284, 26, ' الیگودرز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (285, 26, ' بروجرد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (286, 26, ' پلدختر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (287, 26, ' خرم آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (288, 26, ' دورود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (289, 17, ' لامرد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (290, 17, ' مرودشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (291, 17, ' ممسنی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (292, 17, ' مهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (293, 17, ' نی ریز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (294, 18, ' آبیک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (295, 18, ' البرز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (296, 18, ' بوئین زهرا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (297, 18, ' تاکستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (298, 18, ' قزوین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (299, 19, ' قم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (300, 20, ' بانه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (301, 20, ' بیجار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (302, 20, ' دیواندره');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (303, 20, ' سروآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (304, 20, ' سقز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (305, 20, ' سنندج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (306, 20, ' قروه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (307, 20, ' کامیاران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (308, 20, ' مریوان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (309, 21, ' بافت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (310, 21, ' بردسیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (311, 21, ' بم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (312, 21, ' جیرفت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (313, 21, ' راور');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (314, 21, ' رفسنجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (315, 21, ' رودبار جنوب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (316, 21, ' زرند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (317, 21, ' سیرجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (318, 21, ' شهر بابک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (319, 21, ' عنبرآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (320, 21, ' قلعه گنج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (321, 21, ' کرمان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (322, 21, ' کوهبنان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (323, 21, ' کهنوج');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (324, 21, ' منوجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (325, 22, ' اسلام آباد غرب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (326, 22, ' پاوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (327, 22, ' ثلاث باباجانی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (328, 22, ' جوانرود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (329, 22, ' دالاهو');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (330, 22, ' روانسر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (332, 22, ' سنقر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (333, 22, ' صحنه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (334, 22, ' قصر شیرین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (335, 22, ' کرمانشاه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (336, 22, ' کنگاور');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (337, 22, ' گیلان غرب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (338, 22, ' هرسین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (339, 23, ' بویر احمد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (341, 23, ' دنا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (343, 23, ' گچساران');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (344, 24, ' آزادشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (345, 24, ' آق قلا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (346, 24, ' بندر گز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (347, 24, ' بندر ترکمن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (348, 24, ' رامیان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (349, 24, ' علی آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (350, 24, ' کرد کوی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (351, 24, ' کلاله');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (352, 24, ' گرگان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (353, 24, ' گنبد کاووس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (354, 24, ' مینو دشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (355, 25, ' آستارا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (356, 25, ' آستانه اشرفیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (357, 25, ' املش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (358, 25, ' بندر انزلی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (359, 25, ' رشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (360, 25, ' رضوانشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (361, 25, ' رودبار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (362, 25, ' رودسر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (363, 25, ' سیاهکل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (364, 25, ' شفت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (365, 25, ' صومعه سرا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (366, 25, ' طوالش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (367, 25, ' فومن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (368, 25, ' لاهیجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (369, 25, ' لنگرود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (370, 25, ' ماسال');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (371, 26, ' ازنا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (372, 26, ' الیگودرز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (373, 26, ' بروجرد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (374, 26, ' پلدختر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (375, 26, ' خرم آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (376, 26, ' دورود');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (377, 26, ' دلفان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (378, 26, ' سلسله');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (379, 26, ' کوهدشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (380, 26, ' الشتر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (381, 26, ' نورآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (382, 27, ' آمل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (383, 27, ' بابل');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (384, 27, ' بابلسر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (385, 27, ' بهشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (386, 27, ' تنکابن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (387, 27, ' جویبار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (388, 27, ' چالوس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (389, 27, ' رامسر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (390, 27, ' ساری');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (391, 27, ' سوادکوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (392, 27, ' قائم شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (393, 27, ' گلوگاه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (394, 27, ' محمود آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (395, 27, ' نکا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (396, 27, ' نور');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (397, 27, ' نوشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (398, 27, ' فریدونکنار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (399, 28, ' آشتیان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (400, 28, ' اراک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (401, 28, ' تفرش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (402, 28, ' خمین');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (403, 28, ' دلیجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (404, 28, ' زرندیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (405, 28, ' ساوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (406, 28, ' شازند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (407, 28, ' کمیجان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (408, 28, ' محلات');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (409, 29, ' بندرعباس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (410, 29, ' میناب');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (411, 29, ' بندر لنگه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (412, 29, ' رودان-دهبارز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (413, 29, ' جاسک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (414, 29, ' قشم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (415, 29, ' حاجی آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (416, 29, ' ابوموسی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (417, 29, ' بستک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (418, 29, ' گاوبندی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (419, 29, ' خمیر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (420, 30, ' اسدآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (421, 30, ' بهار');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (422, 30, ' تویسرکان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (423, 30, ' رزن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (424, 30, ' کبودر آهنگ');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (425, 30, ' ملایر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (426, 30, ' نهاوند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (427, 30, ' همدان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (428, 31, ' ابرکوه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (429, 31, ' اردکان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (430, 31, ' بافق');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (431, 31, ' تفت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (432, 31, ' خاتم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (433, 31, ' صدوق');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (434, 31, ' طبس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (435, 31, ' مهریز');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (436, 31, ' میبد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (437, 31, ' یزد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (438, 8, 'قرچک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (439, 8, 'گلستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (440, 8, 'قدس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (441, 8, 'ملارد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (442, 8, 'نسیم‌شهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (443, 8, 'اندیشه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (444, 8, 'صالح‌آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (445, 8, 'باقرشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (446, 8, 'باغستان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (447, 8, 'بومهن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (448, 8, 'چهاردانگه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (449, 8, 'پیشوا');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (450, 8, 'پردیس');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (451, 8, 'وحیدیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (452, 8, 'نصیرآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (453, 8, 'فردوسیه');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (454, 8, 'حسن‌آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (455, 8, 'رودهن');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (456, 8, 'شاهدشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (457, 8, 'صباشهر');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (458, 8, 'صفادشت');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (459, 8, 'لواسان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (460, 8, 'آبسرد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (461, 8, 'شریف‌آباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (462, 8, 'کهریزک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (463, 8, 'فشم');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (464, 8, 'جوادآباد');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (465, 8, 'کیلان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (466, 8, 'آبعلی');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (467, 8, 'ارجمند');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (468, 29, 'کیش');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (469, 29, 'لاوان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (470, 29, 'پارسیان');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (471, 29, 'سیریک');
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES (472, 29, 'بشاگرد');
-- +migrate Down
DELETE
FROM `cities`
WHERE id BETWEEN '1' AND '472';

View File

@ -1,18 +0,0 @@
-- +migrate Up
CREATE TABLE `admins`
(
`id` INT PRIMARY KEY AUTO_INCREMENT,
`first_name` VARCHAR(191),
`last_name` VARCHAR(191),
`password` TEXT NOT NULL,
`phone_number` VARCHAR(191) NOT NULL UNIQUE,
`role` ENUM('super-admin','admin') NOT NULL,
`description` TEXT,
`email` VARCHAR(191) NOT NULL UNIQUE,
`gender` VARCHAR(191),
`status` VARCHAR(191),
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- +migrate Down
DROP TABLE `admins`;

View File

@ -1,24 +0,0 @@
-- +migrate Up
CREATE TABLE `kind_boxes`
(
`id` INT PRIMARY KEY AUTO_INCREMENT,
`kind_box_req_id` INT NOT NULL,
`benefactor_id` INT NOT NULL,
`type` ENUM ('on-table','cylindrical','stand-up') NOT NULL,
`total_amount` INT UNSIGNED NULL NULL,
`serial_number` varchar(255),
`status` varchar(255),
`sender_id` INT NULL,
`receiver_id` INT NULL,
`status_changed_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`kind_box_req_id`) REFERENCES `kind_box_reqs` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`sender_id`) REFERENCES `admins` (`id`),
FOREIGN KEY (`receiver_id`) REFERENCES `admins` (`id`),
index `index_serial_number` (`serial_number`)
);
-- +migrate Down
DROP TABLE `kind_boxes`;

View File

@ -0,0 +1,30 @@
-- +migrate Up
CREATE TABLE `kind_boxes` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`kind_box_req_id` INT NOT NULL,
`benefactor_id` INT NOT NULL,
`type` ENUM('on-table','cylindrical','stand-up') NOT NULL,
`amount` INT UNSIGNED,
`serial_number` varchar(191),
`status` ENUM('delivered','ready-to-return','assigned-receiver-agent','returned','enumerated') NOT NULL,
`deliver_refer_date` DATETIME NOT NULL,
`deliver_address_id` INT NOT NULL,
`sender_agent_id` INT NOT NULL,
`delivered_at` DATETIME NOT NULL,
`return_refer_date` DATETIME,
`return_address_id` INT,
`receiver_agent_id` INT,
`returned_at` DATETIME,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`kind_box_req_id`) REFERENCES `kind_box_reqs` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`sender_agent_id`) REFERENCES `admins` (`id`),
FOREIGN KEY (`return_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`receiver_agent_id`) REFERENCES `admins` (`id`),
INDEX `index_serial_number` (`serial_number`)
);
-- +migrate Down
DROP TABLE `kind_boxes`;

View File

@ -1,9 +1,10 @@
-- +migrate Up -- +migrate Up
-- what can we do for password? -- what can we do for password?
INSERT INTO `admins` (`id`, `phone_number`, `email`,`password`,`role`,`status`) INSERT INTO `admins` (`id`, `phone_number`, `email`,`password`,`role`,`status`)
VALUES (1, '09122702856', 'keshvari@gmail.com','Abc123456','super-admin','active'); VALUES
(1, '09122702856', 'keshvari@gmail.com','Abc123456','super-admin','active');
-- +migrate Down -- +migrate Down
DELETE DELETE
FROM `admins` FROM `admins`
WHERE id '1' ; WHERE id = 1;

View File

@ -0,0 +1,10 @@
-- +migrate Up
ALTER TABLE `admin_access_controls` MODIFY COLUMN `permission`
enum (
'admin-register',
'kindboxreq-accept',
'kindboxreq-reject',
'kindboxreq-getall'
) NOT NULL;
-- +migrate Down

View File

@ -0,0 +1,15 @@
-- +migrate Up
INSERT INTO `admin_access_controls` (`id`, `actor_id`, `actor_type`,`permission`)
VALUES
(1, 1 , 'role','admin-register'),
(2, 1 , 'role','kindboxreq-accept'),
(3, 1 , 'role','kindboxreq-reject'),
(4, 1 , 'role','kindboxreq-getall'),
(5, 2 , 'role','kindboxreq-accept'),
(6, 2 , 'role','kindboxreq-reject'),
(7, 2 , 'role','kindboxreq-getall');
-- +migrate Down
DELETE
FROM `admin_access_controls`
WHERE id BETWEEN 1 AND 7;

View File

@ -0,0 +1,39 @@
-- +migrate Up
INSERT INTO `provinces` (`id`, `name`)
VALUES
(1, 'آذربایجان شرقی'),
(2, 'آذربایجان غربی'),
(3, 'اردبیل'),
(4, 'اصفهان'),
(5, 'البرز'),
(6, 'ایلام'),
(7, 'بوشهر'),
(8, 'تهران'),
(9, 'چهارمحال و بختیاری'),
(10, 'خراسان جنوبی'),
(11, 'خراسان رضوی'),
(12, 'خراسان شمالی'),
(13, 'خوزستان'),
(14, 'زنجان'),
(15, 'سمنان'),
(16, 'سیستان و بلوچستان'),
(17, 'فارس'),
(18, 'قزوین'),
(19, 'قم'),
(20, 'كردستان'),
(21, 'كرمان'),
(22, 'كرمانشاه'),
(23, 'کهگیلویه و بویراحمد'),
(24, 'گلستان'),
(25, 'گیلان'),
(26, 'لرستان'),
(27, 'مازندران'),
(28, 'مركزی'),
(29, 'هرمزگان'),
(30, 'همدان'),
(31, 'یزد');
-- +migrate Down
DELETE
FROM `provinces`
WHERE id BETWEEN 1 AND 31;

View File

@ -0,0 +1,477 @@
-- +migrate Up
INSERT INTO `cities` (`id`, `province_id`, `name`)
VALUES
(1, 1, 'آذرشهر'),
(2, 1, 'اسکو'),
(3, 1, 'اهر'),
(4, 1, 'بستان آباد'),
(5, 1, 'بناب'),
(6, 1, 'تبریز'),
(7, 1, ' جلفا'),
(8, 1, ' چار اویماق'),
(9, 1, ' سراب'),
(10, 1, ' شبستر'),
(11, 1, ' عجبشیر'),
(12, 1, ' کلیبر'),
(13, 1, ' مراغه'),
(14, 1, ' مرند'),
(15, 1, ' ملکان'),
(16, 1, ' میانه'),
(17, 1, ' ورزقان'),
(18, 1, ' هریس'),
(19, 1, 'هشترود'),
(20, 2, ' ارومیه'),
(21, 2, ' اشنویه'),
(22, 2, ' بوکان'),
(23, 2, ' پیرانشهر'),
(24, 2, ' تکاب'),
(25, 2, ' چالدران'),
(26, 2, ' خوی'),
(27, 2, ' سردشت'),
(28, 2, ' سلماس'),
(29, 2, ' شاهین دژ'),
(30, 2, ' ماکو'),
(31, 2, ' مهاباد'),
(32, 2, ' میاندوآب'),
(33, 2, ' نقده'),
(34, 3, ' اردبیل'),
(35, 3, ' بیله سوار'),
(36, 3, ' پارس آباد'),
(37, 3, ' خلخال'),
(38, 3, ' کوثر'),
(39, 3, ' گرمی'),
(40, 3, ' مشگین'),
(41, 3, ' نمین'),
(42, 3, ' نیر'),
(43, 4, ' آران و بیدگل'),
(44, 4, ' اردستان'),
(45, 4, ' اصفهان'),
(46, 4, ' برخوار و میمه'),
(47, 4, ' تیران و کرون'),
(48, 4, ' چادگان'),
(49, 4, ' خمینی شهر'),
(50, 4, ' خوانسار'),
(51, 4, ' سمیرم'),
(52, 4, ' شاهین شهر و میمه'),
(53, 4, ' شهر رضا'),
(54, 4, 'دهاقان'),
(55, 4, ' فریدن'),
(56, 4, ' فریدون شهر'),
(57, 4, ' فلاورجان'),
(58, 4, ' کاشان'),
(59, 4, ' گلپایگان'),
(60, 4, ' لنجان'),
(61, 4, ' مبارکه'),
(62, 4, ' نائین'),
(63, 4, ' نجف آباد'),
(64, 4, ' نطنز'),
(65, 5, ' ساوجبلاق'),
(66, 5, ' کرج'),
(67, 5, ' نظرآباد'),
(68, 5, 'طالقان'),
(69, 6, ' آبدانان'),
(70, 6, ' ایلام'),
(71, 6, ' ایوان'),
(72, 6, ' دره شهر'),
(73, 6, ' دهلران'),
(74, 6, ' شیران و چرداول'),
(75, 6, ' مهران'),
(76, 7, ' بوشهر'),
(77, 7, ' تنگستان'),
(78, 7, ' جم'),
(79, 7, ' دشتستان'),
(80, 7, ' دشتی'),
(81, 7, ' دیر'),
(82, 7, ' دیلم'),
(83, 7, ' کنگان'),
(84, 7, ' گناوه'),
(85, 8, ' اسلام شهر'),
(86, 8, ' پاکدشت'),
(87, 8, ' تهران'),
(88, 8, ' دماوند'),
(89, 8, ' رباط کریم'),
(90, 8, ' ری'),
(91, 8, ' شمیرانات'),
(92, 8, ' شهریار'),
(93, 8, ' فیروزکوه'),
(94, 8, ' ورامین'),
(95, 9, ' اردل'),
(96, 9, ' بروجن'),
(97, 9, ' شهرکرد'),
(98, 9, ' فارسان'),
(99, 9, ' کوهرنگ'),
(100, 9, ' لردگان'),
(101, 10, ' بیرجند'),
(102, 10, ' درمیان'),
(103, 10, ' سرایان'),
(104, 10, ' سر بیشه'),
(105, 10, ' فردوس'),
(106, 10, ' قائن'),
(107, 10, ' نهبندان'),
(108, 11, ' برد سکن'),
(109, 11, ' بجستان'),
(110, 11, ' تایباد'),
(111, 11, ' تحت جلگه'),
(112, 11, ' تربت جام'),
(113, 11, ' تربت حیدریه'),
(114, 11, ' چناران'),
(115, 11, ' جغتای'),
(116, 11, ' جوین'),
(117, 11, ' خلیل آباد'),
(118, 11, ' خواف'),
(119, 11, ' درگز'),
(120, 11, ' رشتخوار'),
(121, 11, ' زاوه'),
(122, 11, ' سبزوار'),
(123, 11, ' سرخس'),
(124, 11, ' فریمان'),
(125, 11, ' قوچان'),
(126, 11, 'طرقبه شاندیز'),
(127, 11, ' کاشمر'),
(128, 11, ' کلات'),
(129, 11, ' گناباد'),
(130, 11, ' مشهد'),
(131, 11, ' مه ولات'),
(132, 11, ' نیشابور'),
(133, 12, ' اسفراین'),
(134, 12, ' بجنورد'),
(135, 12, ' جاجرم'),
(136, 12, ' شیروان'),
(137, 12, ' فاروج'),
(138, 12, ' مانه و سملقان'),
(139, 13, ' آبادان'),
(140, 13, ' امیدیه'),
(141, 13, ' اندیمشک'),
(142, 13, ' اهواز'),
(143, 13, ' ایذه'),
(144, 13, ' باغ ملک'),
(145, 13, ' بندرماهشهر'),
(146, 13, ' بهبهان'),
(147, 13, ' خرمشهر'),
(148, 13, ' دزفول'),
(149, 13, ' دشت آزادگان'),
(150, 13, ' رامشیر'),
(151, 13, ' رامهرمز'),
(152, 13, ' شادگان'),
(153, 13, ' شوش'),
(154, 13, ' شوشتر'),
(155, 13, ' گتوند'),
(156, 13, ' لالی'),
(157, 13, ' مسجد سلیمان'),
(158, 13, ' هندیجان'),
(159, 14, ' ابهر'),
(160, 14, ' ایجرود'),
(161, 14, ' خدابنده'),
(162, 14, ' خرمدره'),
(163, 14, ' زنجان'),
(164, 14, ' طارم'),
(165, 14, ' ماه نشان'),
(166, 15, ' دامغان'),
(167, 15, ' سمنان'),
(168, 15, ' شاهرود'),
(169, 15, ' گرمسار'),
(170, 15, ' مهدی شهر'),
(171, 16, ' ایرانشهر'),
(172, 16, ' چابهار'),
(173, 16, ' خاش'),
(174, 16, ' دلگان'),
(175, 16, ' زابل'),
(176, 16, ' زاهدان'),
(177, 16, ' زهک'),
(178, 16, ' سراوان'),
(179, 16, ' سرباز'),
(180, 16, ' کنارک'),
(181, 16, ' نیکشهر'),
(182, 17, ' آباده'),
(183, 17, ' ارسنجان'),
(184, 17, ' استهبان'),
(185, 17, ' اقلید'),
(186, 17, ' بوانات'),
(187, 17, ' پاسارگاد'),
(188, 17, ' جهرم'),
(189, 17, ' خرم بید'),
(190, 17, ' خنج'),
(191, 17, ' داراب'),
(192, 17, ' زرین دشت'),
(193, 17, ' سپیدان'),
(194, 17, ' شیراز'),
(195, 17, ' فراشبند'),
(196, 17, ' فسا'),
(197, 17, ' فیروزآباد'),
(198, 17, ' قیر و کارزین'),
(199, 17, ' کازرون'),
(200, 17, ' لارستان'),
(201, 17, ' لامرد'),
(202, 17, ' مرودشت'),
(203, 17, ' ممسنی'),
(204, 17, ' مهر'),
(205, 17, ' نی ریز'),
(206, 18, ' آبیک'),
(207, 18, ' البرز'),
(208, 18, ' بوئین زهرا'),
(209, 18, ' تاکستان'),
(210, 18, ' قزوین'),
(211, 19, ' قم'),
(212, 20, ' بانه'),
(213, 20, ' بیجار'),
(214, 20, ' دیواندره'),
(215, 20, ' سروآباد'),
(216, 20, ' سقز'),
(217, 20, ' سنندج'),
(218, 20, ' قروه'),
(219, 20, ' کامیاران'),
(220, 20, ' مریوان'),
(221, 21, ' بافت'),
(222, 21, ' بردسیر'),
(223, 21, ' بم'),
(224, 21, ' جیرفت'),
(225, 21, ' راور'),
(226, 21, ' رفسنجان'),
(227, 21, ' رودبار جنوب'),
(228, 21, ' زرند'),
(229, 21, ' سیرجان'),
(230, 21, ' شهر بابک'),
(231, 21, ' عنبرآباد'),
(232, 21, ' قلعه گنج'),
(233, 21, ' کرمان'),
(234, 21, ' کوهبنان'),
(235, 21, ' کهنوج'),
(236, 21, ' منوجان'),
(237, 22, ' اسلام آباد غرب'),
(238, 22, ' پاوه'),
(239, 22, ' ثلاث باباجانی'),
(240, 22, ' جوانرود'),
(241, 22, ' دالاهو'),
(242, 22, ' روانسر'),
(243, 22, ' سرپل ذهاب'),
(244, 22, ' سنقر'),
(245, 22, ' صحنه'),
(246, 22, ' قصر شیرین'),
(247, 22, ' کرمانشاه'),
(248, 22, ' کنگاور'),
(249, 22, ' گیلان غرب'),
(250, 22, ' هرسین'),
(251, 23, ' بویر احمد'),
(252, 23, ' بهمئی'),
(253, 23, ' دنا'),
(254, 23, ' کهگیلویه'),
(255, 23, ' گچساران'),
(256, 24, ' آزادشهر'),
(257, 24, ' آق قلا'),
(258, 24, ' بندر گز'),
(259, 24, ' بندر ترکمن'),
(260, 24, ' رامیان'),
(261, 24, ' علی آباد'),
(262, 24, ' کرد کوی'),
(263, 24, ' کلاله'),
(264, 24, ' گرگان'),
(265, 24, ' گنبد کاووس'),
(266, 24, ' مینو دشت'),
(267, 25, ' آستارا'),
(268, 25, ' آستانه اشرفیه'),
(269, 25, ' املش'),
(270, 25, ' بندر انزلی'),
(271, 25, ' رشت'),
(272, 25, ' رضوانشهر'),
(273, 25, ' رودبار'),
(274, 25, ' رودسر'),
(275, 25, ' سیاهکل'),
(276, 25, ' شفت'),
(277, 25, ' صومعه سرا'),
(278, 25, ' طوالش'),
(279, 25, ' فومن'),
(280, 25, ' لاهیجان'),
(281, 25, ' لنگرود'),
(282, 25, ' ماسال'),
(283, 26, ' ازنا'),
(284, 26, ' الیگودرز'),
(285, 26, ' بروجرد'),
(286, 26, ' پلدختر'),
(287, 26, ' خرم آباد'),
(288, 26, ' دورود'),
(289, 17, ' لامرد'),
(290, 17, ' مرودشت'),
(291, 17, ' ممسنی'),
(292, 17, ' مهر'),
(293, 17, ' نی ریز'),
(294, 18, ' آبیک'),
(295, 18, ' البرز'),
(296, 18, ' بوئین زهرا'),
(297, 18, ' تاکستان'),
(298, 18, ' قزوین'),
(299, 19, ' قم'),
(300, 20, ' بانه'),
(301, 20, ' بیجار'),
(302, 20, ' دیواندره'),
(303, 20, ' سروآباد'),
(304, 20, ' سقز'),
(305, 20, ' سنندج'),
(306, 20, ' قروه'),
(307, 20, ' کامیاران'),
(308, 20, ' مریوان'),
(309, 21, ' بافت'),
(310, 21, ' بردسیر'),
(311, 21, ' بم'),
(312, 21, ' جیرفت'),
(313, 21, ' راور'),
(314, 21, ' رفسنجان'),
(315, 21, ' رودبار جنوب'),
(316, 21, ' زرند'),
(317, 21, ' سیرجان'),
(318, 21, ' شهر بابک'),
(319, 21, ' عنبرآباد'),
(320, 21, ' قلعه گنج'),
(321, 21, ' کرمان'),
(322, 21, ' کوهبنان'),
(323, 21, ' کهنوج'),
(324, 21, ' منوجان'),
(325, 22, ' اسلام آباد غرب'),
(326, 22, ' پاوه'),
(327, 22, ' ثلاث باباجانی'),
(328, 22, ' جوانرود'),
(329, 22, ' دالاهو'),
(330, 22, ' روانسر'),
(332, 22, ' سنقر'),
(333, 22, ' صحنه'),
(334, 22, ' قصر شیرین'),
(335, 22, ' کرمانشاه'),
(336, 22, ' کنگاور'),
(337, 22, ' گیلان غرب'),
(338, 22, ' هرسین'),
(339, 23, ' بویر احمد'),
(341, 23, ' دنا'),
(343, 23, ' گچساران'),
(344, 24, ' آزادشهر'),
(345, 24, ' آق قلا'),
(346, 24, ' بندر گز'),
(347, 24, ' بندر ترکمن'),
(348, 24, ' رامیان'),
(349, 24, ' علی آباد'),
(350, 24, ' کرد کوی'),
(351, 24, ' کلاله'),
(352, 24, ' گرگان'),
(353, 24, ' گنبد کاووس'),
(354, 24, ' مینو دشت'),
(355, 25, ' آستارا'),
(356, 25, ' آستانه اشرفیه'),
(357, 25, ' املش'),
(358, 25, ' بندر انزلی'),
(359, 25, ' رشت'),
(360, 25, ' رضوانشهر'),
(361, 25, ' رودبار'),
(362, 25, ' رودسر'),
(363, 25, ' سیاهکل'),
(364, 25, ' شفت'),
(365, 25, ' صومعه سرا'),
(366, 25, ' طوالش'),
(367, 25, ' فومن'),
(368, 25, ' لاهیجان'),
(369, 25, ' لنگرود'),
(370, 25, ' ماسال'),
(371, 26, ' ازنا'),
(372, 26, ' الیگودرز'),
(373, 26, ' بروجرد'),
(374, 26, ' پلدختر'),
(375, 26, ' خرم آباد'),
(376, 26, ' دورود'),
(377, 26, ' دلفان'),
(378, 26, ' سلسله'),
(379, 26, ' کوهدشت'),
(380, 26, ' الشتر'),
(381, 26, ' نورآباد'),
(382, 27, ' آمل'),
(383, 27, ' بابل'),
(384, 27, ' بابلسر'),
(385, 27, ' بهشهر'),
(386, 27, ' تنکابن'),
(387, 27, ' جویبار'),
(388, 27, ' چالوس'),
(389, 27, ' رامسر'),
(390, 27, ' ساری'),
(391, 27, ' سوادکوه'),
(392, 27, ' قائم شهر'),
(393, 27, ' گلوگاه'),
(394, 27, ' محمود آباد'),
(395, 27, ' نکا'),
(396, 27, ' نور'),
(397, 27, ' نوشهر'),
(398, 27, ' فریدونکنار'),
(399, 28, ' آشتیان'),
(400, 28, ' اراک'),
(401, 28, ' تفرش'),
(402, 28, ' خمین'),
(403, 28, ' دلیجان'),
(404, 28, ' زرندیه'),
(405, 28, ' ساوه'),
(406, 28, ' شازند'),
(407, 28, ' کمیجان'),
(408, 28, ' محلات'),
(409, 29, ' بندرعباس'),
(410, 29, ' میناب'),
(411, 29, ' بندر لنگه'),
(412, 29, ' رودان-دهبارز'),
(413, 29, ' جاسک'),
(414, 29, ' قشم'),
(415, 29, ' حاجی آباد'),
(416, 29, ' ابوموسی'),
(417, 29, ' بستک'),
(418, 29, ' گاوبندی'),
(419, 29, ' خمیر'),
(420, 30, ' اسدآباد'),
(421, 30, ' بهار'),
(422, 30, ' تویسرکان'),
(423, 30, ' رزن'),
(424, 30, ' کبودر آهنگ'),
(425, 30, ' ملایر'),
(426, 30, ' نهاوند'),
(427, 30, ' همدان'),
(428, 31, ' ابرکوه'),
(429, 31, ' اردکان'),
(430, 31, ' بافق'),
(431, 31, ' تفت'),
(432, 31, ' خاتم'),
(433, 31, ' صدوق'),
(434, 31, ' طبس'),
(435, 31, ' مهریز'),
(436, 31, ' میبد'),
(437, 31, ' یزد'),
(438, 8, 'قرچک'),
(439, 8, 'گلستان'),
(440, 8, 'قدس'),
(441, 8, 'ملارد'),
(442, 8, 'نسیم‌شهر'),
(443, 8, 'اندیشه'),
(444, 8, 'صالح‌آباد'),
(445, 8, 'باقرشهر'),
(446, 8, 'باغستان'),
(447, 8, 'بومهن'),
(448, 8, 'چهاردانگه'),
(449, 8, 'پیشوا'),
(450, 8, 'پردیس'),
(451, 8, 'وحیدیه'),
(452, 8, 'نصیرآباد'),
(453, 8, 'فردوسیه'),
(454, 8, 'حسن‌آباد'),
(455, 8, 'رودهن'),
(456, 8, 'شاهدشهر'),
(457, 8, 'صباشهر'),
(458, 8, 'صفادشت'),
(459, 8, 'لواسان'),
(460, 8, 'آبسرد'),
(461, 8, 'شریف‌آباد'),
(462, 8, 'کهریزک'),
(463, 8, 'فشم'),
(464, 8, 'جوادآباد'),
(465, 8, 'کیلان'),
(466, 8, 'آبعلی'),
(467, 8, 'ارجمند'),
(468, 29, 'کیش'),
(469, 29, 'لاوان'),
(470, 29, 'پارسیان'),
(471, 29, 'سیریک'),
(472, 29, 'بشاگرد');
-- +migrate Down
DELETE
FROM `cities`
WHERE id BETWEEN 1 AND 472;

View File

@ -17,7 +17,7 @@ func (s Service) LoginWithPhoneNumber(ctx context.Context, req adminserviceparam
return adminserviceparam.LoginWithPhoneNumberResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return adminserviceparam.LoginWithPhoneNumberResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
} }
if cErr := CompareHash(admin.GetPassword(), req.Password); cErr != nil { if cErr := CompareHash(admin.Password, req.Password); cErr != nil {
return adminserviceparam.LoginWithPhoneNumberResponse{}, richerror.New(op).WithErr(cErr).WithMessage(errmsg.ErrorMsgPhoneNumberOrPassIsIncorrect).WithKind(richerror.KindForbidden) return adminserviceparam.LoginWithPhoneNumberResponse{}, richerror.New(op).WithErr(cErr).WithMessage(errmsg.ErrorMsgPhoneNumberOrPassIsIncorrect).WithKind(richerror.KindForbidden)
} }
authenticableAdmin := entity.Authenticable{ authenticableAdmin := entity.Authenticable{

View File

@ -43,7 +43,7 @@ func (s Service) Register(ctx context.Context, req adminserviceparam.RegisterReq
if bErr := GenerateHash(req.Password); bErr != nil { if bErr := GenerateHash(req.Password); bErr != nil {
return adminserviceparam.RegisterResponse{}, richerror.New(op).WithErr(bErr).WithKind(richerror.KindUnexpected) return adminserviceparam.RegisterResponse{}, richerror.New(op).WithErr(bErr).WithKind(richerror.KindUnexpected)
} }
newAdmin.SetPassword(*req.Password) newAdmin.Password = *req.Password
admin, err := s.repo.AddAdmin(ctx, newAdmin) admin, err := s.repo.AddAdmin(ctx, newAdmin)
if err != nil { if err != nil {

View File

@ -1 +1,32 @@
package adminkindboxservice package adminkindboxservice
import (
"context"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) AddBatchKindBox(ctx context.Context, req param.AddKindBoxRequest) (param.AddKindBoxResponse, error) {
const op = "adminkindboxservice.AddKindBox"
kindBoxes := make([]entity.KindBox, 0)
kb := entity.KindBox{
KindBoxReqID: req.KindBoxReqID,
BenefactorID: req.BenefactorID,
Type: req.Type,
DeliverReferDate: req.DeliverReferDate,
DeliverAddressID: req.DeliverAddressID,
DeliveredAt: req.DeliveredAt,
SenderAgentID: req.SenderAgentID,
Status: entity.KindBoxDeliveredStatus,
}
for i := uint(0); i < req.CountAccepted; i++ {
kindBoxes = append(kindBoxes, kb)
}
aErr := s.repo.AddBatchKindBox(ctx, kindBoxes)
if aErr != nil {
return param.AddKindBoxResponse{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
}
return param.AddKindBoxResponse{}, nil
}

View File

@ -8,6 +8,7 @@ import (
type Repository interface { type Repository interface {
AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error AddBatchKindBox(ctx context.Context, kindBoxes []entity.KindBox) error
AddKindBox(ctx context.Context, kindBox entity.KindBox) error
} }
type Service struct { type Service struct {

View File

@ -29,7 +29,7 @@ func (s Service) Accept(ctx context.Context, req param.KindBoxReqAcceptRequest)
KindBoxReqStatus: kindBoxReq.Status, KindBoxReqStatus: kindBoxReq.Status,
CountRequested: kindBoxReq.CountRequested, CountRequested: kindBoxReq.CountRequested,
CountAccepted: kindBoxReq.CountAccepted, CountAccepted: kindBoxReq.CountAccepted,
ReferDate: kindBoxReq.ReferDate, DeliverReferDate: kindBoxReq.DeliverReferDate,
AddressID: kindBoxReq.AddressID, DeliverAddressID: kindBoxReq.DeliverAddressID,
}, nil }, nil
} }

View File

@ -0,0 +1,38 @@
package adminkindboxreqservice
import (
"context"
"time"
kindboxParam "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (s Service) Deliver(ctx context.Context, req param.DeliverKindBoxReqRequest) (param.DeliverKindBoxReqResponse, error) {
const op = "adminkindboxreqservice.Deliver"
kindBoxReq, gErr := s.repo.GetByID(ctx, req.KindBoxReqID)
if gErr != nil {
return param.DeliverKindBoxReqResponse{}, richerror.New(op).WithErr(gErr).WithKind(richerror.KindUnexpected)
}
_, aErr := s.kindBoxSvc.AddBatchKindBox(ctx, kindboxParam.AddKindBoxRequest{
KindBoxReqID: kindBoxReq.ID,
BenefactorID: kindBoxReq.BenefactorID,
Type: kindBoxReq.KindBoxType,
DeliverReferDate: kindBoxReq.DeliverReferDate,
DeliverAddressID: kindBoxReq.DeliverAddressID,
SenderAgentID: kindBoxReq.SenderAgentID,
DeliveredAt: time.Now(),
CountAccepted: kindBoxReq.CountAccepted,
})
if aErr != nil {
return param.DeliverKindBoxReqResponse{}, richerror.New(op).WithErr(aErr).WithKind(richerror.KindUnexpected)
}
dErr := s.repo.DeliverKindBoxReq(ctx, req.KindBoxReqID)
if dErr != nil {
return param.DeliverKindBoxReqResponse{}, richerror.New(op).WithErr(dErr).WithKind(richerror.KindUnexpected)
}
return param.DeliverKindBoxReqResponse{}, nil
}

View File

@ -20,13 +20,13 @@ func (s Service) Reject(ctx context.Context, req param.KindBoxReqRejectRequest)
} }
return param.KindBoxReqRejectResponse{ return param.KindBoxReqRejectResponse{
ID: kindBoxReq.ID, ID: kindBoxReq.ID,
KindBoxType: kindBoxReq.KindBoxType, KindBoxType: kindBoxReq.KindBoxType,
CountRequested: kindBoxReq.CountRequested, CountRequested: kindBoxReq.CountRequested,
BenefactorID: kindBoxReq.BenefactorID, BenefactorID: kindBoxReq.BenefactorID,
Status: kindBoxReq.Status, Status: kindBoxReq.Status,
Description: kindBoxReq.Description, Description: kindBoxReq.Description,
ReferDate: kindBoxReq.ReferDate, DeliverReferDate: kindBoxReq.DeliverReferDate,
AddressID: kindBoxReq.AddressID, DeliverAddressID: kindBoxReq.DeliverAddressID,
}, nil }, nil
} }

View File

@ -3,8 +3,9 @@ package adminkindboxreqservice
import ( import (
"context" "context"
"git.gocasts.ir/ebhomengo/niki/entity" entity "git.gocasts.ir/ebhomengo/niki/entity"
paginationparam "git.gocasts.ir/ebhomengo/niki/param" paginationparam "git.gocasts.ir/ebhomengo/niki/param"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box"
) )
type Repository interface { type Repository interface {
@ -13,10 +14,16 @@ type Repository interface {
RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error
RollbackKindBoxRequestStatus(ctx context.Context, id uint) error RollbackKindBoxRequestStatus(ctx context.Context, id uint) error
GetAllKindBoxReq(ctx context.Context, pagination paginationparam.PaginationRequest) ([]entity.KindBoxReq, paginationparam.PaginationResponse, error) GetAllKindBoxReq(ctx context.Context, pagination paginationparam.PaginationRequest) ([]entity.KindBoxReq, paginationparam.PaginationResponse, error)
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
}
type KindBoxSvc interface {
AddBatchKindBox(ctx context.Context, req param.AddKindBoxRequest) (param.AddKindBoxResponse, error)
} }
type Service struct { type Service struct {
repo Repository repo Repository
kindBoxSvc KindBoxSvc
} }
func New(repository Repository) Service { func New(repository Repository) Service {

View File

@ -32,7 +32,6 @@ func (s Service) LoginOrRegister(ctx context.Context, req benefactoreparam.Login
if !isExist { if !isExist {
newBenefactor, err := s.repo.CreateBenefactor(ctx, entity.Benefactor{ newBenefactor, err := s.repo.CreateBenefactor(ctx, entity.Benefactor{
PhoneNumber: req.PhoneNumber, PhoneNumber: req.PhoneNumber,
Status: entity.BenefactorActiveStatus,
Role: entity.UserBenefactorRole, Role: entity.UserBenefactorRole,
}) })
if err != nil { if err != nil {
@ -44,7 +43,7 @@ func (s Service) LoginOrRegister(ctx context.Context, req benefactoreparam.Login
athenticableBenefactor := entity.Authenticable{ athenticableBenefactor := entity.Authenticable{
ID: benefactor.ID, ID: benefactor.ID,
Role: benefactor.Role.String(), Role: entity.UserBenefactorRole.String(),
} }
accessToken, aErr := s.auth.CreateAccessToken(athenticableBenefactor) accessToken, aErr := s.auth.CreateAccessToken(athenticableBenefactor)
if aErr != nil { if aErr != nil {
@ -61,7 +60,7 @@ func (s Service) LoginOrRegister(ctx context.Context, req benefactoreparam.Login
ID: benefactor.ID, ID: benefactor.ID,
FirstName: benefactor.FirstName, FirstName: benefactor.FirstName,
LastName: benefactor.LastName, LastName: benefactor.LastName,
Role: benefactor.Role.String(), Role: entity.UserBenefactorRole.String(),
}, },
Tokens: benefactoreparam.Tokens{ Tokens: benefactoreparam.Tokens{
AccessToken: accessToken, AccessToken: accessToken,

View File

@ -2,21 +2,25 @@ package benefactorkindboxreqservice
import ( import (
"context" "context"
"git.gocasts.ir/ebhomengo/niki/entity"
entity "git.gocasts.ir/ebhomengo/niki/entity"
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req" param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error" richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
"time"
) )
func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) { func (s Service) Add(ctx context.Context, req param.KindBoxReqAddRequest) (param.KindBoxReqAddResponse, error) {
const op = "userkindboxreqservice.Add" const op = "userkindboxreqservice.Add"
t, tErr := time.Parse(time.DateTime, req.DeliverReferDate)
if tErr != nil {
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(tErr).WithKind(richerror.KindInvalid)
}
kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{ kindBoxReq, err := s.repo.AddKindBoxReq(ctx, entity.KindBoxReq{
BenefactorID: req.BenefactorID, BenefactorID: req.BenefactorID,
KindBoxType: req.TypeID, KindBoxType: req.TypeID,
AddressID: req.AddressID, DeliverAddressID: req.DeliverAddressID,
ReferDate: req.ReferDate, DeliverReferDate: t,
CountRequested: req.CountRequested, CountRequested: req.CountRequested,
Status: entity.KindBoxReqPendingStatus, Status: entity.KindBoxReqPendingStatus,
}) })
if err != nil { if err != nil {
return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected) return param.KindBoxReqAddResponse{}, richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)

View File

@ -0,0 +1,37 @@
package adminkindboxreqvalidator
import (
"errors"
param "git.gocasts.ir/ebhomengo/niki/param/admin/kind_box_req"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
func (v Validator) ValidateDeliver(req param.DeliverKindBoxReqRequest) (map[string]string, error) {
const op = "adminkindboxreqvalidator.ValidateAssignSender"
if err := validation.ValidateStruct(&req,
validation.Field(&req.KindBoxReqID, validation.Required, validation.By(v.doesKindBoxRequestExist), validation.By(v.checkKindBoxReqStatusForDelivering))); err != nil {
fieldErrors := make(map[string]string)
var errV validation.Errors
if errors.As(err, &errV) {
for key, value := range errV {
if value != nil {
fieldErrors[key] = value.Error()
}
}
}
return fieldErrors, richerror.New(op).
WithMessage(errmsg.ErrorMsgInvalidInput).
WithKind(richerror.KindInvalid).
WithMeta(map[string]interface{}{"req": req}).
WithErr(err)
}
return map[string]string{}, nil
}

View File

@ -75,3 +75,19 @@ func (v Validator) CheckKindBoxReqStatusForRejecting(value interface{}) error {
return nil return nil
} }
func (v Validator) checkKindBoxReqStatusForDelivering(value interface{}) error {
kindboxreqID, ok := value.(uint)
if !ok {
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
}
kindBoxReq, err := v.repo.GetByID(context.Background(), kindboxreqID)
if err != nil {
return err
}
if kindBoxReq.Status != entity.KindBoxReqAssignedSenderAgentStatus {
return fmt.Errorf(errmsg.ErrorMsgDeliverKindBoxReqStatus)
}
return nil
}

View File

@ -24,11 +24,11 @@ func (v Validator) ValidateAddRequest(req param.KindBoxReqAddRequest) *Validator
validation.Required, validation.Required,
validation.By(v.doesTypeExist)), validation.By(v.doesTypeExist)),
validation.Field(&req.AddressID, validation.Field(&req.DeliverAddressID,
validation.Required, validation.Required,
validation.By(v.doesAddressExist(req.BenefactorID))), validation.By(v.doesAddressExist(req.BenefactorID))),
validation.Field(&req.ReferDate, validation.Field(&req.DeliverReferDate,
validation.Required, validation.Required,
), ),
); err != nil { ); err != nil {