Skip to content

Commit

Permalink
Merge branch 'feat/mvp-20240119' of https://github.com/IRONICBo/commu…
Browse files Browse the repository at this point in the history
…nity into feat/mvp-20240119
  • Loading branch information
IRONICBo committed Jan 31, 2024
2 parents 8cc06a7 + 19bb76f commit d816e4f
Show file tree
Hide file tree
Showing 15 changed files with 788 additions and 2 deletions.
44 changes: 44 additions & 0 deletions docs/architecture/01_architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Go+ Community Architecture

## Architecture Overview

Go+ Community is a community for Go+ developers. It provides a platform for developers to share their knowledge and experience, and to communicate with each other.It contains the following modules:

- Account Module: User login and logout
- Article Package: Article CRUD
- Markdown Component: Markdown Editor
- Translate Package: Markdown and Video Translation
- Media Package: Media Management
- Share Component: Share to Twitter or Facebook
- Web Module: Web UI

## Architecture Design

Community is a web application based on `yap`, the interaction of each module is as follows:

![Interaction](../assets/01_module_interaction_2.png)

The main interaction process is as surrouned by user interaction.

User info is stored in the database, and the user info is used to verify the user's login status and parse the user info. And get the OAuth login authentication information from github twitter facebook and store the user information temporarily in a cookie.

The article module is the core of the goplus community, and it not only connects the user module, but also integrates the article translation and resource upload module. User can create, update, delete and query articles when they login, then the article will be stored in the database. The article operation involves the storage of HTML files, it also needs to be connected to Qiniu cloud storage.

The markdown component is used to edit the article, support markdown syntax and preview. Especially, our markdown editor supports goplus syntax highlighting, markdown translation and video translation, easy to paste pictures and videos.

The share component is used to share the article to Twitter or Facebook.

The Media package is used to manage resources to the cloud storage(QiNiu Cloud Storage). It can upload, delete and query resources.

The web module is the front-end of the community, which is used to display the community interface. It is based on yap template.


## Module list

- [Account Module](./02_account_module.md)
- [Article Package](./03_article_package.md)
- [Markdown Component](./04_markdown_component.md)
- [Translate Package](./05_translation_package.md)
- [Share Component](./06_share_component.md)
- [Media Package](./07_media_package.md)
- [Web Module](./08_web_module.md)
78 changes: 78 additions & 0 deletions docs/architecture/02_account_module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Account module

## Module purpose

This module is responsible for user account management, including login, logout, and user information query.

## Module scope

This module get user information from the database, and return the information to the caller. It gets the OAuth login authentication information from github twitter facebook and stores the user information temporarily in a cookie, which is used to verify the user login status and parse the user information.

- Input: Twitter/Facebook/Github
- Output: User Token
- Dependency: Casdoor OAuth endpoint

## Module structure

```go
type User struct {
Id string `xorm:"varchar(100) index" json:"id"`
Type string `xorm:"varchar(100)" json:"type"`
Name string `xorm:"varchar(100) notnull pk" json:"name"`
Password string `xorm:"varchar(100)" json:"password"`
FirstName string `xorm:"varchar(100)" json:"firstName"`
LastName string `xorm:"varchar(100)" json:"lastName"`
Avatar string `xorm:"varchar(500)" json:"avatar"`
Email string `xorm:"varchar(100) index" json:"email"`
Phone string `xorm:"varchar(20) index" json:"phone"`
GitHub string `xorm:"github varchar(100)" json:"github"`
WeChat string `xorm:"wechat varchar(100)" json:"wechat"`
Facebook string `xorm:"facebook varchar(100)" json:"facebook"`
Twitter string `xorm:"twitter varchar(100)" json:"twitter"`
CreatedTime string `xorm:"varchar(100) index" json:"createdTime"`
UpdatedTime string `xorm:"varchar(100)" json:"updatedTime"`
}
```

## Module Interface

None.

## Functions

### Login
```go
// Get login url and user login
...
// Get token and save token
...
// Redirect to home page
...
```

### Logout
```go
//Get token
...
func DeleteToken(token *Token) (bool, error)
// Redirect to home page
...
```

### GetUserInfo

```go
//Get token
...
//Parse token
func ParseJwtToken(token string) (*Claims, error)
//Get UserId or ...
...

func (c *Client) GetUserByUserId(userId string) (*User, error)

func (c *Client) GetUserByPhone(phone string) (*User, error)

func (c *Client) GetUserByEmail(email string) (*User, error)

```
172 changes: 172 additions & 0 deletions docs/architecture/03_article_package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Article module

## Module purpose

This module is used to add、delete、query and update the article.

## Module scope

This module get article information from the database, and return the information to the caller. In addition to this, the article can also be modified. This module is the core of the goplus community, and it not only connects the user module, but also integrates the article translation and resource upload module.

## Module structure

| Field | Type | Null | Key | Default | Extra |
|----|----|----|----|----|----|
| id | int unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(255) | YES | | | |
| user_id | varchar(255) | NO | | | |
| tags | varchar(255) | YES | | | |
| cover | varchar(255) | YES | | | |
| content | longtext | YES | | NULL | |
| trans_content | longtext | YES | | NULL | |
| html_id | int | YES | | 0 | |
| trans_html_id | int | YES | | 0 | |
| ctime | datetime | YES | | NULL | |
| mtime | datetime | YES | | NULL | on update CURRENT_TIMESTAMP |
| abstract | varchar(255) | YES | | | |
## Module Interface

