Skip to content

Commit

Permalink
fix content type
Browse files Browse the repository at this point in the history
  • Loading branch information
jcageman committed Aug 13, 2020
1 parent dd01108 commit a7e92b6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions d2mapapi/MapRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ init_resp( RESP resp )
resp
.append_header( "Server", "Diablo 2 map server /v.0.1" )
.append_header_date_field()
.append_header( "Content-Type", "text/plain; charset=utf-8" );
.append_header( "Content-Type", "text/json; charset=utf-8" );

return resp;
}
Expand All @@ -25,18 +25,18 @@ static boost::uuids::random_generator m_session_id_generator;
static std::map<std::string, std::unique_ptr<Session>> m_sessions;
static std::mutex m;

restinio::request_handling_status_t MapRequestHandler::get_area(const restinio::request_handle_t& req, const restinio::router::route_params_t& params)
restinio::request_handling_status_t MapRequestHandler::get_area( const restinio::request_handle_t& req, const restinio::router::route_params_t& params )
{
std::scoped_lock lock( m );
auto resp = init_resp( req->create_response() );
const auto session_id = restinio::cast_to<std::string>( params["session_id"] );
const auto area_id = restinio::cast_to<unsigned int>( params["area_id"] );
const auto session_id = restinio::cast_to<std::string>( params[ "session_id" ] );
const auto area_id = restinio::cast_to<unsigned int>( params[ "area_id" ] );
const auto session = m_sessions.find( session_id );
if (session != m_sessions.end())
if ( session != m_sessions.end() )
{
const auto map = session->second->GetMap( area_id );

resp.set_body( json_dto::to_json( map::MapToDto(*map) ) );
resp.set_body( json_dto::to_json( map::MapToDto( *map ) ) );
}
else
{
Expand All @@ -46,37 +46,37 @@ restinio::request_handling_status_t MapRequestHandler::get_area(const restinio::
return resp.done();
}

restinio::request_handling_status_t MapRequestHandler::post_session(const restinio::request_handle_t& req, const restinio::router::route_params_t& params)
restinio::request_handling_status_t MapRequestHandler::post_session( const restinio::request_handle_t& req, const restinio::router::route_params_t& params )
{
std::scoped_lock lock( m );
auto resp = init_resp( req->create_response() );

try
{
auto newSession = json_dto::from_json< NewSessionDto >( req->body() );
std::string uuid = boost::uuids::to_string( m_session_id_generator());
m_sessions[uuid] = std::make_unique<Session>( newSession.m_mapId, newSession.m_difficulty );
std::string uuid = boost::uuids::to_string( m_session_id_generator() );
m_sessions[ uuid ] = std::make_unique<Session>( newSession.m_mapId, newSession.m_difficulty );

const auto createdSession = SessionDto( uuid, newSession.m_mapId, newSession.m_difficulty );
resp.set_body( json_dto::to_json( createdSession ) );
resp.header().status_line( restinio::status_created() );
}
catch (const std::exception&)
catch ( const std::exception& )
{
resp.header().status_line( restinio::status_bad_request() );
}

return resp.done();
}

restinio::request_handling_status_t MapRequestHandler::delete_session(const restinio::request_handle_t& req, const restinio::router::route_params_t& params )
restinio::request_handling_status_t MapRequestHandler::delete_session( const restinio::request_handle_t& req, const restinio::router::route_params_t& params )
{
std::scoped_lock lock( m );
auto resp = init_resp( req->create_response() );
resp.header().status_line( restinio::status_no_content() );
const auto session_id = restinio::cast_to<std::string>( params["session_id"] );
const auto session_id = restinio::cast_to<std::string>( params[ "session_id" ] );
const auto session = m_sessions.find( session_id );
if (session != m_sessions.end())
if ( session != m_sessions.end() )
{
m_sessions.erase( session );
}
Expand Down

0 comments on commit a7e92b6

Please sign in to comment.