Ignore:
Timestamp:
12/08/22 22:44:02 (2 years ago)
Author:
viktor <viktor@…>
Branches:
main
Children:
a5aba17
Parents:
3b6962d
Message:

finished edit/delete/displace opinion/thread from report (react); todo reporting user/opinion/thread interface, public user pages and messaging (springboot)

Location:
springapp/src/main/java/mk/profesori/springapp
Files:
2 added
5 edited

Legend:

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

    r3b6962d raf801e3  
    2525@RestController
    2626@RequestMapping("/public")
    27 @CrossOrigin(origins = { "http://192.168.0.19:3000", "http://192.168.0.39:3000" })
     27@CrossOrigin(origins = { "http://192.168.0.29:3000", "http://192.168.0.28:3000" })
    2828public class PublicController {
    2929
  • springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java

    r3b6962d raf801e3  
    66import mk.profesori.springapp.Model.UserRole;
    77import mk.profesori.springapp.Service.CustomUserDetailsService;
     8import mk.profesori.springapp.Service.DisallowedOperationException;
     9import mk.profesori.springapp.Service.IncompatiblePostId;
    810import mk.profesori.springapp.Service.MainService;
    911import org.apache.tomcat.websocket.AuthenticationException;
     
    1820@RestController
    1921@RequestMapping("/secure")
    20 @CrossOrigin(origins = { "http://192.168.0.19:3000", "http://192.168.0.39:3000" })
     22@CrossOrigin(origins = { "http://192.168.0.29:3000", "http://192.168.0.28:3000" })
    2123public class SecureController {
    2224
     
    133135
    134136    @RequestMapping(value = "/updateOpinion/{postId}", method = RequestMethod.PUT)
    135     public void updateOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long postId,
     137    public String updateOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long postId,
    136138            @CurrentSecurityContext SecurityContext context) {
    137139        Authentication authentication = context.getAuthentication();
     
    140142            String newContent = objectNode.get("newContent").asText();
    141143            Long newTargetProfessorId = objectNode.get("newTargetProfessorId").asLong();
    142             mainService.updateOpinion(newContent, newTargetProfessorId, postId);
    143         }
     144            Long newParentPostId = objectNode.get("newParentPostId").asLong();
     145            try {
     146                mainService.updateOpinion(newContent, newTargetProfessorId, newParentPostId, postId);
     147            } catch (IncompatiblePostId | DisallowedOperationException e) {
     148                return e.getMessage();
     149            }
     150        }
     151
     152        return null;
    144153    }
    145154
    146155    @RequestMapping(value = "/updateThread/{postId}", method = RequestMethod.PUT)
    147     public void updateThread(@RequestBody ObjectNode objectNode, @PathVariable Long postId,
     156    public String updateThread(@RequestBody ObjectNode objectNode, @PathVariable Long postId,
    148157            @CurrentSecurityContext SecurityContext context) {
    149158        Authentication authentication = context.getAuthentication();
     
    153162            String newContent = objectNode.get("newContent").asText();
    154163            Long newTargetSubjectId = objectNode.get("newTargetSubjectId").asLong();
    155 
    156             if (objectNode.has("newParentThreadId")) {
    157                 Long newParentThreadId = objectNode.get("newParentThreadId").asLong();
     164            Long newParentThreadId = objectNode.get("newParentThreadId").asLong();
     165            try {
    158166                mainService.update_Thread(newTitle, newContent, newTargetSubjectId, newParentThreadId, postId);
    159             } else {
    160                 mainService.update_Thread(newTitle, newContent, newTargetSubjectId, null, postId);
     167            } catch (IncompatiblePostId | DisallowedOperationException e) {
     168                return e.getMessage();
    161169            }
    162170        }
     171
     172        return null;
    163173    }
    164174
     
    223233    }
    224234
    225     @RequestMapping(value = "/markReportResolved/{postReportId}/", method = RequestMethod.GET)
     235    @RequestMapping(value = "/markReportResolved/{postReportId}/{action}", method = RequestMethod.GET)
    226236    public void markReportResolved(@PathVariable Long postReportId, @PathVariable String action, @CurrentSecurityContext SecurityContext context) {
    227237        Authentication authentication = context.getAuthentication();
    228         if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) {
     238        if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser &&
     239                currentUser.getUserRole().equals(UserRole.MODERATOR)) {
    229240            mainService.markReport(postReportId, action);
    230241        }
  • springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java

    r3b6962d raf801e3  
    3737            @Override
    3838            public void addCorsMappings(CorsRegistry registry) {
    39                 registry.addMapping("/**").allowedOrigins("http://192.168.0.19:3000", "http://192.168.0.39:3000")
     39                registry.addMapping("/**").allowedOrigins("http://192.168.0.29:3000", "http://192.168.0.28:3000")
    4040                        .allowCredentials(true);
    4141            }
  • springapp/src/main/java/mk/profesori/springapp/Service/MainService.java

    r3b6962d raf801e3  
    141141    public void addThread(String title, String content, Long subjectId, CustomUserDetails currentUser) {
    142142        Subject targetSubject = subjectRepository.findBySubjectId(subjectId);
    143 
    144         _Thread _threadToAdd = new _Thread(title, content, currentUser, null, null, null, targetSubject);
     143        String titleToSet = title.equals("") ? null : title;
     144
     145        _Thread _threadToAdd = new _Thread(titleToSet, content, currentUser, null, null, null, targetSubject);
    145146        _threadRepository.save(_threadToAdd);
    146147    }
     
    199200    public void delete_Thread(Long postId) {_threadRepository.deleteById(postId);}
    200201
    201     public void updateOpinion(String newContent, Long newTargetProfessorId, Long postId) {
     202    public String updateOpinion(String newContent, Long newTargetProfessorId, Long newParentPostId, Long postId) {
    202203        Opinion opinionToUpdate = opinionRepository.findByPostId(postId);
    203204
     
    205206
    206207        Professor newTargetProfessor = professorRepository.findByProfessorId(newTargetProfessorId);
    207         opinionToUpdate.setTargetProfessor(newTargetProfessor); //opcijava da ja dava samo kaj postovi so parentPost==null
     208        opinionToUpdate.setTargetProfessor(newTargetProfessor);
     209
     210        Opinion newParentOpinion = null;
     211        if (newParentPostId != -1) {
     212            newParentOpinion = opinionRepository.findByPostId(newParentPostId);
     213            if (!newParentOpinion.getTargetProfessor().equals(newTargetProfessor))
     214                throw new IncompatiblePostId("Мислењето не припаѓа во специфицираната секција за дискусија.");
     215            if (opinionToUpdate.getChildren().contains(newParentOpinion))
     216                throw new DisallowedOperationException("Мислењето не може да се постави како дете на негово дете (бесконечна рекурзија)");
     217        }
     218        opinionToUpdate.setParent(newParentOpinion);
     219
    208220        for(Post p : opinionToUpdate.getChildren()) {
    209221            Opinion o = (Opinion) p;
     
    212224        opinionToUpdate.setTimeLastEdited(LocalDateTime.now());
    213225        opinionRepository.save(opinionToUpdate);
    214     }
    215 
    216     public void update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) {
     226        return null;
     227    }
     228
     229    public String update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) {
    217230        _Thread _threadToUpdate = _threadRepository.findByPostId(postId);
    218231
     
    222235        _threadToUpdate.setTargetSubject(newTargetSubject);
    223236
    224         if(newParentThreadId != null) { //samo ako e specificirano
    225             _Thread newParentThread = _threadRepository.findByPostId(newParentThreadId);
    226 
    227             if (_threadToUpdate.getParent() == null || _threadToUpdate.getParent().getPostId().equals(postId)) {
    228                 _threadToUpdate.setParent(newParentThread);
    229             }//samo ako e naslovniot post ili directChild
    230             } else if(_threadToUpdate.getParent() != null) {
    231             _threadToUpdate.setParent(null);
    232             }
     237        _Thread newParentThread = null;
     238        if(newParentThreadId != -1) {
     239            newParentThread = _threadRepository.findByPostId(newParentThreadId);
     240            if (!newParentThread.getTargetSubject().equals(newTargetSubject))
     241                throw new IncompatiblePostId("Мислењето не припаѓа во специфицираната секција за дискусија.");
     242            if (_threadToUpdate.getChildren().contains(newParentThread))
     243                throw new DisallowedOperationException("Мислењето не може да се постави како дете на негово дете (бесконечна рекурзија)");
     244        }
     245        _threadToUpdate.setParent(newParentThread);
    233246
    234247            if(_threadToUpdate.getParent() == null) {
    235248             _threadToUpdate.setTitle(newTitle);
    236249            } else {
    237              _threadToUpdate.setTitle(null);
    238              }
     250                _threadToUpdate.setTitle(null);
     251            }
    239252
    240253         for(Post p : _threadToUpdate.getChildren()) {
     
    244257         _threadToUpdate.setTimeLastEdited(LocalDateTime.now());
    245258          _threadRepository.save(_threadToUpdate);
     259          return null;
    246260    }
    247261
     
    280294        if (action.equals("resolve")) report.setResolved(true);
    281295        else if (action.equals("open")) report.setResolved(false);
     296        postReportRepository.save(report);
    282297     }
    283298
  • springapp/src/main/java/mk/profesori/springapp/Service/RegistrationService.java

    r3b6962d raf801e3  
    4545                String tokenToResend = customUserDetailsService
    4646                        .createToken(userRepository.findByEmail(request.getEmail()).get());
    47                 String link = "http://192.168.0.19:8080/registration/confirm?token=" + tokenToResend;
     47                String link = "http://192.168.0.29:8080/registration/confirm?token=" + tokenToResend;
    4848                emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link));
    4949                return tokenToResend;
     
    6666                        UserRole.REGULAR));
    6767
    68         String link = "http://192.168.0.19:8080/registration/confirm?token=" + token;
     68        String link = "http://192.168.0.29:8080/registration/confirm?token=" + token;
    6969
    7070        emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link));
Note: See TracChangeset for help on using the changeset viewer.