Key changes include:
- **Architectural Refactoring (CQRS/DTOs):** Refactored the `work` and `translation` application services to use Data Transfer Objects (DTOs) for query responses. This separates the domain layer from the API layer, improving maintainability and performance.
- **Implemented Core Business Logic:** Implemented the `AnalyzeWork` command, which was previously a stub. This command now performs linguistic analysis on works and translations by calling the analytics service.
- **Dependency Injection Improvements:**
- Refactored the configuration loading in `internal/platform/config/config.go` to use a local `viper` instance, removing the reliance on a global singleton.
- Injected the `analytics.Service` into the `work.Service` to support the `AnalyzeWork` command.
- **Comprehensive Documentation:**
- Created a new root `README.md` with a project overview, setup instructions, and architectural principles.
- Added detailed `README.md` files to key packages (`api`, `analytics`, `auth`, `work`, `db`) to document their purpose and usage.
- **Improved Test Coverage:**
- Added new unit tests for the refactored `work` and `translation` query handlers.
- Added a new test suite for the `translation` queries, which were previously untested.
- Added tests for the new `AnalyzeWork` command.
- Fixed numerous compilation errors in the test suites caused by the refactoring.
|
||
|---|---|---|
| .. | ||
| .keep | ||
| README.md | ||
Tercul API Documentation
This document provides comprehensive documentation for the Tercul GraphQL API. It is designed to give developers all the information they need to interact with the platform's data and services.
Table of Contents
Introduction
The Tercul API is a GraphQL-based service that exposes the full range of the platform's literary and social data. It allows for querying works, translations, authors, and user data, as well as performing actions such as creating content, liking, and commenting.
Authentication
Most mutations and some queries require authentication. To authenticate, you must first use the login mutation to receive a JWT. This token must then be included in the Authorization header of subsequent requests as a Bearer token.
Example Header:
Authorization: Bearer <your_jwt_token>
Queries
This section details all available queries.
Work Queries
work(id: ID!): Work: Retrieves a single work by its unique ID.works(limit: Int, offset: Int, language: String, authorId: ID, categoryId: ID, tagId: ID, search: String): [Work!]!: Retrieves a list of works with optional filters and pagination.
Translation Queries
translation(id: ID!): Translation: Retrieves a single translation by its unique ID.translations(workId: ID!, language: String, limit: Int, offset: Int): [Translation!]!: Retrieves a list of translations for a given work.
Book Queries
book(id: ID!): Book: Retrieves a single book by ID.books(limit: Int, offset: Int): [Book!]!: Retrieves a list of all books.
Author Queries
author(id: ID!): Author: Retrieves a single author by ID.authors(limit: Int, offset: Int, search: String, countryId: ID): [Author!]!: Retrieves a list of authors with optional filters.
User Queries
user(id: ID!): User: Retrieves a single user by ID.userByEmail(email: String!): User: Retrieves a single user by email address.userByUsername(username: String!): User: Retrieves a single user by username.users(limit: Int, offset: Int, role: UserRole): [User!]!: Retrieves a list of users, with optional role filter.me: User: Retrieves the currently authenticated user.userProfile(userId: ID!): UserProfile: Retrieves the profile for a given user.
Collection Queries
collection(id: ID!): Collection: Retrieves a single collection by ID.collections(userId: ID, limit: Int, offset: Int): [Collection!]!: Retrieves a list of collections, optionally filtered by user.
Tag & Category Queries
tag(id: ID!): Tag: Retrieves a single tag by ID.tags(limit: Int, offset: Int): [Tag!]!: Retrieves a list of all tags.category(id: ID!): Category: Retrieves a single category by ID.categories(limit: Int, offset: Int): [Category!]!: Retrieves a list of all categories.
Comment Queries
comment(id: ID!): Comment: Retrieves a single comment by ID.comments(workId: ID, translationId: ID, userId: ID, limit: Int, offset: Int): [Comment!]!: Retrieves a list of comments with optional filters.
Utility Queries
search(query: String!, limit: Int, offset: Int, filters: SearchFilters): SearchResults!: Performs a sitewide search across works, translations, and authors.trendingWorks(timePeriod: String, limit: Int): [Work!]!: Returns a list of works with the highest engagement.timePeriodcan be "daily", "weekly", or "monthly".
Mutations
This section details all available mutations for creating, updating, and deleting data.
Authentication
register(input: RegisterInput!): AuthPayload!: Creates a new user account.login(input: LoginInput!): AuthPayload!: Authenticates a user and returns a JWT.logout: Boolean!: Logs out the currently authenticated user.refreshToken: AuthPayload!: Issues a new JWT for an active session.forgotPassword(email: String!): Boolean!: Initiates the password reset process for a user.resetPassword(token: String!, newPassword: String!): Boolean!: Resets a user's password using a valid token.verifyEmail(token: String!): Boolean!: Verifies a user's email address using a token.resendVerificationEmail(email: String!): Boolean!: Resends the email verification link.
User & Profile
updateUser(id: ID!, input: UserInput!): User!: Updates a user's details (Admin).deleteUser(id: ID!): Boolean!: Deletes a user account (Admin).updateProfile(input: UserInput!): User!: Allows a user to update their own profile information.changePassword(currentPassword: String!, newPassword: String!): Boolean!: Allows an authenticated user to change their password.
Work
createWork(input: WorkInput!): Work!: Creates a new work.updateWork(id: ID!, input: WorkInput!): Work!: Updates an existing work.deleteWork(id: ID!): Boolean!: Deletes a work.
Translation
createTranslation(input: TranslationInput!): Translation!: Creates a new translation for a work.updateTranslation(id: ID!, input: TranslationInput!): Translation!: Updates an existing translation.deleteTranslation(id: ID!): Boolean!: Deletes a translation.
Book
createBook(input: BookInput!): Book!: Creates a new book.updateBook(id: ID!, input: BookInput!): Book!: Updates an existing book.deleteBook(id: ID!): Boolean!: Deletes a book.
Author
createAuthor(input: AuthorInput!): Author!: Creates a new author.updateAuthor(id: ID!, input: AuthorInput!): Author!: Updates an existing author.deleteAuthor(id: ID!): Boolean!: Deletes an author.
Collection
createCollection(input: CollectionInput!): Collection!: Creates a new collection.updateCollection(id: ID!, input: CollectionInput!): Collection!: Updates an existing collection.deleteCollection(id: ID!): Boolean!: Deletes a collection.addWorkToCollection(collectionId: ID!, workId: ID!): Collection!: Adds a work to a collection.removeWorkFromCollection(collectionId: ID!, workId: ID!): Collection!: Removes a work from a collection.
Comment
createComment(input: CommentInput!): Comment!: Adds a comment to a work or translation.updateComment(id: ID!, input: CommentInput!): Comment!: Updates an existing comment.deleteComment(id: ID!): Boolean!: Deletes a comment.
Like
createLike(input: LikeInput!): Like!: Adds a like to a work, translation, or comment.deleteLike(id: ID!): Boolean!: Removes a previously added like.
Bookmark
createBookmark(input: BookmarkInput!): Bookmark!: Creates a bookmark for a work.deleteBookmark(id: ID!): Boolean!: Deletes a bookmark.
Contribution
createContribution(input: ContributionInput!): Contribution!: Creates a new contribution.updateContribution(id: ID!, input: ContributionInput!): Contribution!: Updates a contribution.deleteContribution(id: ID!): Boolean!: Deletes a contribution.reviewContribution(id: ID!, status: ContributionStatus!, feedback: String): Contribution!: Reviews a contribution, setting its status and providing feedback.
Core Types
This section describes the main data structures in the API.
Work: Represents a literary work. Contains fields for content, metadata, and associations to authors, translations, etc.Translation: Represents a translation of aWork.Author: Represents the creator of aWork.User: Represents a platform user.UserProfile: Contains extended profile information for aUser.Book: Represents a book, which can contain multiple works.Collection: Represents a user-curated collection of works.Tag: A keyword or label associated with aWork.Category: A classification for aWork.Comment: A user-submitted comment on aWorkorTranslation.Like: Represents a "like" action from a user on aWork,Translation, orComment.Bookmark: A user's personal bookmark for aWork.Contribution: Represents a user's submission of a new work or translation.ReadabilityScore: Flesch-Kincaid or similar readability score for aWork.WritingStyle: Analysis of the writing style of aWork.Emotion: Emotional analysis result for a piece of content.TopicCluster: A cluster of related topics for aWork.Mood: The detected mood of aWork.Concept: A key concept extracted from aWork.Word: A specific word linked to aConcept.LinguisticLayer: Detailed linguistic analysis of aWork.WorkStats/TranslationStats/ etc.: Analytics data (views, likes, etc.) for various entities.TextMetadata: General metadata from text analysis.PoeticAnalysis: Specific analysis of poetic structure.Copyright/CopyrightClaim: Information related to copyright ownership and claims.Country/City/Place/Address: Location-related data for users and authors.Source: The original source of a work or translation.Edge: A generic graph edge for representing relationships between entities.SearchResults: A container for results from thesearchquery.AuthPayload: A container for the authentication token and user object returned upon login/registration.
Input Types
This section describes the input objects used in mutations.
LoginInput: Containsemailandpasswordfor theloginmutation.RegisterInput: Containsusername,email,password,firstName, andlastNamefor theregistermutation.WorkInput: Used for creating/updating aWork.TranslationInput: Used for creating/updating aTranslation.AuthorInput: Used for creating/updating anAuthor.BookInput: Used for creating/updating aBook.UserInput: Used for updating user data.CollectionInput: Used for creating/updating aCollection.CommentInput: Used for creating/updating aComment.LikeInput: Specifies the entity to be liked (workId,translationId, orcommentId).BookmarkInput: Used for creating aBookmark.ContributionInput: Used for creating/updating aContribution.SearchFilters: A set of optional filters for thesearchquery.
Enums
UserRole: Defines the possible roles for a user (READER,CONTRIBUTOR,REVIEWER,EDITOR,ADMIN).ContributionStatus: Defines the lifecycle status of a contribution (DRAFT,SUBMITTED,UNDER_REVIEW,APPROVED,REJECTED).
Scalars
JSON: A standard JSON object. Used for flexible data fields like user preferences.