delete eg rule
This commit is contained in:
parent
178b25e4f6
commit
5fbbbf281c
@ -59,9 +59,6 @@ paths:
|
|||||||
rule:
|
rule:
|
||||||
type: string
|
type: string
|
||||||
format: base64
|
format: base64
|
||||||
egrule:
|
|
||||||
type: string
|
|
||||||
format: base64
|
|
||||||
certificate:
|
certificate:
|
||||||
type: string
|
type: string
|
||||||
description: только для status == nko
|
description: только для status == nko
|
||||||
@ -120,9 +117,6 @@ paths:
|
|||||||
rule:
|
rule:
|
||||||
type: string
|
type: string
|
||||||
format: base64
|
format: base64
|
||||||
egrule:
|
|
||||||
type: string
|
|
||||||
format: base64
|
|
||||||
certificate:
|
certificate:
|
||||||
type: string
|
type: string
|
||||||
description: только для status == nko
|
description: только для status == nko
|
||||||
|
@ -81,13 +81,6 @@ func (r *VerifyUserController) CreateVerification(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusBadRequest, "rule file required")
|
return fiber.NewError(fiber.StatusBadRequest, "rule file required")
|
||||||
}
|
}
|
||||||
|
|
||||||
// EGRULE FILE
|
|
||||||
egruleFH, err := c.FormFile("egrule")
|
|
||||||
|
|
||||||
if err != nil || egruleFH.Size == 0 || egruleFH == nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, "egrule file required")
|
|
||||||
}
|
|
||||||
|
|
||||||
// CERTIFICATE FILE
|
// CERTIFICATE FILE
|
||||||
var certFH *multipart.FileHeader
|
var certFH *multipart.FileHeader
|
||||||
if req.Status == "nko" {
|
if req.Status == "nko" {
|
||||||
@ -104,7 +97,7 @@ func (r *VerifyUserController) CreateVerification(c *fiber.Ctx) error {
|
|||||||
Accepted: false,
|
Accepted: false,
|
||||||
Status: req.Status,
|
Status: req.Status,
|
||||||
Comment: "",
|
Comment: "",
|
||||||
}, innFH, ruleFH, egruleFH, certFH)
|
}, innFH, ruleFH, certFH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
@ -131,7 +124,7 @@ func (r *VerifyUserController) SetVerificationFile(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusUnauthorized)
|
return fiber.NewError(fiber.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
availableFiles := []string{"inn", "rule", "egrule", "certificate"}
|
availableFiles := []string{"inn", "rule", "certificate"}
|
||||||
var err error
|
var err error
|
||||||
var fileHeader *multipart.FileHeader
|
var fileHeader *multipart.FileHeader
|
||||||
var result *models.Verification
|
var result *models.Verification
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type VerificationRepository struct {
|
type VerificationRepository struct {
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
mongo *mongo.Collection
|
mongo *mongo.Collection
|
||||||
s3 *minio.Client
|
s3 *minio.Client
|
||||||
folder, url string
|
folder, url string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,14 +36,14 @@ func NewVerificationRepository(logger *zap.Logger, mongoDb *mongo.Database, s3 *
|
|||||||
mongo: mongoDb.Collection(VerificationCollection),
|
mongo: mongoDb.Collection(VerificationCollection),
|
||||||
s3: s3,
|
s3: s3,
|
||||||
folder: folder,
|
folder: folder,
|
||||||
url: url,
|
url: url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (r *VerificationRepository) Insert(
|
func (r *VerificationRepository) Insert(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
userID string,
|
userID string,
|
||||||
record *models.Verification,
|
record *models.Verification,
|
||||||
innFH, ruleFH, egruleFH, certFH *multipart.FileHeader) (*models.Verification, error) {
|
innFH, ruleFH, certFH *multipart.FileHeader) (*models.Verification, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
record.ID = primitive.NewObjectIDFromTimestamp(now).Hex()
|
record.ID = primitive.NewObjectIDFromTimestamp(now).Hex()
|
||||||
record.UpdatedAt = now
|
record.UpdatedAt = now
|
||||||
@ -70,17 +70,6 @@ func (r *VerificationRepository) Insert(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put egrule file
|
|
||||||
egrule, err := egruleFH.Open()
|
|
||||||
if r.err(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = r.s3.PutObject(ctx, VerificationBucket, fmt.Sprintf("%s/%s/%s", r.folder, userID, egruleFH.Filename), egrule, egruleFH.Size, minio.PutObjectOptions{})
|
|
||||||
if r.err(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put certificate file
|
// Put certificate file
|
||||||
if certFH != nil {
|
if certFH != nil {
|
||||||
cert, err := certFH.Open()
|
cert, err := certFH.Open()
|
||||||
@ -105,15 +94,11 @@ func (r *VerificationRepository) Insert(
|
|||||||
record.Files = append(record.Files, []models.VerificationFile{
|
record.Files = append(record.Files, []models.VerificationFile{
|
||||||
{
|
{
|
||||||
Name: "inn",
|
Name: "inn",
|
||||||
Url: fmt.Sprintf("%s/%s/%s/%s", r.url,r.folder, userID, innFH.Filename),
|
Url: fmt.Sprintf("%s/%s/%s/%s", r.url, r.folder, userID, innFH.Filename),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "rule",
|
Name: "rule",
|
||||||
Url: fmt.Sprintf("%s/%s/%s/%s", r.url,r.folder, userID, ruleFH.Filename),
|
Url: fmt.Sprintf("%s/%s/%s/%s", r.url, r.folder, userID, ruleFH.Filename),
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "egrule",
|
|
||||||
Url: fmt.Sprintf("%s/%s/%s/%s", r.url,r.folder, userID, egruleFH.Filename),
|
|
||||||
},
|
},
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
@ -210,17 +195,17 @@ func (r *VerificationRepository) UpdateFile(ctx context.Context, userID, fileNam
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fileURL := fmt.Sprintf("%s/%s/%s/%s", VerificationEndpointURL,r.folder, userID, fileHeader.Filename)
|
fileURL := fmt.Sprintf("%s/%s/%s/%s", VerificationEndpointURL, r.folder, userID, fileHeader.Filename)
|
||||||
|
|
||||||
// remove old file
|
// remove old file
|
||||||
verification, err := r.GetByUserID(ctx, userID)
|
verification, err := r.GetByUserID(ctx, userID)
|
||||||
if r.err(err) {
|
if r.err(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if verification == nil {
|
if verification == nil {
|
||||||
return nil, fmt.Errorf("no verification found")
|
return nil, fmt.Errorf("no verification found")
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
for iterator, file := range verification.Files {
|
for iterator, file := range verification.Files {
|
||||||
|
@ -61,10 +61,6 @@ paths:
|
|||||||
type: file
|
type: file
|
||||||
contentMediaType: application/pdf
|
contentMediaType: application/pdf
|
||||||
contentEncoding: base64
|
contentEncoding: base64
|
||||||
egrule:
|
|
||||||
type: file
|
|
||||||
contentMediaType: application/pdf
|
|
||||||
contentEncoding: base64
|
|
||||||
certificate:
|
certificate:
|
||||||
type: file
|
type: file
|
||||||
description: только для status == nko
|
description: только для status == nko
|
||||||
|
@ -33,7 +33,6 @@ func Test_SetVerify(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"inn", "files/inn"},
|
{"inn", "files/inn"},
|
||||||
{"rule", "files/rule"},
|
{"rule", "files/rule"},
|
||||||
{"egrule", "files/egrule"},
|
|
||||||
{"certificate", "files/certificate"},
|
{"certificate", "files/certificate"},
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
@ -32,7 +32,6 @@ func Test_PutFile(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"inn", "files/inn"},
|
{"inn", "files/inn"},
|
||||||
{"rule", "files/rule"},
|
{"rule", "files/rule"},
|
||||||
{"egrule", "files/egrule"},
|
|
||||||
{"certificate", "files/certificate"},
|
{"certificate", "files/certificate"},
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
Loading…
Reference in New Issue
Block a user