Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Structure Updates and Docker integration #5

Merged
merged 7 commits into from
Nov 25, 2024
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
46 changes: 46 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
services:
server:
build:
context: ./server
dockerfile: Dockerfile
container_name: prompt-core-server
depends_on:
db:
condition: service_healthy
ports:
- "8080:8080"
environment:
- DB_USER=prompt-postgres
- DB_PASSWORD=prompt-postgres
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=prompt
- SSL_MODE=disable
- SERVER_ADDRESS=0.0.0.0:8080

db:
image: 'postgres:15.2-alpine'
container_name: prompt-core-db
environment:
- POSTGRES_USER=prompt-postgres
- POSTGRES_PASSWORD=prompt-postgres
- POSTGRES_DB=prompt
healthcheck:
test: ["CMD-SHELL", "pg_isready -d prompt -U prompt-postgres"]
interval: 5s
timeout: 5s
retries: 5
ports:
- "5432:5432"

keycloak:
image: quay.io/keycloak/keycloak:20.0
container_name: prompt-keycloak
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
entrypoint: /opt/keycloak/bin/kc.sh start-dev
ports:
- "8081:8080"


30 changes: 30 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.23-alpine


# Install dependencies
RUN apk add --no-cache curl

# Install migrate
RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.18.1/migrate.linux-amd64.tar.gz | tar xvz && \
mv migrate /usr/local/bin/

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

# Copy the source from the current directory to the Working Directory inside the container
COPY . .

# Build the Go app
RUN go build -o main .

# Expose port 8080 to the outside world
EXPOSE 8080

# Command to run the executable
CMD ["./main"]
4 changes: 4 additions & 0 deletions server/course/courseDTO/create_course.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type CreateCourse struct {
EndDate pgtype.Date `json:"end_date"`
SemesterTag pgtype.Text `json:"semester_tag"`
MetaData meta.MetaData `json:"meta_data"`
CourseType db.CourseType `json:"course_type"`
Ects pgtype.Int4 `json:"ects"`
//TODO: CoursePhases []coursePhaseDTO.CoursePhase `json:"course_phases"`
}

Expand All @@ -29,5 +31,7 @@ func (c CreateCourse) GetDBModel() (db.CreateCourseParams, error) {
EndDate: c.EndDate,
SemesterTag: c.SemesterTag,
MetaData: metaData,
CourseType: c.CourseType,
Ects: c.Ects,
}, nil
}
18 changes: 10 additions & 8 deletions server/coursePhase/coursePhaseDTO/create_course_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
)

type CreateCoursePhase struct {
CourseID uuid.UUID `json:"course_id"`
Name string `json:"name"`
IsInitialPhase bool `json:"is_initial_phase"`
MetaData meta.MetaData `json:"meta_data"`
CourseID uuid.UUID `json:"course_id"`
Name string `json:"name"`
IsInitialPhase bool `json:"is_initial_phase"`
MetaData meta.MetaData `json:"meta_data"`
CoursePhaseTypeID uuid.UUID `json:"course_phase_type_id"`
}

func (cp CreateCoursePhase) GetDBModel() (db.CreateCoursePhaseParams, error) {
Expand All @@ -20,9 +21,10 @@ func (cp CreateCoursePhase) GetDBModel() (db.CreateCoursePhaseParams, error) {
return db.CreateCoursePhaseParams{}, err
}
return db.CreateCoursePhaseParams{
CourseID: cp.CourseID,
Name: pgtype.Text{String: cp.Name, Valid: true},
IsInitialPhase: cp.IsInitialPhase,
MetaData: metaData,
CourseID: cp.CourseID,
Name: pgtype.Text{String: cp.Name, Valid: true},
IsInitialPhase: cp.IsInitialPhase,
MetaData: metaData,
CoursePhaseTypeID: cp.CoursePhaseTypeID,
}, nil
}
22 changes: 12 additions & 10 deletions server/coursePhase/coursePhaseDTO/get_course_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

type CoursePhase struct {
ID uuid.UUID `json:"id"`
CourseID uuid.UUID `json:"course_id"`
Name string `json:"name"`
IsInitialPhase bool `json:"is_initial_phase"`
MetaData meta.MetaData `json:"meta_data"`
ID uuid.UUID `json:"id"`
CourseID uuid.UUID `json:"course_id"`
Name string `json:"name"`
IsInitialPhase bool `json:"is_initial_phase"`
MetaData meta.MetaData `json:"meta_data"`
CoursePhaseTypeID uuid.UUID `json:"course_phase_type_id"`
}

func GetCoursePhaseDTOFromDBModel(model db.CoursePhase) (CoursePhase, error) {
Expand All @@ -21,10 +22,11 @@ func GetCoursePhaseDTOFromDBModel(model db.CoursePhase) (CoursePhase, error) {
}

return CoursePhase{
ID: model.ID,
CourseID: model.CourseID,
Name: model.Name.String,
IsInitialPhase: model.IsInitialPhase,
MetaData: metaData,
ID: model.ID,
CourseID: model.CourseID,
Name: model.Name.String,
IsInitialPhase: model.IsInitialPhase,
MetaData: metaData,
CoursePhaseTypeID: model.CoursePhaseTypeID,
}, nil
}
39 changes: 21 additions & 18 deletions server/coursePhase/coursePhaseDTO/get_course_phase_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
)

type CoursePhaseSequence struct {
ID uuid.UUID `json:"id"`
CourseID uuid.UUID `json:"course_id"`
Name string `json:"name"`
MetaData meta.MetaData `json:"meta_data"`
IsInitialPhase bool `json:"is_initial_phase"`
SequenceOrder int `json:"sequence_order"`
ID uuid.UUID `json:"id"`
CourseID uuid.UUID `json:"course_id"`
Name string `json:"name"`
MetaData meta.MetaData `json:"meta_data"`
IsInitialPhase bool `json:"is_initial_phase"`
SequenceOrder int `json:"sequence_order"`
CoursePhaseTypeID uuid.UUID `json:"course_phase_type_id"`
}

func GetCoursePhaseSequenceDTOFromDBModel(model db.GetCoursePhaseSequenceRow) (CoursePhaseSequence, error) {
Expand All @@ -22,12 +23,13 @@ func GetCoursePhaseSequenceDTOFromDBModel(model db.GetCoursePhaseSequenceRow) (C
}

return CoursePhaseSequence{
ID: model.ID,
CourseID: model.CourseID,
Name: model.Name.String,
MetaData: metaData,
IsInitialPhase: model.IsInitialPhase,
SequenceOrder: int(model.SequenceOrder),
ID: model.ID,
CourseID: model.CourseID,
Name: model.Name.String,
MetaData: metaData,
IsInitialPhase: model.IsInitialPhase,
SequenceOrder: int(model.SequenceOrder),
CoursePhaseTypeID: model.CoursePhaseTypeID,
}, nil
}

Expand All @@ -43,12 +45,13 @@ func GetCoursePhaseSequenceDTO(orderedPhases []db.GetCoursePhaseSequenceRow, not

for _, phase := range notOrderedPhases {
coursePhase, err := GetCoursePhaseSequenceDTOFromDBModel(db.GetCoursePhaseSequenceRow{
ID: phase.ID,
CourseID: phase.CourseID,
Name: phase.Name,
MetaData: phase.MetaData,
IsInitialPhase: phase.IsInitialPhase,
SequenceOrder: -1,
ID: phase.ID,
CourseID: phase.CourseID,
Name: phase.Name,
MetaData: phase.MetaData,
IsInitialPhase: phase.IsInitialPhase,
SequenceOrder: -1,
CoursePhaseTypeID: phase.CoursePhaseTypeID,
})
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions server/coursePhase/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func UpdateCoursePhase(ctx context.Context, coursePhase coursePhaseDTO.UpdateCou
return err
}

dbModel.ID = coursePhase.ID
return CoursePhaseServiceSingleton.queries.UpdateCoursePhase(ctx, dbModel)
}

Expand Down
45 changes: 31 additions & 14 deletions server/db/migration/0001_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ CREATE TYPE gender AS ENUM (
'prefer_not_to_say'
);

CREATE TYPE course_type as ENUM (
'lecture',
'seminar',
'practical course'
);

-- UK data standard for full name is 70 chars and for mail 255 chars
CREATE TABLE student (
id uuid PRIMARY KEY,
Expand All @@ -25,18 +31,29 @@ CREATE TABLE course (
start_date date,
end_date date,
semester_tag text,
course_type course_type NOT NULL,
ects int,
meta_data jsonb
);

CREATE TABLE course_phase_type (
id uuid PRIMARY KEY,
name text UNIQUE NOT NULL
);

CREATE TABLE course_phase (
id uuid PRIMARY KEY,
course_id uuid NOT NULL,
name text,
meta_data jsonb,
is_initial_phase boolean NOT NULL,
course_phase_type_id uuid NOT NULL,
CONSTRAINT fk_course
FOREIGN KEY (course_id)
REFERENCES course(id)
REFERENCES course(id) ON DELETE CASCADE,
CONSTRAINT fk_phase_type
FOREIGN KEY (course_phase_type_id)
REFERENCES course_phase_type(id)
);

CREATE UNIQUE INDEX unique_initial_phase_per_course
Expand All @@ -49,10 +66,10 @@ CREATE TABLE course_participation (
student_id uuid NOT NULL,
CONSTRAINT fk_student
FOREIGN KEY (student_id)
REFERENCES student(id),
REFERENCES student(id) ON DELETE CASCADE,
CONSTRAINT fk_course
FOREIGN KEY (course_id)
REFERENCES course(id),
REFERENCES course(id) ON DELETE CASCADE,
CONSTRAINT unique_course_participation
UNIQUE (course_id, student_id)
);
Expand All @@ -65,10 +82,10 @@ CREATE TABLE course_phase_participation (
meta_data jsonb,
CONSTRAINT fk_course_participation
FOREIGN KEY (course_participation_id)
REFERENCES course_participation(id),
REFERENCES course_participation(id) ON DELETE CASCADE,
CONSTRAINT fk_course_phase
FOREIGN KEY (course_phase_id)
REFERENCES course_phase(id),
REFERENCES course_phase(id) ON DELETE CASCADE,
CONSTRAINT unique_course_phase_participation
UNIQUE (course_participation_id, course_phase_id)
);
Expand All @@ -80,10 +97,10 @@ CREATE TABLE course_phase_graph (
to_course_phase_id uuid NOT NULL,
CONSTRAINT fk_from_course_phase
FOREIGN KEY (from_course_phase_id)
REFERENCES course_phase(id),
REFERENCES course_phase(id) ON DELETE CASCADE,
CONSTRAINT fk_to_course_phase
FOREIGN KEY (to_course_phase_id)
REFERENCES course_phase(id),
REFERENCES course_phase(id) ON DELETE CASCADE,
CONSTRAINT unique_from_course_phase UNIQUE (from_course_phase_id),
CONSTRAINT unique_to_course_phase UNIQUE (to_course_phase_id)
);
Expand All @@ -101,7 +118,7 @@ CREATE TABLE application_question_text (
order_num int,
CONSTRAINT fk_course_phase
FOREIGN KEY (course_phase_id)
REFERENCES course_phase(id)
REFERENCES course_phase(id) ON DELETE CASCADE
);

CREATE TABLE application_question_multi_select (
Expand All @@ -118,7 +135,7 @@ CREATE TABLE application_question_multi_select (
order_num int,
CONSTRAINT fk_course_phase
FOREIGN KEY (course_phase_id)
REFERENCES course_phase(id)
REFERENCES course_phase(id) ON DELETE CASCADE
);

CREATE TABLE application_answer_text (
Expand All @@ -128,10 +145,10 @@ CREATE TABLE application_answer_text (
answer text,
CONSTRAINT fk_application_question
FOREIGN KEY (application_question_id)
REFERENCES application_question_text(id),
REFERENCES application_question_text(id) ON DELETE CASCADE,
CONSTRAINT fk_course_phase_participation
FOREIGN KEY (course_phase_participation_id)
REFERENCES course_phase_participation(id),
REFERENCES course_phase_participation(id) ON DELETE CASCADE,
CONSTRAINT unique_application_answer_text
UNIQUE (course_phase_participation_id, application_question_id)

Expand All @@ -144,10 +161,10 @@ CREATE TABLE application_answer_multi_select (
answer text[],
CONSTRAINT fk_application_question
FOREIGN KEY (application_question_id)
REFERENCES application_question_multi_select(id),
REFERENCES application_question_multi_select(id) ON DELETE CASCADE,
CONSTRAINT fk_course_phase_participation
FOREIGN KEY (course_phase_participation_id)
REFERENCES course_phase_participation(id),
REFERENCES course_phase_participation(id) ON DELETE CASCADE,
CONSTRAINT unique_application_answer_multi_select
UNIQUE (course_phase_participation_id, application_question_id)
);
Expand All @@ -158,7 +175,7 @@ CREATE TABLE application_assessment (
score int,
CONSTRAINT fk_course_phase_participation
FOREIGN KEY (course_phase_participation_id)
REFERENCES course_phase_participation(id)
REFERENCES course_phase_participation(id) ON DELETE CASCADE
);

COMMIT;
4 changes: 2 additions & 2 deletions server/db/query/course.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ WHERE id = $1 LIMIT 1;
SELECT * FROM course;

-- name: CreateCourse :one
INSERT INTO course (id, name, start_date, end_date, semester_tag, meta_data)
VALUES ($1, $2, $3, $4, $5, $6)
INSERT INTO course (id, name, start_date, end_date, semester_tag, course_type, ects, meta_data)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;
4 changes: 2 additions & 2 deletions server/db/query/course_phase.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ SELECT * FROM course_phase
WHERE course_id = $1;

-- name: CreateCoursePhase :one
INSERT INTO course_phase (id, course_id, name, is_initial_phase, meta_data)
VALUES ($1, $2, $3, $4, $5)
INSERT INTO course_phase (id, course_id, name, is_initial_phase, meta_data, course_phase_type_id)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *;

-- name: UpdateCoursePhase :exec
Expand Down
Loading