version up

This commit is contained in:
2023-07-31 17:11:39 +08:00
parent befbc7fc9b
commit 8419c9d389
41 changed files with 1053 additions and 286 deletions

View File

@ -1,7 +1,6 @@
using Blahblah.FlowerStory.Server.Data;
using Blahblah.FlowerStory.Server.Data.Model;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Security.Cryptography;
using System.Text;
@ -55,10 +54,6 @@ public abstract partial class BaseController : ControllerBase
/// 管理员用户
/// </summary>
protected const int UserAdmin = 99;
/// <summary>
/// 封面事件
/// </summary>
protected const int EventCover = 0;
/// <summary>
/// 数据库对象

View File

@ -232,9 +232,7 @@ public class FlowerApiController : BaseController
{
foreach (var f in flowers)
{
f.Photos = database.Photos.Where(p =>
database.Records.Any(r =>
r.FlowerId == f.Id && r.EventId == EventCover && r.Id == p.RecordId)).ToList();
f.Photos = database.Photos.Where(p => p.FlowerId == f.Id && p.RecordId == null).ToList();
foreach (var photo in f.Photos)
{
photo.Url = $"photo/flower/{f.Id}/{photo.Path}";
@ -303,9 +301,7 @@ public class FlowerApiController : BaseController
if (includePhoto == true)
{
item.Photos = database.Photos.Where(p =>
database.Records.Any(r =>
r.FlowerId == item.Id && r.EventId == EventCover && r.Id == p.RecordId)).ToList();
item.Photos = database.Photos.Where(p => p.FlowerId == item.Id && p.RecordId == null).ToList();
foreach (var photo in item.Photos)
{
photo.Url = $"photo/flower/{item.Id}/{photo.Path}";
@ -487,25 +483,6 @@ public class FlowerApiController : BaseController
return BadRequest();
}
var record = database.Records.SingleOrDefault(r => r.FlowerId == item.Id && r.EventId == EventCover);
if (record == null)
{
record = new RecordItem
{
OwnerId = user.Id,
FlowerId = item.Id,
EventId = EventCover,
DateUnixTime = now,
ByUserId = user.Id,
ByUserName = user.Name,
//Memo = flower.Memo,
Latitude = flower.Latitude,
Longitude = flower.Longitude
};
database.Records.Add(record);
}
SaveDatabase();
try
{
await ExecuteTransaction(async token =>
@ -514,7 +491,6 @@ public class FlowerApiController : BaseController
{
OwnerId = user.Id,
FlowerId = item.Id,
RecordId = record.Id,
FileType = file.FileType,
FileName = file.Filename,
Path = file.Path,
@ -538,27 +514,7 @@ public class FlowerApiController : BaseController
var photo = database.Photos.SingleOrDefault(p => p.Id == coverId && p.OwnerId == user.Id);
if (photo != null)
{
var record = database.Records.SingleOrDefault(r => r.FlowerId == item.Id && r.EventId == EventCover);
if (record == null)
{
record = new RecordItem
{
OwnerId = user.Id,
FlowerId = item.Id,
EventId = EventCover,
DateUnixTime = now,
ByUserId = user.Id,
ByUserName = user.Name,
//Memo = flower.Memo,
Latitude = flower.Latitude,
Longitude = flower.Longitude
};
database.Records.Add(record);
SaveDatabase();
}
photo.FlowerId = item.Id;
photo.RecordId = record.Id;
SaveDatabase();
try
@ -737,33 +693,13 @@ public class FlowerApiController : BaseController
}
var now = user.ActiveDateUnixTime ?? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var record = database.Records.SingleOrDefault(r => r.FlowerId == update.Id && r.EventId == EventCover);
if (record == null)
var photos = database.Photos.Where(p => p.FlowerId == update.Id && p.RecordId == null).ToList();
if (photos.Count > 0)
{
record = new RecordItem
database.Photos.Where(p => p.RecordId == null).ExecuteDelete();
foreach (var photo in photos)
{
OwnerId = user.Id,
FlowerId = update.Id,
EventId = EventCover,
DateUnixTime = now,
ByUserId = user.Id,
ByUserName = user.Name,
//Memo = flower.Memo,
Latitude = flower.Latitude,
Longitude = flower.Longitude
};
database.Records.Add(record);
}
else
{
var photos = database.Photos.Where(p => p.RecordId == record.Id).ToList();
if (photos.Count > 0)
{
database.Photos.Where(p => p.RecordId == record.Id).ExecuteDelete();
foreach (var photo in photos)
{
DeleteFile(update.Id, photo.Path);
}
DeleteFile(update.Id, photo.Path);
}
}
SaveDatabase();
@ -776,7 +712,6 @@ public class FlowerApiController : BaseController
{
OwnerId = user.Id,
FlowerId = update.Id,
RecordId = record.Id,
FileType = file.FileType,
FileName = file.Filename,
Path = file.Path,
@ -865,23 +800,6 @@ public class FlowerApiController : BaseController
}
var now = user.ActiveDateUnixTime ?? DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var record = database.Records.SingleOrDefault(r => r.FlowerId == param.Id && r.EventId == EventCover);
if (record == null)
{
record = new RecordItem
{
OwnerId = user.Id,
FlowerId = param.Id,
EventId = EventCover,
DateUnixTime = now,
ByUserId = user.Id,
ByUserName = user.Name,
//Memo = "",
Latitude = param.Latitude,
Longitude = param.Longitude
};
database.Records.Add(record);
}
flower.Latitude = param.Latitude;
flower.Longitude = param.Longitude;
@ -895,7 +813,6 @@ public class FlowerApiController : BaseController
{
OwnerId = user.Id,
FlowerId = param.Id,
RecordId = record.Id,
FileType = file.FileType,
FileName = file.Filename,
Path = file.Path,
@ -934,7 +851,7 @@ public class FlowerApiController : BaseController
///
/// </remarks>
/// <param name="id">花草唯一 id</param>
/// <param name="eventId">事件类型 id, 0 为封面</param>
/// <param name="eventId">事件类型 id</param>
/// <returns>验证通过则返回花草特定类型事件的照片列表</returns>
/// <response code="200">返回花草特定类型事件的照片列表</response>
/// <response code="401">未找到登录会话或已过期</response>
@ -948,7 +865,7 @@ public class FlowerApiController : BaseController
[ProducesErrorResponseType(typeof(ErrorResponse))]
[HttpGet]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public ActionResult<PhotoItem[]> GetCovers([Required][FromQuery] int id, [FromQuery(Name = "eid")] int? eventId = 0)
public ActionResult<PhotoItem[]> GetPhotos([Required][FromQuery] int id, [FromQuery(Name = "eid")] int? eventId = 0)
{
var (result, user) = CheckPermission();
if (result != null)

View File

@ -34,19 +34,19 @@ public partial class UserApiController : BaseController
/// </remarks>
/// <param name="login">登录参数</param>
/// <returns>成功登录则返回自定义认证头</returns>
/// <response code="204">返回自定义认证头</response>
/// <response code="200">返回用户对象,返回头中包含认证信息</response>
/// <response code="401">认证失败</response>
/// <response code="404">未找到用户</response>
/// <response code="500">服务器错误</response>
[Route("auth", Name = "authenticate")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[ProducesErrorResponseType(typeof(ErrorResponse))]
[HttpPost]
[Consumes("application/json")]
public ActionResult Authenticate([FromBody] LoginParamter login)
public ActionResult<UserItem> Authenticate([FromBody] LoginParamter login)
{
#if DEBUG
logger?.LogInformation("user \"{user}\" try to login with password \"{password}\"", login.Id, login.Password);
@ -100,7 +100,7 @@ public partial class UserApiController : BaseController
SaveDatabase();
Response.Headers.Add(AuthHeader, token.Id);
return NoContent();
return Ok(user);
}
/// <summary>

View File

@ -11,7 +11,7 @@ public class Program
/// <inheritdoc/>
public const string ProjectName = "Flower Story";
/// <inheritdoc/>
public const string Version = "0.7.727";
public const string Version = "0.7.731";
/// <inheritdoc/>
public static void Main(string[] args)