None.

## Functions

### Overview

> Before invoke the article functions, we must connect mysql database to get article information. Since the article operation involves the storage of HTML files, it also needs to be connected to Qiniu cloud storage.
Example:

```go
conf := &core.Config{}
community, _ = core.New(todo, conf) // Instantiate the community
```

**community-defined Types and Functions:**

[type ArticleEntry](#type-articleentry)

[type Article](#type-article)

[func Article(ctx context.Context, id string) (article *Article, err error)](#func-article)

[func PutArticle(ctx context.Context, uid string, trans string, article *Article) (id string, err error)](#func-putarticle)

[func TransHtmlUrl(ctx context.Context, id string) (htmlUrl string, err error)](https://github.com/goplus/community/blob/dev/internal/core/community.go#L164)

[func SaveHtml(ctx context.Context, uid, htmlStr, mdData, id string) (articleId string, err error)](https://github.com/goplus/community/blob/dev/internal/core/community.go#L194)

[func DeleteArticle(ctx context.Context, uid, id string) (err error)](https://github.com/goplus/community/blob/dev/internal/core/community.go#L250)

[func DeleteArticles(ctx context.Context, uid string) (err error)](https://github.com/goplus/community/blob/dev/internal/core/community.go#L269)

[func Articles(ctx context.Context, page int, limit int, searchValue string) (items []*ArticleEntry, total int, err error)](https://github.com/goplus/community/blob/dev/internal/core/community.go#L296)

[func GetArticlesByUid(ctx context.Context, uid string) (items []*ArticleEntry, err error)](https://github.com/goplus/community/blob/dev/internal/core/community.go#L359)



### Types

#### type [ArticleEntry](https://github.com/goplus/community/blob/dev/internal/core/community.go#L46)

> Article Brief information.
```go
type ArticleEntry struct {
ID string
Title string
UId string
Cover string
Tags string
User User
Abstract string
Ctime time.Time
Mtime time.Time
}
```

#### type [Article](https://github.com/goplus/community/blob/dev/internal/core/community.go#L58)

> All information of article.
```go
type Article struct {
ArticleEntry
Content string // in markdown
HtmlUrl string // parsed html file url
HtmlData string
}
```

### Functions

#### func [Article](https://github.com/goplus/community/blob/dev/internal/core/community.go#L136)

```go
func Article(ctx context.Context, id string) (article *Article, err error)
```

> All users can view articles in the community, so they don't need user-related permissions, and they can view the corresponding article information only by the article ID.
>
> However, it also needs to support the modification of the article, and the user needs to have the operation permission to make the modification.
>
> We use Article() function to get article by article ID. However, for the above two scenarios, need to use the CanEditable() function to determine the permission before getting the article information.

**Example:**

```go
// if edit the article, we must check the permission
if editable, _ := community.canEditable(todo, uid, id); !editable {
zlog.Error("no permissions")
http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect)
}
article, _ := community.article(todo, id)
```

#### func [PutArticle](https://github.com/goplus/community/blob/dev/internal/core/community.go#L221)

```go
func PutArticle(ctx context.Context, uid string, trans string, article *Article) (id string, err error)
```

> Add or update article. When the ID in the article is not empty, it means the add operation, otherwise it is the update operation.
>
> Since both updates and additions operation require specific user actions, the user ID is required in the input parameters.
>
> When trans is empty, it means add or update origin article content, otherwise translate content.

**Example:**

```go

article := &Article{
ArticleEntry: ArticleEntry{
ID:"", // add
Title: "Test Article",
UId: "1",
Cover: "cover1",
Tags: "tag1",
Abstract: "abstract1"
Ctime: time.Now(),
Mtime: time.Now(),
},
Content: "This is a test article.",
}

uid = "testuid"

id, _ := community.PutArticle(todo, uid, "", article)
```



## Collaboration

### Web

At present, the collaboration with the front-end is mainly that the front-end sends me the written html file, and then I make adjustments and bug fixes.

### Markdown && Media

Invoke functions

74 changes: 74 additions & 0 deletions docs/architecture/04_markdown_component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Markdown module

## Module purpose

The markdown module uses cherry-markdown to implement a markdown online editor, with an editing area on the left and a preview area on the right. Added highlighting for go+ languages.

## Module scope

Module outputs user-edited markdown text, and inputs existing user markdown text.

## Module structure

None.

## Module Interface

Provides details of the module's public interface, including function names, parameters, return values and possible errors.
```js
submit_markdown () {
return {
FormData {
title : String,
content: String,
content: String, trans.
}
}
}
```

## Functions

### gop rendering

Example:

```gop
// go+ code
println ""
```

### submit_markdown

- Function: Submits a user-edited markdown document.
- input: none
- Returns: None
- Error: axios request exception

Example:

```js
async submit_markdown() {
let data = {
title: 'Default Title',
content: this.getCherryContent(),
html_content: this.getCherryHtml()
}
axios({
method: 'post',
url: '/commit',
data: data,
headers: {
}
})
.then(response => {
console.log('内容发送成功');
console.log(response.data);

})
.catch(error => {
console.error('内容发送失败');
console.error(error);
});
},
```
Loading

0 comments on commit d816e4f

Please sign in to comment.