2024-06-25 21:58:11 +00:00
package mysqlkindbox
import (
"context"
2024-07-13 12:33:07 +00:00
"git.gocasts.ir/ebhomengo/niki/entity"
2024-06-25 21:58:11 +00:00
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func ( d DB ) BenefactorKindBoxExist ( ctx context . Context , benefactorID , kindBoxID uint ) ( bool , error ) {
const op = "mysqlkindbox.BenefactorKindBoxExist"
var count int
if err := d . conn . Conn ( ) . QueryRowContext ( ctx , ` SELECT COUNT(*) FROM kind_boxes WHERE benefactor_id = ? AND id = ? ` , benefactorID , kindBoxID ) . Scan ( & count ) ; err != nil {
return false , richerror . New ( op ) . WithErr ( err ) .
WithMessage ( errmsg . ErrorMsgSomethingWentWrong ) . WithKind ( richerror . KindUnexpected )
}
return count > 0 , nil
}
2024-07-01 17:13:28 +00:00
2024-07-13 12:33:07 +00:00
func ( d DB ) KindBoxExistForAgent ( ctx context . Context , kindBoxID , agentID uint ) ( bool , error ) {
const op = "mysqlkindbox.KindBoxExistForAgent"
query := ` SELECT COUNT(*) FROM kind_boxes WHERE id = ? AND receiver_agent_id = ? AND status = ? AND deleted_at IS NULL `
stmt , err := d . conn . PrepareStatement ( op , query )
if err != nil {
return false , richerror . New ( op ) . WithErr ( err ) .
WithMessage ( errmsg . ErrorMsgCantPrepareStatement ) . WithKind ( richerror . KindUnexpected )
}
var count int
if err = stmt . QueryRowContext ( ctx , kindBoxID , agentID , entity . KindBoxAssignedReceiverAgentStatus . String ( ) ) . Scan ( & count ) ; err != nil {
return false , richerror . New ( op ) . WithErr ( err ) .
WithMessage ( errmsg . ErrorMsgSomethingWentWrong ) . WithKind ( richerror . KindUnexpected )
}
return count > 0 , nil
}
2024-07-01 17:13:28 +00:00
func ( d DB ) KindBoxExist ( ctx context . Context , kindBoxID uint ) ( bool , error ) {
const op = "mysqlkindbox.KindBoxExist"
var count int
if err := d . conn . Conn ( ) . QueryRowContext ( ctx , ` SELECT COUNT(*) FROM kind_boxes WHERE id = ? ` , kindBoxID ) . Scan ( & count ) ; err != nil {
return false , richerror . New ( op ) . WithErr ( err ) .
WithMessage ( errmsg . ErrorMsgSomethingWentWrong ) . WithKind ( richerror . KindUnexpected )
}
return count > 0 , nil
}