This commit is contained in:
Artur Kmieckowiak 2020-02-25 10:23:13 +01:00
parent c3c4b1202f
commit d8c8f70ebd
10 changed files with 17 additions and 37 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
### Spring initialzr
HELP.md
.DS_Store
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm

View File

@ -75,7 +75,7 @@ public class BookController {
@RequestParam("file") MultipartFile imageFile,
@RequestParam("author") String author,
@RequestParam("title") String title) throws Exception {
bookService.handleImageUpload(imageFile, author, title);
bookService.handleImageUpload(imageFile, author, title, getUserName());
return ResponseEntity.ok().build();
}

View File

@ -1,26 +0,0 @@
package pl.edu.amu.wmi.bookapi.api;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class SecurityInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return false;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}

View File

@ -1,4 +0,0 @@
package pl.edu.amu.wmi.bookapi.api.dto;
public class PatchBookRequest {
}

View File

@ -24,7 +24,7 @@ public class MessageCustomRepositoryImpl implements MessageCustomRepository {
)
);
Sort sort = Sort.by(Sort.Direction.DESC, "createdAt");
Sort sort = Sort.by(Sort.Direction.ASC, "createdAt");
return mongoTemplate.find(query.with(sort), MessageDocument.class);
}

View File

@ -29,7 +29,7 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
}
public static final String SECRET = "SecretKeyToGenJWTs";
public static final long EXPIRATION_TIME = 864_000_000; // 10 days
public static final long EXPIRATION_TIME = 864_000_000;
public static final String TOKEN_PREFIX = "Bearer ";
public static final String HEADER_STRING = "Authorization";
public static final String SIGN_UP_URL = "/users/sign-up";

View File

@ -48,7 +48,6 @@ public class WebSecurity extends WebSecurityConfigurerAdapter {
}
private JWTAuthenticationFilter getConfiguredJwtAuthenticationFilter() throws Exception{
System.out.println("JWT Auth");
JWTAuthenticationFilter jwtFilter = new JWTAuthenticationFilter(authenticationManager());
jwtFilter.setFilterProcessesUrl("/users/login");

View File

@ -34,9 +34,9 @@ public class BookService {
bookRepository.save(BookDocument.from(userName, bookDto));
}
public void handleImageUpload(MultipartFile imageFile, String author, String title) throws Exception {
public void handleImageUpload(MultipartFile imageFile, String author, String title, String username) throws Exception {
String detectedEan = imageProcessingService.getDecodedEan(imageFile);
saveBook(author, new BookDto(detectedEan, author, title));
saveBook(username, new BookDto(detectedEan, author, title));
if (detectedEan.isEmpty()) {
throw new NoEanCodeDetectedException();
}

View File

@ -10,6 +10,7 @@ import pl.edu.amu.wmi.bookapi.repositories.ThreadRepository;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class MessageService {
@ -28,7 +29,14 @@ public class MessageService {
}
public List<ThreadDocument> getThreads(String user) {
return threadRepository.findByParticipant(user);
List<ThreadDocument> threads = threadRepository.findByParticipant(user);
return threads
.stream()
.map(it -> {
it.getParticipantsIds().remove(user);
return it;
})
.collect(Collectors.toList());
}
public List<MessageDocument> getMessagesInThread(String threadId, String userId) {

View File

@ -1 +1,3 @@
imgproc.debug = true
spring.servlet.multipart.max-file-size=3MB
spring.servlet.multipart.max-request-size=3MB