diff --git a/internal/models/bankAccounts.go b/internal/models/bankAccounts.go index fc1185869d0d29d69cbf83ba06be2d65c50b244c..431d223acbb8144b9475045e4f14db494c851058 100644 --- a/internal/models/bankAccounts.go +++ b/internal/models/bankAccounts.go @@ -31,7 +31,7 @@ func (d *DataHandler) HandleBankAccounts(w http.ResponseWriter, r *http.Request) case "BANKER": d.postBankAccountBanker(w, r, id) case "CLIENT": - d.postBankAccountClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -42,7 +42,7 @@ func (d *DataHandler) HandleBankAccounts(w http.ResponseWriter, r *http.Request) case "BANKER": d.putBankAccountBanker(w, r, id) case "CLIENT": - d.putBankAccountClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -53,7 +53,7 @@ func (d *DataHandler) HandleBankAccounts(w http.ResponseWriter, r *http.Request) case "BANKER": d.deleteBankAccountBanker(w, r, id) case "CLIENT": - d.deleteBankAccountClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -152,10 +152,6 @@ func (d *DataHandler) postBankAccountBanker(w http.ResponseWriter, r *http.Reque json.NewEncoder(w).Encode(o) } -func (d *DataHandler) postBankAccountClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} - func (d *DataHandler) putBankAccountAdmin(w http.ResponseWriter, r *http.Request, id int) { var o BankAccount if err := d.db.Preload("Operations").First(&o, id).Error; err != nil { @@ -202,10 +198,6 @@ func (d *DataHandler) putBankAccountBanker(w http.ResponseWriter, r *http.Reques json.NewEncoder(w).Encode(o) } -func (d *DataHandler) putBankAccountClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} - func (d *DataHandler) deleteBankAccountAdmin(w http.ResponseWriter, r *http.Request, id int) { if id != 0 { var o BankAccount @@ -237,7 +229,3 @@ func (d *DataHandler) deleteBankAccountBanker(w http.ResponseWriter, r *http.Req http.Error(w, ErrorIDIsMissing, http.StatusNotFound) } } - -func (d *DataHandler) deleteBankAccountClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} diff --git a/internal/models/bankers.go b/internal/models/bankers.go index e1a4700d680f3965f884cff7b4810ae400758b56..0a0aaa38de8bac1949c4ff2d7ce91f63b46ede6f 100644 --- a/internal/models/bankers.go +++ b/internal/models/bankers.go @@ -29,7 +29,7 @@ func (d *DataHandler) HandleBankers(w http.ResponseWriter, r *http.Request) { case "ADMIN": d.postBankerAdmin(w, r, id) case "BANKER", "CLIENT": - d.postBankerClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -39,7 +39,7 @@ func (d *DataHandler) HandleBankers(w http.ResponseWriter, r *http.Request) { case "ADMIN": d.putBankerAdmin(w, r, id) case "BANKER", "CLIENT": - d.putBankerClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -48,7 +48,7 @@ func (d *DataHandler) HandleBankers(w http.ResponseWriter, r *http.Request) { case "ADMIN": d.deleteBankerAdmin(w, r, id) case "BANKER", "CLIENT": - d.deleteBankerClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -132,10 +132,6 @@ func (d *DataHandler) postBankerAdmin(w http.ResponseWriter, r *http.Request, id json.NewEncoder(w).Encode(o) } -func (d *DataHandler) postBankerClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} - func (d *DataHandler) putBankerAdmin(w http.ResponseWriter, r *http.Request, id int) { var o UserBanker if err := d.db.Preload("UserClients").Where(reqID, id).First(&o).Error; err != nil { @@ -152,10 +148,6 @@ func (d *DataHandler) putBankerAdmin(w http.ResponseWriter, r *http.Request, id json.NewEncoder(w).Encode(o) } -func (d *DataHandler) putBankerClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} - func (d *DataHandler) deleteBankerAdmin(w http.ResponseWriter, r *http.Request, id int) { if id != 0 { var o UserBanker @@ -168,7 +160,3 @@ func (d *DataHandler) deleteBankerAdmin(w http.ResponseWriter, r *http.Request, http.Error(w, ErrorIDIsMissing, http.StatusNotFound) } } - -func (d *DataHandler) deleteBankerClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} diff --git a/internal/models/clients.go b/internal/models/clients.go index d1af93b8a9e97cb991f4d7da19219ca63c6c5933..7e009b1e0af668d7ec22374391af9d869ab9aa08 100644 --- a/internal/models/clients.go +++ b/internal/models/clients.go @@ -32,7 +32,7 @@ func (d *DataHandler) HandleClients(w http.ResponseWriter, r *http.Request) { case "BANKER": d.postClientBanker(w, r, id) case "CLIENT": - d.postClientClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -43,7 +43,7 @@ func (d *DataHandler) HandleClients(w http.ResponseWriter, r *http.Request) { case "BANKER": d.putClientBanker(w, r, id) case "CLIENT": - d.putClientClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -54,7 +54,7 @@ func (d *DataHandler) HandleClients(w http.ResponseWriter, r *http.Request) { case "BANKER": d.deleteClientBanker(w, r, id) case "CLIENT": - d.deleteClientClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -152,10 +152,6 @@ func (d *DataHandler) postClientBanker(w http.ResponseWriter, r *http.Request, i json.NewEncoder(w).Encode(o) } -func (d *DataHandler) postClientClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} - func (d *DataHandler) putClientAdmin(w http.ResponseWriter, r *http.Request, id int) { var o UserClient if err := d.db.Preload("BankAccounts").Where(reqID, id).First(&o).Error; err != nil { @@ -191,10 +187,6 @@ func (d *DataHandler) putClientBanker(w http.ResponseWriter, r *http.Request, id json.NewEncoder(w).Encode(o) } -func (d *DataHandler) putClientClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} - func (d *DataHandler) deleteClientAdmin(w http.ResponseWriter, r *http.Request, id int) { if id != 0 { var o UserClient @@ -231,7 +223,3 @@ func (d *DataHandler) deleteClientBanker(w http.ResponseWriter, r *http.Request, http.Error(w, ErrorIDIsMissing, http.StatusNotFound) } } - -func (d *DataHandler) deleteClientClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -} diff --git a/internal/models/models.go b/internal/models/models.go index fffe5021b92451ea28bc61a94ee5229b7511c2c7..093594ef8105fdb12bb588ff774766bf0732c1d1 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -17,19 +17,19 @@ type DataHandler struct { db *gorm.DB } -// ErrorIDDoesNotExist = "id does not exist" +// ErrorIDDoesNotExist = "id does not exist" with 404 http.StatusNotFound const ErrorIDDoesNotExist = "id does not exist" -// ErrorIDIsMissing = "id is missing" +// ErrorIDIsMissing = "id is missing" with 404 http.StatusNotFound const ErrorIDIsMissing = "id is missing" -// ErrorCannotAccessRessource = "You can not access this ressource" +// ErrorCannotAccessRessource = "You can not access this ressource" with 403 http.StatusForbidden const ErrorCannotAccessRessource = "You can not access this ressource" -// ErrorRoleOfLoggedUser = "Could not get role of logged user" +// ErrorRoleOfLoggedUser = "Could not get role of logged user" with 500 http.StatusInternalServerError const ErrorRoleOfLoggedUser = "Could not get role of logged user" -// ErrorNotAuthorizeMethodOnRessource = "You're not authorize to execute this method on this ressource." +// ErrorNotAuthorizeMethodOnRessource = "You're not authorize to execute this method on this ressource." with 405 http.StatusMethodNotAllowed const ErrorNotAuthorizeMethodOnRessource = "You're not authorize to execute this method on this ressource." // ErrorUserIDIsMissing = "id of UserClient is missing" diff --git a/internal/models/operations.go b/internal/models/operations.go index 9377fbf7860616f4ebf513ba4273f111993595e1..5374d0fe5858382162ad13e08a89e39c8c03c98b 100644 --- a/internal/models/operations.go +++ b/internal/models/operations.go @@ -34,7 +34,7 @@ func (d *DataHandler) HandleOperations(w http.ResponseWriter, r *http.Request) { case "ADMIN", "BANKER": d.deleteOperationBanker(w, r, id) case "CLIENT": - d.deleteOperationClient(w, r, id) + http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) default: http.Error(w, ErrorRoleOfLoggedUser, http.StatusInternalServerError) } @@ -133,7 +133,3 @@ func (d *DataHandler) deleteOperationBanker(w http.ResponseWriter, r *http.Reque http.Error(w, ErrorIDIsMissing, http.StatusNotFound) } } - -func (d *DataHandler) deleteOperationClient(w http.ResponseWriter, r *http.Request, id int) { - http.Error(w, ErrorNotAuthorizeMethodOnRessource, http.StatusMethodNotAllowed) -}