Skip to content

Commit

Permalink
refactor: Restructure project
Browse files Browse the repository at this point in the history
  • Loading branch information
shorinami committed Jan 10, 2024
1 parent 867334a commit 7d441f7
Show file tree
Hide file tree
Showing 78 changed files with 551 additions and 802 deletions.
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

45 changes: 12 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
# Marketplace (Buy and sell cars)
# eTachka Marketplace (Backend)

This service allows you to buy and sell cars
## The technologies used:
[eTachka Marketplace](https://etachka-marketplace.space) is a web car marketplace. It is built using React for frontend and Java
Spring Boot for backend. Designed and developed by a team joint at [TeamChallenge](https://teamchallenge.io).

#### Front-End
## How to run

- React (Router, Redux)
This section describes how to run the project locally.

#### Back-End
### Prerequisites

- Java, Spring (Boot, Web MVC, Data JPA, Security), JWT, Lombok
- PostgreSQL
- Swagger
- Docker
Ensure you have the following installed on your local machine:

- Java 17
- PostgreSQL 15

## Marketplace URL
### Setting up the environment

### Main page

Server: https://etachka-marketplace.space/

Localhost: https://localhost

### API

Server: https://etachka-marketplace.space//swagger-ui/index.html

Localhost URL: https://localhost/swagger-ui/index.html

## Top 3 Contributors

##### The following are currently working on this project

### Back-End
- [@ahasparian](https://github.com/arturhasparian)

### Front-End
- [@Yura-Platonov](https://github.com/Yura-Platonov)
- [@LaPaNu4](https://github.com/LaPaNu4)
Set up the required environment variables, and any optional ones you want to set.

- DB_SOURCE –
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ services:
SPRING_DATASOURCE_PASSWORD: ${DB_PASSWORD}
EMAIL_HOST: ${EMAIL_HOST}
FRONT_HOST: ${FRONT_HOST}
SSL_PATH: ${SSL_PATH}
SSL_PASSWORD: ${SSL_PASSWORD}
YOUR_EMAIL: ${YOUR_EMAIL}
EMAIL_PASSWORD: ${EMAIL_PASSWORD}
JWT_TOKEN_SECRET_ACCESS: ${JWT_TOKEN_SECRET_ACCESS}
JWT_TOKEN_SECRET_REFRESH: ${JWT_TOKEN_SECRET_REFRESH}

networks:
mynetwork:
mynetwork:
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class ServletInitializer extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MarketplaceApplication.class);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.sellbycar.marketplace.controllers;

import com.sellbycar.marketplace.models.dto.AdvertisementDTO;
import com.sellbycar.marketplace.models.entities.Advertisement;
import com.sellbycar.marketplace.services.AdvertisementService;
import com.sellbycar.marketplace.utilities.exception.FavoritesCarsNotFoundException;
import com.sellbycar.marketplace.utilities.handlers.ResponseHandler;
import com.sellbycar.marketplace.utilities.mapper.AdvertisementMapper;
package com.sellbycar.marketplace.ad;

import com.sellbycar.marketplace.util.ResponseUtil;
import com.sellbycar.marketplace.util.exception.FavoritesCarsNotFoundException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -42,11 +38,11 @@ public ResponseEntity<?> showAllAdvertisement(@RequestParam(name = "sortByDate")
Sort.Order.asc("dateAdded"));
var advertisementDto = advertisementService.findAllAd(sort);

return ResponseHandler.generateResponse("All advertisements", HttpStatus.OK, advertisementDto);
return ResponseUtil.create("All advertisements", HttpStatus.OK, advertisementDto);
}

var advertisementDto = advertisementService.findAllAd();
return ResponseHandler.generateResponse("All advertisements", HttpStatus.OK, advertisementDto);
return ResponseUtil.create("All advertisements", HttpStatus.OK, advertisementDto);
}

@GetMapping("/{id}")
Expand All @@ -56,10 +52,10 @@ public ResponseEntity<?> showAllAdvertisement(@RequestParam(name = "sortByDate")
@ApiResponse(responseCode = "404", description = "Not Found")
})
public ResponseEntity<?> getAdvertisementById(@PathVariable Long id) {
Advertisement adv = advertisementService.getAdvertisement(id);
AdvertisementDAO adv = advertisementService.getAdvertisement(id);
AdvertisementDTO advertisementDTO = advertisementMapper.toDTO(adv);

return ResponseHandler.generateResponse("Advertisement by id", HttpStatus.OK, advertisementDTO);
return ResponseUtil.create("Advertisement by id", HttpStatus.OK, advertisementDTO);
}

@PostMapping(value = "/create", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
Expand All @@ -75,7 +71,7 @@ public ResponseEntity<?> createAdvertisement(
) throws IOException {
long advertisementId = advertisementService.createAdvertisement(advertisementDTO, images);

return ResponseHandler.generateResponse("Created", HttpStatus.CREATED, advertisementId);
return ResponseUtil.create("Created", HttpStatus.CREATED, advertisementId);
}

@PutMapping("/{id}/update")
Expand All @@ -89,22 +85,22 @@ public ResponseEntity<?> createAdvertisement(
})
public ResponseEntity<?> changeAdvertisement(@RequestBody AdvertisementDTO advertisementDTO,
@PathVariable Long id) {
Advertisement advertisement = advertisementService.updateADv(advertisementDTO, id);
AdvertisementDAO advertisement = advertisementService.updateADv(advertisementDTO, id);
AdvertisementDTO advDTO = advertisementMapper.toDTO(advertisement);

return ResponseHandler.generateResponse("Updated", HttpStatus.OK, advDTO);
return ResponseUtil.create("Updated", HttpStatus.OK, advDTO);
}

@GetMapping("/favorites")
@SecurityRequirement(name = "Bearer Authentication")
@Operation(summary = "Get all favorites")
public ResponseEntity<?> getAllFavorites() {
try {
Set<Advertisement> favoritesCars = advertisementService.getAllFavorites();
Set<AdvertisementDAO> favoritesCars = advertisementService.getAllFavorites();
Set<AdvertisementDTO> favCarsDto = advertisementMapper.toDtoSet(favoritesCars);
return ResponseHandler.generateResponse("Data was gotten successfully", HttpStatus.OK, favCarsDto);
return ResponseUtil.create("Data was gotten successfully", HttpStatus.OK, favCarsDto);
} catch (FavoritesCarsNotFoundException e) {
return ResponseHandler.generateError("You did not add a cars to your favorite list",
return ResponseUtil.createError("You did not add a cars to your favorite list",
HttpStatus.NOT_FOUND);
}
}
Expand All @@ -115,12 +111,12 @@ public ResponseEntity<?> getAllFavorites() {
public ResponseEntity<?> addToFavoriteList(@PathVariable Long id) {

try {
Advertisement advertisement = advertisementService.addToFavoriteList(id);
AdvertisementDAO advertisement = advertisementService.addToFavoriteList(id);
AdvertisementDTO advertisementDTO = advertisementMapper.toDTO(advertisement);

return ResponseHandler.generateResponse("The advertisement was added to your favorite list", HttpStatus.OK, advertisementDTO);
return ResponseUtil.create("The advertisement was added to your favorite list", HttpStatus.OK, advertisementDTO);
} catch (FavoritesCarsNotFoundException e) {
return ResponseHandler.generateError(e.getMessage(), HttpStatus.NOT_FOUND);
return ResponseUtil.createError(e.getMessage(), HttpStatus.NOT_FOUND);
}


Expand All @@ -131,7 +127,7 @@ public ResponseEntity<?> addToFavoriteList(@PathVariable Long id) {
@Operation(summary = "Remove the advertisement from favorite list")
public ResponseEntity<?> removeFromFavoriteList(@PathVariable Long id) {
advertisementService.removeFromFavoriteList(id);
return ResponseHandler.generateResponse("The advertisement was removed", HttpStatus.OK);
return ResponseUtil.create("The advertisement was removed", HttpStatus.OK);
}

@DeleteMapping("/{id}/remove")
Expand All @@ -144,19 +140,6 @@ public ResponseEntity<?> removeFromFavoriteList(@PathVariable Long id) {
})
public ResponseEntity<?> deleteAdvertisement(@PathVariable Long id) {
advertisementService.removeAdvertisement(id);
return ResponseHandler.generateResponse("Ok", HttpStatus.OK);
}

@GetMapping("/user")
@SecurityRequirement(name = "Bearer Authentication")
@Operation(summary = "Get all user's advertisement")

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Ok"),
@ApiResponse(responseCode = "401", description = "Unauthorized")
})
public ResponseEntity<?> userAdvertisement() {
var userAdvertisement = advertisementService.findUserAdvertisement();
return ResponseHandler.generateResponse("All advertisements", HttpStatus.OK, userAdvertisement);
return ResponseUtil.create("Ok", HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.sellbycar.marketplace.models.entities;
package com.sellbycar.marketplace.ad;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.sellbycar.marketplace.car.CarDAO;
import com.sellbycar.marketplace.car.dao.Region;
import com.sellbycar.marketplace.image.ImageDAO;
import com.sellbycar.marketplace.user.UserDAO;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -17,7 +21,7 @@
@Getter
@Setter
@NoArgsConstructor
public class Advertisement implements Serializable {
public class AdvertisementDAO implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
Expand All @@ -38,21 +42,21 @@ public class Advertisement implements Serializable {
@ManyToOne(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST
, CascadeType.REFRESH}, fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
private User user;
private UserDAO user;

@JsonManagedReference
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "car_id", referencedColumnName = "id")
private Car car;
private CarDAO car;

@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "region_id", referencedColumnName = "id")
private Region region;

@OneToMany(mappedBy = "advertisement", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<Image> images = new ArrayList<>();
private List<ImageDAO> images = new ArrayList<>();

public void addImageToAdvertisement(Image image) {
public void addImageToAdvertisement(ImageDAO image) {
image.setAdvertisement(this);
images.add(image);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sellbycar.marketplace.models.dto;
package com.sellbycar.marketplace.ad;

import com.sellbycar.marketplace.models.entities.Region;
import com.sellbycar.marketplace.car.CarDTO;
import com.sellbycar.marketplace.car.dao.Region;
import lombok.Data;

@Data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.sellbycar.marketplace.utilities.mapper;
package com.sellbycar.marketplace.ad;

import com.sellbycar.marketplace.models.dto.AdvertisementDTO;
import com.sellbycar.marketplace.models.entities.Advertisement;
import com.sellbycar.marketplace.car.CarMapper;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
Expand All @@ -13,10 +12,10 @@
public interface AdvertisementMapper {
@Mapping(source = "carDTO", target = "car")
@Mapping(target = "name", source = "ownerName")
Advertisement toModel(AdvertisementDTO dto);
AdvertisementDAO toModel(AdvertisementDTO dto);

@Mapping(source = "car", target = "carDTO")
AdvertisementDTO toDTO(Advertisement model);
AdvertisementDTO toDTO(AdvertisementDAO model);

Set<AdvertisementDTO> toDtoSet(Set<Advertisement> advertisements);
Set<AdvertisementDTO> toDtoSet(Set<AdvertisementDAO> advertisements);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sellbycar.marketplace.ad;

import lombok.NonNull;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface AdvertisementRepository extends JpaRepository<AdvertisementDAO, Long> {

@NonNull List<AdvertisementDAO> findAll();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.sellbycar.marketplace.services;
package com.sellbycar.marketplace.ad;

import com.sellbycar.marketplace.models.dto.AdvertisementDTO;
import com.sellbycar.marketplace.models.entities.Advertisement;
import org.springframework.data.domain.Sort;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -25,13 +23,13 @@ public interface AdvertisementService {
* @param id id of user in order to get it
* @return Advertisement object representing the user if found, null otherwise.
*/
Advertisement getAdvertisement(Long id);
AdvertisementDAO getAdvertisement(Long id);

/**
* Finds a user in the database by checking the given user ID and converts it into DTO.
*
* @param advertisementDTO object with datas for creating
* @return id of advertisement
* @return
*/
long createAdvertisement(AdvertisementDTO advertisementDTO, List<MultipartFile> files) throws IOException;

Expand All @@ -41,21 +39,21 @@ public interface AdvertisementService {
* @param advertisementDTO object with datas for changes
* @param id id of advertisement in order to get it
*/
Advertisement updateADv(AdvertisementDTO advertisementDTO, Long id);
AdvertisementDAO updateADv(AdvertisementDTO advertisementDTO, Long id);

/**
* Get all advertisements from favorite list
*
* @return Set of all advertisements in favorite list
*/
Set<Advertisement> getAllFavorites();
Set<AdvertisementDAO> getAllFavorites();

/**
* add the advertisement to favorite list
*
* @param id id of advertisement in order to get it
*/
Advertisement addToFavoriteList(Long id);
AdvertisementDAO addToFavoriteList(Long id);

/**
* remove the advertisement from favorite list
Expand All @@ -70,12 +68,4 @@ public interface AdvertisementService {
* @param id The identifier of the advertisement to be removed.
*/
void removeAdvertisement(Long id);

/**
* Finds all user's advertisements in the database
*
* @return All user's advertisements in list
*/
List<AdvertisementDTO> findUserAdvertisement();

}
Loading

0 comments on commit 7d441f7

Please sign in to comment.