Skip to content

Commit

Permalink
Merge pull request #42 from patou/dev
Browse files Browse the repository at this point in the history
Publish V4
  • Loading branch information
manudss authored Dec 20, 2016
2 parents 8c4a3aa + 3682f11 commit 9c50716
Show file tree
Hide file tree
Showing 96 changed files with 18,542 additions and 911 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.desaintsteban.liste.envies.model.Link;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import java.util.Date;
import java.util.List;

/**
Expand All @@ -14,17 +15,22 @@ public class EnvyDto {

private String owner;
private Boolean suggest = false;
private Boolean deleted = false;
private String label;

private String description;

private String price;
private String picture;
private Date date;
private List<Link> urls;
private List<String> userTake;

private List<NoteDto> notes;


private int rating;

public EnvyDto() {
}

Expand Down Expand Up @@ -52,6 +58,14 @@ public void setSuggest(Boolean suggest) {
this.suggest = suggest;
}

public Boolean getDeleted() {
return deleted;
}

public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

public String getLabel() {
return label;
}
Expand All @@ -76,6 +90,14 @@ public void setPicture(String picture) {
this.picture = picture;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public List<Link> getUrls() {
return urls;
}
Expand Down Expand Up @@ -107,4 +129,12 @@ public List<NoteDto> getNotes() {
public void setNotes(List<NoteDto> notes) {
this.notes = notes;
}

public int getRating() {
return rating;
}

public void setRating(int rating) {
this.rating = rating;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.jdo.annotations.Embedded;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand All @@ -30,13 +31,26 @@ public class Envy {
* L'envie à été suggéré par une autre personne
*/
private Boolean suggest = false;
/**
* L'envie est archivé
*/
private Boolean archived = false;
/**
* L'envie a été supprimé, mais elle a été noté comme donné.
*/
private Boolean deleted = false;

private String label;

private String description;

private String price;
private String picture;
private Date date;



private int rating;
@Embedded
private List<Link> urls;
@Index
Expand All @@ -48,24 +62,29 @@ public class Envy {

public Envy() {
this.notes = new ArrayList<>();
this.rating = 0;
}

public Envy(ListEnvies list, String label) {
this.list = Key.create(list);
this.label = label;
this.notes = new ArrayList<>();
this.rating = 0;
}


public Envy(EnvyDto envie) {
setId(envie.getId());
setOwner(envie.getOwner());
setSuggest(envie.getSuggest());
setDeleted(envie.getDeleted());
setLabel(envie.getLabel());
setDescription(envie.getDescription());
setPrice(envie.getPrice());
setPicture(envie.getPicture());
setDate(envie.getDate());
setUrls(envie.getUrls());
setRating(envie.getRating());
if (envie.getUserTake() != null) {
List<String> userTake = new ArrayList<>();
for (String email : envie.getUserTake()) {
Expand All @@ -80,11 +99,14 @@ public EnvyDto toDto() {
EnvyDto envie = new EnvyDto();
envie.setId(getId());
envie.setOwner(getOwner());
envie.setSuggest(suggest);
envie.setSuggest(getSuggest());
envie.setDeleted(getDeleted());
envie.setLabel(getLabel());
envie.setDescription(getDescription());
envie.setPrice(getPrice());
envie.setPicture(getPicture());
envie.setDate(getDate());
envie.setRating(getRating());
envie.setUrls(getUrls());
List<String> userTake = new ArrayList<>();
if (getUserTake() != null) {
Expand Down Expand Up @@ -131,6 +153,22 @@ public Boolean getSuggest() {
return suggest;
}

public Boolean getArchived() {
return archived;
}

public void setArchived(Boolean archived) {
this.archived = archived;
}

public Boolean getDeleted() {
return deleted;
}

public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

public void setSuggest(Boolean suggest) {
this.suggest = suggest;
}
Expand Down Expand Up @@ -167,6 +205,14 @@ public void setPicture(String picture) {
this.picture = picture;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public List<Link> getUrls() {
return urls;
}
Expand All @@ -175,6 +221,14 @@ public void setUrls(List<Link> urls) {
this.urls = urls;
}

public int getRating() {
return rating;
}

public void setRating(int rating) {
this.rating = rating;
}

public void addUrl(String url) {
if (this.urls == null) {
this.urls = new ArrayList<>();
Expand All @@ -192,6 +246,10 @@ public List<String> getUserTake() {
return userTake;
}

public boolean hasUserTaken() {
return userTake != null && !userTake.isEmpty();
}

public void addUserTake(String userTake) {
if (this.userTake == null) {
this.userTake = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,26 @@ public EnvyDto getEnvie(@PathParam("name") String name, @PathParam("id") Long id
}

@PUT
@Path("/{id}/give")
public void give(@PathParam("name") String name, @PathParam("id") Long id) {
@Path("/give/{id}")
public EnvyDto give(@PathParam("name") String name, @PathParam("id") Long id) {
final AppUser user = ServletUtils.getUserAuthenticated();
if (user != null){
LOGGER.info("Get " + id);
EnviesService.given(user, name, id);
LOGGER.info("Give " + id);
return EnviesService.given(user, name, id);
}
return null;
}


@PUT
@Path("/{id}/cancel")
public void cancel(@PathParam("name") String name, @PathParam("id") Long id) {
@DELETE
@Path("/give/{id}")
public EnvyDto cancel(@PathParam("name") String name, @PathParam("id") Long id) {
final AppUser user = ServletUtils.getUserAuthenticated();
if (user != null){
LOGGER.info("Get " + id);
EnviesService.cancel(user, name, id);
LOGGER.info("Cancel " + id);
return EnviesService.cancel(user, name, id);
}
return null;
}

@GET
Expand All @@ -76,32 +78,37 @@ public List<EnvyDto> getEnvie(@PathParam("name") String name) {
}

@POST
public void addEnvie(@PathParam("name") String name, EnvyDto envie) {
public EnvyDto addEnvie(@PathParam("name") String name, EnvyDto envie) {
final AppUser user = ServletUtils.getUserAuthenticated();
if (user != null) {
LOGGER.info("Put " + envie.getLabel());
EnviesService.createOrUpdate(user, name, new Envy(envie));
return EnviesService.createOrUpdate(user, name, new Envy(envie));
}
return null;
}

@POST
@Path("/{id}/addNote")
public void addNote(@PathParam("name") String name, @PathParam("id") Long envieId, NoteDto note) {
public EnvyDto addNote(@PathParam("name") String name, @PathParam("id") Long envieId, NoteDto note) {
final AppUser user = ServletUtils.getUserAuthenticated();
if (user != null) {
LOGGER.info("add note from " + user.getName());
EnviesService.addNote(user, envieId, name, note);
LOGGER.info("add note from " + user.getName()+"envie id : "+envieId+" Note : "+note.getText());
EnvyDto envyDto = EnviesService.addNote(user, envieId, name, note);
LOGGER.info("Updated envie with notes " + envyDto.getLabel());
return envyDto;
}
return null;
}

@POST
@Path("/{id}")
public void updateEnvie(@PathParam("name") String name, EnvyDto envie) {
public EnvyDto updateEnvie(@PathParam("name") String name, EnvyDto envie) {
final AppUser user = ServletUtils.getUserAuthenticated();
if (user != null) {
LOGGER.info("Put " + envie.getLabel());
EnviesService.createOrUpdate(user, name, new Envy(envie));
return EnviesService.createOrUpdate(user, name, new Envy(envie));
}
return envie;
}

@DELETE
Expand All @@ -113,4 +120,14 @@ public void deleteEnvie(@PathParam("name") String name, @PathParam("id") Long id
EnviesService.delete(user, name, id);
}
}

@PUT
@Path("/archive/{id}")
public void archiveEnvie(@PathParam("name") String name, @PathParam("id") Long id){
final AppUser user = ServletUtils.getUserAuthenticated();
if(user != null){
LOGGER.info("Archive " + id);
EnviesService.archive(user, name, id);
}
}
}
Loading

0 comments on commit 9c50716

Please sign in to comment.