remove /add_plant, add /plants, a board to replace it
This commit is contained in:
parent
8e44a11067
commit
bd99462e0a
13 changed files with 168 additions and 158 deletions
102
src/permap.ml
102
src/permap.ml
|
|
@ -131,14 +131,6 @@ let avatar_image request =
|
|||
| Some avatar -> Dream.respond ~headers:[ ("Content-Type", "image") ] avatar
|
||||
)
|
||||
|
||||
let plant_image request =
|
||||
let plant_id = Dream.param "plant_id" request in
|
||||
let nb = int_of_string (Dream.param "nb" request) in
|
||||
let image = Plant.get_plant_image plant_id nb in
|
||||
match image with
|
||||
| Ok image -> Dream.respond ~headers:[ ("Content-Type", "image") ] image
|
||||
| Error _ -> Dream.empty `Not_Found
|
||||
|
||||
let post_image request =
|
||||
let post_id = Dream.param "post_id" request in
|
||||
let image = Babillard.get_post_image post_id in
|
||||
|
|
@ -146,62 +138,11 @@ let post_image request =
|
|||
| Ok image -> Dream.respond ~headers:[ ("Content-Type", "image") ] image
|
||||
| Error _ -> Dream.empty `Not_Found
|
||||
|
||||
let add_plant_get request =
|
||||
match Dream.session "nick" request with
|
||||
| None -> render_unsafe "Not logged in" request
|
||||
| Some nick -> render_unsafe (Add_plant.f nick request) request
|
||||
let plants_get request = render_unsafe (Plants_page.f request) request
|
||||
|
||||
let add_plant_post request =
|
||||
match Dream.session "nick" request with
|
||||
| None -> render_unsafe "Not logged in" request
|
||||
| Some nick -> (
|
||||
match%lwt Dream.multipart request with
|
||||
| `Ok
|
||||
[ ("files", files)
|
||||
; ("lat_input", [ (_, lat) ])
|
||||
; ("lng_input", [ (_, lng) ])
|
||||
; ("tags", [ (_, tags) ])
|
||||
]
|
||||
| `Ok
|
||||
(("files", files)
|
||||
:: ("lat_input", [ (_, lat) ])
|
||||
:: ("lng_input", [ (_, lng) ]) :: ("tags", [ (_, tags) ]) :: _ :: _
|
||||
) -> (
|
||||
match (Float.of_string_opt lat, Float.of_string_opt lng) with
|
||||
| None, _ -> render_unsafe "Invalide coordinate" request
|
||||
| _, None -> render_unsafe "Invalide coordinate" request
|
||||
| Some lat, Some lng ->
|
||||
let res =
|
||||
match Plant.add_plant (lat, lng) tags files nick with
|
||||
| Ok () -> "Your plant was uploaded!"
|
||||
| Error e -> e
|
||||
in
|
||||
render_unsafe res request )
|
||||
| `Ok _ -> Dream.empty `Bad_Request
|
||||
| `Expired _
|
||||
| `Many_tokens _
|
||||
| `Missing_token _
|
||||
| `Invalid_token _
|
||||
| `Wrong_session _
|
||||
| `Wrong_content_type ->
|
||||
Dream.empty `Bad_Request )
|
||||
|
||||
let plant_markers request =
|
||||
(*TODO should be in plant *)
|
||||
let marker_list = Plant.marker_list () in
|
||||
match marker_list with
|
||||
| Ok marker_list ->
|
||||
let json =
|
||||
{| [ |}
|
||||
^ String.concat "," (List.map Plant.marker_to_geojson marker_list)
|
||||
^ "]"
|
||||
in
|
||||
Dream.respond ~headers:[ ("Content-Type", "application/json") ] json
|
||||
| Error e -> render_unsafe e request
|
||||
|
||||
let thread_markers request =
|
||||
let markers ~board request =
|
||||
(*TODO should be in babillard*)
|
||||
let marker_list = Babillard.marker_list () in
|
||||
let marker_list = Babillard.marker_list board in
|
||||
match marker_list with
|
||||
| Ok marker_list ->
|
||||
let json =
|
||||
|
|
@ -214,9 +155,10 @@ let thread_markers request =
|
|||
|
||||
let babillard_get request = render_unsafe (Babillard_page.f request) request
|
||||
|
||||
let newthread_get request = render_unsafe (Newthread_page.f request) request
|
||||
let newthread_get ~board request =
|
||||
render_unsafe (Newthread_page.f ~board request) request
|
||||
|
||||
let newthread_post request =
|
||||
let newthread_post ~board request =
|
||||
match Dream.session "nick" request with
|
||||
| None -> render_unsafe "Not logged in" request
|
||||
| Some nick -> (
|
||||
|
|
@ -246,10 +188,15 @@ let newthread_post request =
|
|||
| _ :: _ :: _ -> render_unsafe "More than one image" request
|
||||
| [ file ] -> (
|
||||
match
|
||||
Babillard.make_op ~comment ~image:file ~lat ~lng ~subject ~tags nick
|
||||
Babillard.make_op ~comment ~image:file ~lat ~lng ~subject ~tags
|
||||
~board nick
|
||||
with
|
||||
| Ok thread_id ->
|
||||
let adress = Format.sprintf "/babillard/%s" thread_id in
|
||||
let adress =
|
||||
Format.sprintf "/%s/%s"
|
||||
(Babillard.string_of_board board)
|
||||
thread_id
|
||||
in
|
||||
Dream.respond ~status:`See_Other ~headers:[ ("Location", adress) ]
|
||||
"Your thread was posted on the babillard!"
|
||||
| Error e -> render_unsafe e request ) ) )
|
||||
|
|
@ -279,7 +226,7 @@ let thread_view request =
|
|||
| Ok thread_view -> Dream.html (Thread_page.f thread_view thread_id request)
|
||||
|
||||
(*form to reply to a thread *)
|
||||
let thread_post request =
|
||||
let reply_post request =
|
||||
match Dream.session "nick" request with
|
||||
| None -> render_unsafe "Not logged in" request
|
||||
| Some nick -> (
|
||||
|
|
@ -331,17 +278,20 @@ let () =
|
|||
; Dream.get "/logout" logout
|
||||
; Dream.get "/profile" profile_get
|
||||
; Dream.post "/profile" profile_post
|
||||
; Dream.get "/add_plant" add_plant_get
|
||||
; Dream.post "/add_plant" add_plant_post
|
||||
; Dream.get "/plant_pic/:plant_id/:nb" plant_image
|
||||
; Dream.get "/plant_markers" plant_markers
|
||||
; Dream.get "/thread_markers" thread_markers
|
||||
; Dream.get "/thread_view/:thread_id" thread_view
|
||||
; Dream.get "/plants/markers" (markers ~board:Plants)
|
||||
; Dream.get "/babillard/markers" (markers ~board:Babillard)
|
||||
; Dream.get "/plants" plants_get
|
||||
; Dream.get "/plants/new_thread" (newthread_get ~board:Plants)
|
||||
; Dream.post "/plants/new_thread" (newthread_post ~board:Plants)
|
||||
; Dream.get "/plants/:thread_id" thread_get (*todo, bad names ^^*)
|
||||
; Dream.post "/plants/:thread_id" reply_post
|
||||
; Dream.get "/post_pic/:post_id" post_image
|
||||
; Dream.get "/babillard" babillard_get
|
||||
; Dream.get "/babillard/new_thread" newthread_get
|
||||
; Dream.post "/babillard/new_thread" newthread_post
|
||||
; Dream.get "/babillard/:thread_id" thread_get (*todo, bad names ^^*)
|
||||
; Dream.post "/babillard/:thread_id" thread_post
|
||||
; Dream.get "/babillard/new_thread" (newthread_get ~board:Babillard)
|
||||
; Dream.post "/babillard/new_thread" (newthread_post ~board:Babillard)
|
||||
; Dream.get "/babillard/:thread_id" thread_get
|
||||
; Dream.post "/reply/:thread_id" reply_post
|
||||
; Dream.get "/post_pic/:post_id" post_image
|
||||
]
|
||||
@@ Dream.not_found
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue