https://github.com/ahmadammarm/octoscript-intern-test
https://github.com/ahmadammarm/octoscript-intern-test
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ahmadammarm/octoscript-intern-test
- Owner: ahmadammarm
- Created: 2025-02-18T09:28:12.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-02-18T09:29:03.000Z (8 months ago)
- Last Synced: 2025-03-04T06:16:34.835Z (7 months ago)
- Language: Go
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Octoscript Backend Developer Intern Technical Test
A RESTful API for managing social media post tasks built with Go, Gin Framework, GORM, PostgreSQL, and Swagger Documentation.
## Prequisites
- Go 1.24 or later
- PostgreSQL 17 or later## Database Implementation
The project used GORM, a Go ORM for database operations. The database schema includes table for posts.
The `database/connect.go` file sets up the database connection.
The `model` package defines the structs for the posts entity and GORM uses these structs to map between the Go code and the database.
## REST API Design
The project provides a RESTful API for posts. The API follows standard REST conventions:
### Posts API Routes
- `GET /api/posts` - Get all posts.
- `POST /api/posts` - Add or create a post.
- `GET /api/posts/:id` - Get a post by id.
- `PUT /api/posts/:id` - Edit or update a post by id.
- `DELETE /api/posts/:id` - Delete a post by id.## Getting Started
1. Clone the repository:
```sh
git clone https://github.com/ahmadammarm/octoscript-intern-test.git
```2. Navigate to the project directory:
```sh
cd octoscript-intern-test
```3. Install the project dependencies:
```sh
go mod download
```4. Configure database connection in database/connect.go:
```sh
source := "host=localhost user=your_username password=your_password dbname=your_dbname port=5432"
```5. Generate Swagger documentation:
```sh
swag init
```6. Run the project:
```sh
go run main.go
```The project will be available at:
`http://localhost:8080`
After running the application, you can access the Swagger documentation at:
`http://localhost:8080/swagger/index.html`