-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
197 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Theresa3rd-Bot/TheresaBot.Main/Controller/DictionaryController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using TheresaBot.Main.Datas; | ||
using TheresaBot.Main.Helper; | ||
using TheresaBot.Main.Model.DTO; | ||
using TheresaBot.Main.Model.Result; | ||
using TheresaBot.Main.Model.VO; | ||
using TheresaBot.Main.Services; | ||
using TheresaBot.Main.Type; | ||
|
||
namespace TheresaBot.Main.Controller | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class DictionaryController : BaseController | ||
{ | ||
private DictionaryService dictionaryService; | ||
|
||
public DictionaryController() | ||
{ | ||
dictionaryService = new DictionaryService(); | ||
} | ||
|
||
[HttpGet] | ||
[Authorize] | ||
[Route("list")] | ||
public ApiResult GetDictionary() | ||
{ | ||
var datas = dictionaryService.GetDictionary(); | ||
var dataInfos = datas.Select(o => new DictionaryVo | ||
{ | ||
Id = o.Id, | ||
Words = o.Words, | ||
WordType = o.WordType, | ||
SubType = o.SubType, | ||
CreateAt = o.CreateDate.ToTimeStamp() | ||
}).ToList(); | ||
return ApiResult.Success(dataInfos); | ||
} | ||
|
||
[HttpPost] | ||
[Authorize] | ||
[Route("add")] | ||
public ApiResult AddDictionary([FromBody] AddDictionaryDto datas) | ||
{ | ||
var words = datas.Words ?? new(); | ||
if (words.Count == 0) return ApiResult.ParamError; | ||
dictionaryService.InsertDictionary(datas.WordType, words, datas.SubType); | ||
return ApiResult.Success(); | ||
} | ||
|
||
[HttpPost] | ||
[Authorize] | ||
[Route("del")] | ||
public ApiResult DelDictionary(int[] ids) | ||
{ | ||
dictionaryService.DelByIds(ids); | ||
return ApiResult.Success(); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Theresa3rd-Bot/TheresaBot.Main/Model/DTO/AddDictionaryDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using TheresaBot.Main.Type; | ||
|
||
namespace TheresaBot.Main.Model.DTO | ||
{ | ||
public record AddDictionaryDto | ||
{ | ||
public List<string> Words { get; set; } | ||
|
||
public DictionaryType WordType { get; set; } | ||
|
||
public int SubType { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using TheresaBot.Main.Type; | ||
|
||
namespace TheresaBot.Main.Model.VO | ||
{ | ||
public record DictionaryVo | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Words { get; set; } | ||
|
||
public long CreateAt { get; set; } | ||
|
||
public DictionaryType WordType { get; set; } | ||
|
||
public int SubType { get; set; } | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
namespace TheresaBot.Main.Model.VO | ||
using TheresaBot.Main.Helper; | ||
|
||
namespace TheresaBot.Main.Model.VO | ||
{ | ||
public record OptionVo | ||
{ | ||
public int Value { get; set; } | ||
|
||
public string Label { get; set; } | ||
|
||
public List<OptionVo> SubOptions { get; set; } = new(); | ||
|
||
public OptionVo(int value, string label) | ||
{ | ||
Value = value; | ||
Label = label; | ||
} | ||
|
||
public void AddSubOptions(Dictionary<int, string> options) | ||
{ | ||
SubOptions.AddRange(options.ToOptionList()); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...a3rd-Bot/TheresaBot.Main/Type/WordType.cs → ...ot/TheresaBot.Main/Type/DictionaryType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
namespace TheresaBot.Main.Type | ||
{ | ||
public enum WordType | ||
public enum DictionaryType | ||
{ | ||
Other = 0, | ||
WordCloud = 1, | ||
PixivTag = 2 | ||
WordCloud = 1 | ||
} | ||
} |
Oops, something went wrong.