app/controllers/UserController.java
@CorsComposition.Cors
	@ValidateJsonSchema(YmlConstants.JsonSchemaFilePaths.CREATE_POST)
	public CompletionStage<Result> createPostByUser() {
		JsonNode result = null;
		try{
			final JsonNode inputData = request().body().asJson();
			ObjectMapper mapper = new ObjectMapper();
			final CreatePostDTO requestDTO = mapper.convertValue(inputData, CreatePostDTO.class);
			
			// Validate input
			if(requestDTO.description == null || requestDTO.description.trim().isEmpty()) {
				throw new YmlException(EnumMessages.ENTER_DESCRIPTION.toString());
			}
			if(requestDTO.token == null || requestDTO.token.trim().isEmpty()) {
				throw new YmlException(EnumMessages.INVALID_TOKEN.toString());
			}
			
			// Validate user and session
			UserSession userSession = new UserSession();
			Users user = userSession.validateUserSession(requestDTO.token);
			
			// Create post
			Posts posts = new Posts();
			Map<String, Long> response = posts.createPost(user, requestDTO.description);
			if(response == null){
				throw new YmlException(EnumMessages.POST_COULD_NOT_BE_CREATED.toString());
			}
			
			result = mapper.convertValue(response, JsonNode.class);
			return successResponsePromise(result);
		} catch(Exception e) {
			e.printStackTrace();
			return failureResponsePromise(e);
		}
	}
/**
	 * Creates post made by the user in session
	 * @return
	 */
Creates post made by the user in session
@return
Creates post made by the user in session @return
@CorsComposition.Cors
	@ValidateJsonSchema(YmlConstants.JsonSchemaFilePaths.CREATE_POST)
	public CompletionStage<Result> createPostByUser() {
		JsonNode result = null;
		try{
			final JsonNode inputData = request().body().asJson();
			ObjectMapper mapper = new ObjectMapper();
			final CreatePostDTO requestDTO = mapper.convertValue(inputData, CreatePostDTO.class);
			if(requestDTO.description == null || requestDTO.description.trim().isEmpty()) {
				throw new YmlException(EnumMessages.ENTER_DESCRIPTION.toString());
			}
			if(requestDTO.token == null || requestDTO.token.trim().isEmpty()) {
				throw new YmlException(EnumMessages.INVALID_TOKEN.toString());
			}
			UserSession userSession = new UserSession();
			Users user = userSession.validateUserSession(requestDTO.token);
			Posts posts = new Posts();
			Map<String, Long> response = posts.createPost(user, requestDTO.description);
			if(response == null){
				throw new YmlException(EnumMessages.POST_COULD_NOT_BE_CREATED.toString());
			}
			result = mapper.convertValue(response, JsonNode.class);
			return successResponsePromise(result);
		} catch(Exception e) {
			e.printStackTrace();
			return failureResponsePromise(e);
		}
	}
@ CorsComposition . Cors @ ValidateJsonSchema ( YmlConstants . JsonSchemaFilePaths . CREATE_POST ) public CompletionStage < Result > createPostByUser ( ) { JsonNode result = null ; try { final JsonNode inputData = request ( ) . body ( ) . asJson ( ) ; ObjectMapper mapper = new ObjectMapper ( ) ; final CreatePostDTO requestDTO = mapper . convertValue ( inputData , CreatePostDTO . class ) ; if ( requestDTO . description == null || requestDTO . description . trim ( ) . isEmpty ( ) ) { throw new YmlException ( EnumMessages . ENTER_DESCRIPTION . toString ( ) ) ; } if ( requestDTO . token == null || requestDTO . token . trim ( ) . isEmpty ( ) ) { throw new YmlException ( EnumMessages . INVALID_TOKEN . toString ( ) ) ; } UserSession userSession = new UserSession ( ) ; Users user = userSession . validateUserSession ( requestDTO . token ) ; Posts posts = new Posts ( ) ; Map < String , Long > response = posts . createPost ( user , requestDTO . description ) ; if ( response == null ) { throw new YmlException ( EnumMessages . POST_COULD_NOT_BE_CREATED . toString ( ) ) ; } result = mapper . convertValue ( response , JsonNode . class ) ; return successResponsePromise ( result ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return failureResponsePromise ( e ) ; } }
Creates post made by the user in session
 @return
Creates post made by the user in session @return
// Validate input // Validate user and session // Create post