Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

WHERETOGO-0011 Добавлено поле 'duration' для существующих мест в базе данных #29

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions where-to-go-back/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

Для проверки тестового покрытия кода необходимо провести сборку проекта:

mvn clean install
mvn clean package

А затем вызвать sonar с помощью:

mvn sonar:sonar

Также можно использовать комбинированную команду:

mvn clean install sonar:sonar
mvn clean package sonar:sonar

### Docker-контейнер:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package ru.nsu.fit.wheretogo.dto;

import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;

/**
* Базовая модель DTO
*/
@Getter
@Setter
public abstract class BaseDTO {

@NotNull
protected Long id;

public void setId(Long id) {
this.id = id;
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ru.nsu.fit.wheretogo.dto.place;

import lombok.Getter;
import lombok.Setter;
import ru.nsu.fit.wheretogo.dto.BaseDTO;
import ru.nsu.fit.wheretogo.entity.place.Category;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Getter
@Setter
public class CategoryDTO extends BaseDTO {

@NotNull(message = "Enter category name")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package ru.nsu.fit.wheretogo.dto.place;

import lombok.Getter;
import lombok.Setter;
import ru.nsu.fit.wheretogo.entity.place.Coordinates;
import ru.nsu.fit.wheretogo.entity.place.Place;

import java.util.List;

@Getter
@Setter
public class PlaceBriefDTO extends PlaceDTO {

private String name;
private Coordinates coordinates;
private String thumbnailLink;
private List<CategoryDTO> categories;
private Integer duration;

public static PlaceBriefDTO getFromEntity(Place entity) {
if (entity == null) {
Expand All @@ -27,23 +30,8 @@ public static PlaceBriefDTO getFromEntity(Place entity) {
dto.setCoordinates(entity.getCoordinates());
dto.setThumbnailLink(entity.getThumbnail());
dto.setCategories(categories);
dto.setDuration(entity.getDuration());

return dto;
}

public void setName(String name) {
this.name = name;
}

public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}

public void setThumbnailLink(String thumbnailLink) {
this.thumbnailLink = thumbnailLink;
}

public void setCategories(List<CategoryDTO> categories) {
this.categories = categories;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ru.nsu.fit.wheretogo.dto.place;

import lombok.Getter;
import lombok.Setter;
import ru.nsu.fit.wheretogo.entity.place.Coordinates;
import ru.nsu.fit.wheretogo.entity.place.Place;

import java.time.Instant;
import java.util.List;

@Getter
@Setter
public class PlaceDescriptionDTO extends PlaceDTO {

private String name;
Expand All @@ -16,6 +18,7 @@ public class PlaceDescriptionDTO extends PlaceDTO {
private String thumbnail;
private Instant uploadedAt;
private List<CategoryDTO> categories;
private Integer duration;

public static PlaceDescriptionDTO getFromEntity(Place entity) {
if (entity == null) {
Expand All @@ -32,31 +35,8 @@ public static PlaceDescriptionDTO getFromEntity(Place entity) {
dto.setThumbnail(entity.getThumbnail());
dto.setUploadedAt(entity.getUploadedAt());
dto.setCategories(categories);
dto.setDuration(entity.getDuration());

return dto;
}

public void setName(String name) {
this.name = name;
}

public void setDescription(String description) {
this.description = description;
}

public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}

public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}

public void setUploadedAt(Instant uploadedAt) {
this.uploadedAt = uploadedAt;
}

public void setCategories(List<CategoryDTO> categories) {
this.categories = categories;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ru.nsu.fit.wheretogo.dto.user;

import lombok.Getter;
import lombok.Setter;
import ru.nsu.fit.wheretogo.dto.BaseDTO;
import ru.nsu.fit.wheretogo.entity.score.Score;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@Getter
@Setter
public class ScoreDTO extends BaseDTO {

private Long author;
Expand All @@ -29,16 +31,4 @@ public static ScoreDTO getFromEntity(Score score) {

return dto;
}

public void setAuthor(Long author) {
this.author = author;
}

public void setPlace(Long place) {
this.place = place;
}

public void setScore(Integer score) {
this.score = score;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.nsu.fit.wheretogo.dto.user;

import lombok.Getter;
import lombok.Setter;
import ru.nsu.fit.wheretogo.dto.BaseDTO;
import ru.nsu.fit.wheretogo.entity.place.StayPoint;

@Getter
@Setter
public class StayPointDTO extends BaseDTO {

private double latitude;
Expand All @@ -24,16 +26,4 @@ public static StayPointDTO getFromEntity(StayPoint stayPoint) {

return dto;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public void setLongitude(double longitude) {
this.longitude = longitude;
}

public void setUserId(Long userId) {
this.userId = userId;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.nsu.fit.wheretogo.dto.user;

import lombok.Getter;
import lombok.Setter;
import ru.nsu.fit.wheretogo.dto.BaseDTO;
import ru.nsu.fit.wheretogo.entity.user.User;

Expand All @@ -9,6 +10,7 @@
import java.time.Instant;

@Getter
@Setter
public class UserDTO extends BaseDTO {

@NotNull
Expand All @@ -33,16 +35,4 @@ public static UserDTO getFromEntity(User user) {

return dto;
}

public void setEmail(String email) {
this.email = email;
}

public void setUsername(String username) {
this.username = username;
}

public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public class Place {
@Column(name = "UPLOADED_AT", nullable = false)
private Instant uploadedAt;

@Column(name = "DURATION", nullable = false)
private Integer duration;


@PrePersist
public void setUploadDate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE IF EXISTS T_PLACE ADD COLUMN DURATION INT NOT NULL DEFAULT 90;

CREATE INDEX IF NOT EXISTS LATITUDE_INDEX ON T_PLACE USING BTREE(LATITUDE);
CREATE INDEX IF NOT EXISTS LONGITUDE_INDEX ON T_PLACE USING BTREE(LONGITUDE);
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
CREATE OR REPLACE FUNCTION RANDOM_BETWEEN(LOW INT, HIGH INT)
RETURNS INT AS
$$
BEGIN
RETURN FLOOR(RANDOM() * (HIGH - LOW + 1) + LOW);
END;
$$ LANGUAGE PLPGSQL STRICT;

CREATE OR REPLACE FUNCTION CREATE_RANDOM_DURATION()
RETURNS INT AS
$$
BEGIN
RETURN RANDOM_BETWEEN(45, 180);
END;
$$ LANGUAGE PLPGSQL STRICT;

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Заброшенный корабль';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Беловский водопад';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Мира парк';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Новое яркое пятно в городе';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Реконструкция старого города';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Феликс дзержинский';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Страшно красивое место';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Валадилена';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Тут всегда солнечно';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Банкет';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Архитектурное наслаждение';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Безграничность';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Безлюдный обрыв';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Белая соль';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Белена';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Брошенный остров';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Вечное зарево';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'В мире литературы';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'В окружении красок';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Геометрия';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Весенний контраст';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Второе самое красивое место';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Действующая психиатрическая больница';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Громадный шар посреди поля';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Единение с природой';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Восстановление';

UPDATE T_PLACE
SET DURATION = CREATE_RANDOM_DURATION()
WHERE NAME LIKE 'Масштабная забытость';
Loading