Commit e9e445d1 by Bogdan Andjelkovic

komentari - back

parent c3942707
package com.example.SkuciSe.controller;
import com.example.SkuciSe.model.komentar.Komentar;
import com.example.SkuciSe.model.korisnik.KorisnikDetails;
import com.example.SkuciSe.repository.KomentarRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class KomentarController
{
@Autowired
KomentarRepository komentarRepo;
@PostMapping("/profile/moji-zahtevi/sacuvaj-komentar")
public String postSacuvajKomentar(Model model, @AuthenticationPrincipal KorisnikDetails loggedUser, @ModelAttribute("komentar") Komentar komentar)
{
komentarRepo.insert( loggedUser.getKorisnik().getKorisnikId(), komentar);
return ("redirect:/profile/moji-zahtevi");
}
}
package com.example.SkuciSe.model.komentar;
import lombok.*;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Komentar
{
int komentarId;
int oglasId;
int korisnikId;
int ocena;
String komentar;
}
package com.example.SkuciSe.repository;
import com.example.SkuciSe.model.komentar.Komentar;
import org.springframework.stereotype.Component;
@Component
public class KomentarRepository {
public void insert(int korisnikId, Komentar komentar)
{
komentar.setKorisnikId( korisnikId);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment