<commit_before>package catchvifyoucan.grails.server

import grails.converters.JSON

class PlayerController {
    def scaffold = true

    def index = {
        redirect(action: "list")
    }

    def trail = {
        Game game = Game.findById(params.gameId)
        Player player = Player.findByPlayerId(params.playerId)

        def result = [ trail :  player?.trail.locations.collect {[ latitude : it.latitude, longitude : it.longitude]} ]
        withFormat {
            html {
                return result
            }
            json {
                render result as JSON
            }
        }

    }

    def location = {
        Game game = Game.findById(params.gameId)
        Player player = Player.findById(params.playerId)

        Location location = player.trail.locations[params.locationIndex]

        def result = [ longitude: location.longitude, latitude: location.latitude]
        withFormat {
            html {
                return result
            }
            json {
                render result as JSON
            }
        }
    }

    def createPlayer = {
        Player player = new Player(playerId: params.playerId)
        player.save()

       //if (!player.hasErrors()) {
            Game game = Game.findById(params.gameId)
            game.addToPlayers(player)
            game.save()
        //}
    }

    def addLocation = {
        Game game = Game.findById(params.gameId)
        Player player = Player.findByPlayerId(params.playerId)

        Location location = new Location(longitude: Long.valueOf(params.longitude), latitude: Long.valueOf(params.latitude))

        player.trail.addToLocations(location)
        player.save()
    }<commit_msg>Return a json result<commit_after>package catchvifyoucan.grails.server

import grails.converters.JSON

class PlayerController {
    def scaffold = true

    def index = {
        redirect(action: "list")
    }

    def trail = {
        Game game = Game.findById(params.gameId)
        Player player = Player.findByPlayerId(params.playerId)

        def result = [ trail :  player?.trail.locations.collect {[ latitude : it.latitude, longitude : it.longitude]} ]
        withFormat {
            html {
                return result
            }
            json {
                render result as JSON
            }
        }

    }

    def location = {
        Game game = Game.findById(params.gameId)
        Player player = Player.findById(params.playerId)

        Location location = player.trail.locations[params.locationIndex]

        def result = [ longitude: location.longitude, latitude: location.latitude]
        withFormat {
            html {
                return result
            }
            json {
                render result as JSON
            }
        }
    }

    def createPlayer = {
        Player player = new Player(playerId: params.playerId)
        player.save()

       //if (!player.hasErrors()) {
            Game game = Game.findById(params.gameId)
            game.addToPlayers(player)
            game.save()
        //}

        def result = [ status : "ok" ]
        withFormat {
            html {
                return result
            }
            json {
                render result as JSON
            }
        }
    }

    def addLocation = {
        Game game = Game.findById(params.gameId)
        Player player = Player.findByPlayerId(params.playerId)

        Location location = new Location(longitude: Long.valueOf(params.longitude), latitude: Long.valueOf(params.latitude))

        player.trail.addToLocations(location)
        player.save()

        def result = [ status: "ok" ]
        withFormat {
            html {
                return result
            }
            json {
                render result as JSON
            }
        }
    }
{'fraction_non_alphanumeric': 0.08695652173913043, 'fraction_numerical': 0.0, 'mean_word_length': 1.5786630654962863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4337177', 'n_tokens_mistral': 1042, 'n_tokens_neox': 982, 'n_words': 221}