Skip to content

Commit

Permalink
#19 Added request to DB and autoFill result in drop downlist
Browse files Browse the repository at this point in the history
  • Loading branch information
olgapolinkina committed Aug 23, 2018
1 parent 89d9b75 commit 30ba74f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/main/java/lv/ctco/javaschool/goal/boundary/GoalApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lv.ctco.javaschool.auth.control.UserStore;
import lv.ctco.javaschool.auth.entity.domain.User;
import lv.ctco.javaschool.goal.control.GoalStore;

import lv.ctco.javaschool.goal.entity.TagDto;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
Expand All @@ -13,6 +13,9 @@
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Path("/goal")
@Stateless
Expand All @@ -31,4 +34,32 @@ public class GoalApi {
public void startPage() {
// User currentUser = userStore.getCurrentUser();
}

@GET
@RolesAllowed({"ADMIN", "USER"})
@Path("/taglist")
public List<TagDto> drawRecordTable() {
List<TagDto> dto = new ArrayList<>();
int tagCount=new Random().nextInt(5)+3;
for(int i=0; i<tagCount; i++) {
dto.add(new TagDto(generateRandomWord()));
}
return dto;
// return goalStore.getTagList();
// List<TagDto> dto = goalStore.getTagList();
// return new Gson().toJson(dto);
}

private static String generateRandomWord() {
String randomStrings = new String("");
Random random = new Random();
char[] word = new char[random.nextInt(8) + 3]; // words of length 3 through 10. (1 and 2 letter words are boring.)
for (int j = 0; j < word.length; j++) {
word[j] = (char) ('a' + random.nextInt(26));
}
randomStrings = new String(word);
return randomStrings;
}


}

0 comments on commit 30ba74f

Please sign in to comment.