|
| 1 | +using System; |
| 2 | +using System.Collections.Concurrent; |
| 3 | +using F18.Common; |
| 4 | +using F18.Models; |
| 5 | +using F18.Presentation; |
| 6 | +using Microsoft.AspNetCore.Http; |
| 7 | + |
| 8 | +namespace F17.Mapper; |
| 9 | + |
| 10 | +public static class F17HttpResponseMapper |
| 11 | +{ |
| 12 | + private static ConcurrentDictionary< |
| 13 | + F18Constant.AppCode, |
| 14 | + Func<F18AppRequestModel, F18AppResponseModel, F18Response> |
| 15 | + > _httpResponseMapper; |
| 16 | + |
| 17 | + private static void Init() |
| 18 | + { |
| 19 | + if (Equals(_httpResponseMapper, null)) |
| 20 | + { |
| 21 | + _httpResponseMapper = new(); |
| 22 | + } |
| 23 | + |
| 24 | + _httpResponseMapper.TryAdd( |
| 25 | + F18Constant.AppCode.SUCCESS, |
| 26 | + (appRequest, appResponse) => |
| 27 | + new() |
| 28 | + { |
| 29 | + AppCode = (int)F18Constant.AppCode.SUCCESS, |
| 30 | + HttpCode = StatusCodes.Status200OK, |
| 31 | + } |
| 32 | + ); |
| 33 | + |
| 34 | + _httpResponseMapper.TryAdd( |
| 35 | + F18Constant.AppCode.TASK_NOT_FOUND, |
| 36 | + (appRequest, appResponse) => F18Constant.DefaultResponse.Http.TASK_NOT_FOUND |
| 37 | + ); |
| 38 | + |
| 39 | + _httpResponseMapper.TryAdd( |
| 40 | + F18Constant.AppCode.SERVER_ERROR, |
| 41 | + (appRequest, appResponse) => F18Constant.DefaultResponse.Http.SERVER_ERROR |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + public static F18Response Get(F18AppRequestModel appRequest, F18AppResponseModel appResponse) |
| 46 | + { |
| 47 | + Init(); |
| 48 | + |
| 49 | + return _httpResponseMapper[appResponse.AppCode](appRequest, appResponse); |
| 50 | + } |
| 51 | +} |
0 commit comments