Skip to content
Snippets Groups Projects
Commit a5fb7d6a authored by Valentin Degauchy's avatar Valentin Degauchy
Browse files

after conflict

parents 91010be8 912c1e13
No related branches found
No related tags found
No related merge requests found
package com.tpKotlin.glhf.tpkotlin.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
//import org.springframework.ui.ModelMap;
//import org.springframework.validation.BindingResult;
......@@ -9,12 +10,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.tpKotlin.glhf.tpkotlin.entity.FavDir;
import com.tpKotlin.glhf.tpkotlin.service.DossierFavService;
//import com.tpKotlin.glhf.tpkotlin.entity.Bidon;
@Controller
public class SimpleController {
@Autowired
private DossierFavService dfs;
@RequestMapping({ "/", "/index" })
public ModelAndView index() {
return new ModelAndView("index", "msg", "Bienvenue !");
......
......@@ -4,6 +4,5 @@ import com.tpKotlin.glhf.tpkotlin.entity.Meme
interface ImageAccessorDao {
fun getImg(nom: String): Any
fun getAll(): List<Any>
fun saveMeme(meme: Meme)
}
\ No newline at end of file
package com.tpKotlin.glhf.tpkotlin.dao
import com.tpKotlin.glhf.tpkotlin.entity.FavDir
import com.tpKotlin.glhf.tpkotlin.entity.Meme
import com.tpKotlin.glhf.tpkotlin.tools.FileManager
import kotlinx.coroutines.*
import org.springframework.stereotype.Component
@Component
class ImageAccessorDaoImpl : ImageAccessorDao {
override fun getImg(nom: String) {
Thread.sleep(1000L) //celui qui retire ça est maudit pendant 3 generation (la sienne incluse)
runBlocking{
delay(1000L)
} //celui qui retire çeci sera maudit pendant 3 generations (la sienne incluse)
return
}
override fun getAll(): List<Any> {
var liste = FavDir.getAll()
for (img in liste) {
this.getImg("img.name")
}
return liste;
}
override fun saveMeme(meme: Meme) {
FileManager.saveMemeInFile(meme.nom, meme.url)
}
......
......@@ -30,8 +30,7 @@ import com.tpKotlin.glhf.tpkotlin.tools.FileManager
//open class Bidon(open var nom: String, @Id @GeneratedValue open var id: Long? = null)
object FavDir {
val name: String = "FavDir"
val list: MutableList<String> = mutableListOf("hdlof oods q")
val list: MutableList<Meme> = mutableListOf()
init {
println("Dossier de favoris crée")
......@@ -40,27 +39,25 @@ object FavDir {
}
}
fun addMeme(src: String) {
list.add(src)
FileManager.saveMemeInFile(src, src)
}
fun addMeme(meme: Meme) {
//TODO ajouterd dans la liste de Meme et pas de String
list.add(meme)
FileManager.saveMemeInFile(meme.nom, meme.url)
}
fun loadMeme(meme: Meme) {
list.add(meme)
}
@JvmStatic
fun affiche(): String {
var s: String = ""
for (i in 0 until list.size) {
s = s + " " + list.get(i)
//println(list.get(i))
s = list.get(i).url + "&&&"+ s
}
return s
}
fun getAll(): MutableList<String> {
fun getAll(): MutableList<Meme> {
return list
}
}
......
......@@ -2,6 +2,6 @@ package com.tpKotlin.glhf.tpkotlin.service
interface DossierFavService {
fun insertMeme(): Boolean
fun getAllImagesFromFav(): List<Any>
fun getAllImagesFromFavFASTER(): List<Any>
fun getAllImagesFromFav(): String
fun getAllImagesFromFavFASTER(): String
}
\ No newline at end of file
package com.tpKotlin.glhf.tpkotlin.service
import com.tpKotlin.glhf.tpkotlin.dao.ImageAccessorDao
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.springframework.beans.factory.annotation.Autowired
import kotlinx.coroutines.*
import com.tpKotlin.glhf.tpkotlin.entity.FavDir
import com.tpKotlin.glhf.tpkotlin.entity.Meme
import org.springframework.stereotype.Service
import com.tpKotlin.glhf.tpkotlin.dao.ImageAccessorDaoImpl
import org.springframework.beans.factory.annotation.Autowired
@Service
class DossierFavServiceImpl : DossierFavService {
......@@ -19,17 +22,30 @@ class DossierFavServiceImpl : DossierFavService {
}
//Truc lent pour l'exo 3
override fun getAllImagesFromFav(): List<Any> {
return imgDao.getAll()
override fun getAllImagesFromFav(): String {
var liste = FavDir.getAll()
var s: String = ""
for (i in 0 until liste.size) {
s = liste.get(i).url + "&&&" + s
}
for (img in liste) {
imgDao.getImg(img.nom);
}
return s
}
//Truc rapide pour le 4
override fun getAllImagesFromFavFASTER(): List<Any> {
var images = imgDao.getAll()
override fun getAllImagesFromFavFASTER(): String {
var liste = FavDir.getAll()
var s: String = ""
for (i in 0 until liste.size) {
s = liste.get(i).url + "&&&" + s
}
for (img in liste) {
GlobalScope.launch {
imgDao.getImg(img.nom);
}
return images
}
return s;
}
}
\ No newline at end of file
......@@ -10,15 +10,17 @@ object FileManager {
val PATH_TO_FILE = "src/main/resources/files/"
fun thereIsSomethingInTheFile(): Boolean {
var res = false
File(PATH_TO_FILE + FILE_NAME).bufferedReader().lines().use { lines ->
for (line in lines) {
if (!line.startsWith('#')) {
return true
res = true
break
}
}
}
return false
return res
}
fun loadAllFromFile() {
......@@ -28,7 +30,7 @@ object FileManager {
if (!it.startsWith('#')) {
tab = it.split(" ")
if (tab.size == 2)
FavDir.addMeme(Meme(tab[0], tab[1]))
FavDir.loadMeme(Meme(tab[0], tab[1]))
}
}
}
......
......@@ -6,52 +6,21 @@
<head>
<meta charset="UTF-8">
<c:import url="/WEB-INF/jsp/header.jsp" />
<title>Exercice 1</title>
<title>${msg}</title>
</head>
<body>
<h1 class="content-title">Exercice 1 : Singleton</h1>
<br><br>
<br>
<br>
<div class="row">
<div class="col-sm-6">
<h2> Mon Repo Favoris : NAMEREPO </h2> <br><br>
<ul>
<c:forTokens items="${dirfav}" delims=" " var="name">
<li><c:out value="${name}"/>
<div class="offset-sm-1 col-sm-10">
<h2>Mon Repo Favoris :</h2>
<br>
<br>
<c:forTokens items="${dirfav}" delims="&&&" var="name">
<img src="${name}" />
</c:forTokens>
</ul>
</div>
<div class="col-sm-6">
<h2> Ajout Favoris </h2>
<div class="container-fluid">
<form action="/ex1" style="padding-left: 20px;">
<div class="row">
<div class="col-sm-2 offset-md-1">
Fav name:
</div>
<div class="col-sm-auto">
<input type="text" name="Name" placeholder="nom">
</div>
</div><br>
<div class="row">
<div class="col-sm-2 offset-md-1">
URL img:
</div>
<div class="col-sm-auto">
<input type="text" name="URL" placeholder="img">
</div>
</div><br>
<div class="row">
<div class="col-sm-4 offset-md-6 center">
<input type="submit" value="Submit">
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment