Skip to content

Commit

Permalink
Merge pull request #466 from bounswe/dev
Browse files Browse the repository at this point in the history
merging dev into the new branch
  • Loading branch information
kubraaksux authored Nov 27, 2023
2 parents d974e8f + 255988b commit 3f98f08
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 47 deletions.
47 changes: 40 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,51 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4.1.1
uses: actions/checkout@v4

- name: Decrypt and Extract project_env_prod
- name: SSH into AWS EC2
env:
RESQ_PASSPHRASE: ${{ secrets.RESQ_PASSPHRASE }}
AWS_PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
run: |
cd ./resq/backend/resq/
gpg --quiet --batch --yes --decrypt --passphrase="$RESQ_PASSPHRASE" --output project_env_prod.tar.gz project_env_prod.tar.gz.gpg
tar xzvf project_env_prod.tar.gz
echo "$AWS_PRIVATE_KEY" > aws-key.pem
chmod 600 aws-key.pem
ssh -o StrictHostKeyChecking=no -i ./aws-key.pem ec2-user@16.16.63.194
ls
- name: Update and Install libssl-dev
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev
- name: Print libcrypto Version
run: |
openssl version
- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "$PRIVATE_REPO_SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
env:
PRIVATE_REPO_SSH_KEY: ${{ secrets.PRIVATE_REPO_SSH_KEY }}

- name: Clone Private Repository
run: |
cd ..
ls
git clone git@github.com:alitpc25/cmpe451group1configrepo.git
cp -r cmpe451group1configrepo/project_env_prod ./resq/backend/resq/project_env_prod
# - name: Decrypt and Extract project_env_prod
# env:
# RESQ_PASSPHRASE: ${{ secrets.RESQ_PASSPHRASE }}
# run: |
# cd ./resq/backend/resq/
# gpg --quiet --batch --yes --verbose --decrypt --passphrase="$RESQ_PASSPHRASE" --output project_env_prod.tar.gz project_env_prod.tar.gz.gpg
# tar xzvf project_env_prod.tar.gz

- name: Set up Docker
uses: docker/setup-buildx-action@v3.0.0
Expand Down
6 changes: 6 additions & 0 deletions resq/backend/resq/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ build/

### VS Code ###
.vscode/

src/resources/firebase-service-account.json
project_env_prod/
project_env/
/src/main/resources/firebase-service-account.json
/src/main/resources/keystore.jks
6 changes: 0 additions & 6 deletions resq/backend/resq/Dockerfile

This file was deleted.

17 changes: 17 additions & 0 deletions resq/backend/resq/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM maven:3.6.3-openjdk-17 as stage1
WORKDIR /app
COPY pom.xml .
# go-offline using the pom.xml
RUN mvn dependency:go-offline
# copy your other files
COPY ./src ./src
# compile the source code and package it in a jar file
RUN mvn clean install -Dmaven.test.skip=true

FROM openjdk:17-jdk
WORKDIR /app
ARG JAR_FILE=/app/target/resq-0.0.1-SNAPSHOT.jar
COPY --from=stage1 ${JAR_FILE} ./app/app.jar
COPY project_env /app/config
ENV resq.appdir=/app/config
ENTRYPOINT ["java","-jar","./app/app.jar"]
17 changes: 17 additions & 0 deletions resq/backend/resq/Dockerfile.remote
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM maven:3.6.3-openjdk-17 as stage1
WORKDIR /app
COPY ./pom.xml .
# go-offline using the pom.xml
RUN mvn dependency:go-offline
# copy your other files
COPY ./src ./src
# compile the source code and package it in a jar file
RUN mvn clean install -Dmaven.test.skip=true

FROM openjdk:17-jdk
WORKDIR /app
ARG JAR_FILE=./app/target/resq-0.0.1-SNAPSHOT.jar
COPY --from=stage1 ${JAR_FILE} ./app/app.jar
COPY ./project_env_prod /app/config
ENV resq.appdir=/app/config
ENTRYPOINT ["java","-jar","./app/app.jar"]
22 changes: 21 additions & 1 deletion resq/backend/resq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ From Run Configurations Menu add new SpringBootApplication Run Configuration.
In the configuration, add the config folder with environment variable named as resq.appdir
(For example: resq.appdir=C:\Users\alitp\OneDrive\Masaüstü\remoterepo\project_env. In my system, project_env includes the resq folder which is the config folder.)

You may need to change some settings in appparam.txt file according to your system, passwords etc.
### Installing with Docker

First clone all files into local repo.

Place the config folder named as project_env under the resq folder(under the directory bounswe2023group1\resq\backend\resq, resides in the same directory with src.).
Then, run the following commands:

docker build -t resq:latest -f Dockerfile.local .
docker-compose up

## Integrations
### Database Connections

Expand All @@ -44,4 +55,13 @@ You should change the database connection settings based on your PostgreSQL serv

## Project Specific Information

Application context root is /resq/api/v1/. You can reach the application via http://localhost:8081/resq/api/v1/. To reach the API documentation: http://localhost:8081/resq/api/v1/swagger-ui.html
Application context root is /resq/api/v1/. You can reach the application via
https://localhost:8081/resq/api/v1/.
To reach the API documentation:
https://localhost:8081/resq/api/v1/swagger-ui.html


Production API Documentation:
https://api.resq.org.tr/resq/api/v1/swagger-ui/index.html

Production URL: https://api.resq.org.tr/resq/api/v1
34 changes: 34 additions & 0 deletions resq/backend/resq/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.1'
services:
backend:
container_name: backend
image: backend:latest
build:
context: .
dockerfile: Dockerfile.local
ports:
- "8081:8081"
expose:
- "8081"
depends_on:
- db
environment:
- RESQ_APPDIR=/app/config
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
- SPRING_DATASOURCE_USERNAME=compose-postgres
- SPRING_DATASOURCE_PASSWORD=compose-postgres
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
networks:
- app_network

db:
image: 'postgres:13.1'
container_name: db
environment:
- POSTGRES_USER=compose-postgres
- POSTGRES_PASSWORD=compose-postgres
networks:
- app_network

networks:
app_network:
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UserSessionManager(appContext: Context) {
editor.putString(USER_EMAIL, userEmail)
editor.putString(USER_ROLES, rolesJson)
if (userRoles.isNotEmpty()) {
editor.putString(SELECTED_ROLE, userRoles.last())
editor.putString(SELECTED_ROLE, userRoles.first())
}
editor.putBoolean(KEY_IS_LOGGED_IN, true)
editor.apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ data class CategoryNode(
val children: List<CategoryNode>
)

data class CreateNeedRequestBody(
val description: String,
val latitude: Double,
val longitude: Double,
val categoryTreeId: String,
val quantity: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.cmpe451.resq.data.Constants
import com.cmpe451.resq.data.manager.UserSessionManager
import com.cmpe451.resq.data.models.CategoryNode
import com.cmpe451.resq.data.models.CreateNeedRequestBody
import com.cmpe451.resq.data.models.LoginRequestBody
import com.cmpe451.resq.data.models.LoginResponse
import com.cmpe451.resq.data.models.ProfileData
Expand All @@ -26,9 +27,11 @@ interface CategoryTreeNodeService {
interface NeedService {
@POST("need/createNeed")
suspend fun createNeed(
@Query("userId") userId: Int,
@Header("Authorization") jwtToken: String,
@Header("X-Selected-Role") role: String
)
@Header("X-Selected-Role") role: String,
@Body requestBody: CreateNeedRequestBody
): Response<Int>
}

interface AuthService {
Expand All @@ -55,6 +58,7 @@ class ResqService(appContext: Context) {
.build()

private val categoryTreeNodeService: CategoryTreeNodeService = retrofit.create(CategoryTreeNodeService::class.java)
private val needService: NeedService = retrofit.create(NeedService::class.java)
private val authService: AuthService = retrofit.create(AuthService::class.java)
private val profileService: ProfileService = retrofit.create(ProfileService::class.java)

Expand All @@ -71,14 +75,28 @@ class ResqService(appContext: Context) {
)
}

// Need methods
suspend fun createNeed(request: CreateNeedRequestBody): Response<Int> {
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
val selectedRole = userSessionManager.getSelectedRole() ?: ""

return needService.createNeed(
userId = userId,
jwtToken = "Bearer $token",
role = selectedRole,
requestBody = request
)
}

// Auth methods
suspend fun login(request: LoginRequestBody): Response<LoginResponse> = authService.login(request)
suspend fun register(request: RegisterRequestBody): Response<ResponseBody> = authService.register(request)

// Profile methods
suspend fun getUserInfo(): ProfileData {
val token = userSessionManager.getUserToken() ?: ""
val userId = userSessionManager.getUserId()
val token = userSessionManager.getUserToken() ?: ""
val selectedRole = userSessionManager.getSelectedRole() ?: ""

val response = profileService.getUserInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -58,12 +61,11 @@ fun RequestScreen(
val selectedCategoryState = viewModel.selectedCategory
val categories = viewModel.categories.value


val priorities = listOf("HIGH", "MEDIUM", "LOW")
var selectedPriority by remember { mutableStateOf(viewModel.selectedPriority.value) }

var description by remember { mutableStateOf("") }
var quantity by remember { mutableStateOf("") }

val snackbarHostState = remember { SnackbarHostState() }

Column(
modifier = Modifier
.background(Color.White)
Expand Down Expand Up @@ -132,22 +134,18 @@ fun RequestScreen(

Spacer(modifier = Modifier.height(16.dp))

DropdownMenuComponent(
label = "Priority",
items = priorities,
selectedItem = selectedPriority,
itemToString = { it },
onItemSelected = { priority ->
selectedPriority = priority
viewModel.updatePriority(priority)
}
OutlinedTextField(
value = description,
onValueChange = { description = it },
label = { Text("Description") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
modifier = Modifier.fillMaxWidth()
)


Spacer(modifier = Modifier.height(16.dp))

OutlinedTextField(
value = quantity, // you can bind this to a state variable to store the quantity
value = quantity,
onValueChange = { quantity = it },
label = { Text("Quantity") },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
Expand All @@ -158,14 +156,24 @@ fun RequestScreen(

// Enter Button
Button(
onClick = { viewModel.onEnter() },
onClick = { viewModel.onEnter(description, quantity, appContext) },
colors = ButtonDefaults.buttonColors(backgroundColor = LightGreen),
shape = RoundedCornerShape(50)
) {
Text(text = "Enter")
}
}
}
// Success and Error messages
if (viewModel.createNeedResponse.value != null) {
LaunchedEffect(key1 = viewModel.createNeedResponse.value) {
snackbarHostState.showSnackbar(
message = "Need created successfully.",
duration = SnackbarDuration.Long
)
}
}
SnackbarHost(hostState = snackbarHostState)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class LoginViewModel() : ViewModel() {
)
}


private fun validateLoginInputs(email: String, password: String): Boolean {
return when {
email.isBlank() -> {
Expand Down
Loading

0 comments on commit 3f98f08

Please sign in to comment.