1- using Intersect . Enums ;
1+ using System . Net ;
2+ using Intersect . Enums ;
23using Intersect . GameObjects ;
34using Intersect . Server . Database ;
45using Intersect . Server . Database . GameData ;
56using Intersect . Server . Entities ;
7+ using Intersect . Server . Web . Http ;
68using Intersect . Server . Web . RestApi . Payloads ;
79using Intersect . Server . Web . RestApi . Types ;
810using Microsoft . AspNetCore . Authorization ;
911using Microsoft . AspNetCore . Mvc ;
1012
1113namespace Intersect . Server . Web . RestApi . Routes . V1 ;
1214
13- [ Route ( "api/v1/variables/global " ) ]
15+ [ Route ( "api/v1/variables" ) ]
1416[ Authorize ]
1517public sealed partial class VariablesController : IntersectController
1618{
1719 [ HttpGet ]
18- public IActionResult GlobalVariablesGet ( [ FromQuery ] PagingInfo pageInfo )
20+ [ ProducesResponseType ( typeof ( DataPage < ServerVariableBase > ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
21+ public IActionResult ServerVariablesGet ( [ FromQuery ] PagingInfo pageInfo )
1922 {
2023 pageInfo . Page = Math . Max ( pageInfo . Page , 0 ) ;
2124 pageInfo . PageSize = Math . Max ( Math . Min ( pageInfo . PageSize , 100 ) , 5 ) ;
22-
2325 var entries = GameContext . Queries . ServerVariables ( pageInfo . Page , pageInfo . PageSize ) ? . ToList ( ) ;
2426
2527 return Ok (
@@ -35,7 +37,10 @@ public IActionResult GlobalVariablesGet([FromQuery] PagingInfo pageInfo)
3537 }
3638
3739 [ HttpGet ( "{variableId:guid}" ) ]
38- public IActionResult GlobalVariableGet ( Guid variableId )
40+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
41+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
42+ [ ProducesResponseType ( typeof ( ServerVariableBase ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
43+ public IActionResult ServerVariableGet ( Guid variableId )
3944 {
4045 if ( variableId == default )
4146 {
@@ -47,14 +52,17 @@ public IActionResult GlobalVariableGet(Guid variableId)
4752 // ReSharper disable once ConvertIfStatementToReturnStatement
4853 if ( variable == null )
4954 {
50- return NotFound ( $@ "No global variable with id '{ variableId } '.") ;
55+ return NotFound ( $@ "No server variable with id '{ variableId } '.") ;
5156 }
5257
5358 return Ok ( variable ) ;
5459 }
5560
5661 [ HttpGet ( "{variableId:guid}/value" ) ]
57- public IActionResult GlobalVariableGetValue ( Guid variableId )
62+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
63+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
64+ [ ProducesResponseType ( typeof ( VariableValueBody ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
65+ public IActionResult ServerVariableGetValue ( Guid variableId )
5866 {
5967 if ( variableId == default )
6068 {
@@ -65,7 +73,7 @@ public IActionResult GlobalVariableGetValue(Guid variableId)
6573
6674 if ( variable == null )
6775 {
68- return NotFound ( $@ "No global variable with id '{ variableId } '.") ;
76+ return NotFound ( $@ "No server variable with id '{ variableId } '.") ;
6977 }
7078
7179 return Ok (
@@ -77,7 +85,10 @@ public IActionResult GlobalVariableGetValue(Guid variableId)
7785 }
7886
7987 [ HttpPost ( "{variableId:guid}" ) ]
80- public IActionResult GlobalVariableSet ( Guid variableId , [ FromBody ] VariableValueBody variableValue )
88+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . BadRequest , ContentTypes . Json ) ]
89+ [ ProducesResponseType ( typeof ( StatusMessageResponseBody ) , ( int ) HttpStatusCode . NotFound , ContentTypes . Json ) ]
90+ [ ProducesResponseType ( typeof ( ServerVariableBase ) , ( int ) HttpStatusCode . OK , ContentTypes . Json ) ]
91+ public IActionResult ServerVariableSet ( Guid variableId , [ FromBody ] VariableValueBody variableValue )
8192 {
8293 if ( variableId == default )
8394 {
@@ -88,17 +99,14 @@ public IActionResult GlobalVariableSet(Guid variableId, [FromBody] VariableValue
8899
89100 if ( variable == null )
90101 {
91- return NotFound ( $@ "No global variable with id '{ variableId } '.") ;
102+ return NotFound ( $@ "No server variable with id '{ variableId } '.") ;
92103 }
93104
94105 var changed = false ;
95- if ( variable . Value != null )
106+ if ( variable . Value != null && variable . Value . Value != variableValue . Value )
96107 {
97- if ( variable . Value . Value != variableValue . Value )
98- {
99- variable . Value . Value = variableValue . Value ;
100- changed = true ;
101- }
108+ variable . Value . Value = variableValue . Value ;
109+ changed = true ;
102110 }
103111
104112 // ReSharper disable once InvertIf
@@ -109,7 +117,8 @@ public IActionResult GlobalVariableSet(Guid variableId, [FromBody] VariableValue
109117 "" ,
110118 variableId . ToString ( )
111119 ) ;
112- DbInterface . UpdatedServerVariables . AddOrUpdate ( variable . Id , variable , ( _ , _ ) => variable ) ;
120+
121+ _ = DbInterface . UpdatedServerVariables . AddOrUpdate ( variable . Id , variable , ( _ , _ ) => variable ) ;
113122 }
114123
115124 return Ok ( variable ) ;
0 commit comments