Skip to content

Commit

Permalink
feature: Integration with OCI Object Storage - refactor after review
Browse files Browse the repository at this point in the history
task:  8697bjvqr
  • Loading branch information
KinTrae committed Jan 9, 2025
1 parent 2c6711c commit 526ed1c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ResponseEntity<Page<PostDto>> getPostsForUser(@PathVariable("login") Stri
}

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<PostDto> createPost(@RequestPart("content") String content, @RequestPart(value = "pictures", required = false) List<MultipartFile> pictures, @AuthenticationPrincipal UserDetails userDetails) {
public ResponseEntity<PostDto> createPost(@RequestPart(value = "content", required = false) String content, @RequestPart(value = "pictures", required = false) List<MultipartFile> pictures, @AuthenticationPrincipal UserDetails userDetails) {
PostDto postDto = postService.createPost(userDetails.getUsername(), content, pictures);
return ResponseEntity.ok(postDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public Page<PostDto> getPostsForUser(String login, String requestedBy, int pageN
@Override
@Transactional
public PostDto createPost(String login, String content, List<MultipartFile> pictures) {
if((content == null || content.isEmpty()) && (pictures == null || pictures.isEmpty())) {
throw new NullPointerException(AlertConstants.POST_CONTENT_OR_PICTURE_REQUIRED);
}

User postOwner = userPostServiceFacade.findUserByLogin(login);
Post post = new Post();
post.setContentHtml(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class AlertConstants {
public static final String NOT_UNIQUE_OBJECT_TITLE = "Not unique object";
public static final String ILLEGAL_ARGUMENT_TITLE = "Illegal argument";

public static final String VALUE_REQUIRED_TITLE = "Value required";

//message
public static final String USER_WITH_LOGIN_NOT_FOUND = "User with login '%s' not found";

Expand All @@ -25,4 +27,6 @@ public class AlertConstants {
public static final String BAD_CREDENTIALS = "Bad credentials";
public static final String NOT_UNIQUE_OBJECT = "%s:'%s' is not unique";
public static final String ILLEGAL_ARGUMENT = "%s cannot be equal %s";

public static final String POST_CONTENT_OR_PICTURE_REQUIRED = "Post content or picture is required";
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public ResponseEntity<AlertDto> handleIllegalArgumentException(IllegalArgumentEx
return new ResponseEntity<>(AlertUtils.illegalArgumentException(ex.getMessage()), HttpStatus.NOT_ACCEPTABLE);
}

@ExceptionHandler(NullPointerException.class)
public ResponseEntity<AlertDto> handleIllegalStateException(NullPointerException ex) {
return new ResponseEntity<>(AlertUtils.valueRequired(ex.getMessage()), HttpStatus.NOT_ACCEPTABLE);
}
}
10 changes: 10 additions & 0 deletions backend/src/main/java/meowhub/backend/shared/utils/AlertUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ public static AlertDto illegalArgumentException(String msg) {

return alertDto;
}

public static AlertDto valueRequired(String msg){
AlertDto alertDto = new AlertDto();
alertDto.setTitle(AlertConstants.VALUE_REQUIRED_TITLE);
alertDto.setMessage(msg);
alertDto.setLevel(AlertLevel.ERROR);
alertDto.setTimestamp(LocalDateTime.now());

return alertDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UserRepositoryIntegrationTest {
private UserRepository userRepository;

@Test
void testFindUserByLogin(){
void testFindUserByLogin() {
Optional<User> result = userRepository.findByLogin("admin");
assertTrue(result.isPresent());
assertEquals("admin", result.get().getLogin());
Expand All @@ -39,6 +39,5 @@ void testFindBasicUserInfoByLogin() {
assertNotNull(result.get().getId());
assertNotNull(result.get().getName());
assertNotNull(result.get().getSurname());
// assertNotNull(result.get().getProfilePicture());
}
}
2 changes: 1 addition & 1 deletion database/scripts/120_create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CREATE TABLE mh_posts.Posts
(
id varchar2(36) DEFAULT sys_guid() NOT NULL,
user_id varchar2(36) NOT NULL,
content_Html clob NOT NULL,
content_Html clob NULL,
created_at date NOT NULL,
created_by varchar2(36) NOT NULL,
modified_at date NULL,
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/Features/CreatePost/CreatePost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ export const CreatePost = () => {
return;
}

api.post('/api/posts', null, {
params: {content: contentToSave},
headers: {
'Content-Type': 'multipart/form-data'
}
}).then((response) => {
api.post('/api/posts', null, {params: {content: contentToSave}}).then((response) => {
if (response.status === 200) {
close();
}
Expand Down

0 comments on commit 526ed1c

Please sign in to comment.