func addDeviceProfile(dp models.DeviceProfile, dbClient interfaces.DBClient, w http.ResponseWriter) {
	op := device_profile.NewAddDeviceProfileExecutor(dp, dbClient)
	id, err := op.Execute()

	if err != nil {
		switch err.(type) {
		case models.ErrContractInvalid:
			http.Error(w, err.Error(), http.StatusBadRequest)
		case errors.ErrDeviceProfileInvalidState:
			http.Error(w, err.Error(), http.StatusBadRequest)
		case errors.ErrDuplicateName:
			http.Error(w, err.Error(), http.StatusConflict)
		case errors.ErrEmptyDeviceProfileName:
			http.Error(w, err.Error(), http.StatusBadRequest)
		default:
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		LoggingClient.Error(err.Error())
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write([]byte(id))
}
// This function centralizes the common logic for adding a device profile to the database and dealing with the return
This function centralizes the common logic for adding a device profile to the database and dealing with the return
// This function centralizes the common logic for adding a device profile to the database and dealing with the return
func addDeviceProfile(dp models.DeviceProfile, dbClient interfaces.DBClient, w http.ResponseWriter) {
	op := device_profile.NewAddDeviceProfileExecutor(dp, dbClient)
	id, err := op.Execute()
	if err != nil {
		switch err.(type) {
		case models.ErrContractInvalid:
			http.Error(w, err.Error(), http.StatusBadRequest)
		case errors.ErrDeviceProfileInvalidState:
			http.Error(w, err.Error(), http.StatusBadRequest)
		case errors.ErrDuplicateName:
			http.Error(w, err.Error(), http.StatusConflict)
		case errors.ErrEmptyDeviceProfileName:
			http.Error(w, err.Error(), http.StatusBadRequest)
		default:
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		LoggingClient.Error(err.Error())
		return
	}
	w.WriteHeader(http.StatusOK)
	w.Write([]byte(id))
}
func addDeviceProfile ( dp models . DeviceProfile , dbClient interfaces . DBClient , w http . ResponseWriter ) { op := device_profile . NewAddDeviceProfileExecutor ( dp , dbClient ) id , err := op . Execute ( ) if err != nil { switch err . ( type ) { case models . ErrContractInvalid : http . Error ( w , err . Error ( ) , http . StatusBadRequest ) case errors . ErrDeviceProfileInvalidState : http . Error ( w , err . Error ( ) , http . StatusBadRequest ) case errors . ErrDuplicateName : http . Error ( w , err . Error ( ) , http . StatusConflict ) case errors . ErrEmptyDeviceProfileName : http . Error ( w , err . Error ( ) , http . StatusBadRequest ) default : http . Error ( w , err . Error ( ) , http . StatusInternalServerError ) } LoggingClient . Error ( err . Error ( ) ) return } w . WriteHeader ( http . StatusOK ) w . Write ( [ ] byte ( id ) ) }
This function centralizes the common logic for adding a device profile to the database and dealing with the return
This function centralizes the common logic for adding a device profile to the database and dealing with the return