Skip to content

Commit

Permalink
本番環境デプロイ設定完了
Browse files Browse the repository at this point in the history
  • Loading branch information
yokohama committed Aug 13, 2024
1 parent 8d584ae commit ed0a7a0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
3 changes: 3 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ seed:

test: seed
cargo test -- --nocapture --test-threads=1

test-production:
./bin/production_test.sh
38 changes: 38 additions & 0 deletions backend/bin/production_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
URL="https://nps7ce8bkw.ap-northeast-1.awsapprunner.com"
EMAIL="[email protected]"
PASSWORD="XYz1234&&&"

try() {
echo "#-- $1"
}

next() {
echo "\n"
sleep 3
}

# Already created!
#try "POST user/registration"
#curl -X POST "$URL/user/registration" -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}"
#next

try "POST user/session"
JWT=$(curl -s -X POST "$URL/user/session" -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}" | jq -r '.access_token')
echo $JWT
if [ -z "$JWT" ]; then
echo "Error: Failed to retrieve JWT token"
exit 1
fi
next

try "GET user/dashboard"
curl -X GET "$URL/user/dashboard" -H 'Content-Type: application/json' -H "Authorization: Bearer $JWT"
next

try "POST user/point_conditions"
curl -X POST "$URL/user/point_conditions" -H 'Content-Type: application/json' -H "Authorization: Bearer $JWT" -d '{"end_date":"2024-08-13","lat":35.3741,"lon":140.3708,"start_date":"2024-08-13","timezone":"Asia/Tokyo"}'
next

try "GET user/point_conditions"
curl -X GET "$URL/user/point_conditions" -H 'Content-Type: application/json' -H "Authorization: Bearer $JWT"
next
16 changes: 0 additions & 16 deletions backend/src/controllers/user/point_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use axum::{
};
use serde::Serialize;
use sqlx::PgPool;
use tracing::debug;

use crate::{
middleware::{auth, error},
Expand Down Expand Up @@ -35,21 +34,10 @@ pub async fn create(
Json(payload): Json<requests::point_condition::New>,
) -> Result<Json<impl Serialize>, error::AppError> {

debug!(">>");
debug!(">>");
debug!(">>");
debug!(">>");
debug!(">>");
debug!(">>");
debug!(">>");
debug!(">>");
debug!(">>");

let geocode = open_meteo::Geocode {
latitude: payload.lat,
longitude: payload.lon,
};
debug!(">> 1");

let forecast = forecast::fetch(
&geocode,
Expand All @@ -62,7 +50,6 @@ pub async fn create(
&payload.end_date,
&payload.timezone,
).await?;
debug!(">> 2");

let current_user = claims.get_current_user(&pool).await?;
let new = models::point_condition::New {
Expand All @@ -82,11 +69,8 @@ pub async fn create(
weather_code_unit: forecast.units.weather_code,
wind_speed: forecast.current.wind_speed,
wind_speed_unit: forecast.units.wind_speed,

};
debug!(">> 3");
let created = models::point_condition::create(&pool, new).await?;
debug!(">> 4");

Ok(Json(created))
}
12 changes: 1 addition & 11 deletions backend/src/models/point_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sqlx::{
FromRow,
};

use tracing::{debug, error};
use tracing::error;

use crate::middleware::error;

Expand Down Expand Up @@ -62,14 +62,6 @@ pub async fn create(
pool: &PgPool,
new_condition: New
) -> Result<Created, error::AppError> {
debug!("###");
debug!("###");
debug!("###");
debug!("###");
debug!("###");
debug!("###");
debug!("###");
debug!("###");
let sql = r#"
INSERT INTO point_conditions (
user_id,
Expand All @@ -93,7 +85,6 @@ pub async fn create(
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, NOW())
RETURNING id, user_id, lat, lon, time, swell_wave_height, swell_wave_height_unit, swell_wave_direction, swell_wave_direction_unit, rain, rain_unit, temperature, temperature_unit, weather_code, weather_code_unit, wind_speed, wind_speed_unit
"#;
debug!("### 6");

let created = query_as::<_, Created>(sql)
.bind(new_condition.user_id)
Expand All @@ -118,7 +109,6 @@ pub async fn create(
error!("{:#?}", e);
error::AppError::DatabaseError(e.to_string())
})?;
debug!("### 7");

Ok(created)
}
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/e2e/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn registration_and_dashboard() {

assert_eq!(user["email"], NEW_USER_EMAIL);

let res = request_dashboard(&client, NEW_USER_EMAIL, NEW_USER_PASSWORD)
let res = get_dashboard(&client, NEW_USER_EMAIL, NEW_USER_PASSWORD)
.await;

assert_eq!(res.status(), 200);
Expand All @@ -56,7 +56,7 @@ async fn registration_and_dashboard() {
#[tokio::test]
async fn dashboard() {
let client = Client::new();
let res = request_dashboard(&client, EMAIL, PASSWORD).await;
let res = get_dashboard(&client, EMAIL, PASSWORD).await;

assert_eq!(res.status(), 200);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn point_conditions() {
assert_eq!(conditions.len(), 4);
}

async fn request_dashboard(
async fn get_dashboard(
client: &Client,
email: &str,
password: &str
Expand All @@ -137,7 +137,7 @@ async fn request_dashboard(
.await;

common::Curl::new(
"POST".to_string(),
"GET".to_string(),
url.to_string(),
&None,
&Some(jwt.clone())
Expand Down

0 comments on commit ed0a7a0

Please sign in to comment.