has_transcript
This commit is contained in:
parent
f005ed445a
commit
495e781ce2
@ -15,6 +15,7 @@ type transcript struct {
|
|||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
CloseReason *string `json:"close_reason"`
|
CloseReason *string `json:"close_reason"`
|
||||||
Rating *uint8 `json:"rating"`
|
Rating *uint8 `json:"rating"`
|
||||||
|
HasTranscript bool `json:"has_transcript"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListTranscripts(ctx *gin.Context) {
|
func ListTranscripts(ctx *gin.Context) {
|
||||||
@ -92,6 +93,7 @@ func ListTranscripts(ctx *gin.Context) {
|
|||||||
transcript := transcript{
|
transcript := transcript{
|
||||||
TicketId: ticket.Id,
|
TicketId: ticket.Id,
|
||||||
Username: usernames[ticket.UserId],
|
Username: usernames[ticket.UserId],
|
||||||
|
HasTranscript: ticket.HasTranscript,
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := ratings[ticket.Id]; ok {
|
if v, ok := ratings[ticket.Id]; ok {
|
||||||
|
82
app/http/endpoints/api/transcripts/listself.go
Normal file
82
app/http/endpoints/api/transcripts/listself.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
dbclient "github.com/TicketsBot/GoPanel/database"
|
||||||
|
"github.com/TicketsBot/GoPanel/rpc/cache"
|
||||||
|
"github.com/TicketsBot/GoPanel/utils"
|
||||||
|
"github.com/TicketsBot/database"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
gdlutils "github.com/rxdn/gdl/utils"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListSelfTranscripts TODO: Give user option to rate ticket
|
||||||
|
func ListSelfTranscripts(ctx *gin.Context) {
|
||||||
|
userId := ctx.Keys["userid"].(uint64)
|
||||||
|
|
||||||
|
page, err := strconv.Atoi(ctx.Query("page"))
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(400, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var offset int
|
||||||
|
if page > 1 {
|
||||||
|
offset = pageLimit * (page - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := database.TicketQueryOptions{
|
||||||
|
UserIds: []uint64{userId},
|
||||||
|
Open: gdlutils.BoolPtr(false),
|
||||||
|
Order: database.OrderTypeDescending,
|
||||||
|
Limit: pageLimit,
|
||||||
|
Offset: offset,
|
||||||
|
}
|
||||||
|
|
||||||
|
tickets, err := dbclient.Client.Tickets.GetByOptions(opts)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type TranscriptData struct {
|
||||||
|
TicketId int `json:"ticket_id"`
|
||||||
|
GuildId uint64 `json:"guild_id"`
|
||||||
|
GuildName string `json:"guild_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Not O(n)
|
||||||
|
data := make([]TranscriptData, len(tickets))
|
||||||
|
|
||||||
|
group, _ := errgroup.WithContext(context.Background())
|
||||||
|
for i, ticket := range tickets {
|
||||||
|
group.Go(func() error {
|
||||||
|
var guildName string
|
||||||
|
{
|
||||||
|
guild, ok := cache.Instance.GetGuild(ticket.GuildId, false)
|
||||||
|
if ok {
|
||||||
|
guildName = guild.Name
|
||||||
|
} else {
|
||||||
|
guildName = "Unknown server"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data[i] = TranscriptData{
|
||||||
|
TicketId: ticket.Id,
|
||||||
|
GuildId: ticket.GuildId,
|
||||||
|
GuildName: guildName,
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := group.Wait(); err != nil {
|
||||||
|
ctx.JSON(500, utils.ErrorJson(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(200, data)
|
||||||
|
}
|
@ -71,7 +71,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td class="reason">{transcript.close_reason || 'No reason specified'}</td>
|
<td class="reason">{transcript.close_reason || 'No reason specified'}</td>
|
||||||
{#if settings.store_transcripts}
|
{#if transcript.has_transcript}
|
||||||
<td>
|
<td>
|
||||||
<Navigate to="{`/manage/${guildId}/transcripts/view/${transcript.ticket_id}`}" styles="link">
|
<Navigate to="{`/manage/${guildId}/transcripts/view/${transcript.ticket_id}`}" styles="link">
|
||||||
<Button>View</Button>
|
<Button>View</Button>
|
||||||
|
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
|
github.com/TicketsBot/archiverclient v0.0.0-20210220155137-a562b2f1bbbb
|
||||||
github.com/TicketsBot/common v0.0.0-20210910205523-7ce93fba6fa5
|
github.com/TicketsBot/common v0.0.0-20210910205523-7ce93fba6fa5
|
||||||
github.com/TicketsBot/database v0.0.0-20211025101648-1c5a53942cbe
|
github.com/TicketsBot/database v0.0.0-20211025111926-e4c1ec293983
|
||||||
github.com/TicketsBot/worker v0.0.0-20210910205947-89f7bd5ccf67
|
github.com/TicketsBot/worker v0.0.0-20210910205947-89f7bd5ccf67
|
||||||
github.com/apex/log v1.1.2
|
github.com/apex/log v1.1.2
|
||||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
|
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -18,6 +18,8 @@ github.com/TicketsBot/database v0.0.0-20211024191932-85d9cf1d71a8 h1:TROAdrUeCjx
|
|||||||
github.com/TicketsBot/database v0.0.0-20211024191932-85d9cf1d71a8/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
github.com/TicketsBot/database v0.0.0-20211024191932-85d9cf1d71a8/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
||||||
github.com/TicketsBot/database v0.0.0-20211025101648-1c5a53942cbe h1:SImaEnLPwW18P016eBpE+kyneb1Nw8qjJfuTn05v34A=
|
github.com/TicketsBot/database v0.0.0-20211025101648-1c5a53942cbe h1:SImaEnLPwW18P016eBpE+kyneb1Nw8qjJfuTn05v34A=
|
||||||
github.com/TicketsBot/database v0.0.0-20211025101648-1c5a53942cbe/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
github.com/TicketsBot/database v0.0.0-20211025101648-1c5a53942cbe/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
||||||
|
github.com/TicketsBot/database v0.0.0-20211025111926-e4c1ec293983 h1:VNP6gNgxQHvHJmVNOk8aQTUtgwDDOLsXgFlQrYc0AgY=
|
||||||
|
github.com/TicketsBot/database v0.0.0-20211025111926-e4c1ec293983/go.mod h1:72oWvH/Gq1iKeXCZhVRZn1JFbNVC5iAgERZWTrEarEo=
|
||||||
github.com/TicketsBot/logarchiver v0.0.0-20200423221245-a3f92edf8c14/go.mod h1:whts8TRxrAF4WuDuEAMllkWA/inKem0NhDEFeyuoOvE=
|
github.com/TicketsBot/logarchiver v0.0.0-20200423221245-a3f92edf8c14/go.mod h1:whts8TRxrAF4WuDuEAMllkWA/inKem0NhDEFeyuoOvE=
|
||||||
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=
|
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261 h1:NHD5GB6cjlkpZFjC76Yli2S63/J2nhr8MuE6KlYJpQM=
|
||||||
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261/go.mod h1:2zPxDAN2TAPpxUPjxszjs3QFKreKrQh5al/R3cMXmYk=
|
github.com/TicketsBot/ttlcache v1.6.1-0.20200405150101-acc18e37b261/go.mod h1:2zPxDAN2TAPpxUPjxszjs3QFKreKrQh5al/R3cMXmYk=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user