diff --git a/internal/backoffice/backoffice.go b/internal/backoffice/backoffice.go index f89523ae99420595a7f8a34709a296403748ef84..135175db29963e4ae75c9707bf1b96ebd7d572d5 100644 --- a/internal/backoffice/backoffice.go +++ b/internal/backoffice/backoffice.go @@ -2,6 +2,7 @@ package backoffice import ( "io/ioutil" + "log" "net/http" "forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/post" @@ -18,5 +19,12 @@ func HandleCreatePost(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) return } - post.Create(string(body)) + + err = post.Create(string(body)) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + + log.Printf("| New post | %v", r.RemoteAddr) } diff --git a/internal/post/post.go b/internal/post/post.go index f39bfe363804d50926aeed638b067a32981d105b..79a0d7adbb628dea14da062767f152ba5bf30b37 100644 --- a/internal/post/post.go +++ b/internal/post/post.go @@ -39,6 +39,9 @@ func Exists(content string) bool { return true } -func Create(content string) { - db.Create(&Post{Content: content}) +func Create(content string) error { + if err := db.Create(&Post{Content: content}).Error; err != nil { + return err + } + return nil } diff --git a/template.env b/template.env index 8e59d8d526e99ee33a2e8f32a2f4f943281622e9..239c9cca9ceb567c0a390fb3e0e8be6916c37e41 100644 --- a/template.env +++ b/template.env @@ -1,3 +1,19 @@ +# Common settings +HOSTNAME= +ADMIN_ROLE= +DEBUG_MODE= +HTTPS_PORT= + +# Needed to user OAuth2 authentication : +REDIRECT_URL= +CLIENT_ID= +CLIENT_SECRET= +AUTH_URL= +TOKEN_URL= +USERINFO_URL= +LOGOUT_URL= + +# Access to the database DATABASE_USER= DATABASE_PASSWORD= DATABASE_NAME= \ No newline at end of file diff --git a/web/components/post/post.js b/web/components/post/post.js index 58061be295686b9ae720a69055091bdb4693ad20..b99a1faa08938153530a04ec1de82abfb9dc108b 100644 --- a/web/components/post/post.js +++ b/web/components/post/post.js @@ -1,5 +1,6 @@ // Imports import { HandleError } from "/services/common/errors.js"; +import * as Messages from "/services/messages/messages.js"; export async function mount(where, user) { const postComponent = new Post(user); @@ -53,6 +54,8 @@ class Post { `Le post n'a pas pu être créé (code ${response.status})` ); } + Messages.Show("is-success", "Le post a été créé avec succès"); + } catch (e) { HandleError(e); this.post_textarea.value = "Une erreur s'est produite !";