Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon authored and ford-at-aws committed Nov 23, 2022
1 parent 0488cb0 commit 660eebb
Show file tree
Hide file tree
Showing 2 changed files with 437 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package com.aws.rest

import kotlinx.coroutines.runBlocking
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.CrossOrigin
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.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import java.io.IOException

@SpringBootApplication
open class App

fun main(args: Array<String>) {
runApplication<App>(*args)
}

@CrossOrigin(origins = ["*"])
@RestController
class MessageResource {

@Autowired
private lateinit var dbService: DynamoDBService

@Autowired
private lateinit var sendMsg: SendMessage

// Add a new item to the Amazon DynamoDB database.
@PostMapping("api/items")
fun addItems(@RequestBody payLoad: Map<String, Any>): String = runBlocking {
val nameVal = "user"
val guideVal = payLoad.get("guide").toString()
val descriptionVal = payLoad.get("description").toString()
val statusVal = payLoad.get("status").toString()

// Create a Work Item object.
val myWork = WorkItem()
myWork.guide = guideVal
myWork.description = descriptionVal
myWork.status = statusVal
myWork.name = nameVal
val id = dbService.putItemInTable(myWork)
return@runBlocking "Item $id added successfully!"
}

// Retrieve items.
@GetMapping("api/items")
fun getItems(@RequestParam(required = false) archived: String?): MutableList<WorkItem> = runBlocking {
val list: MutableList<WorkItem>
if (archived == "false") {
list = dbService.getOpenItems(false)
} else if (archived == "true") {
list = dbService.getOpenItems(true)
} else {
list = dbService.getAllItems()
}
return@runBlocking list
}

// Flip an item from Active to Archive.
@PutMapping("api/items/{id}:archive")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
fun modUser(@PathVariable id: String) = runBlocking {
dbService.archiveItemEC(id)
return@runBlocking
}

@PostMapping("api/items:report")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
fun sendReport(@RequestBody body: Map<String, String>) = runBlocking {
val email = body.get("email")
val xml = dbService.getOpenReport(false)
try {
if (email != null) {
sendMsg.send(email, xml)
}
} catch (e: IOException) {
e.stackTrace
}
return@runBlocking
}
}
Loading

0 comments on commit 660eebb

Please sign in to comment.