1
Fork 0

Complet exercici 2f

This commit is contained in:
Guillem 2022-04-02 12:23:16 +02:00
parent af36e69df2
commit 36bac13b1b
Signed by: lordwektabyte
GPG key ID: 73C5458905782129

View file

@ -13,6 +13,12 @@
#define VACCINE_LOT_NUM_FIELDS 7
#define MAX_CP_LEN 5
#define MAX_VACCINE_NAME_LEN 15
#define PERSON_TYPE_NAME "PERSON"
#define PERSON_NUM_FIELDS 7
#define MAX_PERSON_DOCUMENT_LEN 9
#define MAX_PERSON_NAME_LEN 15
#define MAX_PERSON_EMAIL_LEN 30
#define MAX_PERSON_ADDRESS_LEN 30
// Get the API version information
const char* api_version() {
@ -168,9 +174,9 @@ tApiError api_freeData(tApiData* data) {
// Ex PR1 2e
/////////////////////////////////
population_free(&data->population);
vaccineList_free(&data->vaccines);
vaccineLotData_free(&data->vaccineLots);
population_free(&(data->population));
vaccineList_free(&(data->vaccines));
vaccineLotData_free(&(data->vaccineLots));
return E_SUCCESS;
}
@ -184,7 +190,44 @@ tApiError api_addDataEntry(tApiData* data, tCSVEntry entry) {
tApiError ret = E_NOT_IMPLEMENTED;
// Check if entry type is Vaccine Lot and its field number is correct
if (strcmp(csv_getType(&entry),VACCINE_LOT_TYPE_NAME) == 0) {
if (csv_numFields(entry) == VACCINE_LOT_NUM_FIELDS) {
ret = api_addVaccineLot(data,entry);
} else { // Num fields does not match
ret = E_INVALID_ENTRY_FORMAT;
}
// Check if entry type is Person and its field number is correct
} else if (strcmp(csv_getType(&entry),PERSON_TYPE_NAME) == 0) {
if (csv_numFields(entry) == PERSON_NUM_FIELDS) {
// Process could be implemented in a "api_addPerson()" function
// as in "api_addVaccineLot()"
tPerson entryPerson;
person_init(&entryPerson);
person_parse(&entryPerson,entry);
// Check if person already exists
if (population_find(data->population,entryPerson.document) == -1) {
population_add(&(data->population),entryPerson);
ret = E_SUCCESS;
} else {
ret = E_DUPLICATED_PERSON;
}
person_free(&entryPerson);
} else { // Num fields does not match
ret = E_INVALID_ENTRY_FORMAT;
}
} else {
ret = E_INVALID_ENTRY_TYPE;
}
return ret;
}