Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
portal-backend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HBP Medical Informatics Platform
portal-backend
Commits
ee34bcd2
Commit
ee34bcd2
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
refactoring articleApi to use SpringData
parent
244480d1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/hbp/mip/controllers/ArticlesApi.java
+17
-19
17 additions, 19 deletions
src/main/java/org/hbp/mip/controllers/ArticlesApi.java
src/main/java/org/hbp/mip/repositories/ArticleRepository.java
+3
-0
3 additions, 0 deletions
...main/java/org/hbp/mip/repositories/ArticleRepository.java
with
20 additions
and
19 deletions
src/main/java/org/hbp/mip/controllers/ArticlesApi.java
+
17
−
19
View file @
ee34bcd2
...
...
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import
javax.validation.Valid
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.Iterator
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
...
...
@@ -45,34 +46,31 @@ public class ArticlesApi {
@ApiParam
(
value
=
"Only ask articles from own team"
)
@RequestParam
(
value
=
"team"
,
required
=
false
)
Boolean
team
)
{
/*User user = mipApplication.getUser();
User
user
=
mipApplication
.
getUser
();
Iterable
<
Article
>
articles
;
String queryString = "SELECT a FROM Article a, User u WHERE a.createdBy=u.username";
if(status != null)
{
queryString += " AND status= :status";
}
if
(
own
!=
null
&&
own
)
{
queryString += " AND u.username= :username"
;
articles
=
articleRepository
.
findByCreatedBy
(
user
)
;
}
else
{
queryString += " AND (status='published' or u.username= :username)"
;
articles
=
articleRepository
.
findByStatusOrCreatedBy
(
"published"
,
user
)
;
}
List articles = new LinkedList<>();
Query query = session.createQuery(queryString);
if (status != null) {
query.setString("status", status);
if
(
status
!=
null
)
{
for
(
Iterator
<
Article
>
i
=
articles
.
iterator
();
i
.
hasNext
();)
{
Article
a
=
i
.
next
();
if
(!
status
.
equals
(
a
.
getStatus
()))
{
i
.
remove
();
}
}
}
query.setString("username", user.getUsername());
articles = query.list();
session.getTransaction().commit();
return ResponseEntity.ok(articles);*/
return
ResponseEntity
.
ok
(
article
Repository
.
findAll
()
);
return
ResponseEntity
.
ok
(
article
s
);
}
...
...
@@ -108,7 +106,7 @@ public class ArticlesApi {
}
}
while
(
count
>
0
);
String
slug
=
null
;
String
slug
;
try
{
slug
=
new
Slugify
().
slugify
(
article
.
getTitle
());
}
catch
(
IOException
e
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/hbp/mip/repositories/ArticleRepository.java
+
3
−
0
View file @
ee34bcd2
package
org.hbp.mip.repositories
;
import
org.hbp.mip.model.Article
;
import
org.hbp.mip.model.User
;
import
org.springframework.data.repository.CrudRepository
;
/**
...
...
@@ -9,4 +10,6 @@ import org.springframework.data.repository.CrudRepository;
public
interface
ArticleRepository
extends
CrudRepository
<
Article
,
String
>
{
Long
countByTitle
(
String
title
);
Iterable
<
Article
>
findByCreatedBy
(
User
user
);
Iterable
<
Article
>
findByStatusOrCreatedBy
(
String
status
,
User
user
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment