teodevgroup / teo

Schema-driven web server framework.
https://teodev.io
Apache License 2.0
1.41k stars 46 forks source link

File Upload example bug #62

Closed akelyasir closed 5 months ago

akelyasir commented 6 months ago

@victorteokw

While reviewing the sample codes, I got an error again.

@map(path: "/upload")
declare form handler upload(UploadInput): Data<UploadOutput>

interface UploadInput {
  file: File
}

interface UploadOutput {
  path: String
}

It gives an error after the entity is created.

error[E0599]: no function or associated item named `from_value_ref` found for struct `teo::prelude::File` in the current scope
     --> src/entities/mod.rs:16999:15
      |
16999 |         File::from_value_ref(self.inner().get("file").unwrap()).unwrap()
      |               ^^^^^^^^^^^^^^ function or associated item not found in `File`

I also want to use a structure like this as a field in the schema file. But it also gives errors.

@relation(fields: .id, references: .id)
 contacts: User[]?
error[E0609]: no field `inner` on type `Vec<User>`
     --> src/entities/mod.rs:13500:77
      |
13500 |         self.inner.force_set_relation_object("contacts", contacts.map(|o| o.inner.clone())).await
      |                                                                             ^^^^^ unknown field
victorteokw commented 6 months ago

Hi @akelyasir, I will fix this bug. I'm currently moving my house. Sorry for this.

akelyasir commented 6 months ago

Hİ @victorteokw

I hope your new home will be beautiful. I found a solution for this problem, but I don't know if it is the right solution.

I added the following code to this file /src/entities/helpers/interface.rs. Also, can we use the multipart feature for uploading? I couldn't find a solution for this. Finally, does it make sense to use unsafe?

`impl AsInterfaceRef for File {

fn from_value_ref(value: &Value) -> Result<&File> {
    Ok(unsafe {
        &*(value as *const Value as *const File)
    })
}

} `

victorteokw commented 5 months ago

I will update the example

victorteokw commented 5 months ago

Hi @akelyasir, sorry for waiting for so long. I look it right now.

victorteokw commented 5 months ago

Hi @akelyasir, temporarily do this, I will update a patch version of the framework.

pub trait UploadInputTrait: Interface {
    /// ## File
    ///
    /// This interface field doesn't have a description.
    fn file(&self) -> &File {
        self.inner().get("file").unwrap().as_file().unwrap()
    }
    /// ## File
    ///
    /// This interface field doesn't have a description.
    fn set_file(&mut self, new_value: File) {
    self.inner_mut().as_dictionary_mut().unwrap().insert("file".to_owned(), new_value.into()).unwrap();
    }
}
victorteokw commented 5 months ago

This bug is fixed in Teo 0.2.36