Skip to content

Commit 76619cb

Browse files
committed
pinnable notes
1 parent b7d3786 commit 76619cb

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/main/java/edu/tamu/app/controller/NoteController.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ public class NoteController {
3030
@Autowired
3131
private NoteRepo noteRepo;
3232

33-
@ApiMapping("/all")
33+
@ApiMapping("/by-service/{pinned}")
3434
@Auth(role = "ROLE_ANONYMOUS")
35-
public ApiResponse getAllNotes() {
36-
return new ApiResponse(SUCCESS, noteRepo.findAll());
37-
}
38-
39-
@ApiMapping("/by-service")
40-
@Auth(role = "ROLE_ANONYMOUS")
41-
public ApiResponse getAllNotesByService(@ApiModel Service service) {
42-
return new ApiResponse(SUCCESS, noteRepo.findAllByService(service));
35+
public ApiResponse getAllNotesByService(@ApiModel Service service, @ApiVariable String pinned) {
36+
if (Boolean.valueOf(pinned)) {
37+
return new ApiResponse(SUCCESS, noteRepo.findAllByServiceAndPinnedTrue(service));
38+
} else {
39+
return new ApiResponse(SUCCESS, noteRepo.findAllByService(service));
40+
}
4341
}
4442

4543
@ApiMapping("/{id}")

src/main/java/edu/tamu/app/model/Note.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class Note extends BaseEntity {
3232
@Column(columnDefinition = "text", nullable = true)
3333
private String body;
3434

35+
@Column(nullable = false)
36+
private boolean pinned;
37+
3538
@Temporal(TemporalType.DATE)
3639
private Calendar scheduledPostingStart;
3740

@@ -49,6 +52,7 @@ public class Note extends BaseEntity {
4952
private AppUser author;
5053

5154
public Note() {
55+
setPinned(false);
5256
setModelValidator(new NoteValidator());
5357
setService(new Service());
5458
}
@@ -102,6 +106,14 @@ public void setBody(String body) {
102106
this.body = body;
103107
}
104108

109+
public boolean isPinned() {
110+
return pinned;
111+
}
112+
113+
public void setPinned(boolean pinned) {
114+
this.pinned = pinned;
115+
}
116+
105117
public Calendar getScheduledPostingStart() {
106118
return scheduledPostingStart;
107119
}

src/main/java/edu/tamu/app/model/repo/NoteRepo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface NoteRepo extends JpaRepository<Note, Long>, NoteRepoCustom, Jpa
2020

2121
public List<Note> findAllByService(Service service);
2222

23+
public List<Note> findAllByServiceAndPinnedTrue(Service service);
24+
2325
public void delete(Note note);
2426

2527
}

0 commit comments

Comments
 (0)