180 lines
6.3 KiB
C#
180 lines
6.3 KiB
C#
using ServerCommon;
|
|
using ServerCommon.UGQ.Models;
|
|
using UGQApiServer.Storage;
|
|
using UGQApiServer.UGQData;
|
|
using UGQDataAccess.Repository.Models;
|
|
using UGQDatabase.Models;
|
|
|
|
namespace UGQApiServer.Converter;
|
|
|
|
|
|
public enum ImageUrlType
|
|
{
|
|
TitleImg,
|
|
BannerImg,
|
|
}
|
|
|
|
public static class InGameConverter
|
|
{
|
|
static IStorageService _storageService = null!;
|
|
static UGQMetaData _ugqMetadata = null!;
|
|
|
|
public static void init(IStorageService storageService, UGQMetaData ugqMetadata)
|
|
{
|
|
_storageService = storageService;
|
|
_ugqMetadata = ugqMetadata;
|
|
}
|
|
|
|
|
|
static BoolType ToProto(this bool value)
|
|
{
|
|
return (value == true) ? BoolType.True : BoolType.False;
|
|
}
|
|
|
|
public static string GetLangText(this TextEntity entity, LangEnum langEnum)
|
|
{
|
|
string text = string.Empty;
|
|
switch(langEnum)
|
|
{
|
|
case LangEnum.Ko:
|
|
text = entity.Kr;
|
|
break;
|
|
case LangEnum.Jp:
|
|
text = entity.Jp;
|
|
break;
|
|
case LangEnum.En:
|
|
text = entity.En;
|
|
break;
|
|
}
|
|
|
|
if (text == string.Empty)
|
|
text = entity.En;
|
|
|
|
return text;
|
|
}
|
|
|
|
public static UgqQuestInTestState ToProtoUgqQuestInTestState(this QuestContentEntity result, LangEnum langEnum, ImageUrlType ImgUrlType)
|
|
{
|
|
string ImagePath = "";
|
|
if (ImgUrlType == ImageUrlType.TitleImg)
|
|
ImagePath = _storageService.fileUrl(result.TitleImagePath);
|
|
else if (ImgUrlType == ImageUrlType.BannerImg)
|
|
ImagePath = _storageService.fileUrl(result.BannerImagePath);
|
|
|
|
return new UgqQuestInTestState
|
|
{
|
|
//ComposedQuestId = result.QuestId << 32 | result.Revision,
|
|
ComposedQuestId = QuestHelper.convertQuestIdAndRevisionToUgqQuestId((UInt32)result.QuestId, (UInt32)result.Revision),
|
|
Title = result.Title.GetLangText(langEnum),
|
|
TitleImagePath = ImagePath,
|
|
};
|
|
}
|
|
|
|
|
|
public static UgqBoardSearchResult ToProto(this QuestBoardQueryResult result, LangEnum langEnum, ImageUrlType ImgUrlType)
|
|
{
|
|
return new UgqBoardSearchResult
|
|
{
|
|
PageNumber = result.PageNumber,
|
|
PageSize = result.PageSize,
|
|
TotalPages = result.TotalPages,
|
|
Items = { result.Items.Select(x => x.ToProto(langEnum, ImgUrlType)).ToList() }
|
|
};
|
|
}
|
|
|
|
public static UgqBoardSportlightResult ToProto(this QuestBoardSportlightQueryResult result, LangEnum langEnum, ImageUrlType ImgUrlType)
|
|
{
|
|
return new UgqBoardSportlightResult
|
|
{
|
|
MostLiked = new DateRangeUgqBoardItem
|
|
{
|
|
Today = result.MostLiked.Today?.ToProto(langEnum, ImgUrlType),
|
|
ThisWeek = result.MostLiked.ThisWeek?.ToProto(langEnum, ImgUrlType),
|
|
ThisMonth = result.MostLiked.ThisMonth?.ToProto(langEnum, ImgUrlType),
|
|
},
|
|
MostBookmarked = new DateRangeUgqBoardItem
|
|
{
|
|
Today = result.MostBookmarked.Today?.ToProto(langEnum, ImgUrlType),
|
|
ThisWeek = result.MostBookmarked.ThisWeek?.ToProto(langEnum, ImgUrlType),
|
|
ThisMonth = result.MostBookmarked.ThisMonth?.ToProto(langEnum, ImgUrlType),
|
|
},
|
|
};
|
|
}
|
|
|
|
|
|
public static UgqBoardItem ToProto(this QuestBoardItemResult result, LangEnum langEnum, ImageUrlType ImgUrlType)
|
|
{
|
|
var compoesed_quest_id = QuestHelper.convertQuestIdAndRevisionToUgqQuestId((UInt32)result.QuestId, (UInt32)result.Revision);
|
|
string ImagePath = "";
|
|
if (ImgUrlType == ImageUrlType.TitleImg)
|
|
ImagePath = _storageService.fileUrl(result.TitleImagePath);
|
|
else if (ImgUrlType == ImageUrlType.BannerImg)
|
|
ImagePath = _storageService.fileUrl(result.BannerImagePath);
|
|
|
|
return new UgqBoardItem
|
|
{
|
|
//ComposedQuestId = result.QuestId << 32 | result.Revision,
|
|
ComposedQuestId = compoesed_quest_id,
|
|
Title = result.Title.GetLangText(langEnum),
|
|
TitleImagePath = ImagePath,
|
|
LikeCount = result.LikeCount,
|
|
BookmarkCount = result.BookmarkCount,
|
|
Author = result.Author ?? "",
|
|
GradeType = result.GradeType,
|
|
Cost = result.Cost,
|
|
};
|
|
}
|
|
|
|
public static UgqBoardItemDetail ToProto(this QuestBoardDetailItemResult result, LangEnum langEnum, ImageUrlType ImgUrlType)
|
|
{
|
|
string beaconName = "";
|
|
|
|
if (result.BeaconId != 0)
|
|
beaconName = _ugqMetadata.getBeaconName((int)result.BeaconId, langEnum);
|
|
else if (result.UgcBeaconNickname != null)
|
|
beaconName = result.UgcBeaconNickname;
|
|
|
|
string ImagePath = "";
|
|
if (ImgUrlType == ImageUrlType.TitleImg)
|
|
ImagePath = _storageService.fileUrl(result.TitleImagePath);
|
|
else if (ImgUrlType == ImageUrlType.BannerImg)
|
|
ImagePath = _storageService.fileUrl(result.BannerImagePath);
|
|
|
|
var compoesed_quest_id = QuestHelper.convertQuestIdAndRevisionToUgqQuestId((UInt32)result.QuestId, (UInt32)result.Revision);
|
|
return new UgqBoardItemDetail
|
|
{
|
|
ComposedQuestId = compoesed_quest_id,
|
|
Title = result.Title.GetLangText(langEnum),
|
|
TitleImagePath = ImagePath,
|
|
LikeCount = result.LikeCount,
|
|
BookmarkCount = result.BookmarkCount,
|
|
AcceptCount = result.QuestAcceptedCount,
|
|
CompleteCount = result.QuestCompletedCount,
|
|
Author = result.Author ?? "",
|
|
Description = result.Description.GetLangText(langEnum),
|
|
Langs = { ConverterCommon.buildLanguages(result.Title) },
|
|
Beacon = beaconName,
|
|
Liked = result.Liked.ToProto(),
|
|
Bookmarked = result.Bookmarked.ToProto(),
|
|
GradeType = result.GradeType,
|
|
Cost = result.Cost,
|
|
};
|
|
}
|
|
|
|
public static GameQuestDataSimple ToSimpleDTO(this GameQuestDataEntity entity)
|
|
{
|
|
return new GameQuestDataSimple
|
|
{
|
|
QuestId = entity.QuestId,
|
|
Revision = entity.Revision,
|
|
UserGuid = entity.UserGuid,
|
|
Author = entity.Author ?? "",
|
|
Title = entity.Title,
|
|
GradeType = entity.GradeType,
|
|
State = entity.State,
|
|
Cost = entity.Cost,
|
|
Shutdown = entity.Shutdown,
|
|
};
|
|
}
|
|
}
|