package
0.0.0-20240414174107-f7ec041e7514
Repository: https://github.com/nerdzeu/nerdz-api.git
Documentation: pkg.go.dev

# README

NERDZ-API - Back-end

In this folder you can find the NERDZ back-end implementation.

Back-end types architecture

In the implementation of the NERDZ's type hierarchy, a lot of data structure are generated in order to manipulate all the information that the social network manages. All the data structure are filled by a database ORM that is used to avoid to rely on the specific query dialect when creating each query. In order to work with it, a specific type has been defined in the file types.go which contains specific details that grant to the ORM to manage all the database's logic.

All the information it's not simply generated and consumed inside the system. In making available an API, we need to decouple all the internal data structure from the one that are returned to the user by the system. It's absolutely NOT correct to return all the data exactly has they are stored in the database. For this reason, according to the state-of-the-art pattern of the Transfer Object, we have defined a main structure and a specific transfer object type which can be generated from it.

In particular, each type defined in the file types.go implements a specific interface, called Transferable, which let to it to define how will be generated the companion transfer object type defined in the file api_types.go. Each transfer object type associated to the main struct, doesn't have all the ORM details and is completely seperated from the database's logic.

Working in this way, will be necessary, to get each transfer object specific type for a data structure, to work a little with type conversion and type switch. In a first moment this could be really tedious, but this approach has a lot of benefits that are appreciable only in the long-run.

Back-end tests

Tests are based on nerdz-test-db. If you want to run rests you must correctly setup this environment.

cd ~/nerdz_env/
git clone https://github.com/nerdzeu/nerdz-test-db.git

You don't need to do anything else in that folder.

Come back here and properly setup your JSON configuration file in order to use a new test-db.

Mine looks like:

{
    "DbUsername" : "test_db",
    "DbPassword" : "test_db",
    "DbName"     : "test_db",
    "DbHost"     : "127.0.0.1",
    "DbPort"     : 0,
    "DbSSLMode"    : "disable",
    "NERDZPath"  : "/home/paolo/nerdz_env/nerdz.eu/",
    "NERDZHost"  : "local.nerdz.eu",
    "EnableLog"  : true,
    "Port"       : 9090,
    "Scheme"     : "http",
    "Host"       : "local.api.nerdz.eu"
}

After that, configure the nvironment variables into test_all.sh.

Run the tests

To run all the test, you need a working database. If you wanto to automatically create a new database, use ./test_all.sh.

If your nerdz-test-db is just ready thus you don't need to create a new one, you can lunch tests in these two ways:

CONF_FILE="/path/to/conf_file/conf_file_name" go test

If you want to see which queries are executed run tests with EnableLog parameter set to true in the configuration file and using the verbose mode for the test tool:

CONF_FILE="/path/to/conf_file/conf_file_name" go test -v |less

# Functions

AtMostComments returns a uint64 that's the number of comments to be retrieved.
AtMostPms returns a uint64 that's the number of pms to be retrieved.
AtMostPosts returns a uint8 that's the number of posts to be retrieved.
Db returns the *igor.Database.
Infos returns a slice of pointer to Info.
Login initializes a User struct if login (id | email | username) and password are correct.
NewPm initializes a Pm struct.
NewPmWhere returns the *Pm fetching the first one that matches the description.
NewProject returns the user with the specified id.
NewProjectPost initializes a ProjectPost struct.
NewProjectPostComment initializes a ProjectPostComment struct.
NewProjectPostCommentWhere returns the *ProjectPostComment fetching the first one that matches the description.
NewProjectPostWhere returns the *ProjectPost fetching the first one that matches the description.
NewProjectWhere returns the first user that matches the description.
NewUser returns the user with the specified id.
NewUserPost returns the *UserPost with id hpid if exists.
NewUserPostComment initializes a UserPostComment struct.
NewUserPostCommentWhere returns the *UserPostComment fetching the first one that matches the description.
NewUserPostWhere returns the *UserPost fetching the first one that matches the description.
NewUserWhere returns the first user that matches the description.
Projects returns a slice of pointer to Project, fetched from its Ids.
Users returns a slice of pointer to User, fetched from its Ids.

# Constants

MaxComments represents the maximum comments number that can be required in a commentList.
MaxPms represents the maximum pms number that can be required in a conversation.
MaxPosts represents the maximum posts number that can be required in a postList.
MinComments represents the minimum comments number that can be required in a commentList.
MinPms represents the minimum pms number that can be required in a conversation.
MinPosts represents the minimum posts number that can be required in a postList.
ProjectBoardID constant (of type boardType) makes possible to distinguish a PROJECT board from a User board.
ProjectPostID constaint is the numeric identifier of a project post when considered as a generic message.
UserBoardID constant (of type boardType) makes possible to distinguish a User board from a Project board.
UserPostID constaint is the numeric identifier of a user post when considered as a generic message.

# Variables

Configuration represent the parsed configuration file.

# Structs

Ban is the model for the relation ban.
BanTO represents the TO of Ban swagger:model.
Blacklist is the model for the relation blacklist.
BlacklistTO represens the TO of Blacklist swagger:model.
BoardInfo is that struct that contains all the information related to the user's board.
CommentlistOptions is used to specify the options for a list of comments.
Config represents the configuration file structure.
ContactInfo is the struct that contains all the contact info of an user.
ContactInfoTO represents the TO of ContactInfo swagger:model.
Conversation represents the details about a single private conversation between two users.
ConversationTO represents the TO of Conversation swagger:model.
DeletedUser is the model for the relation deleted_users.
DeletedUserTO represents the TO of DeletedUserTO swagger:model.
Info contains the information common to every board Used in API output to give user/project basic information.
InfoTO represents the TO of Info swagger:model.
Interest is the model for the relation interests.
Mention is the model for the relation mentions.
MentionTO represents the TO of Mention swagger:model.
Message is the model for the view message.
OAuth2AccessData is the OAuth2 access data.
OAuth2AuthorizeData is the model for the relation oauth2_authorize that represents the authorization granted to to the client.
OAuth2Client implements the osin.Client interface.
OAuth2RefreshToken is the model for the relation oauth2_refresh.
OAuth2Storage implements osin.Storage interface.
PersonalInfo is the struct that contains all the personal info of an user.
PersonalInfoTO represents the TO of PersonalInfo swagger:model.
Pm is the model for the relation pms.
PmsOptions represent the configuration used to fetch a Pm list.
PmTO represents the TO of Pm swagger:model.
Post
Post is the type of a generic post.
PostClassification is the model for the relation posts_classifications.
PostClassificationTO represents the TO of PostClassification swagger:model.
PostlistOptions is used to specify the options for a list of posts.
PostTO is the Transfor Object of Post.
Profile is the model for the relation profiles.
ProfileTO represents the TO of Profile swagger:model.
Project is the model for the relation groups.
ProjectFollower is the model for the relation groups_followers.
ProjectFollowerTO represents the TO of ProjectFollower swagger:model.
ProjectInfo is the struct that contains all the project's information.
ProjectMember is the model for the relation groups_members.
ProjectMemberTO represents the TO of ProjectMember swagger:model.
ProjectNotify is the model for the relation groups_notify.
ProjectNotifyTO represents the TO of ProjectNotify swagger:model.
ProjectOwner is the model for the relation groups_owners.
ProjectOwnerTO represents the TO of ProjectOwner swagger:model.
ProjectPost is the model for the relation groups_posts.
ProjectPostBookmark is the model for the relation groups_bookmarks.
ProjectPostBookmarkTO represents the TO of ProjectPostBookmark swagger:model.
ProjectPostComment is the model for the relation groups_comments.
ProjectPostCommentRevision is the model for the relation groups_comments_revisions.
ProjectPostCommentRevisionTO represents the TO of ProjectPostCommentRevision swagger:model.
ProjectPostCommentsNotify is the model for the relation groups_comments_notify.
ProjectPostCommentsNotifyTO represents the TO of ProjectPostCommentsNotify swagger:model.
ProjectPostCommentTO represents the TO of ProjectPostComment swagger:model.
ProjectPostCommentVote is the model for the relation groups_comment_thumbs.
ProjectPostCommentVoteTO represents the TO of ProjectPostCommentVote swagger:model.
ProjectPostLock is the model for the relation groups_posts_no_notify.
ProjectPostLockTO represents the TO of ProjectPostLock swagger:model.
ProjectPostLurk is the model for the relation groups_lurkers.
ProjectPostLurkTO represents the TO of ProjectPostLurk swagger:model.
ProjectPostRevision is the model for the relation groups_posts_revisions.
ProjectPostRevisionTO represents the TO of ProjectPostRevision swagger:model.
ProjectPostUserLock is the model for the relation groups_comments_no_notify.
ProjectPostUserLockTO represents the TO of ProjectPostUserLock swagger:model.
ProjectPostVote is the model for the relation groups_thumbs.
ProjectPostVoteTO represents the TO of ProjectPostVote swagger:model.
ProjectTO represents the TO of Project swagger:model.
SpecialProject is the model for the relation special_groups.
SpecialProjectTO represents the TO of SpecialProject swagger:model.
SpecialUser is the model for the relation special_users.
SpecialUserTO represents the TO of SpecialUser swagger:model.
Template is the representation of a nerdz website template.
User is the model for the relation users.
UserFollower is the model for the relation followers.
UserFollowerTO represents the TO of UserFollower swagger:model.
UserPost is the model for the relation posts.
UserPostBookmark is the model for the relation bookmarks.
UserPostBookmarkTO represents the TO of UserPostBookmark swagger:model.
UserPostComment is the model for the relation comments.
UserPostCommentRevision is the model for the relation comments_revisions.
UserPostCommentRevisionTO represents the TO of UserPostCommentRevision swagger:model.
UserPostCommentsNotify is the model for the relation comments_notify.
UserPostCommentsNotifyTO represents the TO of UserPostCommentsNotify swagger:model.
UserPostCommentTO represents the TO of UserPostComment swagger:model.
UserPostCommentVote is the model for the relation groups_comment_thumbs.
UserPostCommentVoteTO represents the TO of UserPostCommentVote swagger:model.
UserPostLock is the model for the relation posts_no_notify.
UserPostLockTO represents the TO of UserPostLock swagger:model.
UserPostLurk is the model for the relation lurkers.
UserPostLurkTO represents the TO of UserPostLurk swagger:model.
UserPostRevision is the model for the relation posts_revisions.
UserPostRevisionTO represents the TO of UserPostRevision swagger:model.
UserPostUserLock is the model for the relation comments_no_notify.
UserPostUserLockTO represents the TO of UserPostUserLock swagger:model.
UserPostVote is the model for the relation votes.
UserPostVoteTO represents the TO of UserPostVote swagger:model.
UserTO represents the TO of User swagger:model.
Whitelist is the model for the relation whitelist.
WhitelistTO represents the TO of Whitelist swagger:model.

# Interfaces

Board is the interface that wraps the methods common to every board.
Bookmark is a generic interface to represent a bookmark.
ExistingComment is the interface that wraps the methods common to every existing comment.
ExistingPost is the interface that wraps the methods common to every existing post.
Lock is a generic interface to represent the Lock action.
Lurk is a generic interface to represent the Lurk action.
Reference represents a reference.
Transferable represents a common interface for all the types defined by the backend that are able to generate a data structure that can be returned by the API.
Vote is a generic interface to represent a vote.