Skip to content

Commit

Permalink
new Crud
Browse files Browse the repository at this point in the history
  • Loading branch information
vovangy committed May 3, 2024
1 parent dab00dc commit a508b0e
Show file tree
Hide file tree
Showing 103 changed files with 2,859 additions and 2,691 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ migrate-lib:
go get -tags 'postgres' -u github.com/golang-migrate/migrate/v4/cmd/migrate/

create-migration:
migrate create -dir migrations -ext sql -seq $(TABLE_NAME)
migrate create -dir db/migrations -ext sql -seq $(TABLE_NAME)

migrate-up:
migrate -path migrations -database "postgres://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable" up
migrate -path db/migrations -database "postgres://$(DB_USER):$(DB_PASS)@localhost:$(DB_PORT)/$(DB_NAME)?sslmode=disable" up

migrate-down:
migrate -path migrations -database "postgres://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable" down
migrate -path db/migrations -database "postgres://$(DB_USER):$(DB_PASS)@localhost:$(DB_PORT)/$(DB_NAME)?sslmode=disable" down

dev-compose-up:
$(DOCKER_COMPOSE) -f "dev-docker-compose.yaml" up -d
Expand Down
2 changes: 1 addition & 1 deletion cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func main() {
advert.Handle("/{id}", jwtMd.JwtTMiddleware(http.HandlerFunc(advertHandler.UpdateAdvertById))).Methods(http.MethodPost, http.MethodOptions)
advert.Handle("/{id}", jwtMd.JwtTMiddleware(http.HandlerFunc(advertHandler.DeleteAdvertById))).Methods(http.MethodDelete, http.MethodOptions)
advert.Handle("/houses/", jwtMd.JwtTMiddleware(http.HandlerFunc(advertHandler.CreateHouseAdvert))).Methods(http.MethodPost, http.MethodOptions)
advert.HandleFunc("/buildings/", advertHandler.GetExistBuildingsByAddress).Methods(http.MethodGet, http.MethodOptions)
advert.HandleFunc("/building/", advertHandler.GetExistBuildingByAddress).Methods(http.MethodGet, http.MethodOptions)
advert.Handle("/flats/", jwtMd.JwtTMiddleware(http.HandlerFunc(advertHandler.CreateFlatAdvert))).Methods(http.MethodPost, http.MethodOptions)
advert.HandleFunc("/squarelist/", advertHandler.GetSquareAdvertsList).Methods(http.MethodGet, http.MethodOptions)
advert.HandleFunc("/rectanglelist/", advertHandler.GetRectangeAdvertsList).Methods(http.MethodGet, http.MethodOptions)
Expand Down
1 change: 1 addition & 0 deletions db/migrations/000002_advert.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS advert (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES user_data(id),
title TEXT CONSTRAINT title_length CHECK ( char_length(title) <= 127) NOT NULL,
type_placement TEXT CONSTRAINT type_placement_length CHECK ( char_length(type_placement) <= 6 AND type_placement IN ('Rent', 'Sale')) NOT NULL,
description TEXT CONSTRAINT description_length CHECK ( char_length(description) <= 1500) NOT NULL,
phone TEXT CONSTRAINT phone_length CHECK ( char_length(phone) <= 20) NOT NULL,
is_agent BOOLEAN NOT NULL DEFAULT FALSE,
Expand Down
1 change: 1 addition & 0 deletions db/migrations/000009_province.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS province;
4 changes: 4 additions & 0 deletions db/migrations/000009_province.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE IF NOT EXISTS province (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name TEXT CONSTRAINT name_length CHECK ( char_length(name) <= 120) NOT NULL
);
1 change: 1 addition & 0 deletions db/migrations/000010_town.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS town;
5 changes: 5 additions & 0 deletions db/migrations/000010_town.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS town (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
province_id BIGINT NOT NULL REFERENCES province(id),
name TEXT CONSTRAINT name_length CHECK ( char_length(name) <= 60) NOT NULL
);
1 change: 1 addition & 0 deletions db/migrations/000011_street.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS street;
5 changes: 5 additions & 0 deletions db/migrations/000011_street.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS street (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
town_id BIGINT NOT NULL REFERENCES town(id),
name TEXT CONSTRAINT name_length CHECK ( char_length(name) <= 120) NOT NULL
);
1 change: 1 addition & 0 deletions db/migrations/000012_house_name.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS house_name;
5 changes: 5 additions & 0 deletions db/migrations/000012_house_name.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS house_name (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
street_id BIGINT NOT NULL REFERENCES street(id),
name TEXT CONSTRAINT name_length CHECK ( char_length(name) <= 40) NOT NULL
);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DROP TABLE IF EXISTS building;
DROP TABLE IF EXISTS address;
DROP EXTENSION IF EXISTS postgis;
38 changes: 38 additions & 0 deletions db/migrations/000013_address.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CREATE EXTENSION IF NOT EXISTS postgis;

CREATE TABLE IF NOT EXISTS address (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
address_point GEOGRAPHY(Point, 4326) NOT NULL UNIQUE,
house_name_id BIGINT NOT NULL REFERENCES house_name(id),
metro TEXT CONSTRAINT metro_length CHECK ( char_length(metro) <= 120) NOT NULL
);

INSERT INTO province (name) VALUES ('California');
INSERT INTO province (name) VALUES ('New York');

-- Inserting into town table
INSERT INTO town (province_id, name) VALUES (1, 'Los Angeles');
INSERT INTO town (province_id, name) VALUES (1, 'San Francisco');
INSERT INTO town (province_id, name) VALUES (2, 'New York City');
INSERT INTO town (province_id, name) VALUES (2, 'Buffalo');

-- Inserting into street table
INSERT INTO street (town_id, name) VALUES (1, 'Sunset Boulevard');
INSERT INTO street (town_id, name) VALUES (1, 'Hollywood Boulevard');
INSERT INTO street (town_id, name) VALUES (2, 'Lombard Street');
INSERT INTO street (town_id, name) VALUES (3, 'Broadway');
INSERT INTO street (town_id, name) VALUES (4, 'Main Street');

-- Inserting into house_name table
INSERT INTO house_name (street_id, name) VALUES (1, '1234');
INSERT INTO house_name (street_id, name) VALUES (1, '5678');
INSERT INTO house_name (street_id, name) VALUES (2, '4321');
INSERT INTO house_name (street_id, name) VALUES (3, '9876');
INSERT INTO house_name (street_id, name) VALUES (4, '6543');

-- Inserting into address table with a test value for address_point
INSERT INTO address (address_point, house_name_id, metro) VALUES (ST_GeographyFromText('POINT(-118.2437 34.0522)'), 1, 'Metro Station A');
INSERT INTO address (address_point, house_name_id, metro) VALUES (ST_GeographyFromText('POINT(-122.4194 37.7749)'), 2, 'Metro Station B');
INSERT INTO address (address_point, house_name_id, metro) VALUES (ST_GeographyFromText('POINT(-122.4313 37.8044)'), 3, 'Metro Station C');
INSERT INTO address (address_point, house_name_id, metro) VALUES (ST_GeographyFromText('POINT(-73.9352 40.7306)'), 4, 'Metro Station D');
INSERT INTO address (address_point, house_name_id, metro) VALUES (ST_GeographyFromText('POINT(-78.8784 42.8864)'), 5, 'Metro Station E');
1 change: 1 addition & 0 deletions db/migrations/000014_building.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS building;
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
CREATE EXTENSION IF NOT EXISTS postgis;

CREATE TABLE IF NOT EXISTS building (
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
complex_id BIGINT NULL REFERENCES complex(id),
address_id BIGINT NULL REFERENCES address(id),
floor SMALLINT NOT NULL,
material_building TEXT CONSTRAINT material_building_length CHECK ( char_length(material_building) <= 25 AND material_building IN ('Brick', 'Monolithic', 'Wood', 'Panel', 'Stalinsky', 'Block', 'MonolithicBlock', 'Frame', 'AeratedConcreteBlock', 'GasSilicateBlock', 'FoamСoncreteBlock', 'None')) NOT NULL,
address TEXT CONSTRAINT address_length CHECK ( char_length(address) <= 255) NOT NULL UNIQUE,
address_point GEOGRAPHY(Point, 4326) NOT NULL UNIQUE,
year_creation SMALLINT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
is_deleted BOOLEAN NOT NULL DEFAULT FALSE
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS question (
id UUID NOT NULL PRIMARY KEY,
id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
question_text TEXT CONSTRAINT question_text_length CHECK ( char_length(question_text) <= 120 AND char_length(question_text) >= 1) NOT NULL,
theme TEXT CONSTRAINT theme_length CHECK ( char_length(theme) <= 15 AND theme IN ('mainPage', 'createAdvert', 'filterPage', 'profile', 'myAdverts')) NOT NULL,
max_mark INT NOT NULL,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE IF NOT EXISTS question_answer (
user_id UUID NOT NULL REFERENCES users(id),
question_id UUID NOT NULL REFERENCES question(id),
user_id BIGINT NOT NULL REFERENCES user_data(id),
question_id BIGINT NOT NULL REFERENCES question(id),
mark INT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
is_deleted BOOLEAN NOT NULL DEFAULT FALSE,
Expand Down
Loading

0 comments on commit a508b0e

Please sign in to comment.