You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.8 KiB
C++
74 lines
1.8 KiB
C++
#ifndef VIEWS_H_
|
|
#define VIEWS_H_
|
|
|
|
#include "webcc/fs.h"
|
|
#include "webcc/view.h"
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// URL: /books
|
|
class BookListView : public webcc::View {
|
|
public:
|
|
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
|
|
|
private:
|
|
// Get a list of books based on query parameters.
|
|
webcc::ResponsePtr Get(webcc::RequestPtr request);
|
|
|
|
// Create a new book.
|
|
webcc::ResponsePtr Post(webcc::RequestPtr request);
|
|
};
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// URL: /books/{id}
|
|
class BookDetailView : public webcc::View {
|
|
public:
|
|
explicit BookDetailView(webcc::fs::path photo_dir);
|
|
|
|
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
|
|
|
private:
|
|
// Get the detailed information of a book.
|
|
webcc::ResponsePtr Get(webcc::RequestPtr request);
|
|
|
|
// Update a book.
|
|
webcc::ResponsePtr Put(webcc::RequestPtr request);
|
|
|
|
// Delete a book.
|
|
webcc::ResponsePtr Delete(webcc::RequestPtr request);
|
|
|
|
private:
|
|
webcc::fs::path photo_dir_;
|
|
};
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// URL: /books/{id}/photo
|
|
class BookPhotoView : public webcc::View {
|
|
public:
|
|
explicit BookPhotoView(webcc::fs::path photo_dir);
|
|
|
|
webcc::ResponsePtr Handle(webcc::RequestPtr request) override;
|
|
|
|
// Stream the request data, an image, of PUT into a temp file.
|
|
bool Stream(const std::string& method) override {
|
|
return method == "PUT";
|
|
}
|
|
|
|
private:
|
|
// Get the photo of the book.
|
|
webcc::ResponsePtr Get(webcc::RequestPtr request);
|
|
|
|
// Set the photo of the book.
|
|
webcc::ResponsePtr Put(webcc::RequestPtr request);
|
|
|
|
// Delete the photo of the book.
|
|
webcc::ResponsePtr Delete(webcc::RequestPtr request);
|
|
|
|
private:
|
|
webcc::fs::path photo_dir_;
|
|
};
|
|
|
|
#endif // VIEWS_H_
|