This file contains hidden or 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
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
// Override point for customization after application launch. | |
let builder = RetroSwift.Builder() | |
.baseUrl("http://api.openweathermap.org/data/2.5") | |
.build() | |
_ = RetroSwift(builder: builder) | |
return true | |
} |
This file contains hidden or 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
private fun postNewGroceryItemToServer(dialog: DialogInterface, view: View) { | |
val etItemName = view.findViewById<EditText>(R.id.et_grocery_item_name) | |
val checkBoxIsAvailable = view.findViewById<CheckBox>(R.id.checkbox_grocery_item_is_available) | |
val groceryItem = GroceryItem(etItemName.text.toString(), checkBoxIsAvailable.isChecked) | |
swipe_refresh_grocery_items.isRefreshing = true | |
GroceryServiceFactory.makeService().addGroceryItem(groceryItem).enqueue(object: Callback<StatusResponseEntity<GroceryItem>?> { | |
override fun onFailure(call: Call<StatusResponseEntity<GroceryItem>?>, t: Throwable) { | |
swipe_refresh_grocery_items.isRefreshing = false |
This file contains hidden or 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
package za.co.dubedivine.groceryapp.data.remote | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
import okhttp3.OkHttpClient | |
import okhttp3.logging.HttpLoggingInterceptor | |
object GroceryServiceFactory { |
This file contains hidden or 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
package za.co.dubedivine.groceryapp.data.remote | |
import retrofit2.Call | |
import retrofit2.http.* | |
import za.co.dubedivine.groceryapp.model.GroceryItem | |
import za.co.dubedivine.groceryapp.model.responseModel.StatusResponseEntity | |
interface GroceryService { | |
@GET("groceries") |
This file contains hidden or 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
package za.co.dubedivine.groceryapp.config | |
import org.springframework.boot.CommandLineRunner | |
import org.springframework.stereotype.Component | |
import za.co.dubedivine.groceryapp.model.GroceryItem | |
import za.co.dubedivine.groceryapp.repository.GroceryItemRepository | |
import javax.persistence.PrePersist | |
@Component | |
class DBHelper(private val groceryRepository: GroceryItemRepository) : CommandLineRunner { |
This file contains hidden or 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
package za.co.dubedivine.groceryapp.model.responseModel | |
data class StatusResponseEntity<T>(val status: Boolean, val message: String, val entity: T?) |
This file contains hidden or 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
@PutMapping | |
fun addGroceryItem(@RequestBody groceryItem: GroceryItem): ResponseEntity<StatusResponseEntity<GroceryItem>> { | |
val savedItem = groceryRepository.save(groceryItem) | |
return ResponseEntity(StatusResponseEntity( | |
true, | |
"Added new grocery item to your list", | |
savedItem | |
), HttpStatus.CREATED) | |
} |
This file contains hidden or 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
@GetMapping | |
fun getGroceriesList(): MutableIterable<GroceryItem> { | |
return groceryRepository.findAll() | |
} |
This file contains hidden or 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
@Query("select g from GroceryItem g where g.isAvailable = ?1") | |
fun findItemsByAvailability(availability: Boolean): List<GroceryItem> |
This file contains hidden or 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
package za.co.dubedivine.groceryapp.repository | |
import org.springframework.data.repository.CrudRepository | |
import org.springframework.stereotype.Repository | |
import za.co.dubedivine.groceryapp.model.GroceryItem | |
@Repository | |
interface GroceryItemRepository: CrudRepository<GroceryItem, Long> |
NewerOlder