This project is a web service built using Go (Golang) that runs locally on localhost. It provides endpoints for GET, POST, PUT, and DELETE methods to interact with a PostgreSQL database. The focus of this project is to manage data related to characters from the popular manga and anime series, One Piece.
- GET Method: Retrieves information about One Piece characters from the database.
- POST Method: Adds new characters to the database.
- PUT Method: Updates existing character information in the database.
- DELETE Method: Delete existing character information in the database.
- PostgreSQL Database: Utilizes PostgreSQL to store and manage character data.
- Clone this repository to your local machine.
git clone https://github.com/justkurama/GO-onepiece.git
- Install dependencies.
go mod download
- Ensure PostgreSQL is installed and running on your system.
- Update the database configuration in
db.go
with your PostgreSQL credentials. - Build and run the project.
go build ./GO-onepiece
This application uses GORM to manage its database models. Below are the details of the models used in this project.
The Character
model represents a character in the database.
Field | Type | Description |
---|---|---|
ID | uint | Primary key |
Name | string | The name of the character |
NickName | string | The nickname of the character |
Origin | Origin | Associated origin |
OriginID | uint | Foreign key to Origin |
Race | Race | Associated race |
RaceID | uint | Foreign key to Race |
Organization | Organization | Associated organization |
OrganizationID | uint | Foreign key to Organization |
SubOrganization | SubOrganization | Associated sub-organization |
SubOrganizationID | uint | Foreign key to SubOrganization |
The Origin
model represents the origin or birthplace of a character.
Field | Type | Description |
---|---|---|
ID | uint | Primary key |
Name | string | The name of the origin |
Characters | []Character | List of characters from this origin |
The Race
model represents the race or species of a character.
Field | Type | Description |
---|---|---|
ID | uint | Primary key |
Name | string | The name of the race |
Characters | []Character | List of characters of this race |
The Organization
model represents an organization to which a character may belong.
Field | Type | Description |
---|---|---|
ID | uint | Primary key |
Name | string | The name of the organization |
Characters | []Character | List of characters in this organization |
SubOrganizations | []SubOrganization | List of sub-organizations under this organization |
The SubOrganization
model represents a sub-organization that belongs to an organization.
Field | Type | Description |
---|---|---|
ID | uint | Primary key |
Name | string | The name of the sub-organization |
ParentID | uint | Foreign key to the parent organization |
Parent | Organization | The parent organization to which it belongs |
- A
Character
belongs to anOrigin
,Race
,Organization
, andSubOrganization
. - An
Origin
can have manyCharacters
. - A
Race
can have manyCharacters
. - An
Organization
can have manyCharacters
and manySubOrganizations
. - A
SubOrganization
belongs to anOrganization
.
This structure ensures the proper associations between entities and facilitates the management of relationships using GORM.
- Description: Retrieves information about all One Piece characters.
- Example Response:
[ { "ID": 1, "Name": "Monkey D. Luffy", "NickName": "Mugiwara", "Origin": { "ID": 1, "Name": "East Blue", "Characters": null }, "OriginID": 1, "Race": { "ID": 1, "Name": "Human", "Characters": null }, "RaceID": 1, "Organization": { "ID": 1, "Name": "Pirate Crews", "Characters": null, "SubOrganizations": null }, "OrganizationID": 1, "SubOrganization": { "ID": 1, "Name": "Straw Hat Pirates", "ParentID": 1, "Parent": { "ID": 0, "Name": "", "Characters": null, "SubOrganizations": null } }, "SubOrganizationID": 1 }, { "ID": 2, "Name": "Roronoa Zoro", "NickName": "Pirate Hunter", "Origin": { "ID": 1, "Name": "East Blue", "Characters": null }, "OriginID": 1, "Race": { "ID": 1, "Name": "Human", "Characters": null }, "RaceID": 1, "Organization": { "ID": 1, "Name": "Pirate Crews", "Characters": null, "SubOrganizations": null }, "OrganizationID": 1, "SubOrganization": { "ID": 1, "Name": "Straw Hat Pirates", "ParentID": 1, "Parent": { "ID": 0, "Name": "", "Characters": null, "SubOrganizations": null } }, "SubOrganizationID": 1 }, { "ID": 3, "Name": "Nami", "NickName": "Cat Burglar", "Origin": { "ID": 1, "Name": "East Blue", "Characters": null }, "OriginID": 1, "Race": { "ID": 1, "Name": "Human", "Characters": null }, "RaceID": 1, "Organization": { "ID": 1, "Name": "Pirate Crews", "Characters": null, "SubOrganizations": null }, "OrganizationID": 1, "SubOrganization": { "ID": 1, "Name": "Straw Hat Pirates", "ParentID": 1, "Parent": { "ID": 0, "Name": "", "Characters": null, "SubOrganizations": null } }, "SubOrganizationID": 1 } ... ]
- Description: Adds a new character to the database.
- Payload:
{ "Name": "Smoker", "NickName": "White Hunter", "OriginID": 5, "RaceID": 1, "OrganizationID": 2, "SubOrganizationID": 7 }
- Description: Updates information about a specific character.
- Example Request:
PUT /character/2 { "nickname": "Marine Hero" }
- Name: Straw Hats
- Members: Kurmanbek(22B030597) and Dias(22B031174)
Contributions are welcome! If you want to contribute to this project, please fork the repository and submit a pull request with your changes.