Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 SWE-BARMJZ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public class Folder {
private Date CreatedDate;
private Date modifiedDate;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@ManyToOne(
optional = false,
cascade = CascadeType.ALL
)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(
name = "user_id",
referencedColumnName = "id"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.barmjz.productivityapp.Note;


import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -27,13 +26,13 @@ public ResponseEntity<Note> createNote(@RequestParam("folderId") Long folderId,
}

@PutMapping("/modify")
public ResponseEntity<String> modifyNote(@RequestParam("noteId") Long noteId, @RequestBody ObjectNode objectNode) {
public ResponseEntity<Note> modifyNote(@RequestParam("folderId") Long folderId, @RequestBody String modifiedNote) {
try {
String title = objectNode.get("title").asText();
String content = objectNode.get("content").asText();
return ResponseEntity.status(HttpStatus.OK).body(noteManager.modifyNote(noteId, title, content));
System.out.println(modifiedNote);
// return ResponseEntity.status(HttpStatus.OK).body(noteManager.modifyNote(modifiedNote, folderId));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
} catch (Exception exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Fuck");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ public Note createNote(Long folderId, String noteTitle){
return newNote;
}

public String modifyNote(Long noteId, String title, String content){
if(noteId == null || !noteRepo.existsById(noteId))
public Note modifyNote(Note modifiedNote, Long folderId){
if(modifiedNote == null || modifiedNote.getId() == null)
throw new NullPointerException("note is null");
if(!noteRepo.existsById(modifiedNote.getId()))
throw new NoSuchElementException("note not found");
Note existedNote = noteRepo.getReferenceById(noteId);
if( (noteRepo.existsByTitleAndFolder_Id(title,existedNote.getFolder().getId())) &&
(!noteRepo.findByTitleAndFolder_Id(title,existedNote.getFolder().getId()).getId().equals(existedNote.getId())))
throw new IllegalStateException("note new title already exist");
existedNote.setTitle(title);
existedNote.setContent(content);
// if(!noteRepo.findByTitleAndFolder_Id(modifiedNote.getTitle(),folderId)
// .getId().equals(modifiedNote.getId()))
// throw new IllegalStateException("note title already exist");
Note existedNote = noteRepo.getReferenceById(modifiedNote.getId());
// need more efficient way
existedNote.setTitle(modifiedNote.getTitle());
existedNote.setContent(modifiedNote.getContent());
existedNote.setModifiedDate(new Date());
existedNote.setStarred(modifiedNote.isStarred());
existedNote.setColor(modifiedNote.getColor());
existedNote.setFontSize(modifiedNote.getFontSize());
noteRepo.save(existedNote);
return "note modified";
return existedNote;
}

public List<Note> getFolderNotes(Long folderId){
Expand All @@ -74,8 +80,8 @@ public List<Note> getUserStarredNotes(Long userId){
public Note moveNote(Long newFolderId, Long noteId){
if(noteId == null || newFolderId == null || !folderRepo.existsFolderById(newFolderId) || !noteRepo.existsById(noteId))
throw new NoSuchElementException("not found");
Note note = noteRepo.findById(noteId).get();
note.setFolder(folderRepo.findById(newFolderId).get());
Note note = noteRepo.getReferenceById(noteId);
note.setFolder(folderRepo.getReferenceById(newFolderId));
noteRepo.save(note);
return note;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public TaskService(UserRepo userRepo, CategoryRepo categoryRepo, OneTimeTaskRepo
this.repeatedTaskRepo = repeatedTaskRepo;
}

@Autowired



public Task getTask(Long taskId){
if (oneTimeTaskRepo.existsById(taskId))
return oneTimeTaskRepo.findById(taskId).orElse(null);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
spring.datasource.url=jdbc:mysql://localhost:3306/prod_schema
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.password=1000*1000
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.formate_sql=true
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect
rsa.private-key=classpath:certs/private.pem
rsa.public-key=classpath:certs/public.pem
rsa.public-key=classpath:certs/public.pem
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void getExistedUserFolders(){

@Test
void getNonExistedUserFolders(){
userRepo.save(user1);
folderRepo.save(folder1);
folderRepo.save(folder2);
assertThatThrownBy(() -> folderManager.getUserFolders(user1.getId()+3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.barmjz.productivityapp.Folder.Folder;
import com.barmjz.productivityapp.Folder.FolderRepo;
import com.barmjz.productivityapp.user.User;
import com.barmjz.productivityapp.user.UserRepo;
import lombok.Data;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -20,11 +19,9 @@

@DataJpaTest
class CreateNoteTest {
@Autowired UserRepo userRepo;
@Autowired FolderRepo folderRepo;
@Autowired NoteRepo noteRepo;
NoteManager noteManager;
User user;
Folder folder;
Note note1;
Note note2;
Expand All @@ -36,16 +33,14 @@ void setUp() {
folderRepo.deleteAll();
noteRepo.deleteAll();
date = new Date();
user = User.builder()
.email("user1@gmail.com")
.password("pass")
.firstName("userFirst")
.lastName("userLast")
.build();
userRepo.save(user);
folder = Folder.builder()
.name("folder")
.user(user)
.user(User.builder()
.email("user1@gmail.com")
.password("pass")
.firstName("userFirst")
.lastName("userLast")
.build())
.CreatedDate(date)
.modifiedDate(date)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void getStarredNotes(){
note2 = noteManager.createNote(folder2.getId(),"note2");
note2.setContent("content2");
noteManager.alterStar(note2.getId());
noteManager.modifyNote(note2.getId(), note2.getTitle(), note2.getContent());
noteManager.modifyNote(note2, note2.getFolder().getId());
assertThat(note2.isStarred()).isTrue();
assertThat(noteRepo.findById(note2.getId()).get().getContent()).isEqualTo("content2");
List<Note> starredNotes = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.barmjz.productivityapp.Folder.Folder;
import com.barmjz.productivityapp.Folder.FolderRepo;
import com.barmjz.productivityapp.user.User;
import com.barmjz.productivityapp.user.UserRepo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,8 +18,8 @@
@DataJpaTest
class ModifyNoteTest {

@Autowired UserRepo userRepo;
@Autowired FolderRepo folderRepo;
@Autowired
FolderRepo folderRepo;
@Autowired NoteRepo noteRepo;
NoteManager noteManager;
Folder folder;
Expand All @@ -34,16 +33,14 @@ void setUp() {
folderRepo.deleteAll();
noteRepo.deleteAll();
date = new Date();
User user = User.builder()
.email("user1@gmail.com")
.password("pass")
.firstName("userFirst")
.lastName("userLast")
.build();
userRepo.save(user);
folder = Folder.builder()
.name("folder")
.user(user)
.user(User.builder()
.email("user1@gmail.com")
.password("pass")
.firstName("userFirst")
.lastName("userLast")
.build())
.CreatedDate(date)
.modifiedDate(date)
.build();
Expand All @@ -61,16 +58,19 @@ void modifyNote(){
.folder(folder)
.createdDate(date)
.modifiedDate(date)
.fontSize(8)
.build();
noteManager.modifyNote(note2.getId(), note2.getTitle(), note2.getContent());
noteManager.modifyNote(note2, folder.getId());
assertThat(noteRepo.findById(note1.getId()).get().getContent()).isEqualTo("note 1 content");
assertThat(noteRepo.findById(note1.getId()).get().getFontSize()).isEqualTo(8);
// assertThat(noteRepo.findById(note1.getId()).get()).isEqualTo(note2);
}

@Test
void invalidModifiedNote(){
assertThatThrownBy(() -> noteManager.modifyNote(null, "new title", "new content"))
.isInstanceOf(NoSuchElementException.class)
.hasMessageContaining("note not found");
assertThatThrownBy(() -> noteManager.modifyNote(null, folder.getId()))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("note is null");
}

@Test
Expand All @@ -85,8 +85,9 @@ void modifyNonExistedNote(){
.folder(folder)
.createdDate(date)
.modifiedDate(date)
.fontSize(8)
.build();
assertThatThrownBy(() -> noteManager.modifyNote(note2.getId(),note2.getTitle(), note2.getContent()))
assertThatThrownBy(() -> noteManager.modifyNote(note2,folder.getId()))
.isInstanceOf(NoSuchElementException.class)
.hasMessageContaining("note not found");
}
Expand Down
35 changes: 30 additions & 5 deletions frontend/App.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
import 'react-native-gesture-handler';
import * as React from "react";

import { StatusBar } from "expo-status-bar";
import { Home } from "./components/Home";
import { Login } from "./components/Login";
import { PasswordRecovery } from "./components/PasswordRecovery";
import { SignUp } from "./components/SignUp";
import TodoScreen from "./components/TodoScreen";
import MindMapScreen from "./components/MindMapScreen";
import { Notes } from "./components/notes-component/Notes-Main";
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { NativeBaseProvider } from "native-base";
import { AuthContextProvider } from "./store/auth-context";
import { theme } from "./UI/theme";
import AppNavigation from "./AppNavigation";


const Stack = createNativeStackNavigator();


export default function App() {
return (
<NativeBaseProvider theme={theme}>
<AuthContextProvider>
<StatusBar style="dark" />
<AppNavigation />
<NavigationContainer>

<StatusBar style="dark" />
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="MindMap" component={MindMapScreen} />
<Stack.Screen name="Todo" component={TodoScreen} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Sign Up" component={SignUp} />
<Stack.Screen
name="Password Recovery"
component={PasswordRecovery}
/>
{/* <Stack.Screen name="Home" component={Home} /> */}
<Stack.Screen name="Notes" component={Notes} />
</Stack.Navigator>
</NavigationContainer>
</AuthContextProvider>
</NativeBaseProvider>
);
Expand Down
71 changes: 0 additions & 71 deletions frontend/AppNavigation.js

This file was deleted.

Loading