Complet exercici 2e
This commit is contained in:
parent
5dea15d7a2
commit
af36e69df2
2 changed files with 49 additions and 8 deletions
|
@ -7,6 +7,10 @@
|
|||
#include "person.h"
|
||||
#include "vaccine.h"
|
||||
|
||||
// Max sizes for Date and Time fields
|
||||
#define DATE_SIZE 10
|
||||
#define TIME_SIZE 5
|
||||
|
||||
|
||||
// Type that stores all the application data
|
||||
typedef struct _ApiData {
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#define FILE_READ_BUFFER_SIZE 2048
|
||||
#define VACCINE_LOT_TYPE_NAME "VACCINE_LOT"
|
||||
#define VACCINE_LOT_NUM_FIELDS 7
|
||||
#define MAX_CP_LEN 5
|
||||
#define MAX_VACCINE_NAME_LEN 15
|
||||
|
||||
// Get the API version information
|
||||
const char* api_version() {
|
||||
|
@ -90,13 +92,35 @@ tApiError api_addVaccineLot(tApiData* data, tCSVEntry entry) {
|
|||
|
||||
tApiError ret = E_NOT_IMPLEMENTED;
|
||||
|
||||
// Verify num fields and type of entry
|
||||
if (csv_numFields(entry) == VACCINE_LOT_NUM_FIELDS) {
|
||||
if (csv_getType(&entry) == VACCINE_LOT_TYPE_NAME) {
|
||||
// OK
|
||||
if (strcmp(csv_getType(&entry),VACCINE_LOT_TYPE_NAME) == 0) {
|
||||
|
||||
tVaccine vaccineEntry;
|
||||
tVaccineLot vaccineLotEntry;
|
||||
|
||||
vaccineLot_parse(&vaccineEntry,&vaccineLotEntry,entry);
|
||||
|
||||
if (vaccineList_find(data->vaccines,vaccineEntry.name) == NULL) { // Vaccine does not exist in vaccineList
|
||||
|
||||
ret = E_SUCCESS;
|
||||
// Add vaccine in vaccine list
|
||||
vaccineList_insert(&data->vaccines,vaccineEntry);
|
||||
|
||||
// Get vaccine item position in vaccine list to be added on vaccineLotData
|
||||
vaccineLotEntry.vaccine = vaccineList_find(data->vaccines,vaccineEntry.name);
|
||||
vaccineLotData_add(&(data->vaccineLots),vaccineLotEntry);
|
||||
|
||||
} else { // Vaccine already exists in vaccineList
|
||||
|
||||
// Get vaccine item position in vaccine list to be added on vaccineLotData
|
||||
vaccineLotEntry.vaccine = vaccineList_find(data->vaccines,vaccineEntry.name);
|
||||
vaccineLotData_add(&(data->vaccineLots),vaccineLotEntry);
|
||||
}
|
||||
|
||||
vaccineLot_free(&vaccineLotEntry);
|
||||
vaccine_free(&vaccineEntry);
|
||||
|
||||
ret = E_SUCCESS;
|
||||
|
||||
} else {
|
||||
// numFields other than valid one
|
||||
|
@ -115,7 +139,8 @@ int api_populationCount(tApiData data) {
|
|||
//////////////////////////////////
|
||||
// Ex PR1 2d
|
||||
/////////////////////////////////
|
||||
return -1;
|
||||
|
||||
return population_len(data.population);
|
||||
}
|
||||
|
||||
// Get the number of vaccines registered on the application
|
||||
|
@ -123,7 +148,8 @@ int api_vaccineCount(tApiData data) {
|
|||
//////////////////////////////////
|
||||
// Ex PR1 2d
|
||||
/////////////////////////////////
|
||||
return -1;
|
||||
|
||||
return vaccineList_len(data.vaccines);
|
||||
}
|
||||
|
||||
// Get the number of vaccine lots registered on the application
|
||||
|
@ -131,7 +157,8 @@ int api_vaccineLotsCount(tApiData data) {
|
|||
//////////////////////////////////
|
||||
// Ex PR1 2d
|
||||
/////////////////////////////////
|
||||
return -1;
|
||||
|
||||
return vaccineLotData_len(data.vaccineLots);
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,7 +167,12 @@ tApiError api_freeData(tApiData* data) {
|
|||
//////////////////////////////////
|
||||
// Ex PR1 2e
|
||||
/////////////////////////////////
|
||||
return E_NOT_IMPLEMENTED;
|
||||
|
||||
population_free(&data->population);
|
||||
vaccineList_free(&data->vaccines);
|
||||
vaccineLotData_free(&data->vaccineLots);
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,7 +181,12 @@ tApiError api_addDataEntry(tApiData* data, tCSVEntry entry) {
|
|||
//////////////////////////////////
|
||||
// Ex PR1 2f
|
||||
/////////////////////////////////
|
||||
return E_NOT_IMPLEMENTED;
|
||||
|
||||
tApiError ret = E_NOT_IMPLEMENTED;
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get vaccine data
|
||||
|
|
Reference in a new issue