Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
intranet-synchronizer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mauro Paolo Josue Zuñiga Mallqui
intranet-synchronizer
Commits
a3d6b522
Commit
a3d6b522
authored
Oct 28, 2026
by
Percy Quispe Huarcaya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: test attendance sync
parent
31430f96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
201 additions
and
0 deletions
+201
-0
attendance.go
internal/domain/entities/attendance.go
+2
-0
attendance_to_update.go
...nal/infrastructure/database/mongo/attendance_to_update.go
+75
-0
attendance_to_update_service.go
internal/usecase/attendance_to_update_service.go
+124
-0
No files found.
internal/domain/entities/attendance.go
View file @
a3d6b522
...
...
@@ -10,6 +10,7 @@ type AttendanceRecord struct {
Tipo
string
`bson:"tipo" json:"tipo"`
Justificado
*
bool
`bson:"justificado" json:"justificado"`
MotivoJustificacion
*
string
`bson:"motivo_justificacion" json:"motivo_justificacion"`
ToUpdate
bool
`bson:"to_update,omitempty" json:"to_update,omitempty"`
}
type
AttendanceSummary
struct
{
...
...
@@ -32,6 +33,7 @@ type Attendance struct {
CicloID
int
`bson:"ciclo_id"`
Registros
[]
AttendanceRecord
`bson:"registros"`
ResumenMes
AttendanceSummary
`bson:"resumen_mes"`
ToUpdate
bool
`bson:"to_update,omitempty" json:"to_update,omitempty"`
CreatedAt
time
.
Time
`bson:"created_at"`
UpdatedAt
time
.
Time
`bson:"updated_at"`
RowHash
string
`bson:"row_hash,omitempty" json:"-"`
...
...
internal/infrastructure/database/mongo/attendance_to_update.go
0 → 100644
View file @
a3d6b522
package
mongo
import
(
"context"
"errors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"intranet-synchronizer/internal/usecase"
)
// AttendanceToUpdateReader lee el documento de asistencia desde Mongo y procesa los registros marcados con to_update.
type
AttendanceToUpdateReader
struct
{
db
*
mongo
.
Database
service
*
usecase
.
AttendanceToUpdateService
}
// NewAttendanceToUpdateReader crea una nueva instancia.
func
NewAttendanceToUpdateReader
(
db
*
mongo
.
Database
,
service
*
usecase
.
AttendanceToUpdateService
)
*
AttendanceToUpdateReader
{
return
&
AttendanceToUpdateReader
{
db
:
db
,
service
:
service
,
}
}
// ProcessByAttendanceID busca por attendance_id en c_attendance y ejecuta el proceso.
func
(
r
*
AttendanceToUpdateReader
)
ProcessByAttendanceID
(
ctx
context
.
Context
,
attendanceID
int
)
error
{
if
r
.
db
==
nil
||
r
.
service
==
nil
{
return
errors
.
New
(
"attendance to_update reader no inicializado"
)
}
collection
:=
r
.
db
.
Collection
(
"c_attendance"
)
filter
:=
bson
.
M
{
"attendance_id"
:
attendanceID
}
var
doc
bson
.
M
err
:=
collection
.
FindOne
(
ctx
,
filter
,
options
.
FindOne
())
.
Decode
(
&
doc
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
mongo
.
ErrNoDocuments
)
{
return
err
}
return
err
}
r
.
service
.
ProcessFromBSON
(
ctx
,
doc
)
return
nil
}
// ProcessByMatriculaMes busca por (matricula_id, mes) en c_attendance y ejecuta el proceso.
func
(
r
*
AttendanceToUpdateReader
)
ProcessByMatriculaMes
(
ctx
context
.
Context
,
matriculaID
,
mes
int
)
error
{
if
r
.
db
==
nil
||
r
.
service
==
nil
{
return
errors
.
New
(
"attendance to_update reader no inicializado"
)
}
collection
:=
r
.
db
.
Collection
(
"c_attendance"
)
filter
:=
bson
.
M
{
"matricula_id"
:
matriculaID
,
"mes"
:
mes
}
var
doc
bson
.
M
err
:=
collection
.
FindOne
(
ctx
,
filter
,
options
.
FindOne
())
.
Decode
(
&
doc
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
mongo
.
ErrNoDocuments
)
{
return
err
}
return
err
}
r
.
service
.
ProcessFromBSON
(
ctx
,
doc
)
return
nil
}
// ProcessOne procesa un documento ya decodificado.
func
(
r
*
AttendanceToUpdateReader
)
ProcessOne
(
ctx
context
.
Context
,
doc
bson
.
M
)
{
r
.
service
.
ProcessFromBSON
(
ctx
,
doc
)
}
internal/usecase/attendance_to_update_service.go
0 → 100644
View file @
a3d6b522
package
usecase
import
(
"context"
"encoding/json"
"log"
"go.mongodb.org/mongo-driver/bson"
)
// AttendanceToUpdateService encapsula la lógica para procesar registros de asistencia marcados con to_update.
type
AttendanceToUpdateService
struct
{}
// NewAttendanceToUpdateService crea una nueva instancia del servicio.
func
NewAttendanceToUpdateService
()
*
AttendanceToUpdateService
{
return
&
AttendanceToUpdateService
{}
}
// ProcessFromBSON procesa un documento bson.M obtenido directamente desde Mongo.
// Si doc.to_update es false o no existe -> loguea "no hay nada por actualizar".
// Si doc.to_update es true -> recorre doc.registros y loguea únicamente los registros con to_update=true.
// Si no encuentra ninguno -> loguea "no hay nada por actualizar".
func
(
s
*
AttendanceToUpdateService
)
ProcessFromBSON
(
ctx
context
.
Context
,
doc
bson
.
M
)
{
if
doc
==
nil
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
rootToUpdate
,
ok
:=
doc
[
"to_update"
]
.
(
bool
)
if
!
ok
||
!
rootToUpdate
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
registrosRaw
,
ok
:=
doc
[
"registros"
]
if
!
ok
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
registros
,
ok
:=
registrosRaw
.
(
bson
.
A
)
if
!
ok
||
len
(
registros
)
==
0
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
encontrados
:=
0
for
_
,
item
:=
range
registros
{
reg
,
ok
:=
item
.
(
bson
.
M
)
if
!
ok
{
continue
}
tu
,
ok
:=
reg
[
"to_update"
]
.
(
bool
)
if
!
ok
||
!
tu
{
continue
}
encontrados
++
b
,
err
:=
json
.
MarshalIndent
(
reg
,
""
,
" "
)
if
err
!=
nil
{
log
.
Printf
(
"error al serializar registro con to_update=true: %v"
,
err
)
continue
}
log
.
Printf
(
"Registro con to_update=true:
\n
%s"
,
string
(
b
))
}
if
encontrados
==
0
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
}
// ProcessFromMap procesa un documento map[string]any.
func
(
s
*
AttendanceToUpdateService
)
ProcessFromMap
(
doc
map
[
string
]
any
)
{
if
doc
==
nil
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
rootToUpdate
,
ok
:=
doc
[
"to_update"
]
.
(
bool
)
if
!
ok
||
!
rootToUpdate
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
registrosRaw
,
ok
:=
doc
[
"registros"
]
if
!
ok
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
registros
,
ok
:=
registrosRaw
.
([]
any
)
if
!
ok
||
len
(
registros
)
==
0
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
encontrados
:=
0
for
_
,
item
:=
range
registros
{
reg
,
ok
:=
item
.
(
map
[
string
]
any
)
if
!
ok
{
continue
}
tu
,
ok
:=
reg
[
"to_update"
]
.
(
bool
)
if
!
ok
||
!
tu
{
continue
}
encontrados
++
b
,
err
:=
json
.
MarshalIndent
(
reg
,
""
,
" "
)
if
err
!=
nil
{
log
.
Printf
(
"error al serializar registro con to_update=true: %v"
,
err
)
continue
}
log
.
Printf
(
"Registro con to_update=true:
\n
%s"
,
string
(
b
))
}
if
encontrados
==
0
{
log
.
Println
(
"no hay nada por actualizar"
)
return
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment