-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sympoll/intial-service-build
Intial service build
- Loading branch information
Showing
14 changed files
with
332 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: RELEASE - Build and push Docker official image to Github packages | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- "**/README.md" | ||
- ".github/workflows/**" | ||
- "**/.gitignore" | ||
workflow_dispatch: | ||
|
||
env: | ||
IMAGE_NAME: ghcr.io/${{ github.repository }}/sympoll-group-service | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to GitHub Packages | ||
run: echo "${{ secrets.PACKAGE_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | ||
|
||
- name: Get current date | ||
id: date | ||
run: echo "::set-output name=DATE::$(date +'%d.%m.%Y')" | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.docker/builder | ||
key: ${{ runner.os }}-build-${{ github.sha }} # Cache key based on OS and commit SHA | ||
restore-keys: | # Check for existing cache based on previous builds with same OS and SHA | ||
${{ runner.os }}-build- | ||
- name: Build and push Docker image | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: | | ||
${{ env.IMAGE_NAME }}:${{ steps.date.outputs.DATE }} | ||
${{ env.IMAGE_NAME }}:latest | ||
cache-from: type=gha,key=${{ runner.os }}-build-${{ github.sha }} # Use cached layers based on commit SHA | ||
cache-to: type=gha,mode=max # Enable caching to GitHub Actions | ||
|
49 changes: 49 additions & 0 deletions
49
.github/workflows/TEST_CONTAINER-docker-build-and-push.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: TEST CONTAINER - Build and push Docker test image to Github packages | ||
on: | ||
workflow_dispatch: | ||
|
||
env: | ||
IMAGE_NAME: ghcr.io/${{ github.repository }}/sympoll-group-service-test | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to GitHub Packages | ||
run: echo "${{ secrets.PACKAGE_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | ||
|
||
- name: Get current date | ||
id: date | ||
run: echo "::set-output name=DATE::$(date +'%d.%m.%Y')" | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.docker/builder | ||
key: ${{ runner.os }}-build-${{ github.sha }} # Cache key based on OS and commit SHA | ||
restore-keys: | # Check for existing cache based on previous builds with same OS and SHA | ||
${{ runner.os }}-build- | ||
- name: Build and push Docker image | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
platforms: linux/amd64,linux/arm64 | ||
tags: | | ||
${{ env.IMAGE_NAME }}:${{ steps.date.outputs.DATE }} | ||
${{ env.IMAGE_NAME }}:latest | ||
cache-from: type=gha,key=${{ runner.os }}-build-${{ github.sha }} # Use cached layers based on commit SHA | ||
cache-to: type=gha,mode=max # Enable caching to GitHub Actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Group Service Schema | ||
CREATE TABLE groups | ||
( | ||
group_id VARCHAR(255) PRIMARY KEY, | ||
group_name VARCHAR(255), | ||
description TEXT, | ||
creator_id UUID, | ||
time_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE members | ||
( | ||
user_id uuid NOT NULL, | ||
group_id VARCHAR(255) REFERENCES groups(group_id) ON DELETE CASCADE NOT NULL, | ||
PRIMARY KEY (group_id, user_id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/controller/ServiceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.controller; | ||
|
||
import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.GroupCreateRequest; | ||
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.GroupResponse; | ||
import com.MTAPizza.Sympoll.groupmanagementservice.service.GroupService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("api/group") | ||
@RequiredArgsConstructor | ||
public class ServiceController { | ||
private final GroupService groupService; | ||
|
||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public GroupResponse createGroup(@RequestBody GroupCreateRequest groupCreateRequest) { | ||
log.info("Received request to create a group"); | ||
log.debug("Group to create received: {}", groupCreateRequest); | ||
return groupService.createGroup(groupCreateRequest); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/request/GroupCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.dto.request; | ||
|
||
import java.util.UUID; | ||
|
||
public record GroupCreateRequest( | ||
String groupId, // can be null, if so then generate a group number | ||
String groupName, | ||
String description, | ||
UUID creatorId | ||
) {} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/response/GroupResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record GroupResponse ( | ||
String groupId, | ||
String groupName, | ||
String description, | ||
UUID creatorId, | ||
LocalDateTime timeCreated, | ||
List<MemberResponse> membersList | ||
) {} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/dto/response/MemberResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.dto.response; | ||
|
||
import java.util.UUID; | ||
|
||
public record MemberResponse( | ||
UUID userId | ||
) {} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/model/Group.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.model; | ||
|
||
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.GroupResponse; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "groups") | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Group { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private String groupId; | ||
|
||
@Column(name = "group_name") | ||
private String groupName; | ||
|
||
@Column(name = "description") | ||
private String description; | ||
|
||
@Column(name = "created_by_user") | ||
private UUID creatorId; | ||
|
||
@Column(name = "time_created") | ||
private final LocalDateTime timeCreated = LocalDateTime.now(); // Initialize to the current time. | ||
|
||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) | ||
@JoinColumn(name = "group_id") | ||
private List<Member> membersList = new ArrayList<>(); // Initialize to an empty members list. | ||
|
||
// TODO: Add Admins list, will be initialized with the creatorId as the only admin. | ||
|
||
public GroupResponse toGroupResponse() { | ||
return new GroupResponse( | ||
groupId, | ||
groupName, | ||
description, | ||
creatorId, | ||
timeCreated, | ||
membersList.stream().map(Member::toMemberResponse).toList() // Convert to member response | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/model/Member.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.model; | ||
|
||
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.MemberResponse; | ||
import jakarta.persistence.*; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@Table(name = "members") | ||
@NoArgsConstructor | ||
@Data | ||
public class Member { | ||
@Column(name = "group_id") | ||
private String groupId; | ||
|
||
@Id | ||
@Column(name = "user_id") | ||
private UUID userId; | ||
|
||
public MemberResponse toMemberResponse() { | ||
return new MemberResponse( | ||
userId | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/repository/GroupRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.repository; | ||
|
||
import com.MTAPizza.Sympoll.groupmanagementservice.model.Group; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface GroupRepository extends JpaRepository<Group, Long> { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.repository; | ||
|
||
import com.MTAPizza.Sympoll.groupmanagementservice.model.Member; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/MTAPizza/Sympoll/groupmanagementservice/service/GroupService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.MTAPizza.Sympoll.groupmanagementservice.service; | ||
|
||
import com.MTAPizza.Sympoll.groupmanagementservice.dto.request.GroupCreateRequest; | ||
import com.MTAPizza.Sympoll.groupmanagementservice.dto.response.GroupResponse; | ||
import com.MTAPizza.Sympoll.groupmanagementservice.model.Group; | ||
import com.MTAPizza.Sympoll.groupmanagementservice.repository.GroupRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class GroupService { | ||
private final GroupRepository groupRepository; | ||
|
||
public GroupResponse createGroup(GroupCreateRequest groupCreateRequest) { | ||
// TODO: Validate request | ||
|
||
// TODO: Add creator Id into a new list of admins | ||
Group createdGroup = Group.builder() | ||
.groupId(groupCreateRequest.groupId()) | ||
.groupName(groupCreateRequest.groupName()) | ||
.description(groupCreateRequest.description()) | ||
.creatorId(groupCreateRequest.creatorId()) | ||
.build(); | ||
|
||
groupRepository.save(createdGroup); | ||
log.info("Group with ID - '{}' was created by - '{}'", createdGroup.getGroupId(), createdGroup.getCreatorId()); | ||
|
||
return createdGroup.toGroupResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
spring.application.name=group-management-service | ||
server.port=8085 | ||
spring.application.name=group-service | ||
spring.datasource.url=jdbc:postgresql://group-db:5435/postgres | ||
spring.datasource.username=postgres | ||
spring.datasource.password=1 | ||
spring.datasource.driver-class-name=org.postgresql.Driver | ||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect | ||
|
||
# Use These Settings to Debug Spring Boot: | ||
# --------------------------------------- | ||
# logging.level.root=DEBUG | ||
# logging.level.org.springframework.web=DEBUG | ||
# logging.level.org.springframework=DEBUG | ||
# logging.level.org.hibernate=ERROR |