-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FEAT : 다이나모 기본 설정 * FEAT : gitignore 추가 * FEAT : 센서 데이터 api * FEAT : build.gradle 수정
- Loading branch information
1 parent
d8d8b62
commit 9b448bc
Showing
12 changed files
with
275 additions
and
3 deletions.
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 |
---|---|---|
|
@@ -35,3 +35,4 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
./src/main/resources/application-main.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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/cloudcomputing/ohhanahana/common/DynamoDbConfig.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,52 @@ | ||
package com.cloudcomputing.ohhanahana.common; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration; | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class DynamoDbConfig { | ||
|
||
@Value("${amazon.aws.access-key}") | ||
private String accessKey; | ||
|
||
@Value("${amazon.aws.secret-key}") | ||
private String secretKey; | ||
|
||
@Value("${amazon.aws.region}") | ||
private String region; | ||
|
||
@Value("${amazon.aws.dynamodb.endpoint}") | ||
private String dynamoDBEndpoint; | ||
|
||
@Bean | ||
public DynamoDBMapper dynamoDBMapper() { | ||
DynamoDBMapperConfig mapperConfig = DynamoDBMapperConfig.builder() | ||
.withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.CLOBBER) | ||
.withConsistentReads(DynamoDBMapperConfig.ConsistentReads.CONSISTENT) | ||
.withTableNameOverride(null) | ||
|
||
.withPaginationLoadingStrategy(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING) | ||
.build(); | ||
DynamoDBMapper mapper = new DynamoDBMapper(amazonDynamoDB(), mapperConfig); | ||
return mapper; | ||
} | ||
@Bean | ||
public AmazonDynamoDB amazonDynamoDB() { | ||
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); | ||
AmazonDynamoDB amazonDynamoDB = AmazonDynamoDBClientBuilder.standard() | ||
.withEndpointConfiguration(new EndpointConfiguration(dynamoDBEndpoint, region)) | ||
.withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
.build(); | ||
System.out.println(amazonDynamoDB.listTables()); | ||
return amazonDynamoDB; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/cloudcomputing/ohhanahana/controller/PersonController.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,50 @@ | ||
package com.cloudcomputing.ohhanahana.controller; | ||
|
||
import com.cloudcomputing.ohhanahana.entity.Person; | ||
import com.cloudcomputing.ohhanahana.repository.PersonRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/persons") | ||
public class PersonController { | ||
|
||
@Autowired | ||
private PersonRepository personRepository; | ||
|
||
@PostMapping | ||
public Person save(@RequestBody Person person) { | ||
|
||
return personRepository.save(person); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public Person findById(@PathVariable(value = "id") String id) { | ||
return personRepository.findById(id); | ||
} | ||
|
||
@GetMapping("/all") | ||
public List<Person> findAll() { | ||
return personRepository.findAll(); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public String update(@PathVariable(value="id") String id, | ||
@RequestBody Person person) { | ||
return personRepository.update(id, person); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public String delete(@PathVariable(value="id") String id) { | ||
return personRepository.delete(id); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/cloudcomputing/ohhanahana/controller/SensorDataController.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,22 @@ | ||
package com.cloudcomputing.ohhanahana.controller; | ||
|
||
import com.cloudcomputing.ohhanahana.dto.response.SensorDataResponse; | ||
import com.cloudcomputing.ohhanahana.service.SensorDataService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/congestion") | ||
public class SensorDataController { | ||
|
||
private final SensorDataService sensorDataService; | ||
|
||
@GetMapping | ||
public ResponseEntity<SensorDataResponse> findSensorData() { | ||
return ResponseEntity.ok(sensorDataService.findSensorData()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/cloudcomputing/ohhanahana/dto/response/SensorDataResponse.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,34 @@ | ||
package com.cloudcomputing.ohhanahana.dto.response; | ||
|
||
import com.cloudcomputing.ohhanahana.enums.Congestion; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
|
||
public class SensorDataResponse { | ||
|
||
private String currentLocation; | ||
private String currentDateTime; | ||
private String congestion; | ||
private int expectedWaitingTime; | ||
private int expectedWaitingPeople; | ||
|
||
public static SensorDataResponse toDTO(String currentLocation, String currentDateTime, | ||
String congestion, | ||
int expectedWaitingTime, int expectedWaitingPeople) { | ||
|
||
return SensorDataResponse.builder() | ||
.currentLocation(currentLocation) | ||
.currentDateTime(currentDateTime) | ||
.congestion(congestion) | ||
.expectedWaitingTime(expectedWaitingTime) | ||
.expectedWaitingPeople(expectedWaitingPeople) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/cloudcomputing/ohhanahana/entity/Person.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,22 @@ | ||
package com.cloudcomputing.ohhanahana.entity; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; | ||
import lombok.Data; | ||
|
||
@Data | ||
@DynamoDBTable(tableName = "person") | ||
public class Person { | ||
|
||
@DynamoDBHashKey | ||
@DynamoDBAutoGeneratedKey | ||
private String id; | ||
|
||
@DynamoDBAttribute | ||
private String firstname; | ||
|
||
@DynamoDBAttribute | ||
private String lastname; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/cloudcomputing/ohhanahana/repository/PersonRepository.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,46 @@ | ||
package com.cloudcomputing.ohhanahana.repository; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression; | ||
import com.amazonaws.services.dynamodbv2.model.AttributeValue; | ||
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue; | ||
import com.cloudcomputing.ohhanahana.entity.Person; | ||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class PersonRepository { | ||
|
||
@Autowired | ||
private DynamoDBMapper dynamoDBMapper; | ||
|
||
public Person save(Person person) { | ||
dynamoDBMapper.save(person); | ||
return person; | ||
} | ||
|
||
public Person findById(String id) { | ||
return dynamoDBMapper.load(Person.class, id); | ||
} | ||
|
||
public List<Person> findAll() { | ||
return dynamoDBMapper.scan(Person.class, new DynamoDBScanExpression()); | ||
} | ||
|
||
public String update(String id, Person person) { | ||
dynamoDBMapper.save(person, | ||
new DynamoDBSaveExpression() | ||
.withExpectedEntry("id", | ||
new ExpectedAttributeValue( | ||
new AttributeValue().withS(id) | ||
))); | ||
return id; | ||
} | ||
|
||
public String delete(String id) { | ||
dynamoDBMapper.delete(id); | ||
return "Person deleted successfully::" +id; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/cloudcomputing/ohhanahana/repository/SensorDataRepository.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,13 @@ | ||
package com.cloudcomputing.ohhanahana.repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class SensorDataRepository { | ||
|
||
public void findLatest() { | ||
//TODO - 다이나모 디비에서 최신값 불러오기 | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/cloudcomputing/ohhanahana/service/SensorDataService.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.cloudcomputing.ohhanahana.service; | ||
|
||
import com.cloudcomputing.ohhanahana.dto.response.SensorDataResponse; | ||
import com.cloudcomputing.ohhanahana.enums.Congestion; | ||
import com.cloudcomputing.ohhanahana.repository.SensorDataRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SensorDataService { | ||
|
||
private final SensorDataRepository sensorDataRepository; | ||
|
||
public SensorDataResponse findSensorData() { | ||
sensorDataRepository.findLatest(); | ||
|
||
String congestion = Congestion.NORMAL.getToKorean(); | ||
|
||
return SensorDataResponse.toDTO("인하대학교", | ||
"2024-05-31 16:30 PM", | ||
congestion, | ||
25, | ||
20); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
spring: | ||
application: | ||
name: ohhanahana |