From 7b660cd0dc54b03f7ccf158b16ffbd6585e9e4fd Mon Sep 17 00:00:00 2001 From: Guillem Date: Sat, 2 Apr 2022 12:55:39 +0200 Subject: [PATCH] Complet exercici 3a --- UOC20212/UOCVaccine/src/api.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/UOC20212/UOCVaccine/src/api.c b/UOC20212/UOCVaccine/src/api.c index 5419f04..b88be5b 100644 --- a/UOC20212/UOCVaccine/src/api.c +++ b/UOC20212/UOCVaccine/src/api.c @@ -19,6 +19,7 @@ #define MAX_PERSON_NAME_LEN 15 #define MAX_PERSON_EMAIL_LEN 30 #define MAX_PERSON_ADDRESS_LEN 30 +#define VACCINE_TYPE_NAME "VACCINE" // Get the API version information const char* api_version() { @@ -237,7 +238,29 @@ tApiError api_getVaccine(tApiData data, const char *name, tCSVEntry *entry) { ////////////////////////////////// // Ex PR1 3a ///////////////////////////////// - return E_NOT_IMPLEMENTED; + + tApiError ret = E_NOT_IMPLEMENTED; + tVaccine* found; + char buffer[FILE_READ_BUFFER_SIZE]; + + found = vaccineList_find(data.vaccines,name); + + if (found) { // If pointer is not null, vaccine exists + + // Fill buffer with data from the vaccine on that pointer + sprintf(buffer, "%s;%d;%d", found->name, found->required, found->days); + + // Init CSV entry and set values accordingly + csv_initEntry(entry); + csv_parseEntry(entry,buffer,VACCINE_TYPE_NAME); + + ret = E_SUCCESS; + + } else { // If pointer is null, vaccine does not exist + ret = E_VACCINE_NOT_FOUND; + } + + return ret; } // Get vaccine lot data