Add mapper for entity to dto
This commit is contained in:
parent
43b578d298
commit
bd0bc7da53
@ -1,12 +1,44 @@
|
||||
package ir.chaarfasl.back.api.core.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import ir.chaarfasl.back.api.core.dto.CoordinatesDto;
|
||||
import ir.chaarfasl.back.api.core.dto.PointEpitomeDto;
|
||||
import ir.chaarfasl.back.api.core.service.AttractionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/attractions")
|
||||
@RequestMapping("/api/attractions")
|
||||
public class AttractionController {
|
||||
|
||||
private AttractionService attractionService;
|
||||
|
||||
@Autowired
|
||||
public AttractionController(AttractionService attractionService) {
|
||||
this.attractionService = attractionService;
|
||||
}
|
||||
|
||||
@PostMapping("/getAttraction")
|
||||
public ResponseEntity<List<PointEpitomeDto>> getAttraction(@RequestBody CoordinatesDto coordinatesDtoLeftTop, @RequestBody CoordinatesDto coordinatesDtoRightDown) {
|
||||
List<PointEpitomeDto> attractionsList = attractionService.getAttractions(coordinatesDtoLeftTop, coordinatesDtoRightDown);
|
||||
if(attractionsList != null && !attractionsList.isEmpty()) {
|
||||
return ResponseEntity.ok(attractionsList);
|
||||
} else {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<AttractionDto> getAttractionById(@PathVariable Long id) {
|
||||
AttractionDto attractionDto = attractionService.getAttractionById(id);
|
||||
if (attractionDto != null) {
|
||||
return ResponseEntity.ok(attractionDto);
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package ir.chaarfasl.back.api.core.controller;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.CommentDto;
|
||||
import ir.chaarfasl.back.api.core.service.CommentService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/comments")
|
||||
public class CommentController {
|
||||
private static final Logger log = LoggerFactory.getLogger(new Object() {}.getClass().getEnclosingClass());
|
||||
|
||||
CommentService commentService;
|
||||
|
||||
public CommentController(CommentService commentService) {
|
||||
this.commentService = commentService;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<CommentDto> addComment(@RequestBody CommentDto commentDto){
|
||||
CommentDto addedComment = commentService.addComment(commentDto);
|
||||
// URI uri = URI.create("/comments/" + addedComment.getId());
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(addedComment);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package ir.chaarfasl.back.api.core.controller;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.CoordinatesDto;
|
||||
import ir.chaarfasl.back.api.core.dto.GeneralPointsDto;
|
||||
import ir.chaarfasl.back.api.core.dto.PointEpitomeDto;
|
||||
import ir.chaarfasl.back.api.core.service.AttractionService;
|
||||
import ir.chaarfasl.back.api.core.service.EatingPlaceService;
|
||||
import ir.chaarfasl.back.api.core.service.ResidenceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/general")
|
||||
public class GeneralController {
|
||||
|
||||
private AttractionService attractionService;
|
||||
private EatingPlaceService eatingPlaceService;
|
||||
private ResidenceService residenceService;
|
||||
|
||||
@Autowired
|
||||
public GeneralController(AttractionService attractionService, EatingPlaceService eatingPlaceService, ResidenceService residenceService) {
|
||||
this.attractionService = attractionService;
|
||||
this.eatingPlaceService = eatingPlaceService;
|
||||
this.residenceService = residenceService;
|
||||
}
|
||||
|
||||
@PostMapping("/getAll")
|
||||
public ResponseEntity<GeneralPointsDto> getAll(@RequestBody CoordinatesDto coordinatesDtoLeftTop, @RequestBody CoordinatesDto coordinatesDtoRightDown) {
|
||||
List<PointEpitomeDto> attractionsList = attractionService.getAttractions(coordinatesDtoLeftTop, coordinatesDtoRightDown);
|
||||
List<PointEpitomeDto> eatingPlacesList = eatingPlaceService.getEatingPlace(coordinatesDtoLeftTop, coordinatesDtoRightDown);
|
||||
List<PointEpitomeDto> residencesList = residenceService.getResidences(coordinatesDtoLeftTop, coordinatesDtoRightDown);
|
||||
GeneralPointsDto generalPointsDto = new GeneralPointsDto(attractionsList, eatingPlacesList, residencesList);
|
||||
|
||||
if((attractionsList == null || attractionsList.isEmpty())
|
||||
&& (eatingPlacesList == null && eatingPlacesList.isEmpty())
|
||||
&& (residencesList == null && residencesList.isEmpty())) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
} else {
|
||||
return ResponseEntity.ok(generalPointsDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.repository;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dataAccess.entity.Attraction;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface AttractionRepository extends JpaRepository<Attraction, Long> {
|
||||
List<Attraction> findByLatitudeBetweenAndLatitudeBetween(Double lat1, Double lat2, Double long1, Double long2);
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dataAccess.entity.Province;
|
||||
import ir.chaarfasl.back.api.core.entity.Province;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -11,7 +11,7 @@ public class AttractionDto extends PointDto{
|
||||
private String bestTime;
|
||||
private Float hardnessDegree;
|
||||
|
||||
public AttractionDto(Long id, String name, String description, Double latitude, Double longitude, Province province, Float rate) {
|
||||
super(id, name, description, latitude, longitude, province, rate);
|
||||
public AttractionDto(Long id, String name, Double latitude, Double longitude, Float rate, String description, Province province) {
|
||||
super(id, name, latitude, longitude, rate, description, province);
|
||||
}
|
||||
}
|
||||
|
||||
18
src/main/java/ir/chaarfasl/back/api/core/dto/CommentDto.java
Normal file
18
src/main/java/ir/chaarfasl/back/api/core/dto/CommentDto.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class CommentDto {
|
||||
private Long id;
|
||||
private Long pointId;
|
||||
private String userId;
|
||||
private String title;
|
||||
private String context;
|
||||
}
|
||||
@ -9,7 +9,7 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Coordinates {
|
||||
public class CoordinatesDto {
|
||||
protected Double latitude;
|
||||
protected Double longitude;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Province;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class EatingPlaceDto extends PointDto{
|
||||
public EatingPlaceDto(Long id, String name, Double latitude, Double longitude, Float rate, String description, Province province) {
|
||||
super(id, name, latitude, longitude, rate, description, province);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class GeneralPointsDto {
|
||||
List<PointEpitomeDto> attractionDtoList;
|
||||
List<PointEpitomeDto> eatingPlaceDtoList;
|
||||
List<PointEpitomeDto> residenceDtoList;
|
||||
}
|
||||
@ -1,19 +1,19 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dataAccess.entity.Province;
|
||||
import ir.chaarfasl.back.api.core.entity.Province;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PointDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
public class PointDto extends PointEpitomeDto{
|
||||
private String description;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Province province;
|
||||
private Float rate;
|
||||
|
||||
public PointDto(Long id, String name, Double latitude, Double longitude, Float rate, String description, Province province) {
|
||||
super(id, name, latitude, longitude, rate);
|
||||
this.description = description;
|
||||
this.province = province;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Province;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class PointEpitomeDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Float rate;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package ir.chaarfasl.back.api.core.dto;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Province;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ResidenceDto extends PointDto{
|
||||
public ResidenceDto(Long id, String name, Double latitude, Double longitude, Float rate, String description, Province province) {
|
||||
super(id, name, latitude, longitude, rate, description, province);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AccessLevel;
|
||||
@ -16,7 +16,8 @@ public class AttractionRates extends Rates {
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -15,7 +15,8 @@ import java.time.LocalDateTime;
|
||||
@AllArgsConstructor
|
||||
public class Comment implements Cloneable {
|
||||
@Id
|
||||
@GeneratedValue()
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID", nullable = false)
|
||||
protected Long id;
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -19,10 +17,21 @@ import lombok.Setter;
|
||||
public class CommentStatus {
|
||||
|
||||
@Id
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "NAME", nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(name = "STATUS_VALUE", nullable = false)
|
||||
private Integer statusValue;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
private String description;
|
||||
|
||||
@Column(name = "IS_ACTIVE", nullable = false)
|
||||
private short isActive;
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@ -12,7 +12,8 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class Keywords {
|
||||
@Id
|
||||
@GeneratedValue()
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@ -13,7 +13,8 @@ import java.time.LocalDateTime;
|
||||
@MappedSuperclass
|
||||
public class Point implements Cloneable{
|
||||
@Id
|
||||
@GeneratedValue()
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID", nullable = false)
|
||||
protected Long id;
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -19,12 +17,24 @@ import lombok.Setter;
|
||||
public class PointStatus {
|
||||
|
||||
@Id
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "ID", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "NAME", nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(name = "STATUS_VALUE", nullable = false)
|
||||
private Integer statusValue;
|
||||
|
||||
@Column(name = "DESCRIPTION")
|
||||
private String description;
|
||||
|
||||
@Column(name = "IS_ACTIVE", nullable = false)
|
||||
private short isActive;
|
||||
|
||||
|
||||
/*@OneToMany(mappedBy = "pointStatus")
|
||||
private Set<Attraction> attractions;*/
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PointStatusRepository extends JpaRepository<PointStatus, Integer> {
|
||||
PointStatus findByNameLike(String name);
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -20,8 +18,15 @@ public class Province {
|
||||
|
||||
|
||||
@Id
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "CODE", nullable = false)
|
||||
private Integer code;
|
||||
|
||||
@Column(name = "NATIONAL_IDENTIFIER", nullable = false)
|
||||
private Integer nationalIdentifier;
|
||||
|
||||
@Column(name = "NAME", nullable = false)
|
||||
private String name;
|
||||
|
||||
/* @OneToMany(mappedBy = "province")
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@ -13,7 +13,8 @@ import java.time.LocalDateTime;
|
||||
@MappedSuperclass
|
||||
public class Rates implements Cloneable {
|
||||
@Id
|
||||
@GeneratedValue()
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
protected Long id;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
@ -1,4 +1,4 @@
|
||||
package ir.chaarfasl.back.api.core.dataAccess.entity;
|
||||
package ir.chaarfasl.back.api.core.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
@ -12,14 +12,27 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class Search {
|
||||
@Id
|
||||
@GeneratedValue()
|
||||
// todo: best practice
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "KEYWORD_ID", nullable = false)
|
||||
private long keywordId;
|
||||
|
||||
@Column(name = "POINT_ID", nullable = false)
|
||||
private long pointId;
|
||||
|
||||
@Column(name = "POINT_TYPE", nullable = false)
|
||||
private String pointType;
|
||||
|
||||
@Column(name = "LATITUDE", nullable = false)
|
||||
private Double latitude;
|
||||
|
||||
@Column(name = "LONGITUDE", nullable = false)
|
||||
private Double longitude;
|
||||
|
||||
@Column(name = "INDEX", nullable = false)
|
||||
private Integer index;
|
||||
|
||||
@ManyToOne
|
||||
@ -1,6 +1,6 @@
|
||||
package ir.chaarfasl.back.api.core.mapper;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dataAccess.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package ir.chaarfasl.back.api.core.mapper;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Comment;
|
||||
import ir.chaarfasl.back.api.core.dto.CommentDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
@Component
|
||||
public interface CommentMapper {
|
||||
CommentMapper INSTANCE = Mappers.getMapper(CommentMapper.class);
|
||||
|
||||
CommentDto commentToCommentDto(Comment comment);
|
||||
Comment commentDtoToComment(CommentDto commentDto);
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package ir.chaarfasl.back.api.core.mapper;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import ir.chaarfasl.back.api.core.dto.EatingPlaceDto;
|
||||
import ir.chaarfasl.back.api.core.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.entity.EatingPlace;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface EatingPlaceMapper {
|
||||
EatingPlaceMapper INSTANCE = Mappers.getMapper(EatingPlaceMapper.class);
|
||||
|
||||
EatingPlaceDto eatingPlaceToEatingPlaceDto(EatingPlace eatingPlace);
|
||||
EatingPlace eatingPlaceDtoToEatingPlace(EatingPlaceDto eatingPlaceDto);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package ir.chaarfasl.back.api.core.mapper;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.PointDto;
|
||||
import ir.chaarfasl.back.api.core.dto.PointEpitomeDto;
|
||||
import ir.chaarfasl.back.api.core.entity.Point;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface PointEpitomeMapper {
|
||||
PointEpitomeMapper INSTANCE = Mappers.getMapper(PointEpitomeMapper.class);
|
||||
|
||||
PointEpitomeDto pointToPointDto(Point point);
|
||||
Point pointDtoToPoint(PointDto pointDto);
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package ir.chaarfasl.back.api.core.mapper;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import ir.chaarfasl.back.api.core.dto.ResidenceDto;
|
||||
import ir.chaarfasl.back.api.core.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.entity.Residence;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ResidenceMapper {
|
||||
ResidenceMapper INSTANCE = Mappers.getMapper(ResidenceMapper.class);
|
||||
|
||||
ResidenceDto residenceToResidenceDto(Residence residence);
|
||||
Residence residenceDtoToResidence(ResidenceDto residenceDto);
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package ir.chaarfasl.back.api.core.repository;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface AttractionRepository extends JpaRepository<Attraction, Long> {
|
||||
List<Attraction> findByLatitudeBetweenAndLatitudeBetweenAndPointStatus(Double lat1, Double lat2, Double long1, Double long2, PointStatus pointStatusn);
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package ir.chaarfasl.back.api.core.repository;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Comment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package ir.chaarfasl.back.api.core.repository;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.CommentStatus;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CommentStatusRepository extends JpaRepository<CommentStatus, Long> {
|
||||
CommentStatus findByNameLike(String name);
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package ir.chaarfasl.back.api.core.repository;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.EatingPlace;
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface EatingPlaceRepository extends JpaRepository<EatingPlace, Long> {
|
||||
List<EatingPlace> findByLatitudeBetweenAndLatitudeBetweenAndPointStatus(Double lat1, Double lat2, Double long1, Double long2, PointStatus pointStatusn);
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package ir.chaarfasl.back.api.core.repository;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import ir.chaarfasl.back.api.core.entity.Residence;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ResidenceRepository extends JpaRepository<Residence, Long> {
|
||||
List<Residence> findByLatitudeBetweenAndLatitudeBetweenAndPointStatus(Double lat1, Double lat2, Double long1, Double long2, PointStatus pointStatusn);
|
||||
}
|
||||
@ -1,33 +1,61 @@
|
||||
package ir.chaarfasl.back.api.core.service;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dataAccess.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.dataAccess.repository.AttractionRepository;
|
||||
import ir.chaarfasl.back.api.core.dto.Coordinates;
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import ir.chaarfasl.back.api.core.dto.PointEpitomeDto;
|
||||
import ir.chaarfasl.back.api.core.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import ir.chaarfasl.back.api.core.mapper.AttractionMapper;
|
||||
import ir.chaarfasl.back.api.core.mapper.PointEpitomeMapper;
|
||||
import ir.chaarfasl.back.api.core.repository.AttractionRepository;
|
||||
import ir.chaarfasl.back.api.core.dto.CoordinatesDto;
|
||||
import ir.chaarfasl.back.api.core.util.Constants;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class AttractionService {
|
||||
private static final Logger log = LoggerFactory.getLogger(new Object() {}.getClass().getEnclosingClass());
|
||||
|
||||
AttractionRepository attractionRepository;
|
||||
PointStatusService pointStatusService;
|
||||
AttractionMapper attractionMapper;
|
||||
PointEpitomeMapper pointEpitomeMapper;
|
||||
|
||||
public AttractionService(AttractionRepository attractionRepository) {
|
||||
private PointStatus visiblePintStatus;
|
||||
|
||||
public AttractionService(AttractionRepository attractionRepository, PointStatusService pointStatusService) {
|
||||
this.attractionRepository = attractionRepository;
|
||||
this.pointStatusService = pointStatusService;
|
||||
}
|
||||
|
||||
public List<Attraction> getAttractions(Coordinates leftTop, Coordinates rightDown){
|
||||
List<Attraction> resultPoints = null;
|
||||
@PostConstruct
|
||||
public void loadVisiblePointStatus() {
|
||||
System.out.println("Loading common data at startup...");
|
||||
this.visiblePintStatus = pointStatusService.getPointStatus(Constants.VISIBLE_POINT_STATUS);
|
||||
}
|
||||
|
||||
public List<PointEpitomeDto> getAttractions(CoordinatesDto leftTop, CoordinatesDto rightDown){
|
||||
List<PointEpitomeDto> resultPoints = null;
|
||||
try {
|
||||
resultPoints = attractionRepository.findByLatitudeBetweenAndLatitudeBetween(leftTop.getLatitude(), rightDown.getLatitude(), leftTop.getLongitude(), rightDown.getLongitude());
|
||||
List<Attraction> resultEntityPoints = attractionRepository.findByLatitudeBetweenAndLatitudeBetweenAndPointStatus(leftTop.getLatitude(), rightDown.getLatitude(),
|
||||
leftTop.getLongitude(), rightDown.getLongitude(), visiblePintStatus);
|
||||
for (Attraction resultEntityPoint : resultEntityPoints) {
|
||||
resultPoints.add(pointEpitomeMapper.pointToPointDto(resultEntityPoint));
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
return resultPoints;
|
||||
}
|
||||
|
||||
public AttractionDto getAttractionById(Long id){
|
||||
Optional<Attraction> attraction = attractionRepository.findById(id);
|
||||
return attraction.map(attractionMapper::attractionToAttractionDto).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package ir.chaarfasl.back.api.core.service;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.Comment;
|
||||
import ir.chaarfasl.back.api.core.entity.CommentStatus;
|
||||
import ir.chaarfasl.back.api.core.repository.CommentRepository;
|
||||
import ir.chaarfasl.back.api.core.repository.CommentStatusRepository;
|
||||
import ir.chaarfasl.back.api.core.dto.CommentDto;
|
||||
import ir.chaarfasl.back.api.core.mapper.CommentMapper;
|
||||
import ir.chaarfasl.back.api.core.util.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class CommentService {
|
||||
private static final Logger log = LoggerFactory.getLogger(new Object() {}.getClass().getEnclosingClass());
|
||||
|
||||
CommentRepository commentRepository;
|
||||
CommentStatusRepository commentStatusRepository;
|
||||
CommentMapper commentMapper;
|
||||
|
||||
public CommentService(CommentRepository commentRepository, CommentStatusRepository commentStatusRepository,CommentMapper commentMapper) {
|
||||
this.commentRepository = commentRepository;
|
||||
this.commentStatusRepository = commentStatusRepository;
|
||||
this.commentMapper = commentMapper;
|
||||
}
|
||||
|
||||
public CommentDto addComment(CommentDto commentDto){
|
||||
Comment comment = commentMapper.commentDtoToComment(commentDto);
|
||||
CommentStatus pendingStatus = commentStatusRepository.findByNameLike(Constants.PENDING_COMMENT_STATUS);
|
||||
comment.setCommentStatus(pendingStatus);
|
||||
Comment save = commentRepository.save(comment);
|
||||
return commentMapper.commentToCommentDto(save);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package ir.chaarfasl.back.api.core.service;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import ir.chaarfasl.back.api.core.dto.CoordinatesDto;
|
||||
import ir.chaarfasl.back.api.core.dto.EatingPlaceDto;
|
||||
import ir.chaarfasl.back.api.core.dto.PointEpitomeDto;
|
||||
import ir.chaarfasl.back.api.core.entity.Attraction;
|
||||
import ir.chaarfasl.back.api.core.entity.EatingPlace;
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import ir.chaarfasl.back.api.core.mapper.EatingPlaceMapper;
|
||||
import ir.chaarfasl.back.api.core.mapper.PointEpitomeMapper;
|
||||
import ir.chaarfasl.back.api.core.repository.AttractionRepository;
|
||||
import ir.chaarfasl.back.api.core.repository.EatingPlaceRepository;
|
||||
import ir.chaarfasl.back.api.core.util.Constants;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class EatingPlaceService {
|
||||
private static final Logger log = LoggerFactory.getLogger(new Object() {}.getClass().getEnclosingClass());
|
||||
|
||||
EatingPlaceRepository eatingPlaceRepository;
|
||||
PointStatusService pointStatusService;
|
||||
EatingPlaceMapper eatingPlaceMapper;
|
||||
PointEpitomeMapper pointEpitomeMapper;
|
||||
|
||||
private PointStatus visiblePintStatus;
|
||||
|
||||
public EatingPlaceService(EatingPlaceRepository eatingPlaceRepository, PointStatusService pointStatusService) {
|
||||
this.eatingPlaceRepository = eatingPlaceRepository;
|
||||
this.pointStatusService = pointStatusService;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void loadVisiblePointStatus() {
|
||||
System.out.println("Loading common data at startup...");
|
||||
this.visiblePintStatus = pointStatusService.getPointStatus(Constants.VISIBLE_POINT_STATUS);
|
||||
}
|
||||
|
||||
public List<PointEpitomeDto> getEatingPlace(CoordinatesDto leftTop, CoordinatesDto rightDown){
|
||||
List<PointEpitomeDto> resultPoints = null;
|
||||
try {
|
||||
List<EatingPlace> resultEntityPoints = eatingPlaceRepository.findByLatitudeBetweenAndLatitudeBetweenAndPointStatus(leftTop.getLatitude(), rightDown.getLatitude(),
|
||||
leftTop.getLongitude(), rightDown.getLongitude(), visiblePintStatus);
|
||||
for (EatingPlace resultEntityPoint : resultEntityPoints) {
|
||||
resultPoints.add(pointEpitomeMapper.pointToPointDto(resultEntityPoint));
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
return resultPoints;
|
||||
}
|
||||
|
||||
public EatingPlaceDto getEatingPlaceById(Long id){
|
||||
Optional<EatingPlace> eatingPlace = eatingPlaceRepository.findById(id);
|
||||
return eatingPlace.map(eatingPlaceMapper::eatingPlaceToEatingPlaceDto).orElse(null);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package ir.chaarfasl.back.api.core.service;
|
||||
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatusRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PointStatusService {
|
||||
private static final Logger log = LoggerFactory.getLogger(new Object() {}.getClass().getEnclosingClass());
|
||||
|
||||
PointStatusRepository pointStatusRepository;
|
||||
|
||||
|
||||
public PointStatusService(PointStatusRepository pointStatusRepository) {
|
||||
this.pointStatusRepository = pointStatusRepository;
|
||||
}
|
||||
|
||||
public PointStatus getPointStatus(String name){
|
||||
try {
|
||||
return pointStatusRepository.findByNameLike(name);
|
||||
} catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package ir.chaarfasl.back.api.core.service;
|
||||
|
||||
import ir.chaarfasl.back.api.core.dto.AttractionDto;
|
||||
import ir.chaarfasl.back.api.core.dto.CoordinatesDto;
|
||||
import ir.chaarfasl.back.api.core.dto.PointEpitomeDto;
|
||||
import ir.chaarfasl.back.api.core.dto.ResidenceDto;
|
||||
import ir.chaarfasl.back.api.core.entity.PointStatus;
|
||||
import ir.chaarfasl.back.api.core.entity.Residence;
|
||||
import ir.chaarfasl.back.api.core.mapper.PointEpitomeMapper;
|
||||
import ir.chaarfasl.back.api.core.mapper.ResidenceMapper;
|
||||
import ir.chaarfasl.back.api.core.repository.ResidenceRepository;
|
||||
import ir.chaarfasl.back.api.core.util.Constants;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class ResidenceService {
|
||||
private static final Logger log = LoggerFactory.getLogger(new Object() {}.getClass().getEnclosingClass());
|
||||
|
||||
ResidenceRepository residenceRepository;
|
||||
PointStatusService pointStatusService;
|
||||
ResidenceMapper residenceMapper;
|
||||
PointEpitomeMapper pointEpitomeMapper;
|
||||
|
||||
private PointStatus visiblePintStatus;
|
||||
|
||||
public ResidenceService(ResidenceRepository residenceRepository, PointStatusService pointStatusService) {
|
||||
this.residenceRepository = residenceRepository;
|
||||
this.pointStatusService = pointStatusService;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void loadVisiblePointStatus() {
|
||||
System.out.println("Loading common data at startup...");
|
||||
this.visiblePintStatus = pointStatusService.getPointStatus(Constants.VISIBLE_POINT_STATUS);
|
||||
}
|
||||
|
||||
public List<PointEpitomeDto> getResidences(CoordinatesDto leftTop, CoordinatesDto rightDown){
|
||||
List<PointEpitomeDto> resultPoints = null;
|
||||
try {
|
||||
List<Residence> resultEntityPoints = residenceRepository.findByLatitudeBetweenAndLatitudeBetweenAndPointStatus(leftTop.getLatitude(), rightDown.getLatitude(),
|
||||
leftTop.getLongitude(), rightDown.getLongitude(), visiblePintStatus);
|
||||
for (Residence resultEntityPoint : resultEntityPoints) {
|
||||
resultPoints.add(pointEpitomeMapper.pointToPointDto(resultEntityPoint));
|
||||
}
|
||||
} catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
return resultPoints;
|
||||
}
|
||||
|
||||
public ResidenceDto getResidenceById(Long id){
|
||||
Optional<Residence> residence = residenceRepository.findById(id);
|
||||
return residence.map(residenceMapper::residenceToResidenceDto).orElse(null);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
package ir.chaarfasl.back.api.core.util;
|
||||
|
||||
public class Constants {
|
||||
public static final String PENDING_COMMENT_STATUS = "pending";
|
||||
public static final String VISIBLE_POINT_STATUS = "visible";
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package ir.chaarfasl.back.api.core;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import ir.chaarfasl.back.api.core.controller.AttractionController;
|
||||
import ir.chaarfasl.back.api.core.dto.Coordinates;
|
||||
import ir.chaarfasl.back.api.core.service.AttractionService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user