<commit_before>package controllers

import db.{ MembershipRequest, MembershipRequestJson }
import play.api.mvc._
import play.api.libs.json.Json

object MembershipRequests extends Controller {

  def get(organization_guid: Option[String], user_guid: Option[String], role: Option[String], limit: Int = 50, offset: Int = 0) = Authenticated { request =>
    val requests = MembershipRequest.findAll(user = Some(request.user),
                                             organization_guid = organization_guid,
                                             user_guid = user_guid,
                                             role = role,
                                             limit = limit,
                                             offset = offset)
    Ok(Json.toJson(requests.map(_.json)))
  }

  def post() = TODO

  def putGuidApprove(guid: String) = Authenticated { request =>
    MembershipRequest.findAll(guid = Some(guid), can_be_reviewed_by = Some(request.user), limit = 1).headOption match {<commit_msg>Implement POST membership request<commit_after>package controllers

import core.{ Organization, User }
import db.{ MembershipRequest, MembershipRequestJson, OrganizationDao, UserDao }
import play.api.mvc._
import play.api.libs.json.Json
import java.util.UUID

object MembershipRequests extends Controller {

  def get(organization_guid: Option[String], user_guid: Option[String], role: Option[String], limit: Int = 50, offset: Int = 0) = Authenticated { request =>
    val requests = MembershipRequest.findAll(user = Some(request.user),
                                             organization_guid = organization_guid,
                                             user_guid = user_guid,
                                             role = role,
                                             limit = limit,
                                             offset = offset)
    Ok(Json.toJson(requests.map(_.json)))
  }

  def post() = Authenticated(parse.json) { request =>
    val role = (request.body \ "role").as[String]
    val organizationGuid = (request.body \ "organization_guid").as[String]
    val userGuid = (request.body \ "user_guid").as[String]

    OrganizationDao.findByUserAndGuid(request.user, UUID.fromString(organizationGuid)) match {
      case None => NotFound("Organization not found or you are not authorized to create membership requests for this org")
      case Some(org: Organization) => {
        UserDao.findByGuid(userGuid) match {
          case None => NotFound("User not found")
          case Some(user: User) => {
            val mr = MembershipRequest.upsert(request.user, org, user, role)
            Created(Json.toJson(mr.json))
          }
        }
      }
    }
  }

  def putGuidApprove(guid: String) = Authenticated { request =>
    MembershipRequest.findAll(guid = Some(guid), can_be_reviewed_by = Some(request.user), limit = 1).headOption match {
{'fraction_non_alphanumeric': 0.09707401032702237, 'fraction_numerical': 0.002753872633390706, 'mean_word_length': 2.1794310722100656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3216206', 'n_tokens_mistral': 739, 'n_tokens_neox': 721, 'n_words': 182}