From a15e818110e465f45b196a0686f503946e029ef3 Mon Sep 17 00:00:00 2001 From: Guillem Date: Sat, 2 Apr 2022 13:18:51 +0200 Subject: [PATCH] Complet exercici 3b --- UOC20212/UOCVaccine/src/api.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/UOC20212/UOCVaccine/src/api.c b/UOC20212/UOCVaccine/src/api.c index b88be5b..822d573 100644 --- a/UOC20212/UOCVaccine/src/api.c +++ b/UOC20212/UOCVaccine/src/api.c @@ -268,7 +268,37 @@ tApiError api_getVaccineLot(tApiData data, const char* cp, const char* vaccine, ////////////////////////////////// // Ex PR1 3b ///////////////////////////////// - return E_NOT_IMPLEMENTED; + + tApiError ret = E_NOT_IMPLEMENTED; + tVaccineLot found; + int index; + char buffer[FILE_READ_BUFFER_SIZE]; + + index = vaccineLotData_find(data.vaccineLots,cp,vaccine,timestamp); + + if (index != -1) { // If value is not -1, vaccineLot exists + + vaccineLot_cpy(&found,data.vaccineLots.elems[index]); + + // Fill buffer with data from the vaccine on that pointer + sprintf(buffer, "%02d/%02d/%04d;%02d:%02d;%s;%s;%d;%d;%d", + found.timestamp.date.day,found.timestamp.date.month,found.timestamp.date.year, + found.timestamp.time.hour,found.timestamp.time.minutes, + found.cp, + found.vaccine->name,found.vaccine->required,found.vaccine->days, + found.doses); + + // Init CSV entry and set values accordingly + csv_initEntry(entry); + csv_parseEntry(entry,buffer,VACCINE_LOT_TYPE_NAME); + + ret = E_SUCCESS; + + } else { // If value is -1, vaccineLot does not exist + ret = E_LOT_NOT_FOUND; + } + + return ret; } // Get registered vaccines