Skip to content

Commit

Permalink
feat: add api subject reviews (#831)
Browse files Browse the repository at this point in the history
Co-authored-by: Trim21 <[email protected]>
  • Loading branch information
everpcpc and trim21 authored Dec 15, 2024
1 parent 2172c82 commit f1d64a9
Show file tree
Hide file tree
Showing 8 changed files with 418 additions and 3 deletions.
4 changes: 4 additions & 0 deletions drizzle/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ISubject = typeof schema.chiiSubjects.$inferSelect;
export type ISubjectFields = typeof schema.chiiSubjectFields.$inferSelect;
export type ISubjectInterest = typeof schema.chiiSubjectInterests.$inferSelect;
export type ISubjectRelation = typeof schema.chiiSubjectRelations.$inferSelect;
export type ISubjectRelatedBlog = typeof schema.chiiSubjectRelatedBlogs.$inferSelect;
export type ISubjectTopic = typeof schema.chiiSubjectTopics.$inferSelect;
export type ISubjectPost = typeof schema.chiiSubjectPosts.$inferSelect;
export type ISubjectEpStatus = typeof schema.chiiEpStatus.$inferSelect;
Expand All @@ -29,5 +30,8 @@ export type IPersonCollect = typeof schema.chiiPersonCollects.$inferSelect;
export type IIndex = typeof schema.chiiIndexes.$inferSelect;
export type IIndexCollect = typeof schema.chiiIndexCollects.$inferSelect;

export type IBlogEntry = typeof schema.chiiBlogEntries.$inferSelect;
export type IBlogPhoto = typeof schema.chiiBlogPhotos.$inferSelect;

export type ITimeline = typeof schema.chiiTimeline.$inferSelect;
export type ITimelineComment = typeof schema.chiiTimelineComments.$inferSelect;
87 changes: 87 additions & 0 deletions drizzle/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,26 @@ export const chiiSubjectInterests = mysqlTable(
},
);

export const chiiSubjectRelatedBlogs = mysqlTable(
'chii_subject_related_blog',
{
id: mediumint('srb_id').autoincrement().notNull(),
uid: mediumint('srb_uid').notNull(),
subjectID: mediumint('srb_subject_id').notNull(),
entryID: mediumint('srb_entry_id').notNull(), // blog etry id
spoiler: mediumint('srb_spoiler').notNull(),
like: mediumint('srb_like').notNull(),
dislike: mediumint('srb_dislike').notNull(),
createdAt: int('srb_dateline').notNull(),
},
(table) => {
return {
srbUid: index('srb_uid').on(table.uid, table.subjectID, table.entryID),
subjectRelated: index('subject_related').on(table.subjectID),
};
},
);

export const chiiSubjectPosts = mysqlTable(
'chii_subject_posts',
{
Expand Down Expand Up @@ -1184,3 +1204,70 @@ export const chiiUsergroup = mysqlTable('chii_usergroup', {
perm: mediumtext('usr_grp_perm').notNull(),
updatedAt: int('usr_grp_dateline').notNull(),
});

export const chiiBlogComments = mysqlTable(
'chii_blog_comments',
{
id: mediumint('blg_pst_id').autoincrement().notNull(),
mid: mediumint('blg_pst_mid').notNull(), // blog entry id
uid: mediumint('blg_pst_uid').notNull(),
related: mediumint('blg_pst_related').notNull(),
updatedAt: int('blg_pst_dateline').notNull(),
content: mediumtext('blg_pst_content').notNull(),
},
(table) => {
return {
blgCmtEid: index('blg_cmt_eid').on(table.mid),
blgCmtUid: index('blg_cmt_uid').on(table.uid),
blgPstRelated: index('blg_pst_related').on(table.related),
};
},
);

export const chiiBlogEntries = mysqlTable(
'chii_blog_entry',
{
id: mediumint('entry_id').autoincrement().notNull(),
type: smallint('entry_type').notNull(),
uid: mediumint('entry_uid').notNull(),
title: varchar('entry_title', { length: 80 }).notNull(),
icon: varchar('entry_icon', { length: 255 }).notNull(),
content: mediumtext('entry_content').notNull(),
tags: mediumtext('entry_tags').notNull(),
views: mediumint('entry_views').notNull(),
replies: mediumint('entry_replies').notNull(),
createdAt: int('entry_dateline').notNull(),
updatedAt: int('entry_lastpost').notNull(),
like: int('entry_like').notNull(), // 未使用
dislike: int('entry_dislike').notNull(), // 未使用
noreply: smallint('entry_noreply').notNull(),
related: tinyint('entry_related').default(0).notNull(),
public: customBoolean('entry_public').default(true).notNull(),
},
(table) => {
return {
entryType: index('entry_type').on(table.type, table.uid, table.noreply),
entryRelate: index('entry_relate').on(table.related),
entryPublic: index('entry_public').on(table.public),
entryDateline: index('entry_dateline').on(table.createdAt),
entryUid: index('entry_uid').on(table.uid, table.public),
};
},
);

export const chiiBlogPhotos = mysqlTable(
'chii_blog_photo',
{
id: mediumint('photo_id').autoincrement().notNull(),
eid: mediumint('photo_eid').notNull(),
uid: mediumint('photo_uid').notNull(),
target: varchar('photo_target', { length: 255 }).notNull(),
vote: mediumint('photo_vote').notNull(),
createdAt: int('photo_dateline').notNull(),
},
(table) => {
return {
photoEid: index('photo_eid').on(table.eid),
};
},
);
43 changes: 43 additions & 0 deletions lib/types/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,37 @@ export function toSubjectStaffPosition(relation: orm.IPersonSubject): res.ISubje
};
}

export function toBlogEntry(entry: orm.IBlogEntry, user: orm.IUser): res.IBlogEntry {
return {
id: entry.id,
type: entry.type,
user: toSlimUser(user),
title: entry.title,
icon: entry.icon,
content: entry.content,
tags: splitTags(entry.tags),
views: entry.views,
replies: entry.replies,
createdAt: entry.createdAt,
updatedAt: entry.updatedAt,
noreply: entry.noreply,
related: entry.related,
public: entry.public,
};
}

export function toSlimBlogEntry(entry: orm.IBlogEntry): res.ISlimBlogEntry {
return {
id: entry.id,
type: entry.type,
title: entry.title,
summary: entry.content.slice(0, 120),
replies: entry.replies,
createdAt: entry.createdAt,
updatedAt: entry.updatedAt,
};
}

export function toSubjectComment(
interest: orm.ISubjectInterest,
user: orm.IUser,
Expand All @@ -340,6 +371,18 @@ export function toSubjectComment(
};
}

export function toSubjectReview(
review: orm.ISubjectRelatedBlog,
blog: orm.IBlogEntry,
user: orm.IUser,
): res.ISubjectReview {
return {
id: review.id,
user: toSlimUser(user),
entry: toSlimBlogEntry(blog),
};
}

export function toEpisode(episode: orm.IEpisode): res.IEpisode {
return {
id: episode.id,
Expand Down
45 changes: 45 additions & 0 deletions lib/types/res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,41 @@ export const SlimPerson = t.Object(
},
);

export type IBlogEntry = Static<typeof BlogEntry>;
export const BlogEntry = t.Object(
{
id: t.Integer(),
type: t.Integer(),
user: t.Ref(SlimUser),
title: t.String(),
icon: t.String(),
content: t.String(),
tags: t.Array(t.String()),
views: t.Integer(),
replies: t.Integer(),
createdAt: t.Integer(),
updatedAt: t.Integer(),
noreply: t.Integer(),
related: t.Integer(),
public: t.Boolean(),
},
{ $id: 'BlogEntry', title: 'BlogEntry' },
);

export type ISlimBlogEntry = Static<typeof SlimBlogEntry>;
export const SlimBlogEntry = t.Object(
{
id: t.Integer(),
type: t.Integer(),
title: t.String(),
summary: t.String(),
replies: t.Integer(),
createdAt: t.Integer(),
updatedAt: t.Integer(),
},
{ $id: 'SlimBlogEntry', title: 'SlimBlogEntry' },
);

export type ISubjectComment = Static<typeof SubjectComment>;
export const SubjectComment = t.Object(
{
Expand All @@ -429,6 +464,16 @@ export const SubjectComment = t.Object(
{ $id: 'SubjectComment', title: 'SubjectComment' },
);

export type ISubjectReview = Static<typeof SubjectReview>;
export const SubjectReview = t.Object(
{
id: t.Integer(),
user: t.Ref(SlimUser),
entry: t.Ref(SlimBlogEntry),
},
{ $id: 'SubjectReview', title: 'SubjectReview' },
);

export type ISubjectRelation = Static<typeof SubjectRelation>;
export const SubjectRelation = t.Object(
{
Expand Down
Loading

0 comments on commit f1d64a9

Please sign in to comment.