Skip to content

Commit

Permalink
fix k6 update delete nurse
Browse files Browse the repository at this point in the history
  • Loading branch information
najamuslim committed May 19, 2024
1 parent c6fa8a9 commit ba65c66
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/handler/nurse_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"regexp"
"strconv"
"strings"
"time"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -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) {
Expand All @@ -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})
Expand Down

0 comments on commit ba65c66

Please sign in to comment.