diff --git a/src/handler/nurse_handler.go b/src/handler/nurse_handler.go index c2380ad..ad1dd56 100644 --- a/src/handler/nurse_handler.go +++ b/src/handler/nurse_handler.go @@ -9,6 +9,7 @@ import ( "net/http" "regexp" "strconv" + "strings" "time" "github.com/gin-gonic/gin" @@ -151,18 +152,24 @@ func (h *NurseHandler) UpdateNurse(c *gin.Context) { return } - // Validate request payload - err = ValidateRegisterNurseRequest(request.Nip, request.Name) + user, err := h.iNurseUsecase.GetNurseByID(userId) if err != nil { log.Println("Update bad request ", err) - c.JSON(400, gin.H{"status": "bad request", "message": err.Error()}) - return + c.JSON(404, gin.H{"status": "bad request", "message": "userId not found"}) } - user, err := h.iNurseUsecase.GetNurseByID(userId) + nStr := strconv.FormatInt(user.Nip, 10) + if !strings.HasPrefix(nStr, "303") { + c.JSON(404, gin.H{"status": "bad request", "message": "user not found"}) + return + } + + // Validate request payload + err = ValidateRegisterNurseRequest(request.Nip, request.Name) if err != nil { log.Println("Update bad request ", err) - c.JSON(404, gin.H{"status": "bad request", "message": "userId not found"}) + c.JSON(400, gin.H{"status": "bad request", "message": err.Error()}) + return } if (user.Nip != request.Nip) { @@ -181,6 +188,16 @@ func (h *NurseHandler) UpdateNurse(c *gin.Context) { func (h *NurseHandler) DeleteNurse(c *gin.Context) { userId := c.Param("userId") + user, err := h.iNurseUsecase.GetNurseByID(userId) + if err != nil { + log.Println("Update bad request ", err) + c.JSON(404, gin.H{"status": "bad request", "message": "userId not found"}) + } + nStr := strconv.FormatInt(user.Nip, 10) + if !strings.HasPrefix(nStr, "303") { + c.JSON(404, gin.H{"status": "bad request", "message": "user not found"}) + return + } statusCode := h.iNurseUsecase.DeleteNurse(userId) c.JSON(statusCode, gin.H{"status": statusCode})