Giter VIP home page Giter VIP logo

code-sharing-platform's Introduction

Code Sharing Platform

About

There is a lot of collaboration in programming: many projects require sharing your code with other developers. Using open web resources such as Pastebin is not always an option. In this project, you will create your own secure version of a code-sharing platform.

Overview

The Code Sharing Platform is a Java application built using the Spring Boot framework designed to enable users to share and view code snippets. It offers a RESTful API and a web interface for users to interact with the service.

Functionality

The platform provides the following features:

  • REST API endpoints for submitting and retrieving code snippets in JSON format.
  • A web interface for viewing code snippets in HTML format.
  • Exception handling for consistent error responses across the application.
  • A service layer that contains the business logic for code snippet management.
  • An embedded static code snippet for demonstration purposes.

Project Structure

The project is structured into the following packages:

  • src/platform/controller: Contains controllers for handling HTTP requests.
    • ApiController.java: Handles API requests and returns JSON responses.
    • WebController.java: Handles web interface requests and returns HTML responses.
  • src/platform/errorhandling: Contains the global exception handler for the application.
    • GlobalExceptionHandler.java: Manages exceptions across controllers.
  • src/platform/model: Contains the data models for the application.
    • CodeSnippet.java: Represents the structure of a code snippet.
  • src/platform/service: Contains the service logic for code snippet operations.
    • CodeSnippetService.java: Manages retrieval and storage of code snippets.
  • src/resources: Holds the application's configuration properties.
  • test: Contains tests for validating the application's functionality.

Configuration

Configuration settings are located in the application.properties file, which includes:

  • Server port configuration.
  • Logging level and file output settings.
  • Thymeleaf template locations.

Setup

To set up the platform, clone the repository and import it as a Maven project into an IDE. Ensure Java and Maven are installed on the system.

Start the application with:

mvn spring-boot:run

Endpoints

The application exposes the following endpoints:

  • POST /api/code/new: Accepts a new code snippet and returns its ID.
  • GET /api/code/{id}: Retrieves a code snippet by its ID in JSON format.
  • GET /api/code/latest: Returns the latest code snippets in JSON format.
  • GET /code/new: Displays a form for submitting a new code snippet.
  • GET /code/{id}: Displays a code snippet by its ID in HTML format.
  • GET /code/latest: Shows the latest code snippets in HTML format.

Restrictions

View Restriction

The view restriction feature limits the number of times a code snippet can be viewed. Once the snippet has been viewed a certain number of times, it becomes inaccessible. This is typically implemented by storing a counter with each snippet that tracks the number of views. Each time the snippet is accessed, the counter is decremented. When the counter reaches zero, the snippet is no longer available.

Time Restriction

The time restriction feature limits the duration that a code snippet is available after it has been posted. This is usually implemented by storing a timestamp with each snippet that represents the time at which the snippet will expire. Each time the snippet is requested, the current time is compared to the expiration timestamp. If the current time is past the expiration time, the snippet is considered expired and is no longer available.

Contribution

Contributors can fork the repository, make changes, and submit a pull request for review.

License

The project is under the MIT License, as found in the LICENSE file.

For more information, please refer to the source code and comments within the files.

code-sharing-platform's People

Contributors

ryuukae avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.