diff --git a/Server/Controller/EventApiController.cs b/Server/Controller/EventApiController.cs index a44d86c..54e23c2 100644 --- a/Server/Controller/EventApiController.cs +++ b/Server/Controller/EventApiController.cs @@ -116,7 +116,14 @@ public class EventApiController : BaseController if (includePhoto == true) { - records = records.Include(r => r.Photos); + foreach (var r in records) + { + r.Photos = database.Photos.Where(p => p.RecordId == r.Id).ToList(); + foreach (var photo in r.Photos) + { + photo.Url = $"photo/flower/{r.FlowerId}/{photo.Path}?thumb=1"; + } + } } var array = records.ToArray(); @@ -131,6 +138,70 @@ public class EventApiController : BaseController return Ok(array); } + /// + /// 查询事件 + /// + /// + /// 请求示例: + /// + /// GET /api/event/get + /// Authorization: authorization id + /// + /// 参数: + /// + /// id: int + /// photo: bool? + /// + /// + /// 事件唯一 id + /// 是否包含图片 + /// 会话有效则返回查询到的事件对象 + /// 返回查询到的事件对象 + /// 未找到登录会话或已过期 + /// 用户已禁用 + /// 未找到关联用户或者未找到事件 + [Route("get", Name = "getEvent")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesErrorResponseType(typeof(ErrorResponse))] + [HttpGet] + [ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)] + public ActionResult GetEvent( + [FromQuery][Required] int id, + [FromQuery(Name = "photo")] bool? includePhoto) + { + var (result, user) = CheckPermission(); + if (result != null) + { + return result; + } + if (user == null) + { + return NotFound(); + } + + SaveDatabase(); + + var item = database.Records.Find(id); + if (item == null) + { + return NotFound($"Event id {id} not found"); + } + + if (includePhoto == true) + { + item.Photos = database.Photos.Where(p => p.RecordId == item.Id).ToList(); + foreach (var photo in item.Photos) + { + photo.Url = $"photo/flower/{item.FlowerId}/{photo.Path}"; + } + } + + return Ok(item); + } + /// /// 移除用户的事件 ///