Esempio n. 1
0
 def create(self, data: any):
     try:
         serializer = BrandSerializer(data=data)
         if serializer.is_valid():
             return self.repository.create(serializer)
         raise Exception('data is not valid')
     except Exception as e:
         raise e
Esempio n. 2
0
 def update(self, newdata: any, pk: str):
     try:
         old = self.repository.get_by_pk(pk)
         serializer = BrandSerializer(old, data=newdata)
         if serializer.is_valid(raise_exception=True):
             serializer.save()
             return serializer
     except Exception as e:
         raise e
Esempio n. 3
0
 def create(self, data: any):
     try:
         serializer = BrandSerializer(data=data)
         if serializer.is_valid():
             serializer.save()
             return serializer
         raise None
     except:
         return None
Esempio n. 4
0
 def get_by_pk(self, pk: str):
     try:
         brand = self.repository.get_by_pk(pk)
         serializer = BrandSerializer(brand)
         return serializer
     except Brand.DoesNotExist:
         raise http.Http404
Esempio n. 5
0
 def get_by_name(self, name: str):
     try:
         brands = self.repository.get_by_name(name)
         serializer = BrandSerializer(brands, many=True)
         return serializer
     except Brand.DoesNotExist:
         raise http.Http404
Esempio n. 6
0
 def update(self, newdata: BrandSerializer):
     newdata.save()
     return newdata
Esempio n. 7
0
    def create(self, serializer: BrandSerializer):

        serializer.save()
        return serializer
Esempio n. 8
0
 def get_all(self):
     brands = self.repository.getAll()
     serializer = BrandSerializer(brands, many=True)
     return serializer