@@ -23,20 +23,20 @@ func startWebserver(env Env, api *API, loginUsers []EnvUser) string {
2323 body := ctx .Request .Body ()
2424 switch path {
2525 case "/send_cv" :
26- cvContent := map [ string ] interface {} {}
27- err := json .Unmarshal (body , & cvContent )
26+ cvForChecking := StrippedCV {}
27+ err := json .Unmarshal (body , & cvForChecking )
2828 if err != nil {
2929 errorResp (ctx , 400 , "invalid CV" )
3030 return
3131 }
3232
33- referenceNr , err := checkIfCVHasReferenceNr ( cvContent )
33+ err = cvForChecking . checkRefNr ( )
3434 if err != nil {
3535 errorResp (ctx , 400 , err .Error ())
3636 return
3737 }
3838
39- cacheEntryExists := api .CacheEntryExists (referenceNr )
39+ cacheEntryExists := api .CacheEntryExists (cvForChecking . ReferenceNumber )
4040 if cacheEntryExists {
4141 // Cannot send the same cv twice
4242 ctx .Response .AppendBodyString ("false" )
@@ -45,7 +45,7 @@ func startWebserver(env Env, api *API, loginUsers []EnvUser) string {
4545
4646 hasMatch := false
4747 if api .MockMode {
48- api .SetCacheEntry (referenceNr , time .Hour * 72 )
48+ api .SetCacheEntry (cvForChecking . ReferenceNumber , time .Hour * 72 )
4949 hasMatch = true
5050 } else {
5151 scanCVBody := json .RawMessage (append (append ([]byte (`{"cv":` ), body ... ), '}' ))
@@ -65,33 +65,48 @@ func startWebserver(env Env, api *API, loginUsers []EnvUser) string {
6565 hasMatch = response .HasMatches
6666 if hasMatch {
6767 // Only cache the CVs that where matched to something
68- api .SetCacheEntry (referenceNr , time .Hour * 72 ) // 3 days
68+ api .SetCacheEntry (cvForChecking . ReferenceNumber , time .Hour * 72 ) // 3 days
6969 }
7070 }
7171 }
7272 }
7373
7474 ctx .Response .AppendBodyString ("true" )
7575 case "/cvs_list" :
76- cvsContent := []map [ string ] interface {} {}
77- err := json .Unmarshal (body , & cvsContent )
76+ cvs := []StrippedCVWithOriginal {}
77+ err := json .Unmarshal (body , & cvs )
7878 if err != nil {
7979 errorResp (ctx , 400 , "invalid CV" )
8080 return
8181 }
8282
83- for idx , cv := range cvsContent {
84- _ , err := checkIfCVHasReferenceNr (cv )
83+ checkedRefNrs := map [string ]struct {}{}
84+ for idx := 10 ; idx >= 0 ; idx -- {
85+ cv := cvs [idx ]
86+ err := cv .checkRefNr ()
8587 if err != nil {
8688 errorResp (ctx , 400 , fmt .Sprintf ("error in cv with index %d, error: %s" , idx , err .Error ()))
8789 return
8890 }
91+
92+ _ , ok := checkedRefNrs [cv .ReferenceNumber ]
93+ if ok {
94+ // Remove this cv as it's a duplicate of another one in the list
95+ cvs = append (cvs [:idx ], cvs [idx + 1 :]... )
96+ continue
97+ }
98+ checkedRefNrs [cv .ReferenceNumber ] = struct {}{}
99+
100+ if cv .checkMustHaveValidZip () != nil {
101+ // Remove this cv from the list as it does not have a valid zip code
102+ cvs = append (cvs [:idx ], cvs [idx + 1 :]... )
103+ continue
104+ }
89105 }
90106
91107 if ! api .MockMode {
92- body := append (append ([]byte (`{"cvs":` ), body ... ), '}' )
93108 for _ , conn := range api .connections {
94- err = conn .Post ("/api/v1/scraper/allCVs" , json . RawMessage ( body ) , nil )
109+ err = conn .Post ("/api/v1/scraper/allCVs" , map [ string ] any { "cvs" : cvs } , nil )
95110 if err != nil {
96111 errorResp (ctx , 500 , err .Error ())
97112 return
0 commit comments