Skip to content

Dijkstra-Edu/Archivist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Archivist - Go & Gin Backend Service

A RESTful backend service built with Go and Gin framework using MongoDB.

Architecture

src/
├── controllers/       # HTTP request handlers and routing
├── services/         # Business logic layer
├── repositories/     # Data access layer
├── entities/         # Domain models
└── dto/             # Data Transfer Objects

Prerequisites

  • Go 1.21 or higher
  • MongoDB running locally or remotely

Setup

  1. Install dependencies:

    go mod download
  2. Update .env file with your MongoDB connection string:

    MONGODB_CONNECTION_STRING=mongodb://localhost:27017/archivist
    SERVER_PORT=8080
    

    The connection string format includes the database name in the path.

  3. Start MongoDB (if running locally):

    mongod

Running the Application

go run main.go

The server will start on http://localhost:8080

API Endpoints

Health Check

  • GET /health
  • Returns the health status of the service and MongoDB connection

Blog Management

Create Blog

  • POST /blogs
  • Request Body:
    {
      "title": "My First Blog",
      "content": "This is the content of my blog post"
    }
  • Response: Returns the created blog with ID and timestamps

Get All Blogs

  • GET /blogs
  • Returns a list of all blogs sorted by creation date (newest first)

Get Blog by ID

  • GET /blogs/:id
  • Returns a specific blog by its ID

Update Blog

  • PUT /blogs/:id
  • Request Body (all fields optional):
    {
      "title": "Updated Title",
      "content": "Updated content"
    }
  • Returns the updated blog

Delete Blog

  • DELETE /blogs/:id
  • Deletes a blog by its ID
  • Response: {"message": "blog deleted successfully"}

Search Blogs

  • GET /blogs/search?q=query
  • Performs case-insensitive search on blog titles and content
  • Example: GET /blogs/search?q=programming

Project Structure

  • src/controllers/ - HTTP handlers for incoming requests
  • src/services/ - Business logic implementation
  • src/repositories/ - MongoDB data access layer
  • src/entities/ - Domain models (Blog)
  • src/dto/ - Data Transfer Objects for API responses

About

Dijkstra Blog Service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages