2626 * #L%
2727 */
2828
29- import de .OneManProjects .Database ;
3029import de .OneManProjects .data .Group ;
3130import de .OneManProjects .data .Project ;
3231import de .OneManProjects .data .Tracked ;
3332import de .OneManProjects .data .User ;
3433import de .OneManProjects .data .dto .*;
34+ import de .OneManProjects .database .Projects ;
35+ import de .OneManProjects .database .Users ;
3536import de .OneManProjects .export .Exporter ;
3637import de .OneManProjects .mail .Mail ;
3738import de .OneManProjects .security .Auth ;
@@ -71,10 +72,10 @@ public static void getGroupDetails(final Context ctx) throws SQLException {
7172 if (Auth .isUserGroup (ctx )) {
7273 final int userId = Auth .getUserFromContext (ctx );
7374 final int groupId = ctx .bodyAsClass (Integer .class );
74- final Optional <de .OneManProjects .data .Group > group = Database .getGroup (groupId , userId );
75+ final Optional <de .OneManProjects .data .Group > group = de . OneManProjects . database . Groups .getGroup (groupId , userId );
7576 if (group .isPresent ()) {
76- final List <User > users = Database .getUsersInGroup (groupId );
77- final List <Project > projects = Database .getProjectsFromGroup (groupId , true );
77+ final List <User > users = de . OneManProjects . database . Groups .getUsersInGroup (groupId );
78+ final List <Project > projects = Projects .getProjectsFromGroup (groupId , true );
7879 Responses .setResponseOrError (ctx , new GroupDetails (group .get (), users , projects ));
7980 } else {
8081 ctx .status (HttpStatus .FORBIDDEN );
@@ -113,7 +114,7 @@ public static void exportData(final Context ctx) throws SQLException {
113114 final ExportFilter filter = ctx .bodyAsClass (ExportFilter .class );
114115 if (filter .groupId ().isPresent ()) {
115116 final int userId = Auth .getUserFromContext (ctx );
116- final Optional <Group > group = Database .getGroup (filter .groupId ().get (), userId );
117+ final Optional <Group > group = de . OneManProjects . database . Groups .getGroup (filter .groupId ().get (), userId );
117118 if (group .isPresent ()) {
118119 final byte [] data = Exporter .exportGroupData (filter , group .get ().getId ());
119120 final String fileName = getExportFilename (filter .filter (), group .get ().getTitle ());
@@ -148,11 +149,11 @@ public static void getGroupDataToAnalyse(final Context ctx) throws SQLException
148149 final int userId = Auth .getUserFromContext (ctx );
149150 final DataFilter filter = ctx .bodyAsClass (DataFilter .class );
150151 if (filter .groupId ().isPresent ()) {
151- final Optional <de .OneManProjects .data .Group > group = Database .getGroup (filter .groupId ().get (), userId );
152+ final Optional <de .OneManProjects .data .Group > group = de . OneManProjects . database . Groups .getGroup (filter .groupId ().get (), userId );
152153 if (group .isPresent () && group .get ().getOwner () == userId ) {
153- final List <Project > groupProjects = Database .getGroupProjects (filter .groupId ().get (), true );
154+ final List <Project > groupProjects = Projects .getGroupProjects (filter .groupId ().get (), true );
154155 final List <Integer > groupProjectIds = groupProjects .stream ().map (Project ::getId ).toList ();
155- final List <Tracked > tracked = Database .getGroupTrackedForRange (groupProjectIds , Instant .parse (filter .start ()), Instant .parse (filter .end ()));
156+ final List <Tracked > tracked = Projects .getGroupTrackedForRange (groupProjectIds , Instant .parse (filter .start ()), Instant .parse (filter .end ()));
156157 Responses .setResponseOrError (ctx , new AnalysisData (new ArrayList <>(), groupProjects , tracked ));
157158 }
158159
@@ -181,7 +182,7 @@ public static void groupUserCreateGroup(final Context ctx) throws SQLException {
181182 if (Auth .isUserGroup (ctx )) {
182183 final int userID = Auth .getUserFromContext (ctx );
183184 final de .OneManProjects .data .Group newGroup = ctx .bodyAsClass (de .OneManProjects .data .Group .class );
184- final boolean res = Database .addNewGroup (newGroup , userID );
185+ final boolean res = de . OneManProjects . database . Groups .addNewGroup (newGroup , userID );
185186 Responses .setResponseOrError (ctx , res );
186187 } else {
187188 ctx .status (HttpStatus .FORBIDDEN );
@@ -207,15 +208,15 @@ public static void groupDelete(final Context ctx) throws SQLException {
207208 if (Auth .isUserGroup (ctx )) {
208209 final int userID = Auth .getUserFromContext (ctx );
209210 final int groupId = ctx .bodyAsClass (Integer .class );
210- final boolean res = Database .deleteGroup (groupId , userID );
211+ final boolean res = de . OneManProjects . database . Groups .deleteGroup (groupId , userID );
211212 Responses .setResponseOrError (ctx , res );
212213 } else {
213214 ctx .status (HttpStatus .FORBIDDEN );
214215 }
215216 }
216217
217218 private static boolean canUserManageGroup (final int userID , final int groupId ) throws SQLException {
218- final Optional <de .OneManProjects .data .Group > group = Database .getGroup (groupId , userID );
219+ final Optional <de .OneManProjects .data .Group > group = de . OneManProjects . database . Groups .getGroup (groupId , userID );
219220 return group .isPresent ();
220221 }
221222
@@ -238,12 +239,12 @@ public static void groupUserInvite(final Context ctx) throws SQLException, Messa
238239 if (Auth .isUserGroup (ctx )) {
239240 final int userID = Auth .getUserFromContext (ctx );
240241 final GroupToUser groupToUser = ctx .bodyAsClass (GroupToUser .class );
241- final Optional <de .OneManProjects .data .Group > group = Database .getGroup (groupToUser .groupId (), userID );
242+ final Optional <de .OneManProjects .data .Group > group = de . OneManProjects . database . Groups .getGroup (groupToUser .groupId (), userID );
242243 if (group .isPresent ()) {
243- final Optional <Integer > id = Database .getUserID (groupToUser .mail ());
244+ final Optional <Integer > id = Users .getUserID (groupToUser .mail ());
244245 if (id .isPresent ()) {
245- final boolean res = Database .addUserToGroup (groupToUser .groupId (), id .get ());
246- final Optional <String > userMail = Database .getUserMail (id .get ());
246+ final boolean res = de . OneManProjects . database . Groups .addUserToGroup (groupToUser .groupId (), id .get ());
247+ final Optional <String > userMail = Users .getUserMail (id .get ());
247248 if (res && userMail .isPresent ()) {
248249 Mail .sendGroupInvite (userMail .get (), group .get ().getTitle ());
249250 Responses .setResponseOrError (ctx , "Invite sent" );
@@ -281,9 +282,9 @@ public static void groupUserRemove(final Context ctx) throws SQLException {
281282 final GroupToUser groupToUser = ctx .bodyAsClass (GroupToUser .class );
282283 boolean res = false ;
283284 if (canUserManageGroup (userID , groupToUser .groupId ())) {
284- final Optional <Integer > id = Database .getUserID (groupToUser .mail ());
285+ final Optional <Integer > id = Users .getUserID (groupToUser .mail ());
285286 if (id .isPresent ()) {
286- res = Database .removeUserFromGroup (groupToUser .groupId (), id .get ());
287+ res = de . OneManProjects . database . Groups .removeUserFromGroup (groupToUser .groupId (), id .get ());
287288 }
288289 }
289290 Responses .setResponseOrError (ctx , res );
@@ -313,7 +314,7 @@ public static void groupAddProject(final Context ctx) throws SQLException {
313314 final Project project = ctx .bodyAsClass (Project .class );
314315 boolean res = false ;
315316 if (canUserManageGroup (userID , project .getRef ())) {
316- res = Database .addGroupProject (project );
317+ res = Projects .addGroupProject (project );
317318 }
318319 Responses .setResponseOrError (ctx , res );
319320 } else {
@@ -342,7 +343,7 @@ public static void groupUpdate(final Context ctx) throws SQLException {
342343 final de .OneManProjects .data .Group group = ctx .bodyAsClass (de .OneManProjects .data .Group .class );
343344 boolean res = false ;
344345 if (canUserManageGroup (userID , group .getId ())) {
345- res = Database .updateGroup (group , userID );
346+ res = de . OneManProjects . database . Groups .updateGroup (group , userID );
346347 }
347348 Responses .setResponseOrError (ctx , res );
348349 } else {
@@ -371,7 +372,7 @@ public static void groupDeleteProject(final Context ctx) throws SQLException {
371372 final IdTupel tuple = ctx .bodyAsClass (IdTupel .class );
372373 boolean res = false ;
373374 if (canUserManageGroup (userID , tuple .id1 ())) {
374- res = Database .deleteProject (tuple .id2 (), tuple .id1 ());
375+ res = Projects .deleteProject (tuple .id2 (), tuple .id1 ());
375376 }
376377 Responses .setResponseOrError (ctx , res );
377378 } else {
@@ -392,7 +393,7 @@ public static void groupDeleteProject(final Context ctx) throws SQLException {
392393 public static void getManagedGroups (final Context ctx ) throws SQLException {
393394 if (Auth .isUserGroup (ctx )) {
394395 final int userId = Auth .getUserFromContext (ctx );
395- final List <de .OneManProjects .data .Group > groups = Database .getManagedGroups (userId );
396+ final List <de .OneManProjects .data .Group > groups = de . OneManProjects . database . Groups .getManagedGroups (userId );
396397 Responses .setResponseOrError (ctx , groups );
397398 } else {
398399 ctx .status (HttpStatus .FORBIDDEN );
@@ -416,7 +417,7 @@ public static void getManagedGroups(final Context ctx) throws SQLException {
416417 public static void userLeaveGroup (final Context ctx ) throws SQLException {
417418 final int groupId = ctx .bodyAsClass (Integer .class );
418419 final int userId = Auth .getUserFromContext (ctx );
419- final boolean res = Database .leaveGroup (userId , groupId );
420+ final boolean res = de . OneManProjects . database . Groups .leaveGroup (userId , groupId );
420421 Responses .setResponseOrError (ctx , res );
421422 }
422423}
0 commit comments