Ignore:
Timestamp:
08/30/22 15:33:18 (22 months ago)
Author:
unknown <mlviktor23@…>
Branches:
main
Children:
cae16b5
Parents:
2fcbde4
Message:

implemented upvote/downvote func. in react

File:
1 edited

Legend:

Unmodified
Added
Removed
  • springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java

    r2fcbde4 r62b653f  
    2525@RestController
    2626@RequestMapping("/secure")
    27 @CrossOrigin(origins = { "http://192.168.0.19:3000", "http://192.168.0.24:3000" })
     27@CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0.24:3000" })
    2828public class SecureController {
    2929
     
    7272    }
    7373
     74    @RequestMapping(value = "/professor/{professorId}/upvoteOpinion/{postId}", method = RequestMethod.GET)
     75    public void upvoteOpinion(@PathVariable Long professorId,
     76            @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) {
     77
     78        Authentication authentication = context.getAuthentication();
     79
     80        if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) {
     81            CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal();
     82            mainService.upvoteOpinion(postId, currentUser);
     83        }
     84    }
     85
     86    @RequestMapping(value = "/professor/{professorId}/downvoteOpinion/{postId}", method = RequestMethod.GET)
     87    public void downvoteOpinion(@PathVariable Long professorId,
     88            @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) {
     89
     90        Authentication authentication = context.getAuthentication();
     91
     92        if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) {
     93            CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal();
     94            mainService.downvoteOpinion(postId, currentUser);
     95        }
     96    }
     97
    7498}
Note: See TracChangeset for help on using the changeset viewer.