Working on more renames
This commit is contained in:
parent
274675d02a
commit
bca2d67b02
@ -391,9 +391,9 @@ func TestPutTaskInvalidTaskId(t *testing.T) {
|
||||
func TestPostAllowance(t *testing.T) {
|
||||
e := startServer(t)
|
||||
|
||||
e.POST("/user/1/history").WithJSON(PostAllowance{Allowance: 100}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostAllowance{Allowance: 20}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostAllowance{Allowance: -10}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: 100}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: 20}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: -10}).Expect().Status(200)
|
||||
|
||||
response := e.GET("/user/1").Expect().Status(200).JSON().Object()
|
||||
response.Value("allowance").Number().IsEqual(100 + 20 - 10)
|
||||
@ -402,16 +402,16 @@ func TestPostAllowance(t *testing.T) {
|
||||
func TestPostAllowanceInvalidUserId(t *testing.T) {
|
||||
e := startServer(t)
|
||||
|
||||
e.POST("/user/999/history").WithJSON(PostAllowance{Allowance: 100}).Expect().
|
||||
e.POST("/user/999/history").WithJSON(PostHistory{Allowance: 100}).Expect().
|
||||
Status(404)
|
||||
}
|
||||
|
||||
func TestGetHistory(t *testing.T) {
|
||||
e := startServer(t)
|
||||
|
||||
e.POST("/user/1/history").WithJSON(PostAllowance{Allowance: 100}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostAllowance{Allowance: 20}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostAllowance{Allowance: -10}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: 100}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: 20}).Expect().Status(200)
|
||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: -10}).Expect().Status(200)
|
||||
|
||||
response := e.GET("/user/1/history").Expect().Status(200).JSON().Array()
|
||||
response.Length().IsEqual(3)
|
||||
|
@ -67,7 +67,7 @@ func (db *Db) UserExists(userId int) (bool, error) {
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (db *Db) GetUserGoals(userId int) ([]Goal, error) {
|
||||
func (db *Db) GetUserAllowances(userId int) ([]Goal, error) {
|
||||
goals := make([]Goal, 0)
|
||||
var err error
|
||||
|
||||
@ -236,7 +236,7 @@ func (db *Db) UpdateTask(id int, task *CreateTaskRequest) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (db *Db) AddAllowance(userId int, allowance *PostAllowance) error {
|
||||
func (db *Db) AddHistory(userId int, allowance *PostHistory) error {
|
||||
tx, err := db.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -18,7 +18,7 @@ type Allowance struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
type PostAllowance struct {
|
||||
type PostHistory struct {
|
||||
Allowance int `json:"allowance"`
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ func getUser(c *gin.Context) {
|
||||
c.IndentedJSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
func getUserGoals(c *gin.Context) {
|
||||
func getUserAllowance(c *gin.Context) {
|
||||
userIdStr := c.Param("userId")
|
||||
userId, err := strconv.Atoi(userIdStr)
|
||||
if err != nil {
|
||||
@ -97,16 +97,16 @@ func getUserGoals(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
goals, err := db.GetUserGoals(userId)
|
||||
allowances, err := db.GetUserAllowances(userId)
|
||||
if err != nil {
|
||||
log.Printf("Error getting user goals: %v", err)
|
||||
log.Printf("Error getting user allowance: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": ErrInternalServerError})
|
||||
return
|
||||
}
|
||||
c.IndentedJSON(http.StatusOK, goals)
|
||||
c.IndentedJSON(http.StatusOK, allowances)
|
||||
}
|
||||
|
||||
func createUserGoal(c *gin.Context) {
|
||||
func createUserAllowance(c *gin.Context) {
|
||||
userIdStr := c.Param("userId")
|
||||
userId, err := strconv.Atoi(userIdStr)
|
||||
if err != nil {
|
||||
@ -146,7 +146,7 @@ func createUserGoal(c *gin.Context) {
|
||||
c.IndentedJSON(http.StatusCreated, response)
|
||||
}
|
||||
|
||||
func deleteUserGoal(c *gin.Context) {
|
||||
func deleteUserAllowance(c *gin.Context) {
|
||||
userIdStr := c.Param("userId")
|
||||
goalIdStr := c.Param("goalId")
|
||||
|
||||
@ -290,7 +290,7 @@ func putTask(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Task updated successfully"})
|
||||
}
|
||||
|
||||
func postAllowance(c *gin.Context) {
|
||||
func postHistory(c *gin.Context) {
|
||||
userIdStr := c.Param("userId")
|
||||
userId, err := strconv.Atoi(userIdStr)
|
||||
if err != nil {
|
||||
@ -299,8 +299,8 @@ func postAllowance(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var allowanceRequest PostAllowance
|
||||
if err := c.ShouldBindJSON(&allowanceRequest); err != nil {
|
||||
var historyRequest PostHistory
|
||||
if err := c.ShouldBindJSON(&historyRequest); err != nil {
|
||||
log.Printf("Error parsing request body: %v", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
||||
return
|
||||
@ -317,13 +317,13 @@ func postAllowance(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = db.AddAllowance(userId, &allowanceRequest)
|
||||
err = db.AddHistory(userId, &historyRequest)
|
||||
if err != nil {
|
||||
log.Printf("Error updating allowance: %v", err)
|
||||
log.Printf("Error updating history: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": ErrInternalServerError})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Allowance updated successfully"})
|
||||
c.JSON(http.StatusOK, gin.H{"message": "History updated successfully"})
|
||||
}
|
||||
|
||||
func getHistory(c *gin.Context) {
|
||||
@ -359,11 +359,11 @@ func start(ctx context.Context, config *ServerConfig) {
|
||||
}))
|
||||
router.GET("/api/users", getUsers)
|
||||
router.GET("/api/user/:userId", getUser)
|
||||
router.POST("/api/user/:userId/allowance", postAllowance)
|
||||
router.POST("/api/user/:userId/history", postHistory)
|
||||
router.GET("/api/user/:userId/history", getHistory)
|
||||
router.GET("/api/user/:userId/goals", getUserGoals)
|
||||
router.POST("/api/user/:userId/goals", createUserGoal)
|
||||
router.DELETE("/api/user/:userId/goal/:goalId", deleteUserGoal)
|
||||
router.GET("/api/user/:userId/allowance", getUserAllowance)
|
||||
router.POST("/api/user/:userId/allowance", createUserAllowance)
|
||||
router.DELETE("/api/user/:userId/allowance/:allowance", deleteUserAllowance)
|
||||
router.POST("/api/tasks", createTask)
|
||||
router.GET("/api/tasks", getTasks)
|
||||
router.GET("/api/task/:taskId", getTask)
|
||||
|
Loading…
x
Reference in New Issue
Block a user