<commit_before>package arn

import (
	"errors"
	"reflect"
	"strings"

	"github.com/aerogo/aero"
	"github.com/aerogo/api"
)

// Force interface implementations
var (
	_ api.Newable  = (*SoundTrack)(nil)
	_ api.Editable = (*SoundTrack)(nil)
	_ Publishable  = (*SoundTrack)(nil)
)

// Actions
func init() {
	API.RegisterActions("SoundTrack", []*api.Action{
		// Publish
		PublishAction(),

		// Unpublish
		UnpublishAction(),
	})
}

// Create sets the data for a new soundtrack with data we received from the API request.
func (soundtrack *SoundTrack) Create(ctx *aero.Context) error {
	user := GetUserFromContext(ctx)

	if user == nil {
		return errors.New("Not logged in")
	}

	soundtrack.ID = GenerateID("SoundTrack")
	soundtrack.Likes = []string{}
	soundtrack.Created = DateTimeUTC()
	soundtrack.CreatedBy = user.ID
	soundtrack.Media = []*ExternalMedia{}
	soundtrack.Tags = []string{}

	return soundtrack.Unpublish()
}

// Edit updates the external media object.
func (soundtrack *SoundTrack) Edit(ctx *aero.Context, key string, value reflect.Value, newValue reflect.Value) (bool, error) {
	if strings.HasPrefix(key, "Media[") && strings.HasSuffix(key, ".Service") {
		newService := newValue.String()

		if !Contains(ExternalMediaServices, newService) {
			return true, errors.New("Invalid service name")
		}

		value.SetString(newService)
		return true, nil
	}

	return false, nil
}

// AfterEdit updates the metadata.
func (soundtrack *SoundTrack) AfterEdit(ctx *aero.Context) error {
	soundtrack.Edited = DateTimeUTC()
	soundtrack.EditedBy = GetUserFromContext(ctx).ID
	return nil
}

// Authorize returns an error if the given API POST request is not authorized.
func (soundtrack *SoundTrack) Authorize(ctx *aero.Context, action string) error {
	if !ctx.HasSession() {
		return errors.New("Neither logged in nor in session")<commit_msg>Added soundtrack deletion<commit_after>package arn

import (
	"errors"
	"reflect"
	"strings"

	"github.com/aerogo/aero"
	"github.com/aerogo/api"
)

// Force interface implementations
var (
	_ api.Newable   = (*SoundTrack)(nil)
	_ api.Editable  = (*SoundTrack)(nil)
	_ api.Deletable = (*SoundTrack)(nil)
	_ Publishable   = (*SoundTrack)(nil)
)

// Actions
func init() {
	API.RegisterActions("SoundTrack", []*api.Action{
		// Publish
		PublishAction(),

		// Unpublish
		UnpublishAction(),
	})
}

// Create sets the data for a new soundtrack with data we received from the API request.
func (soundtrack *SoundTrack) Create(ctx *aero.Context) error {
	user := GetUserFromContext(ctx)

	if user == nil {
		return errors.New("Not logged in")
	}

	soundtrack.ID = GenerateID("SoundTrack")
	soundtrack.Likes = []string{}
	soundtrack.Created = DateTimeUTC()
	soundtrack.CreatedBy = user.ID
	soundtrack.Media = []*ExternalMedia{}
	soundtrack.Tags = []string{}

	return soundtrack.Unpublish()
}

// Edit updates the external media object.
func (soundtrack *SoundTrack) Edit(ctx *aero.Context, key string, value reflect.Value, newValue reflect.Value) (bool, error) {
	if strings.HasPrefix(key, "Media[") && strings.HasSuffix(key, ".Service") {
		newService := newValue.String()

		if !Contains(ExternalMediaServices, newService) {
			return true, errors.New("Invalid service name")
		}

		value.SetString(newService)
		return true, nil
	}

	return false, nil
}

// AfterEdit updates the metadata.
func (soundtrack *SoundTrack) AfterEdit(ctx *aero.Context) error {
	soundtrack.Edited = DateTimeUTC()
	soundtrack.EditedBy = GetUserFromContext(ctx).ID
	return nil
}

// Delete deletes the object from the database.
func (soundtrack *SoundTrack) Delete() error {
	_, err := DB.Delete("SoundTrack", soundtrack.ID)
	return err
}

// Authorize returns an error if the given API POST request is not authorized.
func (soundtrack *SoundTrack) Authorize(ctx *aero.Context, action string) error {
	if !ctx.HasSession() {
		return errors.New("Neither logged in nor in session")
{'fraction_non_alphanumeric': 0.12817878243000258, 'fraction_numerical': 0.0, 'mean_word_length': 4.547008547008547, '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': '3343443', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1237, 'n_words': 338}