Background - I am very new to d and haven't programmed anything for over 30 years when I used C so please excuse what might be a simple question.
I am working through the exercises in the D Web Development by Kai "redstar" Nacke and have made it to the chapter on REST interfaces. I was able to get both a server and client working using the redis examples.
Now I want to use mySql and I was successful in getting it working both with a server and client.
I need to add a method to my class and there is no way I can get the program to recognize the route to the method adduserId. It is my understanding that this should end up with a router.post("/userid",&adduserId(......)) which would mean my client would access it with a post to /userid.
Any hints will certainly be appreciated.
Thanks
John
class NoteStoreImplementation : NoteStore
{
uint myid = 1;
string anyThing;
Note[] getNotes(string id)
{
Note toNote(Row r)
{
Note note;
r.toStruct(note);
return note;
}
auto con = db.lockConnection();
scope(exit) con.close();
auto cmd = Command(con, "SELECT id, topic, content FROM Notes WHERE userid = ?");
cmd.prepare();
cmd.bindParameter(myid, 0);
auto result = cmd.execPreparedResult();
return array(map!(r => toNote(r))(result));
}
long addNote(string name, Note note)
{
auto con = db.lockConnection();
scope(exit) con.close();
auto cmd = Command(con, "INSERT INTO Notes (userid, topic, content) VALUES(?, ?, ?)");
cmd.prepare();
cmd.bindParameter(myid, 0);
cmd.bindParameter(note.topic, 1);
cmd.bindParameter(note.content, 2);
ulong changed;
cmd.execPrepared(changed);
return changed;
}
string adduserId(string ud)
{
checkUser("yourid", "secret", myid);
return "anyThing";
}
}
module notestore;
struct Note
{
long id;
string topic;
string content;
}
struct userData
{
uint id;
string userName;
string password;
}
interface NoteStore
{
string adduserId(string ud);
Note[] getNotes(string name);
long addNote(string name, Note note);
}