DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 5eb68743888e7bb529a8d0e31aadbac396cbc286 deck-builder/api/handlers/createaction.go -rw-r--r-- 927 bytes
5eb68743Jonni Liljamo fix(client): give card default translation, fix rotation 1 year, 7 months ago
                                                                                
6aef1e4c skye
6aef1e4c skye
395ef277 skye
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * This file is part of laurelin_api
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

package handlers

import (
	"api/apierror"
	"api/db"
	"api/models"
	"net/http"

	"github.com/gin-gonic/gin"
	"gorm.io/datatypes"
)

func CreateAction(c *gin.Context) {
	var input models.PostAction
	if err := c.ShouldBindJSON(&input); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": apierror.InvalidInput})
		c.Abort()
		return
	}

	var action models.Action

	action.GameID = input.GameID
	action.Invoker = input.Invoker
	action.Target = input.Target
	action.Command = datatypes.JSON(input.Command)
	action.Seed = input.Seed

	entry := db.DbConn.Create(&action)
	if entry.Error != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": apierror.ActionCreationFailed})
		c.Abort()
		return
	}

	c.JSON(http.StatusCreated, action)
}