0.0.11, enable cors
This commit is contained in:
1 parent
68ab91e4fc
commit
ac328d8cef
13 files changed
+69
-12
No files matched your search
@@ -39,7 +39,7 @@ public class AuthController {
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
|
||||
|
||||
//@
|
||||
@PostMapping("/signup")
|
||||
public ResponseEntity<Object> registration(@Valid @RequestBody SignupRequest signupRequest,
|
||||
BindingResult bindingResult) {
|
||||
@@ -54,6 +54,7 @@ public class AuthController {
|
||||
return ResponseEntity.ok(new MessageResponse("Account registered successfully!"));
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<Object> authentication(@Valid @RequestBody LoginRequest loginRequest,
|
||||
BindingResult bindingResult) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import site.easystartup.web.domain.model.Role;
|
||||
@@ -20,11 +21,13 @@ public class RegistrationController {
|
||||
|
||||
private final UserRepo userRepo;
|
||||
|
||||
//@
|
||||
@GetMapping("/registration")
|
||||
public String registration() {
|
||||
return "registration";
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/registration")
|
||||
public String addUser(User user, Model model) {
|
||||
User userFromDb = userRepo.findByUsername(user.getUsername());
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package site.easystartup.web.config;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableWebMvc
|
||||
|
||||
public class MvcConfig extends WebMvcConfigurerAdapter {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("PUT", "GET", "DELETE", "OPTIONS", "PATCH", "POST");
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class UserController {
|
||||
private final ResponseErrorValidation responseErrorValidation;
|
||||
private final FastChecksUtil checksUtil;
|
||||
|
||||
//@
|
||||
@GetMapping("/user/current")
|
||||
public ResponseEntity<Object> getCurrentUser(Principal principal) {
|
||||
//if(principal == null)
|
||||
@@ -43,15 +44,16 @@ public class UserController {
|
||||
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/user/{username}")
|
||||
public ResponseEntity<UserDto> getUser(@PathVariable String username) {
|
||||
Long id = Long.parseLong(username);
|
||||
ResponseEntity<UserDto> result = checksUtil.nullIfValid(id);
|
||||
ResponseEntity<UserDto> result = checksUtil.nullIfValid(username);
|
||||
return result == null ? ResponseEntity.ok().body(modelMapper.map(userService.getUserByUsername(username), UserDto.class)) : result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//@
|
||||
@PutMapping("/user/edit/{username}")
|
||||
public ResponseEntity<Object> userEdit(@PathVariable String username,@Valid @RequestBody UserRequest userRequest,
|
||||
BindingResult bindingResult, Principal principal) {
|
||||
|
||||
@@ -38,6 +38,7 @@ public class ForumController {
|
||||
private final ModelMapper modelMapper;
|
||||
private final ResponseErrorValidation responseErrorValidation;
|
||||
|
||||
//@
|
||||
@GetMapping("/")
|
||||
public ResponseEntity<List<TopicDto>> main(@Valid @RequestBody ProjectRequest projectRequest,
|
||||
BindingResult bindingResult,
|
||||
@@ -47,6 +48,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(topics);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/my")
|
||||
public ResponseEntity<List<DiscussionDto>> my(Principal principal) {
|
||||
var discussions = forumService.getDiscussionsByAuthor(principal)
|
||||
@@ -55,6 +57,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(discussions);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/takepart")
|
||||
public ResponseEntity<List<DiscussionDto>> takePart(Principal principal) {
|
||||
var discussions = forumService.getDiscussionsByMember(principal)
|
||||
@@ -62,6 +65,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(discussions);
|
||||
}
|
||||
|
||||
//@
|
||||
@Secured({"ADMIN", "MODER"})
|
||||
@PostMapping("/new")
|
||||
public ResponseEntity<Object> forumNew(@Valid @RequestBody TopicRequest topicRequest,
|
||||
@@ -74,6 +78,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(topic, TopicDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{topic_id}/{page_id}")
|
||||
public ResponseEntity<List<DiscussionDto>> topicPage(@PathVariable long topic_id,
|
||||
@PathVariable long page_id) {
|
||||
@@ -82,11 +87,13 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(discussions);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/discussion/{discussion_id}")
|
||||
public ResponseEntity<DiscussionDto> discussion(@PathVariable(value = "discussion_id") long discussion_id) {
|
||||
return ResponseEntity.ok().body(modelMapper.map(forumService.getDiscussionById(discussion_id), DiscussionDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/new/{topic_id}")
|
||||
public ResponseEntity<Object> discussionNew(@PathVariable long topic_id,
|
||||
@Valid @RequestBody DiscussionRequest discussionRequest,
|
||||
@@ -99,6 +106,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(discussion, DiscussionDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/discussion/edit/{discussion_id}")
|
||||
public ResponseEntity<Object> discussionEdit(@Valid @RequestBody DiscussionRequest discussionRequest,
|
||||
@PathVariable long discussion_id,
|
||||
@@ -111,6 +119,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(discussionUpdated, DiscussionDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/discussion/new/{discussion_id}")
|
||||
public ResponseEntity<Object> messageAdd(@PathVariable long discussion_id,
|
||||
@Valid @RequestBody DiscussionMessageRequest messageRequest,
|
||||
@@ -123,11 +132,13 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(discussionMessage, DiscussionMessageDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/message/{message_id}")
|
||||
public ResponseEntity<DiscussionMessageDto> message(@PathVariable long message_id) {
|
||||
return ResponseEntity.ok().body(modelMapper.map(forumService.getDiscussionMessageById(message_id), DiscussionMessageDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/message/edit/{message_id}")
|
||||
public ResponseEntity<Object> messageEdit(@Valid @RequestBody DiscussionMessageRequest messageRequest,
|
||||
@PathVariable long message_id,
|
||||
@@ -140,6 +151,7 @@ public class ForumController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(messageUpdated, DiscussionMessageDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@DeleteMapping("/message/delete/{message_id}")
|
||||
public ResponseEntity<Object> messageDelete(@PathVariable long message_id, Principal principal) {
|
||||
DiscussionMessage message = forumService.getDiscussionMessageById(message_id);
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import site.easystartup.web.notification.domian.Notification;
|
||||
@@ -18,6 +19,7 @@ public class NotificationController {
|
||||
private final SimpMessagingTemplate messagingTemplate;
|
||||
Logger logger = Logger.getGlobal();
|
||||
|
||||
//@
|
||||
@GetMapping("/notify")
|
||||
public void notification(Principal principal, @Payload Notification notification) {
|
||||
logger.info("Web socket sent notification to " + principal.getName());
|
||||
|
||||
+3
-4
@@ -3,10 +3,7 @@ package site.easystartup.web.notification.controller;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import site.easystartup.web.notification.domian.Notification;
|
||||
import site.easystartup.web.notification.repo.NotificationRepo;
|
||||
import site.easystartup.web.notification.service.NotificationService;
|
||||
@@ -19,11 +16,13 @@ import java.util.List;
|
||||
public class NotificationRestController {
|
||||
private final NotificationService notificationService;
|
||||
|
||||
//@
|
||||
@GetMapping("/notifications/{username}")
|
||||
public ResponseEntity<List<Notification>> notification(@PathVariable String username, Principal principal) {
|
||||
return ResponseEntity.ok().body(notificationService.getNotificationByRecipient(username, principal));
|
||||
}
|
||||
|
||||
//@
|
||||
@DeleteMapping("/notifications/{id}/delete")
|
||||
public void delete(@PathVariable long id,
|
||||
Principal principal) {
|
||||
|
||||
@@ -33,6 +33,7 @@ public class PostController {
|
||||
private final ModelMapper modelMapper;
|
||||
private final ResponseErrorValidation responseErrorValidation;
|
||||
|
||||
//@
|
||||
@GetMapping("/")
|
||||
public ResponseEntity<List<PostDto>> main(Principal principal) {
|
||||
var posts = postService.getAllPostsByAuthor(principal.getName())
|
||||
@@ -40,6 +41,7 @@ public class PostController {
|
||||
return ResponseEntity.ok().body(posts);
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/new")
|
||||
public ResponseEntity<Object> createPost(@Valid @RequestBody PostRequest postRequest, BindingResult bindingResult,
|
||||
Principal principal) {
|
||||
@@ -50,6 +52,7 @@ public class PostController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(post, PostDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/user/{username}")
|
||||
public ResponseEntity<List<PostDto>> user(@PathVariable String username) {
|
||||
var posts = postService.getAllPostsByAuthor(username)
|
||||
@@ -57,6 +60,7 @@ public class PostController {
|
||||
return ResponseEntity.ok().body(posts);
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/edit/{post_id}")
|
||||
public ResponseEntity<Object> edit(@Valid @RequestBody PostRequest postRequest, BindingResult bindingResult,
|
||||
Principal principal, @PathVariable long post_id) {
|
||||
@@ -67,6 +71,7 @@ public class PostController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(post, PostDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@DeleteMapping("/delete/{post_id}/")
|
||||
public void delete(@PathVariable long post_id,
|
||||
Principal principal) {
|
||||
@@ -76,6 +81,7 @@ public class PostController {
|
||||
else postService.delete(post);
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/like/{post_id}/")
|
||||
public ResponseEntity<Object> like(Principal principal, @PathVariable long post_id) {
|
||||
Post post = postService.getPostById(post_id);
|
||||
@@ -84,6 +90,7 @@ public class PostController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(edited, PostRequest.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/dislike/{post_id}/")
|
||||
public ResponseEntity<Object> dislike(Principal principal, @PathVariable long post_id) {
|
||||
Post post = postService.getPostById(post_id);
|
||||
|
||||
@@ -34,6 +34,7 @@ public class ProjectController {
|
||||
|
||||
private final ParticipantService participantService;
|
||||
|
||||
//@
|
||||
@PostMapping
|
||||
@Operation(summary = "Создание проекта")
|
||||
public ResponseEntity<Object> createProject(@Valid @RequestBody ProjectRequest projectRequest,
|
||||
@@ -46,6 +47,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(project, ProjectDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/{projectId}")
|
||||
@Operation(summary = "Изменение проекта")
|
||||
public ResponseEntity<Object> editProject(@Valid @RequestBody ProjectRequest projectRequest,
|
||||
@@ -59,6 +61,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(projectUpdated, ProjectDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PutMapping("/{projectId}/{partId}/part")
|
||||
@Operation(summary = "Изменение позиции в проекте: Дизайнер/Ui designer")
|
||||
public ResponseEntity<Object> editPart(@Valid @RequestBody ParticipantDto participantDto,
|
||||
@@ -74,6 +77,7 @@ public class ProjectController {
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@DeleteMapping("/{projectId}")
|
||||
@Operation(summary = "Удаление проекта")
|
||||
public ResponseEntity<Object> deleteProject(@PathVariable("projectId") Long projectId,
|
||||
@@ -82,13 +86,14 @@ public class ProjectController {
|
||||
return ResponseEntity.ok(new MessageResponse("Project was deleted!"));
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{projectId}")
|
||||
@Operation(summary = "получение проекта по id")
|
||||
public ResponseEntity<ProjectDto> getProject(@PathVariable("projectId") Long projectId) {
|
||||
return ResponseEntity.ok().body(modelMapper.map(projectService.getProjectById(projectId), ProjectDto.class));
|
||||
}
|
||||
|
||||
//
|
||||
//@
|
||||
@GetMapping("/{userId}/all")
|
||||
@Operation(summary = "Получение всех проектов для пользователя")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsForUser(@PathVariable("userId") Long userId) {
|
||||
@@ -97,6 +102,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{technology}/tech")
|
||||
@Operation(summary = "Получение всех проектов с опредлененной технологией")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsWithTechnology(@PathVariable("technology") String technology) {
|
||||
@@ -113,7 +119,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
|
||||
//@
|
||||
@GetMapping("/{nameOfPosition}/positions")
|
||||
@Operation(summary = "Получение всех проектов с указанной позицией : Дизайнер")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsWithPosition(@PathVariable("nameOfPosition") String nameOfPosition) {
|
||||
@@ -122,6 +128,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/{commercialStatus}/commercial_status")
|
||||
@Operation(summary = "получение всех проектов по коммерческому статусу")
|
||||
public ResponseEntity<List<ProjectDto>> getAllProjectsWithCommercialStatus(@PathVariable("commercialStatus") int commercialStatus) {
|
||||
@@ -130,6 +137,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(projects);
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/requests")
|
||||
@Operation(summary = "получение всех поданных заявок на проект")
|
||||
public ResponseEntity<List<ParticipantDto>> getAllRequestsForProject(@RequestBody Long projectId) {
|
||||
@@ -138,6 +146,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(requests);
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/apply")
|
||||
@Operation(summary = "подать заявку на участие в проекте")
|
||||
public ResponseEntity<ProjectDto> applyOnProject(@RequestBody ParticipantRequest participantRequest,
|
||||
@@ -147,6 +156,7 @@ public class ProjectController {
|
||||
return ResponseEntity.ok().body(modelMapper.map(project, ProjectDto.class));
|
||||
}
|
||||
|
||||
//@
|
||||
@PostMapping("/participant")
|
||||
@Operation(summary = "утвердить участница на проект")
|
||||
public ResponseEntity<ProjectDto> confirmParticipant(@RequestBody ParticipantRequest participantRequest,
|
||||
|
||||
@@ -25,6 +25,7 @@ public class FileUploadController {
|
||||
this.storageService = storageService;
|
||||
}
|
||||
|
||||
//@
|
||||
@GetMapping("/upload")
|
||||
public String listUploadedFiles(Model model) {
|
||||
if(storageService.loadAll() == null) {
|
||||
@@ -43,6 +44,7 @@ public class FileUploadController {
|
||||
@SneakyThrows
|
||||
@GetMapping("/files/{filename:.+}")
|
||||
@ResponseBody
|
||||
//@
|
||||
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
|
||||
Resource file = storageService.load(filename);
|
||||
return ResponseEntity.ok()
|
||||
@@ -50,6 +52,7 @@ public class FileUploadController {
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
//@
|
||||
public String handleFileUpload(@RequestParam("file") MultipartFile file,
|
||||
Model model) {
|
||||
storageService.save(file);
|
||||
|
||||
@@ -11,7 +11,7 @@ import site.easystartup.web.service.UserService;
|
||||
public class FastChecksUtil {
|
||||
private final UserService userService;
|
||||
|
||||
public<T> ResponseEntity<T> nullIfValid(Long user) {
|
||||
public<T> ResponseEntity<T> nullIfValid(String user) {
|
||||
if(!userService.userExists(user)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user