<commit_before>package studentcapture.course.invite;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import studentcapture.course.CourseModel;
import studentcapture.login.LoginDAO;

/**
 * CourseInviteResource is a controller that maps REST requests related to 
 * 
 * @author tfy12hsm
 *
 */
@RestController
@RequestMapping(value = "/invite")
public class CourseInviteResource {
	@Autowired
    private CourseInviteDAO courseInviteDAO;
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.GET,
    value = "")
    @ResponseBody
    public InviteModel postCourseInvite() {
		InviteModel result = new InviteModel();
		result.setCourse(new CourseModel());
		
		return result;
    }
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.POST,
    value = "")
    @ResponseBody
    public InviteModel postCourseInvite(
    		@RequestBody InviteModel invite) {
		InviteModel result = courseInviteDAO.addCourseInvite(invite.getCourse());
    	if(result.getHex()!=null) {
    		return result;
    	} else {
    		throw new ResourceConflictException(); 
    	}
    }
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.POST,
    value = "/{Hex}")
    @ResponseBody
    public InviteModel joinCourse(
    		HttpSession session,
    		@PathVariable(value = "Hex") String hex) {
    	InviteModel result = courseInviteDAO.joinCourseThroughInvite(
    			LoginDAO.getUserIdFromSession(session), hex);
    	if(result.getCourse().getCourseId()==null) {
    		if(result.getCourse().getErrorCode()==HttpStatus.CONFLICT.value()) {
    			throw new ResourceConflictException();
    		} else {
    			throw new ResourceNotFoundException();
    		}
    	}
    	return result;
    }
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.GET,
    value = "/{Hex}")
    @ResponseBody
    public InviteModel getCourseInviteThroughHex(
    		@PathVariable(value = "Hex") InviteModel invite) {
    	InviteModel result = courseInviteDAO.getCourseThroughInvite(invite.getHex());
    	if(result.getCourse().getCourseId()==null)
    		throw new ResourceNotFoundException();
    	return result;
    }
	
    @ResponseStatus(value = HttpStatus.NOT_FOUND)
    public static class ResourceNotFoundException extends RuntimeException {
		private static final long serialVersionUID = 1L;
    }
    
    @ResponseStatus(value = HttpStatus.CONFLICT)
    public static class ResourceConflictException extends RuntimeException {
		private static final long serialVersionUID = 1L;
    }
}
<commit_msg>remapped courseInvite further.<commit_after>package studentcapture.course.invite;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import studentcapture.course.CourseModel;
import studentcapture.login.LoginDAO;

/**
 * CourseInviteResource is a controller that maps REST requests related to 
 * 
 * @author tfy12hsm
 *
 */
@RestController
@RequestMapping(value = "/invite")
public class CourseInviteResource {
	@Autowired
    private CourseInviteDAO courseInviteDAO;
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.GET,
    value = "")
    @ResponseBody
    public InviteModel postCourseInvite() {
		InviteModel result = new InviteModel();
		result.setCourse(new CourseModel());
		
		return result;
    }
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.POST,
    value = "")
    @ResponseBody
    public InviteModel postCourseInvite(
    		@RequestBody InviteModel invite) {
		InviteModel result = courseInviteDAO.addCourseInvite(invite.getCourse());
    	if(result.getHex()!=null) {
    		return result;
    	} else {
    		throw new ResourceConflictException(); 
    	}
    }
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.POST,
    value = "/{Hex}")
    @ResponseBody
    public InviteModel joinCourse(
    		HttpSession session,
    		@PathVariable(value = "Hex") String hex) {
    	InviteModel result = courseInviteDAO.joinCourseThroughInvite(
    			LoginDAO.getUserIdFromSession(session), hex);
    	if(result.getCourse().getCourseId()==null) {
    		if(result.getCourse().getErrorCode()==HttpStatus.CONFLICT.value()) {
    			throw new ResourceConflictException();
    		} else {
    			throw new ResourceNotFoundException();
    		}
    	}
    	return result;
    }
	
	@CrossOrigin
    @RequestMapping(
    produces = MediaType.APPLICATION_JSON_VALUE,
    method = RequestMethod.GET,
    value = "/{CourseId}")
    @ResponseBody
    public InviteModel getCourseInviteThroughHex(
    		@PathVariable(value = "CourseId") Integer courseId) {
		CourseModel course = new CourseModel();
		course.setCourseId(courseId);
		InviteModel result = courseInviteDAO.addCourseInvite(course);
    	if(result.getHex()!=null) {
    		return result;
    	} else {
    		throw new ResourceConflictException(); 
    	}
    }

	
//	@CrossOrigin
//    @RequestMapping(
//    produces = MediaType.APPLICATION_JSON_VALUE,
//    method = RequestMethod.GET,
//    value = "/{Hex}")
//    @ResponseBody
//    public InviteModel getCourseInviteThroughHex(
//    		@PathVariable(value = "Hex") InviteModel invite) {
//    	InviteModel result = courseInviteDAO.getCourseThroughInvite(invite.getHex());
//    	if(result.getCourse().getCourseId()==null)
//    		throw new ResourceNotFoundException();
//    	return result;
//    }
	
    @ResponseStatus(value = HttpStatus.NOT_FOUND)
    public static class ResourceNotFoundException extends RuntimeException {
		private static final long serialVersionUID = 1L;
    }
    
    @ResponseStatus(value = HttpStatus.CONFLICT)
    public static class ResourceConflictException extends RuntimeException {
		private static final long serialVersionUID = 1L;
    }
}

{'fraction_non_alphanumeric': 0.09442289688377692, 'fraction_numerical': 0.0010699478400427978, 'mean_word_length': 3.472488038277512, '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': '139593', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2162, 'n_words': 397}