Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f669ef0b
authored
Jun 03, 2015
by
Liv Haapala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
korjauksia v2 restiapiin userin lisäykseen
1 parent
f4550fa2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
code/moya-web/src/main/java/fi/codecrew/moya/rest/v2/UserRestViewV2.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/v2/pojo/UserPojo.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/v2/UserRestViewV2.java
View file @
f669ef0
...
...
@@ -106,10 +106,12 @@ public class UserRestViewV2 {
eventUser
.
setGender
(
Gender
.
UNDEFINED
);
}
eventUser
.
setPhone
(
userPojo
.
phoneNumber
);
eventUser
.
setEmail
(
userPojo
.
email
);
eventUser
.
setAddress
(
userPojo
.
streetAddress
);
eventUser
.
setZip
(
userPojo
.
zipCode
);
eventUser
.
setTown
(
userPojo
.
postOffice
);
userBean
.
createNewUser
(
eventUser
,
null
);
userBean
.
createNewUser
(
eventUser
,
userPojo
.
password
);
return
Response
.
ok
(
pojoFactory
.
createUserPojo
(
eventUser
)).
build
();
}
catch
(
Exception
e
)
{
...
...
@@ -132,14 +134,18 @@ public class UserRestViewV2 {
public
Response
updateUserImage
(
@Context
HttpServletRequest
request
,
@PathParam
(
"userid"
)
@ApiParam
(
"User ID"
)
Integer
userId
,
@FormDataParam
(
"image"
)
FormDataContentDisposition
imageInfo
,
@FormDataParam
(
"image"
)
InputStream
imageStream
)
{
@FormDataParam
(
"image"
)
InputStream
imageStream
,
@FormDataParam
(
"image"
)
FormDataBodyPart
body
)
{
logger
.
info
(
"Starting to upload new user image for user {}"
,
userId
);
try
{
if
(
permissionBean
.
hasPermission
(
UserPermission
.
MODIFY
)
==
false
||
permissionBean
.
hasPermission
(
UserPermission
.
VIEW_ALL
)
==
false
)
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
).
build
();
}
EventUser
eventUser
=
userBean
.
findByUserId
(
userId
,
true
);
userBean
.
uploadImage
(
eventUser
,
imageInfo
.
getType
(),
imageStream
,
imageInfo
.
getFileName
(),
null
);
logger
.
info
(
"Mimetype: "
+
body
.
getMediaType
());
userBean
.
uploadImage
(
eventUser
,
body
.
getMediaType
().
getType
(),
imageStream
,
imageInfo
.
getFileName
(),
null
);
logger
.
info
(
"Image uploaded"
);
return
Response
.
ok
(
pojoFactory
.
createUserPojo
(
eventUser
)).
build
();
...
...
@@ -157,12 +163,15 @@ public class UserRestViewV2 {
@GET
@Path
(
"/{userid}/image"
)
@ApiOperation
(
value
=
"Download user image"
)
@Consumes
(
MediaType
.
MULTIPART_FORM_DATA
)
@Produces
({
MediaType
.
APPLICATION_JSON
,
"image/png"
,
"image/jpeg"
})
//@Consumes()
//@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
//@Produces({MediaType.APPLICATION_JSON, "image/png", "image/jpeg"})
//@Produces({MediaType.MULTIPART_FORM_DATA, "image/png", "image/jpeg"})
public
Response
downloadUserImage
(
@PathParam
(
"userid"
)
@ApiParam
(
"User ID"
)
Integer
userId
)
{
try
{
User
user
=
userBean
.
getUser
(
userId
);
UserImage
image
=
user
.
getCurrentImage
();
//logger.info("Mimetype: " + body.getMediaType());
return
Response
.
ok
(
image
.
getImageData
(),
image
.
getMimeType
()).
build
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"Getting image failed"
,
e
);
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/v2/pojo/UserPojo.java
View file @
f669ef0
...
...
@@ -21,11 +21,13 @@ public class UserPojo {
public
Integer
userId
=
0
;
public
String
firstname
=
""
;
public
String
lastname
=
""
;
public
String
password
=
""
;
// foo..
public
Date
birthday
;
public
UserGender
gender
;
public
String
phoneNumber
;
public
String
email
;
// address info
public
String
streetAddress
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment