<commit_before>import Vapor
import HTTP

final class TagController: ResourceRepresentable {
    
    func index(_ req: Request) throws -> ResponseRepresentable {
        let tags = try Tag.makeQuery().sort(Tag.Properties.id, .ascending).all()
        return try tags.makeJSON()
    }
    
    func create(_ req: Request) throws -> ResponseRepresentable {
        let tag = try req.tag()
        try tag.save()
        return tag
    }
    
    func show(_ req: Request, tag: Tag) throws -> ResponseRepresentable {
        let own = req.query?["own"]?.bool
        if own == nil {
            return try tag.makeJsonWithNotes()
        }

        let userId = try req.userId()
        return try tag.makeJsonWithNotes(userId: userId)
    }
    
    func update(_ req: Request, tag: Tag) throws -> ResponseRepresentable {
        try tag.update(for: req)
        try tag.save()
        return tag
    }
    
//    func delete(_ req: Request, tag: Tag) throws -> ResponseRepresentable {
//        
//        
//    }
    
    func makeResource() -> Resource<Tag> {
        return Resource(
            index: index,
            store: create,
            show: show,
            update: update
        )
    }
}<commit_msg>Implemented provisional delete method in TagController<commit_after>import Vapor
import HTTP

final class TagController: ResourceRepresentable {
    
    func index(_ req: Request) throws -> ResponseRepresentable {
        let tags = try Tag.makeQuery().sort(Tag.Properties.id, .ascending).all()
        return try tags.makeJSON()
    }
    
    func create(_ req: Request) throws -> ResponseRepresentable {
        let tag = try req.tag()
        try tag.save()
        return tag
    }
    
    func show(_ req: Request, tag: Tag) throws -> ResponseRepresentable {
        let own = req.query?["own"]?.bool
        if own == nil {
            return try tag.makeJsonWithNotes()
        }

        let userId = try req.userId()
        return try tag.makeJsonWithNotes(userId: userId)
    }
    
    func update(_ req: Request, tag: Tag) throws -> ResponseRepresentable {
        try tag.update(for: req)
        try tag.save()
        return tag
    }
    
    func delete(_ req: Request, tag: Tag) throws -> ResponseRepresentable {
        // TODO: no need to fetch notes from database
        let notes = try tag.notes.all()
        // TODO: no need to access database for each note
        try notes.forEach { note in
            try tag.notes.remove(note)
        }
        try tag.delete()
        return Response(status: .ok)
    }
    
    func makeResource() -> Resource<Tag> {
        return Resource(
            index: index,
            store: create,
            show: show,
            update: update
        )
    }
}
{'fraction_non_alphanumeric': 0.09840232389251997, 'fraction_numerical': 0.0, 'mean_word_length': 1.8697916666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6603579', 'n_tokens_mistral': 761, 'n_tokens_neox': 747, 'n_words': 231}